Info
Content

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:

Command

Description

__cmp(...)

The global __cmp function will always also return the object/result of the command instead of only passing it to the callback function.

__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("getVendorConsents", …)

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

__tcfapi("getTCData", …)

Equal to IAB getTCData but also returns customPurposeConsents, customVendorConsents and googleVendorConsents properties


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