Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Functionality

This function is used to retrieve the users consent. It is part of the IAB Europe Transparency and Consent Framework (TCF) Specifications.

Syntax

function __tcfapi()

argument name

type

optional

value

description

command

string

'getTCData'

version

integer

null|2

The TCF API version to use. Can be null instead.

callback

function

function(tcData:TCData, success:boolean)

The callback function that is called with the function call result.

parameter

int array

✔️

vendorIds

Array holding the specific vendor ids from which we want to know consent.

Description

In order to retrieve user consent, the IAB specification provides two different functions: addEventListener and getTCData. Although both can retrieve user consent, addEventListener is recommended, given it can "follow" the user interaction, making sure that it will eventually return the consent data once the user has finished interacting with the CMP GUI. On the other hand, getTCData function just returns the current consent status. This means that it may return uninitialized, incomplete or full consent data, depending on the timing it is called. This means that the responsibility to obtain the definite data for the consent falls over the publisher lap. With addEventListener every consent status change triggers a new call to the given callback, which means that the only thing needed to process the consent data is a simple check for whether or not that consent data is final, thus usable down the line.

Scope

The function can be called at any time, but the response will change depending when it is called.

Examples

Basic usage

When getTCData is called, it will immediately respond with a result, no matter if the user consented already or not. The callback will be only called once.

__tcfapi('getTCData', 2, function(tcData, success) {
  if(success && (tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete')) {
    if(Object.keys(tcData.vendor.consents).length == 0 && Object.keys(tcData.purpose.consents).length == 0) {
      // User clicked "Customize choices" and then "Save preferences"
      console.log("User rejected consent", tcData);
    } else {
      // User either clicked "Accept All" (most likely) and gave full consent or configured individual consent (unlikely). If required, check vendor and purpose individual user choices.
      console.log("User gave full or partial consent", tcData);
    }
  } else {
    console.log("User consent not available yet", tcData);
  }
});

  • No labels