IAB TCF 2.0 SDK Developer Guide
As of September 2021, global scope will no longer be supported per the recent TCF Policy and Technical Specifications. To view the formal notification, please refer to the IAB Europe PDF Notification and IAB Europe PDF Notification Update.
Required API Commands
All CMPs must support four required API commands: getTCData, ping, addEventListener, and removeEventListener.
The TCF API 2.0 function take the general form:
__tcfapi(command, version, callback, parameter)
getTCData
|
Argument Name |
Type |
Optional |
Value |
|---|---|---|---|
|
command |
string |
No |
|
|
verson |
number |
No |
|
|
callback |
function |
No |
|
|
parameter |
int array |
Yes |
|
Example:
__tcfapi('getTCData', 2, (tcData, success) => {
if(success) {
// do something with tcData
} else {
// do something else
}
}, [1,2,3]);
This will return TCData.
ping
|
Argument Name |
Type |
Value |
|---|---|---|
|
command |
string |
|
|
version |
number |
|
|
callback |
function |
|
Example:
__tcfapi('ping', 2, (pingReturn) => {
// do something with pingReturn
});
addEventListener
|
Argument Name |
Type |
Value |
|---|---|---|
|
command |
string |
|
|
version |
number |
|
|
callback |
function |
|
Example:
const callback = (tcData, success) => {
if(success && tcData.eventStatus === 'tcloaded') {
// do something with tcData.tcString
// remove the ourself to not get called more than once
__tcfapi('removeEventListener', 2, (success) => {
if(success) {
// oh good...
}
}, callback);
} else {
// do something else
}
}
__tcfapi('addEventListener', 2, callback);
|
eventStatus |
Description |
|---|---|
|
|
The CMP is loaded and prepared to sent a TC string. |
|
|
The TC string is available and has rendered 'Transparency'. The CMP will create TC string will contain the vendors' Legitimate Interest and the consent signals set to false. |
|
|
The user has confirmed or re-confirmed their consent choices and the CMP will respond with the corresponding TC string. |
removeEventListener
|
Argument Name |
Type |
Value |
|---|---|---|
|
command |
string |
|
|
version |
number |
|
|
callback |
function |
|
|
parameter |
function |
previously registered callback ( |
For example, see addEventListener. The callback will be false if the listener could not be removed. This may happen, for instance, if a listener corresponding to listenerId is not found.
Optional API commands
getInAppTCData
|
Argument Name |
Type |
Value |
|---|---|---|
|
command |
string |
|
|
version |
number |
|
|
callback |
function |
|
Example:
__tcfapi('getInAppTCData', 2, (inAppTCData, success) => {
if(success) {
// do something with inAppTCData
} else {
// do something else
}
});
getVendorList
|
Argument Name |
Type |
Optional |
Value |
|---|---|---|---|
|
command |
string |
No |
|
|
version |
number |
No |
|
|
callback |
function |
No |
|
|
parameter |
int or string |
Yes |
|
Example:
__tcfapi('getVendorList', 2, (gvl, success) => {
if(success) {
// do something with gvl
} else {
// do something else
}
}, 'LATEST');
Returned Objects
TCData
TCData = {
tcString: 'base64url-encoded TC string with segments',
tcfPolicyVersion: 2,
cmpId:1000,
cmpVersion: 1000,
gdprApplies: Boolean | undefined,
eventStatus: String,
cmpStatus: 'string',
listenerId: Number | undefined,
isServiceSpecific: Boolean,
useNonStandardStacks: Boolean,
publisherCC: 'Two-letter ISO 3166-1 alpha-2 code',
purposeOneTreatment: Boolean,
outOfBand: {
allowedVendors: {
'[vendor id]': Boolean
},
discloseVendors: {
'[vendor id]': Boolean
}
},
purpose: {
consents: {
'[purpose id]': Boolean
},
legitimateInterests: {
'[purpose id]': Boolean
}
},
vendor: {
consents: {
'[vendor id]': Boolean
},
legitimateInterests: {
'[vendor id]': Boolean
}
},
specialFeatureOptins: {
'[special feature id]': Boolean
},
publisher: {
consents: {
'[purpose id]': Boolean
},
legitimateInterests: {
'[purpose id]': Boolean
},
customPurpose: {
consents: {
'[purpose id]': Boolean
},
legitimateInterests: {
'[purpose id]': Boolean
},
},
restrictions: {
'[purpose id]': {
'[vendor id]': 1
}
}
}
}
|
Value |
Description |
|---|---|
|
|
|
|
|
See addEventListener command. |
|
|
See Ping Status Codes in following table. |
|
|
|
|
|
|
|
|
|
|
|
Country code of the country that determines the policy. |
|
|
Only exists on service-specific TC.
|
|
|
Only exists on global-scope TC.
|
|
|
|
|
|
|
|
|
|
|
|
|
InAppTCData
InAppTCData = {
tcString: 'base64url-encoded TC string with segments',
tcfPolicyVersion: 2,
cmpId:1000,
cmpVersion: 1000,
gdprApplies: 1,
eventStatus: 'string',
isServiceSpecific: 1,
useNonStandardStacks: 1,
publisherCC: 'Two-letter ISO 3166-1 alpha-2 code',
purposeOneTreatment: 1,
purpose: {
consents: '01010 -- Purpose bitfield'
legitimateInterests: '01010 -- Purpose bitfield'
},
vendor: {
consents: '01010 -- Vendor bitfield',
legitimateInterests: '01010 -- Vendor bitfield'
},
specialFeatureOptins: '01010 -- Special Feature bitfield',
publisher: {
consents: '01010 -- Purpose bitfield',
legitimateInterests: '01010 -- Purpose bitfield',
customPurpose: {
consents: '01010 -- Purpose bitfield',
legitimateInterests: '01010 -- Purpose bitfield'
},
restrictions: {
'[purpose id]': '01201221'
}
}
}
|
Value |
Description |
|---|---|
|
|
|
|
|
See addEventListener. |
|
|
|
|
|
|
|
|
Country code of the country that determines the policy. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PingReturn
PingReturn = {
gdprApplies: Boolean | undefined,
cmpLoaded: Boolean,
cmpStatus: String,
displayStatus: String,
apiVersion: String,
cmpVersion: Number | undefined,
cmpId: Number | undefined,
gvlVersion: Number | undefined,
tcfPolicyVersion: Number | undefined,
};
|
Value |
Description |
|---|---|
|
|
* true - GDPR Applies * false - GDPR Does not apply * undefined - unknown whether GDPR Applies * see the section: "What does the gdprApplies value mean?" |
|
|
* true - CMP main script is loaded * false - still running stub |
|
|
|
|
|
|
|
|
Version of the CMP API that is supported, e.g. "2.0". |
|
|
CMPs own/internal version that is currently running. It is undefined if still the stub |
|
|
IAB assigned CMP ID. It is undefined if the stub is still in place. |
|
|
Version of the GVL currently loaded by the CMP. It is undefined if the stub is still in place. |
|
|
Number of the supported TCF version. It is undefined if the stub is still in place. |