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.
- Didomi Events
didomi-consent: when page has loaded, and when there is a change in consent
didomi-ready: when the page is loadeddidomi-consent-changed: when there is a change in consent
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.
- Didomi Variables
Didomi events will generate Didomi variables in the GTM Data Layer.
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)
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.
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.
Integration
To get started, you need to activate the GTM integration when you set up your consent notice.- Go to Consent notices (1) and click to edit your notice.
- Go to step 2. Customization (2) and the Integrations tab (3).
- Make sure you are in the Tag Managers section (4).
- Scroll down to select the Google Tag Manager integration.
- In the Data Layer Name field, write the name of your data layer.
- The standard name "dataLayer" is used by default.
- If you keep the standard name you can leave the field as is.
- If you chose a new name, you can see it in the code of your website (ask your tech team).
- If you didn't use the Console to create your consent notice, add this in the object didomiConfig:
tagManager: {
provider: 'gtm'
} - Do not add this code if you have checked the box in the console.
Create a variable
- 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. - Click on Folders in the left menu.
- Click on New Folder.
- Name your folder "Didomi".
- Click on the three dots to the left of the Didomi file.
- Click on Add a variable.
- 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
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:
- Click on Folders in the left menu.
- Click on the three dots to the right of the Didomi file.
- Click on Add New trigger.
- Enter this information:
Name of the trigger: "{Vendor name} – Didomi", for example
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 (didomi-consent, didomi-ready or didomi-consent-changed). We recommend using didomi-consent.
"Conditions in which the trigger can be executed" and select “Some custom events”.
"Fire this trigger when an event occurs and all of these conditions are true": Didomi Vendors Enabled contains {ID vendor}
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.
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" so that the tag is activated when condition 1 (the existing one) and condition 2 (the one linked to consent) both meet.
👉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).
To create a group of triggers:
- Click on Folders in the left menu.
- Click on the three dots of the Didomi file, and Add new trigger.
- Enter this information:
Name of trigger group: "Group of triggers – Consent + {name of the other condition} - {vendor name}", for example
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 , to the right of Triggers.
Select the existing trigger for your tag.
Click on again.
Select the Didomi trigger matching the vendor, previously created (cf. previous step). - 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.
Trigger groups are triggered once per page only. This can be problematic when using dynamic websites. In such case, you can use Didomi functions and events. Specifically for SPA, please refer to our dedicated GitHub page.
Where to find the vendor ID?
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 .
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:
- Click on one of your existing tags for a non-IAB vendor.
- Add the trigger or the group of triggers (created previously) matching with the vendor of the tag, instead of the trigger used previously.
- Save.
⚠️ Repeat for EACH of the existing triggers for non-IAB vendors.
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.