# Block tags with Google Tag Manager integration

This article will guide you through Didomi's integration with Google Tag Manager (GTM) to configure the loading of tags on your website when there is consent from the user.

### Introduction:  events and variables sent in the Data Layer

The GTM integration enables the Didomi SDK to send events. These events can generate variables in the GTM Data Layer.&#x20;

* **Didomi Events**

{% hint style="info" %}
**didomi-consent:** when page has loaded, and when there is a change in consent&#x20;

**didomi-ready**: when the page is loaded

**didomi-consent-changed**: when there is a change in consent&#x20;
{% endhint %}

We recommend using the **didomi-consent** event as it includes the others and is usually the most suitable.

You can find these events in our 📰 [technical documentation](https://developers.didomi.io/cmp/web-sdk/third-parties/custom-integrations/tag-managers/google-tag-manager#what-events-are-available).&#x20;

* **Didomi Variables**

Didomi events will generate Didomi variables in the GTM Data Layer.

{% hint style="info" %}
Didomi variables include the following information:

* Vendors (subset variables: consent given/ consent denied/ consent unknown)
* Purposes (subset variables: consent given/ consent denied/ consent unknown)
* Vendors and purposes (subset variables: consent given/ consent denied/ consent unknown)
* IAB TCF Consent string / GDPR (if GPDR applies)
  {% endhint %}

You do not have to use all variables. The most used variable is "**didomiVendorsEnabled**", which holds the list of all vendors with user consent.

You can find the variables 📰 [here](https://developers.didomi.io/cmp/web-sdk/third-parties/tags-management/events-and-variables).

The goal here is to use these events and variables in the triggers you create, in order to activate tag loading only if the user has given consent. A trigger is activated depending on the event and the variable.

### &#x20;**Integration**

To get started, you need to activate the GTM integration when you set up your consent notice.&#x20;

1. Go to **Consent notices (1)** and click to **edit** your notice.
2. Go to step **2. Customization** **(2)** and the **Integrations** tab **(3)**.
3. Make sure you are in the **Tag Managers** section **(4)**.<br>

   <figure><img src="https://support.didomi.io/hs-fs/hubfs/New%20console%20flow/Capture%20d%E2%80%99%C3%A9cran%202023-03-09%20%C3%A0%2012.11.10.png?width=655&#x26;height=317&#x26;name=Capture%20d%E2%80%99%C3%A9cran%202023-03-09%20%C3%A0%2012.11.10.png" alt="" width="563"><figcaption></figcaption></figure>
4. Scroll down to select the **Google Tag Manager** integration.&#x20;

   <figure><img src="https://support.didomi.io/hs-fs/hubfs/New%20console%20flow/Capture%20d%E2%80%99%C3%A9cran%202023-03-09%20%C3%A0%2012.11.03.png?width=688&#x26;height=314&#x26;name=Capture%20d%E2%80%99%C3%A9cran%202023-03-09%20%C3%A0%2012.11.03.png" alt="" width="563"><figcaption></figcaption></figure>
5. In the **Data Layer Name** field, write the name of your [data layer](https://support.google.com/tagmanager/answer/6164391?hl=en#:~:text=A%20data%20layer%20is%20a,developer%20documentation%20for%20more%20information\)).
6. The standard name "dataLayer" is used by default.&#x20;
7. If you keep the standard name you can leave the field as is.
8. If you chose a new name, you can see it in the code of your website (ask your tech team).&#x20;
9. If you didn't use the Console to create your consent notice, add this in the object didomiConfig:\
   tagManager: {\
   \
   provider: 'gtm'\
   \
   }
10. Do not add this code if you have checked the box in the console.&#x20;

### **Create a variable**

1. Go to your Google Tag Manager account.\
   👉 Let's begin by creating a variable "didomiVendorsEnabled" (i.e., the most commonly used variable). This will enable you to set up tag loading when consent is given by a user for each vendor.
2. Click on **Folders** in the left menu.<br>

   <figure><img src="https://p59.f1.n0.cdn.getcloudapp.com/items/wbu60pnv/60d590c2-1e2c-4541-b916-515e57c4b2f9.jpeg?source=viewer&#x26;v=52c0f03d1845087eae4c7e4d4b479738" alt="" width="563"><figcaption></figcaption></figure>
3. Click on **New Folder.**
4. Name your folder "Didomi".<br>

   <figure><img src="https://support.didomi.io/hs-fs/hubfs/New%20folder%20Didomi-png.png?width=438&#x26;name=New%20folder%20Didomi-png.png" alt=""><figcaption></figcaption></figure>
5. Click on the three dots to the left of the Didomi file.
6. Click on **Add a variable**.<br>

   <figure><img src="https://p59.f1.n0.cdn.getcloudapp.com/items/RBulvjPx/f12a2921-d553-4d63-b454-75605030ae1c.jpeg?source=viewer&#x26;v=60b46bce911219a6b3624aaffe3fabb5" alt="" width="563"><figcaption></figcaption></figure>
7. Enter this information:

**Name:** Didomi Vendors Enabled (instead of “variable without title”)\
**Type of Variable**: Variable of the Data Layer (use the pencil icon to open the choice menu).\
**Name of Data Layer variable**: didomiVendorsEnabled

<figure><img src="https://support.didomi.io/hs-fs/hubfs/Variable%20GTM.png?width=688&#x26;height=369&#x26;name=Variable%20GTM.png" alt="" width="563"><figcaption></figcaption></figure>

### **Create triggers**

You will now create triggers and connect these triggers to one of the Didomi events (we recommend using didomi-consent) and to the "Didomi Vendors Enabled" variable (created in the previous step).

You will need to create a trigger for **each** non-IAB vendor that you wish to block.

To create a trigger:

1. Click on **Folders** in the left menu.
2. Click on the three dots to the right of the Didomi file.
3. Click on **Add New trigger**.<br>

   <figure><img src="https://support.didomi.io/hubfs/image-png-Jun-10-2021-08-49-35-67-AM.png" alt="" width="563"><figcaption></figcaption></figure>
4. Enter this information:

{% hint style="info" %}
**Name of the trigger**: "{Vendor name} – Didomi", for example\
\&#xNAN;*Replace what is written between the curly brackets {} with the name of the corresponding vendor and make sure to remove the {}.*\
The name has no impact. You can use whatever name  you prefer.\
\
**Type of trigger**: custom event (use the pencil icon to open the choice menu)\
\
**Name of the event**: [one of the events generated by Didomi](https://developers.didomi.io/cmp/web-sdk/third-parties/custom-integrations/tag-managers/google-tag-manager#events) (didomi-consent, didomi-ready or didomi-consent-changed). We recommend using didomi-consent.\
\&#xNAN;**"Conditions in which the trigger can be executed"** and select “Some custom events”.\
\
\&#xNAN;**"Fire this trigger when an event occurs and all of these conditions are true"**: Didomi Vendors Enabled        contains        {ID  vendor}\
\
\&#xNAN;*Replace what is written between the curly brackets {} with the corresponding vendor ID: cf. “Where to find the vendor ID?” further down in this article.*
{% endhint %}

<figure><img src="https://support.didomi.io/hs-fs/hubfs/DidomiVendorsEnabled.png?width=688&#x26;height=343&#x26;name=DidomiVendorsEnabled.png" alt="" width="563"><figcaption></figcaption></figure>

**Repeat for all non-IAB vendors.** You need to create one trigger **per** non-IAB vendor.

👉If your existing trigger is a personalised trigger, you need to "[create a group of triggers"](https://support.google.com/tagmanager/answer/9164222?hl=fr)  so that the tag is activated when condition 1 (the existing one) and condition 2 (the one linked to consent) **both meet**.&#x20;

👉If you add both the existing trigger linked to consent AND the existing trigger to the tag, the latter will be launched when the condition 1 OR 2 is valid. Do not use both at the same time, as this causes cookies to be dropped before/without consent (non-compliant).&#x20;

To create a group of triggers:

1. Click on **Folders** in the left menu.
2. Click on the three dots of the Didomi file, and **Add new trigger**.<br>

   <figure><img src="https://support.didomi.io/hubfs/image-png-Jun-10-2021-08-49-35-67-AM.png" alt="" width="563"><figcaption></figcaption></figure>
3. Enter this information:<br>

   **Name of trigger group:** "Group of triggers – Consent + {name of the other condition} - {vendor name}", for example\
   \&#xNAN;*Replace what is written between the curly brackets {} with the corresponding information (and remove the {}).*\
   The name of the trigger group has no impact, you can use whatever name you prefer.

   **Type of trigger**: click on the pencil icon and choose "**Group of triggers**".

   Click on ![](https://lh6.googleusercontent.com/dJcxlqYfmCgkk1gbTkveVaqV7Eu6lkm09UZw5cWCwJ6b_dHvuAKoojnmQ1GHkoNd7HP5S2e8FR-vVKTx3Bh_wYpsT0kF2YROzsSgsxhyMBpcNhVG3KoX_o1GhMmGlG-8QkVDJ5Y),  to the right of **Triggers**.\
   Select the existing trigger for your tag.\
   Click on ![](https://lh6.googleusercontent.com/dJcxlqYfmCgkk1gbTkveVaqV7Eu6lkm09UZw5cWCwJ6b_dHvuAKoojnmQ1GHkoNd7HP5S2e8FR-vVKTx3Bh_wYpsT0kF2YROzsSgsxhyMBpcNhVG3KoX_o1GhMmGlG-8QkVDJ5Y)  again.\
   Select the Didomi trigger matching the vendor, previously created (cf. previous step).<br>

   <figure><img src="https://support.didomi.io/hubfs/image-png-Jun-10-2021-08-57-38-09-AM.png" alt="" width="563"><figcaption></figcaption></figure>
4. **Save**.

👉This trigger (or group of triggers) can now be used in tags so they are activated whenever the user gives his consent for this vendor.&#x20;

Trigger groups are triggered once per page only. This can be problematic when using dynamic websites. In such case, you can use Didomi [functions](https://developers.didomi.io/cmp/web-sdk/reference/api) and [events](https://developers.didomi.io/cmp/web-sdk/third-parties/custom-integrations/tag-managers/google-tag-manager/configure-the-didomi-gtm-integration#events). Specifically for SPA, please refer to our dedicated [GitHub page](https://github.com/didomi/samples/tree/main/how-to-track-SPA-with-GTM-and-Didomi).

#### **Where to find the vendor ID?**&#x20;

To find the vendor ID, go to step **1. Regulations**, then the **Regulations** tab and **Edit Vendors and Purposes** under each regulation.  You can select and copy the API ID .

<figure><img src="https://support.didomi.io/hs-fs/hubfs/ID%20vendor%20to%20use%20GTM.png?width=688&#x26;height=366&#x26;name=ID%20vendor%20to%20use%20GTM.png" alt="" width="563"><figcaption></figcaption></figure>

#### **Match the trigger to the tag**

Finally, you need to connect the trigger to its tag. **This last step is very important.**

In the **Tags** section of your GTM account:&#x20;

<img src="https://support.didomi.io/hs-fs/hubfs/image-png-Jun-10-2021-08-58-57-51-AM.png?width=232&#x26;name=image-png-Jun-10-2021-08-58-57-51-AM.png" alt="" width="232">

1. Click on one of your existing tags for a non-IAB vendor.
2. Add the trigger or the group of triggers (created previously) matching with the vendor of the tag, instead of the trigger used previously.&#x20;
3. **Save**.

{% hint style="danger" %}
**Repeat for EACH of the existing triggers for non-IAB vendors.**&#x20;

Remember to set up the tags for **all** your containers.

From now on, each time you add a new tag for a non-IAB vendor requiring GDPR- compliant consent, you need to go through the setup and tick this new vendor in the list displayed in the console.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.didomi.io/integrations/google/block-tags-with-google-tag-manager-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
