Gtag Integration (Consent Mode)
The following guide shows how to send the update consent signal to gtag through the mapping offered by PubConsent.
This documentation is intended to provide a detailed overview of each setting in Google’s Consent Mode, strictly following the explanations and guidelines as provided by Google. It does not imply that the Consent Mode settings are designed to satisfy or address any particular regulatory requirements.
The complete explanation of how Google's consent mode works is available at the following link: https://support.google.com/google-ads/answer/10000067
Before following this guide, make sure that the PubConsent integration code available in the configurator is present on the page.
Make sure you have followed the steps provided by the Google documentation at the following link: https://developers.google.com/tag-platform/security/guides/consent?consentmode=advanced
There are also optional consent status available for Google Consent Mode integration, functionality_storage, personalization_storage and security_storage. The are available in our callback by checking the values of functionalityConsentGranted, personalizationConsentGranted and securityConsentGranted.
Add the following script to set the default consent status, before the CMP script integration code:
<script>
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied'
});
// Other calls to the gtag method MUST be placed after the call with consent default.
</script>The call shown must be the first call to the gtag method, even before the call: gtag('config', <code>). The gtag('consent', 'default', ...) call must be made in the following callback by using the __pubtch_queue_on_consent before the gtag('consent', 'update', ...) call to be considered a Google Consent Mode BASIC version, otherwise it's the Advanced (to know more read Google Consent Mode.
After configuring the default state of the consent mode, you need to configure the callback that will allow you to execute the update with the values of the consent mode taken from the user's consent.
<script>
var __pubtech_queue_on_consent = __pubtech_queue_on_consent || [];
__pubtech_queue_on_consent.push(
function onConsent(
cmpType,
data
) {
if (cmpType == 'TCF-V2-GDPR') {
var googleConsents = data.integrations.googleConsentMode;
gtag("consent", "update", {
ad_user_data: googleConsents.adUserDataGranted ? "granted" : "denied",
ad_personalization: googleConsents.adPersonalizationGranted
? "granted"
: "denied",
ad_storage: googleConsents.adConsentGranted ? "granted" : "denied",
analytics_storage: googleConsents.analyticsConsentGranted
? "granted"
: "denied",
});
}
if (cmpType == 'GOOGLE-CONSENT-MODE') {
var googleConsents = data.integrations.googleConsentMode;
gtag("consent", "update", {
ad_user_data: googleConsents.adUserDataGranted ? "granted" : "denied",
ad_personalization: googleConsents.adPersonalizationGranted
? "granted"
: "denied",
ad_storage: googleConsents.adConsentGranted ? "granted" : "denied",
analytics_storage: googleConsents.analyticsConsentGranted
? "granted"
: "denied",
});
}
},
);
</script>Consents' Mapping (Google Consent Mode)
To know which user choices correspond to Google's consent types, here's the corresponding mapping we provide:
- ad_storage -> TCF Purpose 1
- ad_user_data -> TCF Purpose 1 e 7
- ad_personalization -> TCF Purpose 3 e 4
- analytics_storage -> Cookie Measurement
- functionality_storage -> Cookie Feature
- personalization_storage -> Cookie User Experience
- security_storage -> Cookie Feature
Prevent tags from loading
You can implement Google Consent Mode in either Basic or Advanced mode. In Basic mode, manually block any tags until the user grants consent (see Manual Script Blocking) to prevent them from loading.