Google Tag Manager (GTM) is a tool that allows you to manage and deploy tags (snippets of code or tracking pixels) on your website without having to modify your site code.

If you use Google Tag Manager (GTM) to inject cookies on your website and manage site content, you can set it up so that the scripts are controlled by the consent preferences choices selected by visitors.

In this article you will learn:

  1. How it works

  2. Create new variables

  3. Create new triggers

  4. Adding the triggers to tags

How it Works

To pass data to Google Tag Manager, our application uses the custom consent event through the Data Layer Variable.

Our application uses the existing dataLayer object or creates a new one if it doesn’t already exist. If your store creates a dataLayer object, ensure that this does not overwrite the one our application creates.

When a user updates their consent a dataLayer event Pandectes_Consent_Update will be triggered. You will use this event when creating triggers to apply to your tags.

By creating GTM Custom Variables and Triggers, you can make GTM tags only trigger when specific categories within Pandectes_Consent_Update are accepted.

Create new variables

  1. Open your container in Google Tag Manager.

  2. Select the Variables tab from the main menu. The Variable screen appears.

  3. Create a new User-Defined Variable.

  4. Name the variable. (We suggest naming the variable Pandectes C000x where x is the number of the category found here so you know what it refers to)

  5. Set the Variable Type to Data Layer Variable under the Page Variables section.

  6. Set the Data Layer Variable Name to pandectes_categories.C000x where is the number of the category found here (for example for the category Functionality you can put pandectes_categories.C0001).

  7. Press the Save button.

You can follow the same process creating one new variable for all the categories of your app.

Create new triggers

In GTM, triggers prompt tags to fire or not fire on certain criteria. You may already have a variety of different triggers applied to your tags.

As part of our Google Consent Mode integration with GTM you are going to create a trigger associated with each cookie category.

When you apply these triggers to your tags, this will prompt your tags to fire or not fire based on the Cookie Category being active or the consent given by the user.

You will need a separate trigger for each of the Cookie Categories that you will be blocking cookies under. For example, you may have a group called 'Performance Cookies', which has a category id of C0002 and contains the cookies set by your Google Analytics tag.

Each trigger needs to be in line with the category ids that are set in your cookie consent application. You can find the cookie category IDs in the custom consent event here and in the Google Consent Mode integration section inside the app where there is a structure popup of the custom consent event.

We want the cookie category id triggers that you create to be applied to your existing tags in such a way that our app's trigger is the limiting factor to the tag firing. This can be done in several different ways. Two different ways are outlined below.

  1. Creating a Firing Trigger

  2. Creating Exception Triggers

Creating a Firing Trigger

  1. Open your container in Google Tag Manager.

  2. Select the Triggers tab from the main menu. The Triggers screen appears.

  3. Press New. The Trigger Configuration screen appears.

  4. Name it accordingly, e.g. Pandectes Performance Allowed.

  5. Press the Trigger Configuration and set the Trigger type to Custom Event.

  6. Set the Event name to Pandectes_Consent_Update.

  7. Select Some Custom Events and set it to fire when the following is true:

    Pandectes C0001   equals   allow  
  8. Save the Trigger.

  9. Repeat this process for the remaining Cookie Categories.

  10. Apply the Triggers to Tags as a firing trigger.

Note: If a tag is blocked and then allowed, it'll fire without the need for a page reload because of listening for Pandectes_Consent_Update. If it had been previously allowed and then blocked, the tag would be blocked on subsequent page loads.

Creating Exception Triggers

You can also set up an exception trigger to fire the script if a category of cookies is not allowed.

You will only want to use an exception trigger if you already have a different firing trigger set up on your tag.

For example, set a trigger to fire when Pandectes_Consent_Update does not allow C0002 (where C0002 is the id for performance category). Apply this blocking trigger as an exception to tags in this group.

  1. Select the Triggers tab from the main menu. The Triggers screen appears.

  2. Press New. The Trigger Configuration screen appears.

  3. Create a new trigger and name it accordingly, e.g. Pandectes Performance Blocked.

  4. Press the Trigger Configuration and set the Trigger type to Custom Event.

  5. Set the Event name to Pandectes_Consent_Update.

  6. Select Some Custom Events and set it to fire when the following is true:

    Pandectes C0001   equals   deny 
  7. Save the Trigger.

  8. Repeat this process for the remaining Cookie Categories.

  9. Apply the Triggers to Tags as an exception trigger.

Adding the triggers to tags

  1. On the main navigation menu in Google Tag Manager, select Tags.

  2. Select a tag to apply the appropriate Pandectes Cookie Category Trigger to.

  3. Apply the appropriate Firing Trigger or Exception Trigger that you have created.

  4. Click the Save button.

Did this answer your question?