Google Tag Manager (GTM)

Please note: Only the manual blocking code can be delivered using a TagManager. If you want to use automatic code blocking, you need to insert the CMP-Code directly into your website.

Please note: When using automatic blocking, please ensure that the TagManager is prevented from being blocked by inserting  the attribute data-cmp-ab="1" into the TagManager code.

Please note: The system will push information to window.dataLayer. GTM offers the option to rename this variable to another value. If that is the case, the data will no longer be received by GTM. Therefore please ensure not to (re)name the variable other than "dataLayer".

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,s22,31,c88, (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,s3,s4,s5, (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, cmpConsentVendors)

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

  7. Set the event rules to cmpConsentVendors contains ,x, where x is the ID of the vendor. 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.

  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 or event order?

In some cases tags should be fired only when more than event has occured, e.g. a certain action by the user and consent is given. In order to combine an existing event with the ConsentManager cmpEvent, please follow these steps:

  1. Edit the tag and remove the exitsing trigger from it.
  2. Click on the icon to assign a new trigger to the tag and then create a new trigger:

  3. Give the new trigger a name and choose trigger type "Trigger Group":

  4. Add your existing trigger and the cmpEvent trigger to the trigger group:

  5. Set the trigger conditions in the same way you do with normal triggers (e.g. add cmpGDPR equals 1 as a condition).
  6. Save the trigger group and assign it to the tag.


Back to top