Info
Content

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:

Variable

Description

cmpGDPR

0 if GDPR does not apply, 1 if GDPR applies

cmpConsentString

Sets the IAB consent string

cmpConsentVendors

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

cmpGoogleVendorsConsent

Same as cmpConsentVendors but included are the Google ATP IDs.

cmpConsentPurposes

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.

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://"!


    gtm_inputs.jpg

  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, set the Variable Name to cmpGDPR, cmpConsentVendors 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.

    Important: For iab TCF vendors, please use the iab ID instead of the internal vendor ID. Iab vendors are marked with a small iab icon and their iab ID:

  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.

Trigger

Trigger Google Analytics on all pages when consent is given:

Tag

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:

<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-ABCDEF');</script>

In order to allow the consentmanager.net 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],
        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-ABCDEF');</script>

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.

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