All pages
Powered by GitBook
1 of 1

Loading...

consent.onReady

Method to obtain Commanders Act consent when it becomes available.

Method to obtain consent when it becomes available.The Commanders Act OnSite API stub has to be installed before using any of the OnSite API functions.

cact('consent.onReady', function (result) { ... })

The consent.onReady method allow to subscribe a callback function for when consent is set. The callback function will be called only once, with the updated Consent Object. It is called whenever the consent is set via a consent banner interaction or when a consent cookie is already set.

Like in the command consent.onUpdate, the consentObject argument will be enriched with the property updateEvent, but only with the value 'set'.

Example

Example to wait for consent availability and do something on a specific category

In this example, the code is waiting for the user's interaction with the consent banner. The Analytics category was configured with the consent category id 2 on privacy banner.

At the container level, consent.onReady cannot work with a blocked on category. The blocked on categories are defined in the banner. For this specific usage, we recommend to use the consent.get method

cact('consent.onReady', function (result) { 
    
    var ANALYTICS_ID = 2;
    var analyticsCategory = result.consent.categories[ANALYTICS_ID] || {};
     
    if (analyticsCategory.status === 'on') {
    
        // Consent was provided for the category. 
    
    } else {
        
        // Consent was not provided for the category. 
           
    }
    
});