Info
Content

Changes to the IAB CMP Framework JS API

In order to allow more flexibility, we added some extensions to our implementation of the IAB CMP Framework JS API. These are:

Command

Description

__cmp( … , … , …, async)

The global __cmp function is extended by a fourth parameter. If present and set to false, the callback function will fire immediately and will not be queued.

__cmp("addEventListener", …) and __cmp("removeEventListener", …)

See section CMP Events.

__cmp("consentStatus", …)

Returns a consent status object: {'consentExists': true/false, 'consentData': '…'}

__cmp("getVendorConsents", …)

Equal to IAB getVendorConsents but also returns “customPurposeConsents”, “customVendorConsents” and “googleVendorConsents” properties

__cmp("getUserID", …) and
__cmp("setUserID", x,  …) and
__cmp("setUserID2", x,  …) and
__cmp("setUserID3", x,  …) and

setUserID, setUserID2 and setUserID3 sets the external IDs for which the user is known. getUserID and setUserID both return a user-ID object: {'external': ..., 'external2': ..., 'external3': ..., 'internal': ...}.
Note: The internal user ID is only available if enabled in CMP settings and after “settings” event is fired (see CMP events below).

__cmp("showScreen", …) and

__cmp("showAdvancedScreen", …)

Opens the consent layer on welcome page / on custom choices page

__cmp("setConsent", …)

Sets the consent information to accept (by passing parameter value 1) or reject (by passing parameter value 0)

__cmp("setAgeCallback", …)

Sets a callback function for age verification. More details see section on Working with Age-Verification.


Example:

<script>
  var vendorid = 3; //vendor number 3
  var purposeid = 1; //allow cookies
  var x = __cmp("consentStatus", null, null, false);
  if(typeof(x) == 'object' && "consentExists" in x && x.consentExists)
  { 
    //consent data is present, check if consent for vendor is given 
    var y = __cmp("getVendorConsents", new Array(vendorid), null, false); 
    if(typeof(y) == 'object' && "gdprApplies" in y && (!y.gdprApplies || (y.vendorConsents[vendorid] && y.purposeConsents[purposeid]))) 
    {  
      //everything is fine! 
    }
  }
</script> 

(Please make sure to remove incorrect line breaks when coping the text above)

The example above shows a sample code on how you can check if the consent string is present and if consent is given for a certain vendor & purpose in a synchronous way.

Back to top