Google Tag Manager (GTM)

Please note: If you want to deliver the consentmanager code via GTM, 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: 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
deprecated: use cmpRegulation instead


0 if CCPA does not apply, 1 if CCPA applies
deprecated: use cmpRegulation instead


String of Regulation name (e.g. GDPR, CCPA and so on)


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 cmpConsentVendors 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)


Current cmp event status name. Possible values: unknown, loading, consent, legitimateInterest
Note: Additional status may be added from time to time


Last/previous cmp event status name. Possible values: unknown, loading, loaded, consent, legitimateInterest, disabled, hidden, visible, tcloaded, consent-loaded, useraction.
Note: Additional status may be added from time to time
Note: This also includes ALL TCF and GPP status names, e.g. sectionChange.*, cmpDisplayStatus.*, and so on


Status name of the loading sequence (stub, loading, loaded, error)


Status name of the display of the consent layer (visible, hidden, disabled)


A consent status exists (true/false). Please note that this is true as soon as the consent layer is shown and/or in cases when no consent is required.


A consent status exists that is based on the users choice (true/false), e.g. the user clicked on accept, reject or saved the custom settings.

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.

Integration via GTM Template

  1. Login to your Google Tag Manager and click on Tags > New > Tag Configuration
  2. From the Tag Type menu, choose Features Community CMP Templates > Consentmanager CMP

  3. Click on Add to Workspace > Add

  4. Get your CMP-ID, CDN and Host from your Account from Menu > CMPs > Get Codes

  5. Insert your CMP-ID, CDN and Host to our GTM Template and save.

    Insert without the protocol "https://"!


  6. Set the Tag with CMP-Code to trigger on every pageview:


Please note: Due to Google guidelines, we have to initially enable Consent Mode. This can be confusing when customers integrate our template and e.g. do not see live Google Analytics numbers. If you do NOT want to use Consent Mode, please do not forget to deactivate the feature in the template.


Manual integration

If you do not want to use the GTM template or the GTM recipe (see above), you can insert the CMP code manually in yout TagManager. Therefore copy the semi-automatic / manual blocking code from Menu > Get code and paste it into your TagManager as a new tag. Set the tag to be fired with the earliest possible event (PageView or earlier). Do not set a condition / exclusion to the tag.

Updating your tags & conditions

Note: If Google Consent Mode is enabled, you can use the build in consent variables in order to filter the tags. In most cases this is easier compared to updating trigger conditions. More Info on Google Consent Mode see here.

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, create the needed variables, usually you will need at least the variable cmpConsentVendors. Add more variables from the table above if necessary:

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

  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 one rule is necessary:  cmpConsentVendors contains ...  (or cmpConsentPurposes 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.
    Important: Please always use comma before and after the vendor ID (e.g. cmpConsentVendors contains ,x,and not cmpConsentVendors contains x)


  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:

    Example for Google Analytics:

    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.


Trigger Google Analytics on all pages when consent is given:


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

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

Please note: If you do not want to block GTM itself but only the tags that are fired by GTM and 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.

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],

Please note that the automatic blocking code may prevent the browser from executing the GTM code but may not be able to stop the browser from downloading the GTM source codes. Therefore it can be that the crawler will alert you that GTM is loaded without consent. If you want to be sure that GTM is not loaded without consent, you MUST change the GTM code as described above.

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 false"):

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.

Pausing / postponing dataLayer events until consent is given

As an alternative to Trigger Groups you can use consentmanager's own dataLayer function by calling window.cmp_gtag(...)  instead of Google's window.gtag(...) or pushing data into cmp_dataLayer instead of dataLayer. All calls to cmp_gtag(...) will automatically paused and postponed until the user made a choice (accept, reject or custom). Once the choice is made, the CMP will automatically transfer all calls to window.gtag(...) that have previously been sent to window.cmp_gtag(...) (and all subsequent calls). In order to use the function, please ensure to add the following code to your website (before the first call):

if(!('cmp_dataLayer' in window)){window.cmp_dataLayer = [];}
if(!('cmp_gtag' in window)){ window.cmp_gtag = function (){window.cmp_dataLayer.push(arguments);}}

You can then simply change all calls from gtag(...) to cmp_gtag(...) and dataLayer to cmp_dataLayer and our system will take care of the rest.

Example with dataLayer


 var gtmInitialData = {"general":{"language":"en","country":"GB","page_type":"LISTPAGE"}};        
 window.dataLayer = window.dataLayer || [];


if(!('cmp_dataLayer' in window)){window.cmp_dataLayer = [];}
var gtmInitialData = {"general":{"language":"en","country":"GB","page_type":"LISTPAGE"}}; 

Important: Do not replace the dataLayer name in the initialization call for GTM or Analytics. For example do not replace "dataLayer" in this code:

 (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;
 )(window,document,'script','dataLayer','GTM-...'); /* do NOT replace dataLayer with cmp_dataLayer */
Example with gtag


 window.gtag = function (){dataLayer.push(arguments);};
 window.gtag("myEvent",{...some event data ...});


 if(!('cmp_dataLayer' in window)){window.cmp_dataLayer = [];}
 if(!('cmp_gtag' in window)){ window.cmp_gtag = function (){window.cmp_dataLayer.push(arguments);}}
 window.cmp_gtag("myEvent",{...some event data ...});

Webinar/tutorial about GTM implementation

Please note: Currently we can only offer this tutorial video in german. The GTM setup starts about minute 05:00 - 22:00. If you do not use Google Consent Mode you can skip the rest of the video.


Back to top