Read TC string using TCF v2 API
The Consent Management Platform (CMP) API provides your organization and third-party vendors access to user consent preferences managed by the CMP.

The __tcfapi function

The __tcfapi allows your organization, advertisers and third party vendors to read the consent data. Below are different ways to call the function. In this article, we will primarily focus on the response received in the browser console.
Browser console command
Javascript code
Input the following command into your browser console to receive a response.
__tcfapi('getTCData', 2, function(tcdata,success){console.log("GET TCDATA:", tcdata);});
Use the following example in your javascript code to action upon tcData. Click here for more information.
__tcfapi('getTCData', 2, function(tcdata,success) {
// your custom callback code can be included here
console.log("retrieving TCDATA:", tcdata)
The console window will return the response from the TCFv2 API command as shown below. The categories for publisher, purpose, tcString and vendor provide full consent information granted by the user.
Console window
Expand the API response. In the table below, we have provide descriptions for some key categories in the response:
Category description
If your organization acts in a data processing capacity. If a user has given you consent or accepts your legitimate interest to process data for IAB or custom purposes. Also if your organization has restrictions on certain vendors to process data for a purpose.
which purpose the user grants vendors consent or accepts legitimate interest for data processing.
an encoded string containing all the information from the __tcfapi response.
The value can be copied and decoded using a service provided by the IAB here.
which vendor has consent or approved legitimate interest to process user data.
Each category has sub-categories for consent (consents), legitimate interests (legitimateInterests) and restrictions (restrictions, for publishers only).
Last modified 4mo ago
Export as PDF
Copy link