Skip to content

Google Tag Manager & CookieTractor

Google Tag Manager (GTM) is a tag manager from Google that is used to trigger scripts and tags on a web page. Here are instructions on how to set up GTM to adapt to user selections in CookieTractor.

Setup CookieTractor with GTM

To control which of your scripts belong to the respective cookie category, the scripts need to be categorized. CookieTractor has built-in support for Google Tag Manager and will trigger events based on the visitor's consent settings. To use these inside Google Tag Manager, we need to create "Triggers" for any "Tags" dependent on the consent settings.

If you want to import all triggers and variables instead of creating them yourself, you can find instructions below.

Create the following triggers inside your Google Tag Manager account:

Name

Trigger Type

Event Name

Consent - Necessary (All Pages)

Custom Event

cookies_necessary

Consent - Functional (All Pages)

Custom Event

cookies_functional

Consent - Statistical (All Pages)

Custom Event

cookies_statistical

Consent - Marketing (All Pages)

Custom Event

cookies_marketing

Consent - Undefined (All Pages)

Custom Event

cookies_undefined

Now, update any Tags that require consent from your users to be triggered by any of these Triggers.

Note that CookieTractor supports Google Consent Mode, services that support this technology should continue to go against "All Pages" in Google Tag Manager.

If you need to listen to events when a user revokes a consent, you can create the following Triggers and use them on your Tags:

Name

Trigger Type

Event Name

Consent Revoked - Functional (All Pages)

Custom Event

cookies_revoked_functional

Consent Revoked - Statistical (All Pages)

Custom Event

cookies_revoked_statistical

Consent Revoked - Marketing (All Pages)

Custom Event

cookies_revoked_marketing

Variables to check for consent

In some cases, one might need to check if a visitor has consented to a specific type of cookie using "Conditions" in Google Tag Manager. To make it easier to access this information, we can add User-Defined Variables to get this information. In Google Tag Manager, go to "Variables" and add the following:

CookieConsent_AllowFunctional

Name: CookieConsent_AllowFunctional
Type: Custom Javascript
Code:
function(){
  return cookieTractor.consent.contains('functional');
}

CookieConsent_AllowStatistical

Name: CookieConsent_AllowStatistical
Type: Custom Javascript
Code:
function(){
  return cookieTractor.consent.contains('statistical');
}

CookieConsent_AllowMarketing

Name: CookieConsent_AllowMarketing
Type: Custom Javascript
Code:
function(){
  return cookieTractor.consent.contains('marketing');
}

Import settings

You can import this JSON-file into Tag Manager, under Admin/Container/Import Container.

  1. Unzip the downloaded file, and select the JSON-file as the file to import
  2. Select your existing/current workspace 
  3. Choose Merge to append the settings, rather than to replace them
  4. Check that everything looks correct, and continue by confirming the changes

The file contains all triggers and variables mentioned above. Please be careful though, an import with override will delete all current settings in the container.


Rename the data layer

Google Tag Manager supports renaming the data layer to use another variable name than the default "dataLayer". For CookieTractor to be able to communicate with Google Tag Manager our script tag needs to be updated to indicate the new data layer name.

Example:

<script src="//cdn.cookietractor.com/cookietractor.js" ... data-gtm-data-layer-name="myNewName"></script>


Support

If you have any questions about the installation process, please email info@cookietractor.com.