Configure the Didomi / GTM integration
Last updated
Last updated
Events and variables used by GTM are detailed in this documentation.
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=[];
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 GDPR 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.
Make sure that our SDK is setup
Before continuing, please read our section on setting up our SDK 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.
Enable the GTM integration in the Integrations tab of your consent notice by selecting this box:
By default, Didomi uses the name “dataLayer” as the variable name for your GTM data layer.
If you are using another name for your data layer, 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).
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.
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:
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
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 for the list of all variables that are pushed to GTM by the Didomi SDK.
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:
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 (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.
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
.
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, 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
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 and events. And in the specific context of a SPA, you can refer to our dedicated GitHub page.
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.
This trigger (or trigger group) can now be used to define tags that fire only when the user has given consent for that vendor.
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.
If enabling Google Consent Mode via our GCM direct integration, 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.
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.
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.
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 for more details.