__tcfapi function - getTCData command

In this article we will cover the IAB __tcfapi() function with the getTCData command. Your organization can use this command to retrieve end-user consent data for IAB purposes, vendors, legitimate interest, publisher restrictions and more. The IAB has more information about the getTCData API command.


the getTCData command

The getTCData command can be called with the following example:

getTCData command

__tcfapi('getTCData', 2, function(tcdata, success) { console.log(tcdata); });

Example implementation

Your organization can call the getTCData command through the browser console or Javascript code on a webpage. The command returns the end-user's consent as a data object.

With browser console Javascript code

Once your organization's website has loaded enter this command directly into the browser tools console window and press enter:

__tcfapi('getTCData', 2, (tcdata, success) => {
   console.log("show tcdata: ", tcdata)
});

API response

The response is an end-user's consent data object with the following information:

Parameter Description
success true if the getTCData API call has been successful
addtlConsent Google Additional Consent allows Google and the IAB Framework to pass end-user consent to Google Ad Technology Providers despite not adhering to the IAB TCF v2 Framework
cmpId CMP id assigned by the IAB
cmpStatus An CMP status that can be stub, loading, loaded, error
cmpVersion The version of the CMP API that is currently supported, e.g. "2.0"
eventStatus The event status which can be: useractioncomplete, tcloaded, cmpuishown
gdprApplies true if GDPR applies to this implementation
isServiceSpecific
  • true - if using a service-specific or publisher-specific TC String
  • false - if using a global TC String
listenerId
  • If the consent data is sent to the addEventListener callback, listenerId is the unique ID assigned by the CMP to the listener function registered via addEventListener
  • Otherwise listenerId is set to undefined
publisherCC Country code of the country that determines the policy.
purposeOneTreatment

Only exists on service-specific TC.

  • true - Purpose 1 not disclosed at all. CMPs use PublisherCC to indicate the publisher's country of establishment to help determine whether the vendor requires Purpose 1 consent.
  • false - There is no special Purpose 1 treatment status. Purpose 1 was disclosed normally (consent) as expected by TCF Policy.
tcString base64 url-encoded consent string
tcfPolicyVersion Number of the supported TCF version
useNonStandardStacks true if the CMP is using publisher-customized stack descriptions
publisher object A list of publisher consent purposes or legitimate interest purposes the end-user has agreed to or rejected. Click here for more information.
purpose object A list of consent purposes or legitimate interest purposes the end-user has agreed to or rejected. Click here for more information.
vendor object A list of vendors with consent or legitimate interest purposes the end-user has agreed to or rejected. Click here for more information.
addtlConsent: "1~"
cmpId: 6
cmpStatus: "loaded"
cmpVersion: 1
eventStatus: "tcloaded"
gdprApplies: true
isServiceSpecific: true
listenerId: 0
publisher Object {
   consents Object { 1: true, 2: true, 3: true, 4: true, 5: true, 6: true	},
   legitimateInterests Object { 1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true, 9: true, 10: true },
   restrictions Object {
      2:   { 755:1 },
      5:   { 755:1 },
      6:   { 755:1 },
      7:   { 755:1 },
      9:   { 109:1, 755:1 },
      10:  { 755:1 } 
   } 
}
publisherCC: "DE"
purpose Object {
   consents Object { 1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true, 9: true, 10: true },
   legitimateInterests Object { 1: false, 2: false, 3: false, 4: false, 5: false, 6: false, 7: true, 8: true, 9: true, 10: true } 
}
purposeOneTreatment: false
specialFeatureOptins: Object { 1: true, 2: true }
tcString: "CPUW9Z2PUW9Z2AGABCENCCCsAP_AAAPAAAYgF5wAwA2gHTAXmANsAEANoAwyACAvMVABAXmSgBABtAXmUgAgLzCQAQF5joAIC8wA.f4AAAHgAAAAA"
tcfPolicyVersion: 2
useNonStandardStacks: false
vendor Object {
   consents Object { 1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true, 9: true, 10: true },
   legitimateInterests Object { 1: false, 2: false, 3: false, 4: false, 5: false, 6: false, 7: true, 8: true, 9: true, 10: true } 
}

publisher object

Parameter Description
consents object This object is a list of key:value pairs where:
  • key is the IAB purpose id
  • value is true if the end-user has consented to this purpose
legitimateInterests object This object is a list of key:value pairs where:
  • key is the IAB purpose id
  • value is true if the end-user has consented to this legitimate interest purpose
restrictions object

This object is a list of key:sub-objects where each sub-object describes if an end-user accepts a vendor with the following legal basis: consent, legitimate interest or not allowed. The key is the IAB purpose id.

Each sub-object is a list of key:value pair where the key is the IAB vendor id and the value is an id between 0 and 2:

  • 0 - CONSENT
  • 1 - LEGITIMATE INTEREST
  • 2 - NOT ALLOWED
publisher Object {
   consents Object { 1: true, 2: true, 3: true, 4: true, 5: true, 6: true },
   legitimateInterests Object { 1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true, 9: true, 10: true },
   restrictions Object {
      2:   { 755:1 },
      5:   { 755:1 },
      6:   { 755:1 },
      7:   { 755:1 },
      9:   { 109:1, 755:1 },
      10:  { 755:1 } 
   } 
}

purpose object

Parameter Description
consents object This object is a list of key:value pairs where:
  • key is the IAB purpose id
  • value is true if the end-user has consented to this purpose
legitimateInterests object This object is a list of key:value pairs where:
  • key is the IAB purpose id
  • value is true if the end-user has consented to this legitimate interest purpose
purpose Object {
   consents Object { 1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true, 9: true, 10: true },
   legitimateInterests Object { 1: false, 2: false, 3: false, 4: false, 5: false, 6: false, 7: true, 8: true, 9: true, 10: true } 
}

vendor object

Parameter Description
consents object This object is a list of key:value pairs where:
  • key is the IAB purpose id
  • value is true if the end-user has consented to this purpose
legitimateInterests object This object is a list of key:value pairs where:
  • key is the IAB purpose id
  • value is true if the end-user has consented to this legitimate interest purpose
vendor Object {
   consents Object { 1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true, 9: true, 10: true },
   legitimateInterests Object { 1: false, 2: false, 3: false, 4: false, 5: false, 6: false, 7: true, 8: true, 9: true, 10: true } 
}
Was this article helpful?
0 out of 0 found this helpful