Changes to the IAB CMP Framework JS API

Important: If CMP settings are used that are not compliant with the IAB TCF, the system will automatically disable some commands. The standard IAB TCF commands (e.g. getVendorConsents) will then only be available via prefixed command name (e.g. noncompliant_getVendorConsents instead of getVendorConsents). More information on TCF compliance can be found here.

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



__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", …)  __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", …)
__cmp("setUserID", x,  …)
__cmp("setUserID2", x,  …)
__cmp("setUserID3", x,  …)

setUserID sets the external ID (ID 2, ID 3) 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).

__cmp("showScreen", …)

__cmp("showCCPAScreen", …)

__cmp("showGDPRScreen", …)

__cmp("showScreenAdvanced", …),

__cmp("showCCPAScreenAdvanced", …)
__cmp("showGDPRScreenAdvanced", …)

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.


  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! 

(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