Clickio CMP Simplified API

consentQueue tasks registry

To prevent race condition errors, when calling the consent api methods (which are not available while the consent is loading), you can use the consent commands queue, which will be executed automatically when the consent logic fires up. The queue may be consistently used even after the logic loading, there is no need to add any additional checks. The example below shows how to properly initialize the global variable and the queue array.

window.__lxG__ = window.__lxG__ || {};
window.__lxG__.consentQueue = window.__lxG__.consentQueue || [];

window.__lxG__.consentQueue.push(function() {
    // Clickio consent API calls
});
getConsentType method 
This method is used to determine the type of consent framework that is currently active for the user. It returns a string indicating which consent regulation or mode is being used.
Possible return values:
  • tcf - TCF (Transparency and Consent Framework) mode is active
  • nontcf - Non-TCF mode is active (GDPR without TCF)
  • usnat - US National (GPP) mode is active
  • nonusnat - Non-US National mode is active (may be used for US states, that are not required an Opt-out by law)
let consentType = window.__lxG__.getConsentType();

switch (consentType) {
  case 'tcf':
    // TCF v2.2 framework is active
    console.log('TCF mode active');
    break;
  case 'nontcf':
    // Non-TCF GDPR mode is active
    console.log('Non-TCF mode active');
    break;
  case 'usnat':
    // US National (GPP) regulation is active
    console.log('US National (GPP) mode active');
    break;
  case 'nonusnat':
    // Non-US National regulation is active
    console.log('Non-US National mode active');
    break;
  default:
    // Consent type not yet determined or unknown
    console.log('Consent type not available');
}
getConsentApplicable method 
This method is used to determine whether consent management is applicable for the current user. It returns true if the user is within the scope of consent regulation (e.g., GDPR, US) and consent management is required, or false if the user is outside the scope and consent management is not applicable.
The method takes into account Clickio Consent settings: Regulation, GDPR Consent Scope, US Compliance Scope, as well as the user's geographic location. The returned value reflects whether consent management is required for the current user, based on these configuration options and the user's region.

 

let consentApplicable = window.__lxG__.getConsentApplicable();

if (consentApplicable === true) {
  // user is within consent regulation scope, consent management is required
  // proceed with consent-dependent logic
} else if (consentApplicable === false) {
  // user is outside consent regulation scope, consent management is not applicable
  // you may proceed with all tracking/analytics without consent restrictions
}
onConsentStateUpdate method 
This method allows you to register a callback function that will be called whenever the consent state is updated. This is useful for reacting to consent changes in real-time, such as when a user modifies their consent preferences.

The callback function receives a consentData object containing detailed information about the current consent state. The structure of this object may vary depending on the consent type (TCF, non-TCF, US National, etc.).
window.__lxG__.onConsentStateUpdate(function (consentData) {
  // This callback is called whenever consent state changes
  console.log('Consent state updated:', consentData);
  
  // Access consent information from consentData object
  // The structure depends on consent type (TCF, non-TCF, US etc.)
});
Demonstration
This code demonstrates how all the methods work.
You can paste it directly into a page or into the DevTools console to see the example of the returned data.

window.__lxG__ = window.__lxG__ || {};
window.__lxG__.consentQueue = window.__lxG__.consentQueue || [];
window.__lxG__.consentQueue.push(function() {
    __lxG__.onConsentStateUpdate(function (consentData) {
        console.log("\n= = = = =\n\n");
        console.log('consent applicable: '+(__lxG__.getConsentApplicable()?'true':'false'));
        console.log('consent type: '+__lxG__.getConsentType()); // possible values: usnat, nonusnat, nontcf, tcf
        console.groupCollapsed('consent data:');
        console.log(consentData);
        console.groupEnd();
        console.log("\n= = = = =\n\n");
    });
});