Google Tag Manager configuration

Prev Next

Google Tag Manager (GTM) is a tool that controls when the tags on your website fire. Usercentrics connects to it through a data layer variable, so your tags only fire after a user has given consent in the Usercentrics CMP.

This page shows how to set up that connection. It uses Google Analytics 4 as the example.

Prerequisites

Before following this documentation, we assume you have:

  • Created a Google Tag Manager account.

  • Created a Google Tag Manager container on your website.

  • Inserted the Google Tag Manager script into your website.

  • Inserted your Usercentrics script into your website. Learn how to do this here.

    You can also directly integrate the Usercentrics Script via the Google Tag Manager. Usercentrics does NOT recommend this. However, you can learn how to do it here.

  • Your Usercentrics script

How Google Tag Manager works

Read the following information if you are new to Google Tag Manager implementations:

  • Google Tag Manager helps you configure when the Javascript tags on your website are activated.

  • Each tag needs to have at least one trigger.

  • Triggers listen for certain website events (e.g. the website is fully loaded). Once this event takes place the trigger determines if the tag is activated.

  • Triggers can be firing or exception triggers:

    • Exception triggers determine when a tag is NOT fired and take precedence over other triggers.

    • Firing triggers determine when a tag is fired.

  • Triggers can be reliant on variables. The firing of a tag will be blocked, if a condition based on the value of such a variable is not met.

  • Usercentrics uses a special type of variable, a data layer variable, to communicate between your Google Tag Manager settings and your CMP.

Adding data-processing technologies

Note

This documentation will use Google Analytics 4 as an example. However, the following process needs to be repeated separately for each technology.

Replace "Google Analytics 4" in the naming of tags, triggers and variables with the name of the technology you are currently implementing, e.g Matomo.

If you already have a Google Analytics 4 tag in your Google Tag Manager configuration, you can jump to the Create a new Google Analytics variable section.

Important

The Google Consent Mode is activated by default in the Admin Interface. To deactivate the Google Consent Mode, go to the Admin Interface under Configuration / CMP Settings [CMP V2]. As the implementation differs for the Google Tags supported by the Google consent mode, please see our technical documentation for more information on the Google consent mode and the correct templates to use with your CMP.

Create a new Google Analytics 4 tag

  1. Navigate to Tags in the side-menu and then click on New.

  2. Select Google Analytics as the tag type.

  3. Choose Google Tag.

  4. Name it Google Analytics 4 Tag.

  5. Enter your Measurement ID in the Tag ID field. You can read more here.

  6. Navigate to Advanced Settings > Tag firing options and select Once per page.

  7. Save the Google Analytics 4 Tag.

    Explanation

    • Once per page option means that, once consent is granted, the Tag will only fire once per page view. Even if consent is revoked and granted again the Tag will only fire if a page reload happens (which means a new page view).

    • Once per event option allows you to fire the Tag every time an event happens and meets the specific triggering criteria. In Usercentrics case you can listen to the consent_status event and trigger every time that event happens. The downside of this approach is that some tags inject scripts on the client's page and therefore, every time the event occurs the Tag will try to inject the script again which will cause a file load. In the worst case scenario, if for some reason we have consecutive consent updates the website may enter an "Out of memory" state.

    • Unlimited option should be selected if you want a certain technology to fire without any limitations (the downsides from "Once per event" option also apply here).

    Taking the above options into account, we recommend the Once per page setup.

cmp_tag

Create a new Google Analytics 4 variable

You have to create consent default status variables for each of your non-IAB vendor script tags so that they are not triggered without consent.

  1. Navigate to Variables in the side-menu (User-Defined Variables) and then click New.

  2. Add a new variable of type Data Layer Variable.

  3. In the top left, name the variable Google Analytics 4 Variable.

  4. 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".

  5. Tick Set Default Value and set the default value to false.

  6. Save the Google Analytics 4 Variable.

cmp_tag

Create a Google Analytics 4 trigger

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.

For basic Google consent mode:

  1. Navigate to Triggers in the side-menu and click New.

  2. Add a new trigger of type Custom Event.

  3. In the top left, name the trigger Google Analytics 4 Trigger.

  4. Next to the Event Name input field, select Use regex matching.

  5. Under Event Name, insert (consent_status.*).

    Note

    Correct spelling, hyphenation and capitalization are mandatory for this field.

  6. Select Some Custom Events.

  7. 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.

  8. Save Google Analytics 4 Trigger.

cmp_tag

  1. Add the trigger to Google Analytics 4 Tag.

cmp_tag

For advanced Google consent mode:

  1. Navigate to Tags > Google Analytics 4 Tag.

  2. Add a new trigger of type All Pages.

Note

Repeat this for each non-IAB vendor script in your Tag Manager.

Testing in preview mode

In order to make sure your Google Tag Manager setup works, test it in preview mode.

  1. Activate preview mode by clicking on Preview in the top-right corner.

  2. Visit your website.

  3. Open the development tools of your browser and navigate to the Network tab.

  4. Network requests of the implemented data-processing technologies should not be visible, unless they were defined as Essential in your Admin Interface.

  5. Click Accept All on the Usercentrics CMP.

  6. Now network requests of the implemented data-processing technologies should be visible in the Network tab.