Google Tag Manager (GTM)

General Information

In order to use consent information with Google Tag Manager (GTM), the CMP will push so called data layers into GTM. The CMP will create the following data layer variables:




0 if GDPR does not apply, 1 if GDPR applies


Sets the IAB consent string


Sets a comma separated list of vendor IDs that got consent, e.g. ,3,7,22,31,88, (list starts and ends with comma)


Sets a comma separated list of custom vendor IDs (vendors that are not part of the IAB global vendor list) that got consent, e.g. ,82,112,556, (list starts and ends with comma)


Same as cmpVendorsConsent but included are the Google ATP IDs.


Sets a comma separated list of purposes that got consent, e.g. ,1,2,3,4,5, (list starts and ends with comma)


Sets a comma separated list of custom purposes that got consent, e.g. ,1,2,3,4,5, (list starts and ends with comma)

The event "cmpEvent" in combination with above variables can then be used as a trigger for the tag manager in order to know if/when to fire the codes.

ConsentManager GTM Container (recipe)

In order to skip some of the manual steps that are outlined below, we have created a GTM Container or so called "recipe" that can be imported into your GTM account and will save you some time and might help avoiding some common mistakes.

Importing the recipe

In order to begin you need to import the recipe into your account:

  1. Download the recipe json file (see attachements on the left side)
  2. Login to your GTM account and go to Admin > Import container

  3. Choose the json file to be uploaded, choose the workspace into which the file should be imported and choose import option Merge

  4. Click on Confirm in order to finish the import.
  5. In your account you will now find some example tags labeled "DEMO ..." as well as a Custom HTML tag which is meant to be used for the consentmanager CMP-Code. Also you will find some new Triggers labeled "cmpEvent ..." and some variables labeled "cmp...".

Using the recipe

Once the recipe is imported you will find some new demo tags, triggers and variables in your GTM. Please note that these are DEMO tags and need adjustment.

Example: Setup for Google Analytics

  1. Go to Tags and edit the tag DEMO Example Tag for Google Analytics
  2. Unpause the tag and rename it to your needs

  3. Go to Variables and edit the variable DEMO Google Analytics settings
  4. Insert the Tracking ID of your Google Analytics account and rename the variable to your needs

Example: Setup for Google Ads conversion tracking

  1. Go to Tags and edit the tag DEMO Example Tag for Google Ads Conversion Tracking
  2. Unpause the tag, set the conversion ID , conversion label and change the name according to your needs

  3. Go to Triggers and edit the trigger cmpEvent GDPR does not apply CONVERSION Trigger
  4. For demonstrational purposes we used a page url trigger which fires when the url contains a certain string ("thank-you"). Edit the trigger and align the rules to your needs.

  5. Repeat the changes from the last step also with trigger cmpEvent s1 Google Ads CONVERSION Trigger

Example: Setup for LinkedIn Insight Tags

  1. Go to Tags and edit the tag DEMO Example Tag for LinkedIn
  2. Unpause the tag and insert your partner ID. Align the tag name to your needs.

Example: Setup for HotJar

  1. Go to Tags and edit the tag DEMO Example Tag for HotJar
  2. Unpause the tag and insert the HotJar HTML-Code into the field. Align the tag name to your needs.

Applying the demo data on other scenarios

The demo tags, triggers and variables are there in order to help you better understand how a normal tag setup is done. You can simply copy each tag and trigger and apply it to other scenarios.

Please note that the triggers are set to fire only for certain vendor IDs. If you want to use the demo data for other vendors, you will need to copy the tag and the triggers and then change the triggers to the new vendor ID:

Createing blocking rules manually (without recipe)

In order to display certain codes only if consent is given, please follow these steps:

  1. Create variables in GTM: In GTM go to Variables > New and click on configure:

  2. Choose variable type Page Variables > Data Layer Variable, set the Variable Name to cmpGDPR, cmpVendorsConsent or any other variable name as from the table above:

  3. Repeat the steps above for all other variables that you require (usually cmpGDPR, cmpVendorsConsent, cmpCustomVendorsConsent)

  4. Go to Triggers > New and click on configure:

  5. Use event Name cmpEvent and add custom events to it:


  6. For each event at least two rules are necessary: cmpGDPR equals 1 and cmpVendorsConsents contains ... or cmpCustomVendorsConsents contains ... (see next step).

  7. Set the event rules to cmpVendorsConsent contains ,x, where x is the ID of the vendor and/or cmpCustomVendorsConsent contains ,x, where x is the ID of a system- or custom vendor (vendor-IDs that start with "c" or "s"). The IDs for the vendors can be found under menu Vendors/Whitelist:

    Important: Always only use one vendor per trigger (... contains ,x, and not ... contains ,x,y,z,). If you are working with multiple vendors, create multiple trigger and one trigger per vendor.
    Important: Ensure that you are using the correct variable. All vendors that begin with s or c can be found in variable cmpCustomVendorsConsent. All vendors without s or c can be found in cmpVendorsConsent.

  8. Repeat the above step for each vendor and create a new trigger for each vendor

  9. Apply the trigger to your tags and ensure that the tags do not fire with pageView event but only with the cmpEvent:

    Important: Ensure that the trigger is the only trigger for each tag you are using. Do not combine triggers with other triggers/events like "All pages" or "On page load" and so on.

Example: Blocking Google Analytics with Google TagManager (GTM)

Here are some example screenshots how a setup would look like in order to block Google Analytics if no consent is given.


a) Trigger Google Analytics on all pages when consent is given:

b) (optional) Trigger Google Analytics on Thank-You page after an order has been placed:


Google Analytics Tag with assigned Triggers (second trigger is optional):

How to block the Google TagManager Code if no consent is given?

If you not only want to block the codes within the TagManager but also the TagManager itself, you can do so by following these steps:

Your GTM code will look somehow like this:

        new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],

In order to allow the CMP to block and only enable the code on consent you will need to change the code in the following way: (see changes in <script ...> part of the code)

<script data-cmp-vendor="s905" type="text/plain" class="cmplazyload" >(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],

How to prevent Google TagManager to fire multiple times?

The CMP will fire the cmpEvent datalayer every time when the consent information is refreshed. This occurs when the page is loaded and consent information is found in the visitors cookie, when the consent layer is displayed and the visitor makes a choice or when the visitor resurfaces the consent layer and changes the settings. In the last case it can occur that the visitor opens and closes the consent layer several times. Each time the layer closes, the datalayer will be fired and the Google TagManager might show some tags or fire Google Analytics counting. In order to prevent tags from being fired multiple times on a page, please follow these steps:

  1. Create a new tag for each tag that you want to prevent from being fired again. Use a custom HTML code and insert the following code:

    <script> window.prevent_duplicate_googleanalytics = true; </script>

  2. Use the same trigger for this new tag as you use for the original tag.

  3. Create a new variable of type custom javascript and use the following code:
    function (){ return ("prevent_duplicate_googleanalytics" in window); }

  4. Add another condition to your existing trigger using the variable you created before ("Variable XXX equals true"):

How to handle dataLayer / event order?

In some cases tags should be fired depending on a certain event. In this case the TagManager basically needs to combine two events: Fire the tag only if cmpEvent is given (with the necessary variable values) AND the other event is called. Unfortunatly GTM does not offer a build-in feature for this. Here is an example how to work around it:

  1. Create a new tag of type custom HTML with the following content:


    dataLayer.push({'myTrackingEvent': true});


  2. Assign a trigger which fires with your custom event and has a condition cmpGDPR equals -1

  3. Create a new datalayer variable with the same name you used in the custom HTML (step 1) and set default value to false

  4. Change the existing variable "cmpGDPR" and set default value to -1.

  5. Adjust the trigger of your tag (the one that you want to fire when both events are present) and set two triggers with the following conditions:
    Trigger 1)
    Event: Your event 
    Condition: cmpGDPR equals 1 and cmpVendorsConsent contains ...

    Trigger 2)
    Event: cmpEvent
    Condition: same as above plus myTrackingEvent equals false
The logic behind this

In case the custom event fires first: The cmpEvent is not yet fired and no consent data is present, cmpGDPR will be -1. The TagManager will only fire the new custom HTML and with it set a variable (myTrackingEvent) to true in order to notify us that the custom event has been fired. When the cmpEvent fires the TagManager will check both triggers. Trigger 1 will not fire because the event does not match. Trigger 2 will fire because event, variables and the new variable myTrackingEvent match the conditions.

In case the cmpEvent fires first: The custom event did not yet fire and the variable myTrackingEvent is false. None of the triggers conditions match, but the TagManager will set the values of the cmp... variables (e.g. cmpGDPR will be set to 1). Once the custom event fires, the first trigger's conditions will be meet and the tag can fire.

Back to top