Step-by-Step Guide to Implementing Google Consent Mode in Tealium iQ
Learn how to implement Google Consent Mode in Tealium iQ with this comprehensive step-by-step guide. Discover setup instructions, JavaScript code examples, UDO variable configurations, and testing tips to ensure compliance and optimize tracking.
Rob English
Lead Implementation Specialist
Tealium iQ, like GTM, has its own tag template to integrate Google Consent Mode settings. While reading through some of their online documentation, I found that there were some areas where more information could’ve been provided on tag configuration and expected output. So I set out to write a post that I hope will help clarify those areas of working with this template.
Firstly, there's no need to make any changes to your existing Google tags within your Tealium profile in order to capture Consent Mode values. We'll only need to apply the Google Consent Mode tag to your profile and some additional Javascript code changes to capture and communicate privacy preferences from their source, onto the destination UDO parameters.
The Tealium Consent Mode tag has been built to support integration with Tealium's consent manager and OneTrust, by following the code snippet examples in here.
I'm not going to be implementing Tealium’s Consent Manager, nor OneTrust, so this example will show how to customize the provided Tealium example for a custom solution. Whether that be another consent manager, or something built by you, this should provide a base to work off of.
I’ll be storing my consent settings in a localStorage entry so that I can very quickly modify and test the Consent Mode tag functionality. Despite this the logic will be very similar regardless of whether consent settings are communicated to your Tealium UDO from another consent manager, or whether you reference these values from a cookie.
// My consent settings will follow the same naming convention as those provided in Tealium's consent mode documentation
var settings = ['display_ads', 'personalization', 'analytics'];
//I'll then set on consentSettings in localStorage as a stringlocalStorage.setItem("consentSettings", JSON.stringify(settings));
Step 1: Creating a JavaScript Extension for Google Consent Mode in Tealium iQ
First we’ll create a new Javascript Code extension.
We’ll then define settings for this extension as follows:
Scope: After Load Rules (default)
Occurrence: Run Always
And then copy/paste the following code into the Configuration section:
// Where we'll be pulling our consent settings from
b.consent_decision = JSON.parse(localStorage.getItem("consentSettings")) || [];
// How we'll define our Consent Mode flags based on consent settings source
b.google_ad_storage_consent = b.consent_decision.indexOf('display_ads') !== -1 ? 'granted' : 'denied';
b.google_ad_user_data_consent = b.consent_decision.indexOf('personalization') !== -1 ? 'granted' : 'denied';
b.google_analytics_storage_consent = b.consent_decision.indexOf('analytics') !== -1 ? 'granted' : 'denied';
b.google_ad_personalization_consent = b.consent_decision.indexOf('personalization') !== -1 && b.consent_decision.indexOf('display_ads') !== -1 ? 'granted' : 'denied';
b.google_ads_data_redaction = b.consent_decision.indexOf('personalization') === -1 || b.consent_decision.indexOf('display_ads') === -1 ? 'true' : 'false';
This code is an exact copy of the code provided by Tealium here. The only change has been where we source the b.consent_decision variable from, which will be my consentSettings localStorage entry if it exists, otherwise an empty array.
Step 2: Defining UDO Variables for Privacy Flags
Using the Javascript code snippet above, we’ll then need to define UDO variables for each consent flag variable:
google_ad_storage_consent
google_ad_user_data_consent
google_analytics_storage_consent
google_ad_personalization_consent
google_ads_data_redaction
google_url_passthrough
These will be key, as we’ll need to communicate these values to our Google Consent tag.
Step 3: Configuring the Google Consent Mode Tag in Tealium iQ
The Google Consent Mode tag is a preconfigured template that is available in the Tealium Tag Marketplace.
Within the template, we can define our default settings based on all of the categories we previously defined variables for in the Javascript code extension.
In my case I’m going to set these default values to ‘denied’.
We also need to define mappings to capture the values set in the UDO for each category, as consent preferences are communicated to the page, otherwise these will always be set to ‘denied’ regardless of what the user consents to onsite.
For my example, these mappings look like this:
The Variables listed on the left, are each of the variables I created in Step 2, mapped to their associated destination within the Consent Mode template.
For my particular tag, I’ve left Rules and Events with the default setting of ‘All Pages and Events’.
As mentioned previously, we don’t need to make any changes to our Google product tags (Analytics, Ads, Floodlight) to communicate these settings to them. The settings defined via the Consent Mode tag will automatically be communicated onto these tags.
I’ll now publish my work, and test.
Step 4: Testing the Google Consent Mode Configuration
Once my work has been published, I can jump over to my test page, and have a look at the Analytics Debugger output for my GA4 tags.
When publishing in Tealium (or any tag manager), always make sure to keep track of your last production ready build, so that you can rollback to it if necessary.
This is the first visit to my site, so I haven’t defined consent mode preferences yet. My localStorage entry is non-existent. Given this we can see that the Default settings have been applied to my GA4 tag, and the Consent Mode status is set to G100 (denied).
Now, as my test page doesn’t have a consent manager on it, I’m going to manually push code to my console to update the consentSettings entry, as follows:
var settings = ['display_ads', 'personalization', 'analytics'];
localStorage.setItem("consentSettings", JSON.stringify(settings));
This will allow tracking on all supported categories within my code.
This should update the consent mode flags and apply them to any events triggered after this update. So now I’ll trigger a new page_view event to confirm this.
Perfect! It's now set to G111 (Granted).
And then, if we alter our localStorage entry to test out variations on which categories were allowed, we should see the Consent Mode flag applied accordingly in those scenarios as well.
Display Ads denied
Analytics denied
While these are quick tests to check functionality, it’s always recommended to run through as many (if not all) of the variations on tracking flags to ensure that Consent mode is behaving as expected in every scenario, AND across various events and pages on your website(s).
Conclusion
Implementing Google Consent Mode via Tealium’s Consent Mode template is straightforward and requires minimal changes to existing tags. However, if you’re not using Tealium’s Consent Manager or OneTrust, customizing a solution to retrieve and communicate consent preferences to the Tealium UDO may take additional effort.
For more information on tag configuration, check Tealium’s Consent Mode documentation or contact us for implementation support. With proper setup, you’ll ensure compliance with privacy regulations and maintain robust tracking capabilities across your web properties.
More Insights
Step-by-Step Guide to Implementing Google Consent Mode in Tealium iQ
Rob English
Lead Implementation Specialist
Jan 29, 2025
Read More
Google Tag Manager Tag Diagnostics: Troubleshooting and Optimization Guide
Ricardo Cristofolini
Senior Implementation Specialist, Data Solutions
Dec 11, 2024
Read More
November 2024 GA4 & GMP Updates
Napkyn
Dec 4, 2024
Read More
More Insights
Sign Up For Our Newsletter
Napkyn Inc.
204-78 George Street, Ottawa, Ontario, K1N 5W1, Canada
Napkyn US
6 East 32nd Street, 9th Floor, New York, NY 10016, USA
212-247-0800 | info@napkyn.com
Step-by-Step Guide to Implementing Google Consent Mode in Tealium iQ
Learn how to implement Google Consent Mode in Tealium iQ with this comprehensive step-by-step guide. Discover setup instructions, JavaScript code examples, UDO variable configurations, and testing tips to ensure compliance and optimize tracking.
Rob English
Lead Implementation Specialist
Tealium iQ, like GTM, has its own tag template to integrate Google Consent Mode settings. While reading through some of their online documentation, I found that there were some areas where more information could’ve been provided on tag configuration and expected output. So I set out to write a post that I hope will help clarify those areas of working with this template.
Firstly, there's no need to make any changes to your existing Google tags within your Tealium profile in order to capture Consent Mode values. We'll only need to apply the Google Consent Mode tag to your profile and some additional Javascript code changes to capture and communicate privacy preferences from their source, onto the destination UDO parameters.
The Tealium Consent Mode tag has been built to support integration with Tealium's consent manager and OneTrust, by following the code snippet examples in here.
I'm not going to be implementing Tealium’s Consent Manager, nor OneTrust, so this example will show how to customize the provided Tealium example for a custom solution. Whether that be another consent manager, or something built by you, this should provide a base to work off of.
I’ll be storing my consent settings in a localStorage entry so that I can very quickly modify and test the Consent Mode tag functionality. Despite this the logic will be very similar regardless of whether consent settings are communicated to your Tealium UDO from another consent manager, or whether you reference these values from a cookie.
// My consent settings will follow the same naming convention as those provided in Tealium's consent mode documentation
var settings = ['display_ads', 'personalization', 'analytics'];
//I'll then set on consentSettings in localStorage as a stringlocalStorage.setItem("consentSettings", JSON.stringify(settings));
Step 1: Creating a JavaScript Extension for Google Consent Mode in Tealium iQ
First we’ll create a new Javascript Code extension.
We’ll then define settings for this extension as follows:
Scope: After Load Rules (default)
Occurrence: Run Always
And then copy/paste the following code into the Configuration section:
// Where we'll be pulling our consent settings from
b.consent_decision = JSON.parse(localStorage.getItem("consentSettings")) || [];
// How we'll define our Consent Mode flags based on consent settings source
b.google_ad_storage_consent = b.consent_decision.indexOf('display_ads') !== -1 ? 'granted' : 'denied';
b.google_ad_user_data_consent = b.consent_decision.indexOf('personalization') !== -1 ? 'granted' : 'denied';
b.google_analytics_storage_consent = b.consent_decision.indexOf('analytics') !== -1 ? 'granted' : 'denied';
b.google_ad_personalization_consent = b.consent_decision.indexOf('personalization') !== -1 && b.consent_decision.indexOf('display_ads') !== -1 ? 'granted' : 'denied';
b.google_ads_data_redaction = b.consent_decision.indexOf('personalization') === -1 || b.consent_decision.indexOf('display_ads') === -1 ? 'true' : 'false';
This code is an exact copy of the code provided by Tealium here. The only change has been where we source the b.consent_decision variable from, which will be my consentSettings localStorage entry if it exists, otherwise an empty array.
Step 2: Defining UDO Variables for Privacy Flags
Using the Javascript code snippet above, we’ll then need to define UDO variables for each consent flag variable:
google_ad_storage_consent
google_ad_user_data_consent
google_analytics_storage_consent
google_ad_personalization_consent
google_ads_data_redaction
google_url_passthrough
These will be key, as we’ll need to communicate these values to our Google Consent tag.
Step 3: Configuring the Google Consent Mode Tag in Tealium iQ
The Google Consent Mode tag is a preconfigured template that is available in the Tealium Tag Marketplace.
Within the template, we can define our default settings based on all of the categories we previously defined variables for in the Javascript code extension.
In my case I’m going to set these default values to ‘denied’.
We also need to define mappings to capture the values set in the UDO for each category, as consent preferences are communicated to the page, otherwise these will always be set to ‘denied’ regardless of what the user consents to onsite.
For my example, these mappings look like this:
The Variables listed on the left, are each of the variables I created in Step 2, mapped to their associated destination within the Consent Mode template.
For my particular tag, I’ve left Rules and Events with the default setting of ‘All Pages and Events’.
As mentioned previously, we don’t need to make any changes to our Google product tags (Analytics, Ads, Floodlight) to communicate these settings to them. The settings defined via the Consent Mode tag will automatically be communicated onto these tags.
I’ll now publish my work, and test.
Step 4: Testing the Google Consent Mode Configuration
Once my work has been published, I can jump over to my test page, and have a look at the Analytics Debugger output for my GA4 tags.
When publishing in Tealium (or any tag manager), always make sure to keep track of your last production ready build, so that you can rollback to it if necessary.
This is the first visit to my site, so I haven’t defined consent mode preferences yet. My localStorage entry is non-existent. Given this we can see that the Default settings have been applied to my GA4 tag, and the Consent Mode status is set to G100 (denied).
Now, as my test page doesn’t have a consent manager on it, I’m going to manually push code to my console to update the consentSettings entry, as follows:
var settings = ['display_ads', 'personalization', 'analytics'];
localStorage.setItem("consentSettings", JSON.stringify(settings));
This will allow tracking on all supported categories within my code.
This should update the consent mode flags and apply them to any events triggered after this update. So now I’ll trigger a new page_view event to confirm this.
Perfect! It's now set to G111 (Granted).
And then, if we alter our localStorage entry to test out variations on which categories were allowed, we should see the Consent Mode flag applied accordingly in those scenarios as well.
Display Ads denied
Analytics denied
While these are quick tests to check functionality, it’s always recommended to run through as many (if not all) of the variations on tracking flags to ensure that Consent mode is behaving as expected in every scenario, AND across various events and pages on your website(s).
Conclusion
Implementing Google Consent Mode via Tealium’s Consent Mode template is straightforward and requires minimal changes to existing tags. However, if you’re not using Tealium’s Consent Manager or OneTrust, customizing a solution to retrieve and communicate consent preferences to the Tealium UDO may take additional effort.
For more information on tag configuration, check Tealium’s Consent Mode documentation or contact us for implementation support. With proper setup, you’ll ensure compliance with privacy regulations and maintain robust tracking capabilities across your web properties.
More Insights
Step-by-Step Guide to Implementing Google Consent Mode in Tealium iQ
Rob English
Lead Implementation Specialist
Jan 29, 2025
Read More
Google Tag Manager Tag Diagnostics: Troubleshooting and Optimization Guide
Ricardo Cristofolini
Senior Implementation Specialist, Data Solutions
Dec 11, 2024
Read More
November 2024 GA4 & GMP Updates
Napkyn
Dec 4, 2024
Read More
More Insights