IAB TCF V2.0 Consent
Description of how to interact with IAB consent API
If you are using IAB TCF option (see this page 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.

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.
1
__tcfapi('addEventListener', 2, function(tcData, success) {
2
if(success &&
3
(tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete')) {
4
5
// do something with tcData.tcString
6
7
} else {
8
9
// do something else
10
11
}
12
});
Copied!
Sometimes you do not want to be notified of consent updates. You can achieve this by using the more advanced code below:
1
__tcfapi('addEventListener', 2, function(tcData, success) {
2
if(success &&
3
(tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete')) {
4
5
// do something with tcData.tcString
6
7
// remove ourselves to not get called more than once
8
__tcfapi('removeEventListener', 2, tcData.listenerId);
9
10
} else {
11
12
// do something else
13
14
}
15
});
Copied!
You can use this copy-paste a Consent-String on this page: https://iabtcf.com/#/decode.
This an optional extension to IAB TCF. Once setup in TrustCommander Options, an additional addtlConsent property will be available on the tcData object.
1
__tcfapi('addEventListener', 2, function(tcData, success) {
2
if(success &&
3
(tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete')) {
4
5
// do something with tcData.addtlConsent
6
7
} else {
8
9
// do something else
10
11
}
12
});
Copied!
Last modified 8mo ago