Cookie consent JavaScript API

 
This section is for JavaScript developers comfortable with defining callback functions to dynamically load third-party scripts.  If you have JavaScript embed code, and need to implement it in a compliant way, please reach out to help@compendiummedia.com.


Consent given callback functions


Your site exposes several global callback functions off the window object that can be used to dynamically load third party scripts once cookie consent is given.  These include the following:

window.onAcceptConsentPerformanceGlobalCb
Called when the visitor provides for performance cookies.

window.onAcceptConsentMarketingGlobalCb
Called when the visitor provides for marketing cookies.
 

Consent rejected callback functions


After a visitor to your site provides consent, they also have the option of clicking a Manage Cookies link at the bottom of the site, and then retracting their consent. When consent is retracted (rejected) the following callback functions will be called:

window.onRejectConsentPerformanceGlobalCb
Called when the visitor retracts consent for performance cookies.

window.onRejectConsentMarketingGlobalCb
Called when the visitor retracts consent for marketing cookies.

These functions would be used to remove cookies and teardown methods used by that particular category of cookie script.  
 

Using the API functions


API functions can be defined in the admin section > Site settings > Template > Advanced > Site preferences > Javascript > Cookie management.  

For example, the onAcceptConsentMarketingGlobalCb function could be used to load a MailChimp "subscribe" pop-up script like so:
 
window.onRejectConsentMarketingGlobalCb = function() {
   !function(c,h,i,m,p){m=c.createElement(h),p=c.getElementsByTagName(h)[0];
   m.async=1;
   m.src=i;
   p.parentNode.insertBefore(m,p)}(document,"script","https://chimpstatic.com/mcjs-connected/js/users/XXXXXXXXXXXXX.js");
}


When consent is not required


You can set your cookie consent preference (in the admin section > Site settings > Template > Advanced > Site preferences > Display a cookie warning) to When required, Never, or Always.

If set to Never, the "on accept" callback functions (listed above) will be executed on page load.

If set to When required, and the system determines consent is not required based on the visitor's location, the "on accept" callback functions (listed above) will be executed on page load.