arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

IAB TCF V2.0 Consent

Description of how to interact with IAB consent API

If you are using IAB TCF option (see this pagearrow-up-right to setup IAB TCF on your account), you will be able to use IAB TCF's __tcfapi where your privacy banner is deployed.

That function is defined in your container and in your privacy banner so that you can use it before your privacy banner has finished loading. It is sometimes referred by IAB as the TCF API stub.

IAB TCF consent is encoded in a format called the Consent-String.

hashtag
How to use the TCF API

The recommended way of getting the value of TCF's consent-string (tcData.tcString in the example below) is by using the addEventListener command.

Sometimes you do not want to be notified of consent updates. You can achieve this by using the more advanced code below:

  • Reference:

hashtag
How to decode the Consent-String

You can use this copy-paste a Consent-String on this page: .

  • Reference:

hashtag
Google Additional Consent Mode

This an optional extension to IAB TCF. Once setup in TrustCommander Options, an additional addtlConsent property will be available on the tcData object.

  • Reference:

IAB TCF commandsarrow-up-right
https://iabtcf.com/#/decodearrow-up-right
IAB TCF Consent-String formatarrow-up-right
Google Additional Consent Mode Technical Specificationarrow-up-right
__tcfapi('addEventListener', 2, function(tcData, success) {
  if(success &&
    (tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete')) {

    // do something with tcData.tcString

  } else {

    // do something else

  }
});
__tcfapi('addEventListener', 2, function(tcData, success) {
  if(success &&
    (tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete')) {

    // do something with tcData.tcString

    // remove ourselves to not get called more than once
    __tcfapi('removeEventListener', 2, tcData.listenerId);

  } else {

    // do something else

  }
});
__tcfapi('addEventListener', 2, function(tcData, success) {
  if(success &&
    (tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete')) {

    // do something with tcData.addtlConsent

  } else {

    // do something else

  }
});