# Didomi's GTM template

This section describes how to enable and configure Didomi's GTM custom template. The template is part of [Google's Community Template Gallery.](https://tagmanager.google.com/gallery/)

There are a few reasons why you might want to make use of this template:

* Enabling this template on your site automatically enables [Google Consent Mode](https://developers.didomi.io/cmp/web-sdk/third-parties/direct-integrations/google-consent-mode#configuring-google-tags) support.
* Templates are a native way to integrate with GTM.
* Any time a template is updated you will have the chance to automatically update it via the GTM console.
* No custom events or triggers are needed to handle Google consent mode statuses. *The template currently supports GCM statuses only (Google Ads and Google Analytics).*

### How to enable and configure Didomi's GTM template?

{% hint style="info" %}
When using the template, please disable the Google Consent Mode integration in the console to prevent conflicts.\
Also remember to enable the GTM integration within the Didomi's console
{% endhint %}

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

In order to use this GTM template (Didomi CMP), you will need to create a new tag and associate the template with at least one trigger.

#### **Creating a new tag**

After accessing your Google Tag Manager account and select your workspace of choice.

* Click the "New Tag" button as shown here,

![New tag - option 1](https://user-images.githubusercontent.com/30706016/128257772-25becf03-3933-452a-8f1d-812b27cc8fcb.png)

Or navigate to the "Tags" tab, and click on the "New" button at the top right side of the tags table.

![New tag - option 2](https://user-images.githubusercontent.com/30706016/128257780-83929c88-0006-4c0d-a111-14fb1d301670.png)

* Use a relevant name for the new tag ("Didomi CMP" was used for this example) and hit the "Tag Configuration" card.

![](https://user-images.githubusercontent.com/30706016/128257793-23fb07a4-1457-4196-9aab-0121880e7d7e.png)

* From that screen you should have access to all the templates in the Community Template Gallery, including the "Didomi CMP" one. Look for it and load it.

![Didomi GTM template in the Community Gallery](https://user-images.githubusercontent.com/30706016/128257687-d36f0833-9814-4592-8c74-79a8ccf5ef9a.png)

At this point, you should have access to the template UI

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

#### **Associating a trigger to a tag**

We want our tag to be fired on all pages and make sure that it is fired before any other tags. In order to achieve that,

* Click on the "Triggering" card to choose a trigger so that the tag fires.

![Associating a trigger to the template](https://user-images.githubusercontent.com/30706016/128259753-938464b6-fe65-4b43-90c3-1dba7f754865.png)

* Select the "Consent Initialization" trigger.

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

* Save the tag. This is where you will choose the default values for the consent mode parameters.

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

### Setting Default Consent Values by Region

The Didomi GTM template allows you to configure default consent states for different regions, ensuring compliance with various privacy regulations while optimizing user experience.

**Regional Default Behavior**

The template includes pre-configured regional settings that align with Didomi's regulation logic:

* GDPR regions are set to denied by default, including:
  * EU countries: AT, BE, BG, CY, CZ, DE, DK, EE, ES, FI, FR, GR, HR, HU, IE, IT, LT, LU, LV, MT, NL, PL, PT, RO, SE, SI, SK
  * Other GDPR-regulated territories: AD, BR, GB, GF, GG, GI, GP, IS, JE, LI, MC, MF, MQ, NO, RE, SM, VA, YT
* Non-GDPR regions: Default behavior depends on the global configuration option

**Global Configuration Option**

Use the "Set all GCM purposes to GRANTED by default - for all regions except EU" checkbox to control the default consent behavior:

* When enabled:
  * GDPR regions are denied by default
  * Non-GDPR regions are granted by default.
* When disabled: All regions are denied by default (legacy behavior)

**Custom Regional Overrides**

For more granular control, you can override default settings for specific regions using the parameter table:

1. Region field: Enter ISO 3166-2 region codes (e.g., "US-CA, US-CO" for California and Colorado)
2. Leave blank: To apply settings to all regions not covered by other entries
3. Consent types: Set individual consent states for each Google Consent Mode purpose

The template processes these overrides in order, with later entries taking precedence over earlier ones.

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

### Embedding the Didomi Web SDK from the GTM template

The template's UI will give you the option of embedding the Didomi Web SDK from within the template:

<figure><img src="/files/Lr7yflsAsJYAen5EONkX" alt=""><figcaption><p>Embedding Didomi's SDK via the GTM template</p></figcaption></figure>

While the template can embed the SDK directly on your website, we do not recommend this setup in production as it delays loading the Web SDK and subsequent tags that depend on it like advertising, analytics, etc. We are leaving the option available for testing purposes. Embedding the Didomi SDK through GTM will result in fewer consents being passed to vendors and a lower consent rate from their perspective.

We recommend embedding the Web SDK directly into the source code of your website for the best performance. By being directly in the source code of your website, the Didomi Web SDK can load faster and also ensures that IAB vendors can detect a CMP on the page as soon as possible.

{% hint style="danger" %}
When embedding the Didomi Web SDK directly in the code of your website, make sure that the "Embed the Didomi Web SDK" option on the template is disabled.
{% endhint %}

#### Embedding the Web SDK configuration

Once you have enabled the "Embed the Didomi Web SDK" option, the UI will change as follows.

\
A quick note on the fields,

<figure><img src="/files/9CSdBweEdeuXr3ZdJnTo" alt=""><figcaption></figcaption></figure>

* **Public API key:** Required field. It must be a valid UUID value.
* **Notice ID:** Optional field. Setting its value would be the equivalent to configuring "Manual Targeting" in the Didomi console. Leaving it blank would be the equivalent to "Domain Targeting" in the Didomi console.
* **Enable IAB TCF support:** Enable this option if the IAB TCF is enabled for your consent notice in the Didomi Console. See [here](https://docs.didomi.io/consent-management-platform-cmp/frameworks-regulations/iab-tcf) for more information.

### Preview

In order to test the tag on a website, you can make use of the "Preview" feature of the GTM platform. You can find a "Preview" button at the top right of the GTM navbar menu.

![](/files/-Mi2_bqe-gJThiaP1Blb)

You will be prompted by the following screen where you can set up the URL of your website.

![This example uses https://sandbox.didomi.io/gtm.html](https://user-images.githubusercontent.com/30706016/128261167-d8dc858c-5502-4583-83c3-cdd2a4d04945.png)

Clicking continue opens the "Tag Assistant" website. This assistant is a live tool that can help tremendously with debugging your tags and/or templates.

You can see that the tag being previewed is in fact being fired during the initial load of the site.

![Didomi CMP Test is the name of the tag used in this example](https://user-images.githubusercontent.com/30706016/128379448-39b95cfe-8334-4715-aae3-da03badd94b8.png)

### Submit

Once the testing/previewing process has been successful, you can "Submit" a tag to a website so that it goes live.

In this case, click on the "Submit" button at the top right of the GTM nav bar menu (to the right of the "Preview" button).

### Debugging

You can check whether "hits" are being correctly transmitted to Google or not. To do so, go to the DevTools/Network tab, filter by "collect" and look for the `gcs` parameter (as shown in the image below).

![](/files/-Mi2SNHexPCvxelWBMdx)

You will find a value for the parameter (G111 in this case). It can be understood as follows:

* G1: This initial value is always the same.
* The following digit (0 or 1) refers to `ad_storage`.
* The third number (0 or 1) refers to `analytics_storage`.

For both cases 0 means **“denied”** and 1 means **“granted”**.

In our case, **G111** means that marketing and statistics cookies have both received consent.

{% hint style="danger" %}
If you're previewing and/or have submitted our GTM template to your site and the `gcs` parameter values don't match, please make sure to enable the following vendor IDs via the DIDOMI console: `google`, `googleana-4TXnJigR`
{% 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://developers.didomi.io/cmp/web-sdk/third-parties/tags-management/tag-managers/google-tag-manager/didomis-gtm-template.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.
