Read TC string using TCFv2 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. It can be called in Javascript code (see here) but this article describes how it can used in a browser console window.

Example

Open the Sourcepoint website to display a consent message and open the console in the browser developer tools. Click the provided button to give full consent and in the console type this command:

__tcfapi('getTCData', 2, function(tcdata,success){console.log("GET 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.

Expand the API response. In the table below, we have provide descriptions for some key categories in the response:

Category

Description

publisher

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.

purpose

which purpose the user grants vendors consent or accepts legitimate interest for data processing.

tcString

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.

vendor

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).