Many users have reported difficulties with setting up the CMP so that Google receives consent in time and in return serves their ads based on the consent signal received. The following article explains how the CMP needs to be setup along with the recommendation we received from Google.
Who is responsible for checking consent?
That really depends on whether consent is needed on the client side or not. If you use Google Tag Manager, Google AdSense or another component you may need to check for consent yourself before you call the function to request ads, otherwise your request for the ad might timeout and no ad is served.
How to do this?
For example, AdSense is not checking for consent on the client side itself, rather it requires the publisher to check for consent and initiate the AdSense tag once consent is given. Google will issue error 2.1a if they don't see a consent string in the ad call.
Error | Description | Suggested action to take |
---|---|---|
2.1a | Tag or SDK isn’t receiving a TC string due to CMP status being stub, loading, or error. |
If you're manually invoking the function to request ads, make sure the response to getTCData or addEventListener returns TCData.eventStatus = 'tcloaded' OR TCData.eventStatus = 'useractioncomplete'. These indicate the CMP has obtained the user choice regarding consent. |
Choice supports the TCF APIs as specified by the IAB API specification and does return the correct TCData.eventStatus. If you get reports from Google about the 2.1a error, you can workaround this by making sure the CMP is fully loaded before you invoke the function to request the ad as illustrated below.
Sample code:
// This sample code illustrate how to implement a addEventListener callback
// function and triggers a Google publisher tag refresh when consent is
// either available or obtained. NOTE: Please review and update this code for
// your own needs.
// Register the addEventListener at the beginning of your page load
// after the CMP JS as been loaded
__tcfapi('addEventListener', 2, function(tcData, success) {
if (success) {
if (tcData.gdprApplies) {
if (tcData.eventStatus === 'tcloaded') {
// We have consent, get the tcData string and do the ad request.
// The example here is for Google publisher tag. You may need to modify
// this code for usage in your web page.
googletag.cmd.push(function(){
googletag.pubads().refresh();
});
// print a debug message to the console
console.log('Debug: tcloaded');
} else if (tcData.eventStatus === 'useractioncomplete') {
// The user gave consent through the UI, get the tcdata string and
// do the ad request. The example here is for Google publisher tag.
// You may need to modify this code for usage in your web page.
googletag.cmd.push(function() {
googletag.pubads().refresh();
});
// print a debug message to the console
console.log('Debug: useractioncomplete');
} else {
// print a debug message to the console
console.log('Debug: tcData.eventStatus: ', tcData.eventStatus);
}
} else { /* gdpr does not apply */
// Most likely you want to make the ad request in this case
googletag.cmd.push(function() {
googletag.pubads().refresh();
});
// print a debug message to the console
console.log('Debug: gdpr doesn\'t apply');
}
}
})
Using Google Tag Manager
To check for user consent within Google Tag Manager (GTM), and block a vendor like Google Advertise Products until consent has been established you can follow the example documented in our GTM tag blocking guide.
Basically, you implement a custom event trigger for Google Advertise products. It will use our trigger events __cmpLoaded and __cmpConsents. If the CMP is loaded and consent is available, the __cmpConsents will return the consent string. The check in the custom trigger for the vendor Google Ad Products will then unblock the vendor tag when consent is given.
We have made a sample GTM container available that implements this trigger for Choice and working with Google advertise products. (Note: this is ZIP file that needs be unzipped before you can import it into GTM.)