Implementation instructions
The instructions below are to implement proper consent when using Google Tag Manager to deliver Google Services such as Google Analytics 4, Google Ads, Conversion Linker, and more.
⚠️ Note: Usercentrics is a Certified CMP Partner of Google. Regardless of which Certified CMP you use, these steps (or very similar steps) will need to be be taken for your website to be compatible with Google's Consent Mode V2.
Prerequisites
The overall approach to updating your consent tool to be compatible with consent mode V2 is similar in nature for all Google certified CMP partners. In this example, we will show how to make these updates using Termageddon (and its 3rd party partner Usercentrics CMP).
The prerequisites for setting up GTM V2 compatibility are:
A Termageddon license, set up for GDPR and/or UK DPA and an activated Cookie Policy and consent tool. It is assumed the Usercentrics consent script is pasted immediately after <head> within the website (required just in general).
A Google Tag Manager account, with the regular GTM script added to the <head> of your website (just below the Usercentrics script).
Please note this is documentation to set up with Google Consent Mode V2. This is not how to set up with the TCF framework.
Step #1 - Update your Google Tag Manager Script to V2
The first step is to update the Google Tag Manager script within your website to the Consent Mode V2 script provided by Google.
The original script will look something like this:
<script> (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,’script','dataLayer','GTM-XXXXXX');</script>
You need to replace this script with the updated GTM Consent Mode V2 script:
<script type="text/javascript"> // create dataLayer window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } // set „denied" as default for both ad and analytics storage, as well as ad_user_data and ad_personalization, gtag("consent", "default", { ad_user_data: "denied", ad_personalization: "denied", ad_storage: "denied", analytics_storage: "denied", wait_for_update: 2000 // milliseconds to wait for update }); // Enable ads data redaction by default [optional] gtag("set", "ads_data_redaction", true); </script> <script type="text/javascript"> // Google Tag Manager (function(w, d, s, l, i) { w[l] = w[l] || []; w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' }); var f = d.getElementsByTagName(s)[0], j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f); })(window, document, 'script', 'dataLayer', 'GTM-XXXXX'); //replace GTM-XXXXXX with Google Tag Manager ID </script>
Be sure to update “'GTM-XXXXX'” to your respective GTM ID in the above code.
Step #2 - Add the Usercentrics Tag Template to your GTM account
For a google certified consent tool to properly respond to user consent settings, you will need to add a CMP tag template to your Google Tag Manager account. For our example, we will add the Usercentrics tag template.
Log into Google Tag Manager account and select the respective account (website or app) that you will be performing this update for.
Click Templates on the left hand side
For “Tag Templates”, click “Search Gallery”.
Via the search icon, type in Usercentrics and then select Usercentrics CMP
Click add to workspace, then click add
Now go to Tags, click New
Add a title to the tag (for example type in “Usercentrics CMP”)
Under Tag Configuration, lick Choose a tag type to begin setup
Using the search icon, type in and select Usercentrics CMP
Enter your Usercentrics Settings-ID. This can be found on the ‘view embed code’ page of your Termageddon License Cookie Policy and Consent Tool “View embed code” page (see highlighted example screenshot of a SettingsID here).
All other default settings can remain unchanged.
Under Triggering, click Choose a Trigger to make this tag fire
Select Consent Initialization - All Pages
Click Save
You have now implemented the Google Certified Usercentrics CMP via the community templates feature. The next step will be to set up the consent overview along with events and triggers to ultimately capture consent on a per tag basis.
Step #3 - Enable consent overview
Consent overview provides a high level view of all the consent settings across the tags in your container. Although in Beta, it’s best to enable this feature for testing purposes later on in the documentation.
In your Google Tag Manager account, click Admin
Click Container Settings
Click/enable Enable consent overview (BETA)
Click Save
Step #4 - Add the respective variables and triggers to your GTM account
Now we need to set up variables and triggers for the consent tool to respond to user consent choices and for those consent events to be properly captured within Google Tag Manager. This will allow us to set up triggers and then ultimately be able to update our tags to respond based on consent choices.
The following Google Services currently support the Consent Mode:
Steps to add Variables
For this example, we will set up a Google Analytics 4 variable. You will want to repeat this process for each Google Service you utilize within Google Tag Manager (see tables above). Use the exact wording provided in the first column for the respective Google Service that you use (for example if you use Google Analytics 4, you must type that in exactly, not just Google Analytics, as that is technically a different Google Service).
Navigate to Variables in the side-menu and then click on New.
Name your variable. In this example, we will name it Google Analytics 4 Variable
Add a new variable of type "Data Layer Variable".
Under Data Layer Variable Name, insert Google Analytics 4.
⚠️ Note: Correct spelling, hyphenation and capitalization are mandatory for this field. Every technology must be added the way it is spelled in the Usercentrics Admin Interface. Here: "Google Analytics 4".
Click/enable Set Default Value and type in false
Click Save
You have now set up the Google Analytics 4 variable. Repeat this process for any other Google Services you use, outlined in the tables above.
Steps to add Triggers
For this example, we will now set up a Trigger for Google Analytics 4. You will want to repeat this process for each Google Service you utilize within Google Tag Manager (see tables above).
⚠️ Note: There are several ways to implement this logic. Usercentrics recommends the following option, however, depending on your setup, other structures might be more reasonable.
Navigate to Triggers in the side-menu and click on New
Add a title to your trigger. For this example, we will type in “Google Analytics 4 Trigger”
Click Trigger Configuration and select Custom Event
Click/enable Use regex matching
Under Event Name, paste in (consent_status.*)
⚠️ Note: Correct spelling, hyphenation and capitalization are mandatory for this field.
Click/enable Some Custom Events
In the drop-down menus, set the following condition: "Google Analytics 4 Variable" contains true.
Explanation: The variable contains the user's consent information (variable=true - user opted in || variable=false - user opted out) for a specific technology. Hence, the trigger should only be fired (and tag therefore activated), if the variable=true.
Clicks Save
You have now set up the Google Analytics 4 trigger. Repeat this process for any other Google Services you use, outlined in the tables above.
Step #5 - Add new tags or update existing tags within your account with new triggers
You can choose to pause your existing tags and create new ones, or you can modify your existing tags where you will remove the existing trigger and replace it with the new trigger. In this example, we will update an existing Tag. You can still utilize the steps below if you are creating new tags (just remember to pause any existing tags prior to testing in the final step).
Navigate to Tags in the side-menu and click on your Google Analytics 4 tag
Remove the preexisting trigger(s) and replace it with the newly created “Google Analytics 4 Trigger”
Click save
You have now set updated the Google Analytics 4 tag to fire only after a website visitor provides respectful consent. Repeat this process for any other Google Services you use, outlined in the tables above.
Step #6 - Enable Consent Mode in your Termageddon account
If not enabled already, you will need to enable Consent Mode within your Termageddon license.
Log in (https://app.termageddon.com)
Click into your respective license
Click ‘edit policy details’ for the ‘Cookie Policy and Consent Tool’.
Click Enable for Google Consent Mode (on page 4)
Click ‘next’ several times and ultimately ‘submit’ for Consent Mode to be activated.
If not done already, this is also a good time to mark “Google Tag Manager” as “Essential” on the final page of the Termageddon “Cookie Policy and Consent Tool” questionnaire and click ‘submit’ for changes to take effect. To do this, click ‘edit’ next to “Google Tag Manager” and under “General”, change the “Category” to “Essential”. Google Tag Manager does not place cookies on a website by default, and since the Usercentrics consent tool needs to load to fulfil a compliance requirement, GTM will now be considered an Essential Service (and consent will still be captured on a per Service basis for other tags that fire from GTM).
Step #7 - Test
Navigate to Tags in the side-menu and click Preview
A new tab will open, bringing you to Tag Assistant (tagassistant.google.com…)
Click Connect.
A new tab will open bringing you to your website.
Click back to the Tag Assistant browser window (tagassistant.google.com…..)
You should only see that the Usercentrics script has fired
Now in the other browser window (your website), within the cookie consent modal, click ‘more information’, and proceed with only accepting the “Google Analytics 4” Service, then click save settings.
Now head back to the Tag Assistant window, you should now see the Google Analytics 4 tag has now fired:
Click “consent” to view/confirm the proper “analytics_storage” consent has been granted
Go back to your website, and change your consent settings to ‘deny’
Go back to the Tag Assistant tab, and you should see that consent status has reverted back to denied. If you click ‘tags’, you will see Google Analytics 4 only fired one time (from when you first consented in Testing step #5 above).
Repeat testing for all respective Tags to confirm your consent tool (and Google Tag Manager) is properly responding to user consent choices.