> For the complete documentation index, see [llms.txt](https://developers.didomi.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.didomi.io/cmp/web-sdk/third-parties/tags-management/tag-managers/google-tag-manager/configure-the-didomi-gtm-integration.md).

# Configure the Didomi / GTM integration

{% hint style="info" %}
Events and variables used by GTM are detailed in [this documentation.](/cmp/web-sdk/third-parties/tags-management/events-and-variables.md)
{% endhint %}

{% hint style="danger" %}
To avoid overriding our variables in the dataLayer in the case where Didomi is loaded before the dataLayer initialization, we recommend to instantiate it with this syntax : `window.dataLayer=window.dataLayer || [];` instead of `window.dataLayer=[];`
{% endhint %}

This section describes how to control what tags are embedded on your website when using Google Tag Manager for managing tags.

The key idea of the integration is that Didomi pushes consent information into Google Tag Manager as variables of the data layer. You should then configure GTM to only fire tags after consent has been collected for every vendor.

The integration relies on adding a trigger to all the tags from vendors that do not support the IAB framework to make them fire on a custom event from the data layer. The Didomi SDK will then fire an event with the list of vendors that the user has given consent to, which will ensure that Google Tag Manager only loads the tags matching the user consent.

For instance, if the user gives consent to the vendor `google`, the SDK will push the event `didomi-consent` and the variable `didomiVendorsEnabled` with the value `google,`. The tags setup in Google Tag Manager and with a trigger `"didomiVendorsEnabled" contains "google,"` will then be loaded by Google Tag Manager and other tags with triggers for a different vendor ID will not be loaded.

{% hint style="warning" %}
**Make sure that our SDK is setup**

Before continuing, please read our section on [setting up our SDK](/cmp/web-sdk/getting-started.md) to learn how to do the initial setup of your tag. It is particularly important that our tag gets embedded before all the other tags on your page.
{% endhint %}

### Step 1 - Enable our GTM integration

Enable the GTM integration in the Integrations tab of your consent notice by selecting this box:

<figure><img src="/files/ARRpgGfncpG2Khn6G6ov" alt=""><figcaption><p>GTM integration in the Didomi Console</p></figcaption></figure>

By default, Didomi uses the name “dataLayer” as the variable name for your [GTM data layer](https://support.google.com/tagmanager/answer/6164391?hl=en).

If you are using [another name for your data layer](https://developers.google.com/tag-manager/devguide#renaming), you can instruct Didomi to use this name instead, by typing it in the “DATA LAYER NAME” field.

If you are configuring Didomi through the Console, you can now go to the next step (2 - Create the variables in GTM).

{% hint style="danger" %}
**Embedding the Didomi SDK through GTM**

We recommend not embedding the Didomi SDK through GTM. By being directly on your pages, the Didomi SDK can load faster and also ensures that IAB vendors can detect a CMP on the page as soon as possible.

Embedding the Didomi SDK through GTM will result in fewer consents being passed to vendors and a lower consent rate from their perspective.
{% endhint %}

### Step 2 - Create the variables in GTM

The Didomi SDK will automatically push variables and events to GTM that contain the user consent status. You can then use these custom variables and events to decide when to load a vendor tag on your website.

First, you need to create a data layer variable that maps to the `didomiVendorsEnabled` variable for example, that will be pushed by the SDK onto the data layer.

1\) Go to the "Folders" section of your Google Tag Manager workspace:

![GTM folders](/files/-LDh8jbIiLL0-DcBDbs6)

2\) Create a new folder named "Didomi"

3\) Click on “add new variable”

4\) Create new user-defined variables, using the following configuration:

* Name: Didomi Vendors Consent
* Variable type: Data Layer Variable
* Data layer variable name: didomiVendorsEnabled

<figure><img src="/files/q3czKctCEf3an4majsDe" alt=""><figcaption><p>GTM Didomi variable</p></figcaption></figure>

Note: We recommend keeping Didomi's variables and triggers in a dedicated "Didomi" folder but you are free to structure resources differently.

Please read [this documentation](/cmp/web-sdk/third-parties/tags-management/events-and-variables.md#variables) for the list of all variables that are pushed to GTM by the Didomi SDK.

### Step 3 - Create triggers

You need to create triggers that will be used to decide when to load each tag in Google Tag Manager.

For every vendor tag that you need to control, in the "Folders" section of the manager, add a new trigger to the Didomi folder:

<figure><img src="/files/UoZWXO7RqxDsSAgCl4G6" alt=""><figcaption><p>New trigger</p></figcaption></figure>

And use the following configuration:

* Trigger name: "{name of the Vendor} – {id of the vendor}" for example (see “how to find your vendor ID” further down in the article)
* Trigger type: Custom event
* Event name: one of the [events pushed by Didomi ](/cmp/web-sdk/third-parties/tags-management/events-and-variables.md#events)(`didomi-consent`, `didomi-ready` or `didomi-consent-changed`). We recommend using didomi-consent, because this event is merging didomi-consent-changed and didomi-ready. As a result, it will take care of a change of consent and a simple page load.
* “This trigger fires on “: Some Custom Events
* “Fire this trigger when an Event occurs and all of these conditions are true” :`Didomi Vendors Enabled` contains `{id of the vendor},`. Use the full ID of the vendor with an additional comma (`,`) at the end.
* Save.

<figure><img src="/files/VIZw0vEeT5hAAdvb0SIp" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
When matching vendors by IDs in variables, use the full ID of the vendor with an additional comma (`,`) at the end to ensure IDs do not get mixed and matched.\
Example: Use `google,` to match the vendor with ID `google` and not the vendor with ID `googleana-4TXnJigR`.
{% endhint %}

**Repeat this process for every non-IAB vendor that you have.** You need to create one trigger **per** non-IAB vendor.

Then, if your existing trigger is a custom trigger, you will need to create [a Trigger group](https://support.google.com/tagmanager/answer/9164222?hl=en), so that the tag triggers when condition 1 (already existing condition) **AND** condition 2 (related to consent) are both met.

Otherwise, if you just add another firing trigger related to consent to a tag with an already existing condition, the tag will trigger when condition 1 OR condition 2 are met. But not necessarily both at the same time, and this will not be compliant.

In the "Folders" section of the manager, add a new trigger to the Didomi folder, using the following configuration :

* Trigger group name : Trigger Group - Consent + {other condition} - {name of the Vendor} – {id of the vendor}
* Trigger type: “Trigger Group”.
* Select the existing trigger of your tag.
* Also select the Didomi trigger for this vendor, that you created in step 3.
* Save

![Trigger group](/files/QcWUa6mXqCkx91mqmXYK)

{% hint style="info" %}
**Note**: Please note that trigger groups are triggered once per page only, which can be an issue when using dynamic websites. In that case, you can use our [functions](/cmp/web-sdk/reference/api.md) and [events](/cmp/web-sdk/third-parties/tags-management/events-and-variables.md). And in the specific context of a SPA, you can refer to our dedicated [GitHub page](https://github.com/didomi/samples/tree/main/how-to-track-SPA-with-GTM-and-Didomi).
{% endhint %}

**How to find your vendor ID?**

To find your vendor ID, in your Didomi account, go to Consent notices -> Open your notice -> Regulation -> Edit vendors and Purposes: copy the API ID. Learn more about variables in [this documentation.](/cmp/web-sdk/third-parties/tags-management/events-and-variables.md#variables)

<figure><img src="/files/rzArfbsk2g40tYqpnidh" alt=""><figcaption></figcaption></figure>

This trigger (or trigger group) can now be used to define tags that fire only when the user has given consent for that vendor.

{% hint style="danger" %}
Following these instructions while also enabling Google Consent Mode, will result in negatively impacting the Consent Mode functionality by blocking the Google tags from firing until consent is granted.
{% endhint %}

If enabling Google Consent Mode via our [GCM direct integration](https://docs.didomi.io/consent-management-platform-cmp/frameworks-regulations/google-consent-mode-v2), make sure that no consent-aware tags are configured for Google tags (vendors `google` , `googleana-4TXnJigR`).

To make sure Google Consent Mode is working, you will have to remove any consent-aware event and only use the didomi-ready event.

![](/files/LmTIw1IGkmNvQv2iFbqI)

Google Consent Mode only supports GDPR. For multi-regulation notices, you may want to duplicate your tags and condition them according to the applicable regulation. To do this, you can use the variable `didomiRegulationName`.

Alternatively, you could use two GTM containers, one for GDPR, one for the other regulations, and load one or the other based on the applicable regulation.

### Step 4 - Classify your tags

You now need to classify your tags and define what user consent is required for firing each of them. This last step is very important.

In the "Tags" section of your Google Tag Manager, edit **EACH** of your existing tag concerning non-IAB vendors and add the trigger or the trigger group (created at step 3) corresponding to the vendor that owns the tag instead of what was previously used.

Remember to condition the tags of **all your containers.**

![GTM didomi tag](/files/-LDh8jcgWN33A34qdvf8)

Moving forward, every time you add a new tag that does not implement the IAB specification and that requires GDPR consent, you must categorise it by adding the adequate trigger.

### Custom events and consent

If you have your own custom events that you use as triggers for tags and also want to add an additional condition on the consent status of the user, check [this page](/cmp/web-sdk/third-parties/tags-management/events-and-variables/custom-events.md) for more details.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://developers.didomi.io/cmp/web-sdk/third-parties/tags-management/tag-managers/google-tag-manager/configure-the-didomi-gtm-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.
