consent.onUpdate

Method to subscribe to Commanders Act consent status updates OnSite via JavaScript.

Method to subscribe to Commanders Act consent updates OnSite via JavaScript.The Commanders Act OnSite API stub has to be installed before using any of the OnSite API functions.

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

The consent.onUpdate method allow to subscribe a callback function for consent updates. The callback function will be called with the updated Consent Object. It is called whenever the consent is changed via a Commanders Act banner interaction or the consent.update method of the OnSite API.

The consentObject argument will also be enriched with an additional property updateEvent to signal how the update happened. It can have following values:

When consent is revoked it fires two events: One changed followed by one revoked.

Examples

In this example the Analytics category was configured with the consent category id 2 in Commanders Act Consent settings.

cact('consent.onUpdate', 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. 
           
    }
    
});

In this example the Analytics category was configured with the consent category id 2 in TrustCommander.

cact('consent.onUpdate', function (result) { 

    var ANALYTICS_ID = 2;
    var analyticsCategory = result.consent.categories[ANALYTICS_ID] || {};

    if (result.updateEvent === "changed" && analyticsCategory.status === 'on') {
    
        // Consent was provided for the category during an update.
    
    } 
    
});

Last updated