> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.pandectes.io/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Integration with Google Tag Manager

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 the following:

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](/en/article/pandectes-custom-event-yfr7jh/) through the Data Layer Variable.

![](https://storage.crisp.chat/users/helpdesk/website/-/1/a/5/a/1a5af239e847cf00/image_urf7g0.png =800x113)

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. 

| You can also rename this property to any custom property you have used. This is available as an option inside the GTM integration form of our app.

### Video Guide


${youtube}[Integration with Google Tag Manager](BPu8xsH3lmc)

### 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](/en/article/pandectes-custom-event-yfr7jh/) 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](/en/article/pandectes-custom-event-yfr7jh/) (for example for the category *Functionality* you can put **pandectes_categories.C0001**).

    ![](https://storage.crisp.chat/users/helpdesk/website/a9d7ec56f6baf800/dfc98d3e-716c-44e6-a1e8-985028_9evj16.png =1000x341)

7. Press the Save button.
    
You can follow the same process creating one new variable for all the categories of your app and finally have here 4 variables in total.

### 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](/en/article/using-google-consent-mode-integration-1xkfv6o/) 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.

### 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
```

    ![](https://storage.crisp.chat/users/helpdesk/website/8de68f7bcb67b800/ffe2428f-7e0a-417e-8c1f-a8c733_a0ccz.png =1000x516)

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 the 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
```

    ![](https://storage.crisp.chat/users/helpdesk/website/5e3631a87e0ad400/98c395a5-729c-4a6b-9506-0763ff_1th1t7j.png =1000x512)

7. Save the Trigger.
8. Repeat this process for the remaining Cookie Categories.
9. Apply the Triggers to Tags as exception triggers.
    

### 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 too.
3. Apply the appropriate **Firing Trigger** or **Exception Trigger** that you have created.
4. Click the **Save** button.
