...
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 publisher’s 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.
When addEventListener
is called, it will immediately respond with a result, no matter if the user consented already or not. The callback will be called again for every status change so that it will eventually receive the users' consent.
An event listener registered with addEventListener
can be removed with removeEventListener
Scope
The function can be called at any time, but the response will change depending on when it is called.
Examples
Wait for AdConsent to ask for
...
user's consent
AdConsent will ask the user for consent, if required, and wait until the user finished, then fire the callback.
For regions where no consent is required, AdConsent will immediately continue and fire the callback.
This example is used, when using a 3rd party library that requires the __tcfapi
and the user to finish his choices.
...
Wait for consent and check if Google got consent
Google API's like gpt GPT or adsense Adsense require vendor consent for Google and devices access. This example will wait for the users user’s consent choice and check the requirements.
...