GTM template for Didomi
This template integrates with GTM Consent APIs to allow consent mode and settings in Tag Manager. It is part of the Tag Manager Community Template Gallery.
- Didomi clients
- Developers
The idea behind enabling and using GTM templates is to share with all Didomi clients a proven and more frictionless way to interact with Google Consent Mode. This template allows Didomi's clients to create a tag with a simple upload process, so that their websites have Google Consent Mode enabled.
To better understand how to setup and enable GTM within Didomi's SDK, please refer to https://developers.didomi.io/cmp/web-sdk/third-parties/custom-integrations/tag-managers/google-tag-manager
The official GTM documentation regarding templates can be found here https://developers.google.com/tag-manager/templates
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.
After accessing your Google Tag Manager account and selecting a workspace (we use the Default Workspace for testing purposes),
- Click the "New Tag" button as shown here,
Or navigate to the "Tags" tab, and click on the "New" button at the top right side of the tags table.
- Use a relevant name for the new tag ("Didomi CMP" was used for this example) and hit the "Tag Configuration" card.
- 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.
At this point you should have access to the template UI - which includes two checkboxes to set the desired default status for GCM.
We want our tag to be fired on all pages. In order to achieve that,
- Click on the "Triggering" card to choose a trigger so that the tag fires.
- Select the "All pages" trigger
- Save the tag. Here it is where you will choose the default values for Analytics and Ad storage
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 nav bar menu. Note that for the example above, three tags are active("Analytics Demo", "Didomi CMP Test" and Google Analytics GA4 configuration") and one tag is paused("Track Consent Value")
You will be prompted the following screen where you can setup the URL of the website you can to test the tag on. We used https://sandbox.didomi.io/gtm.html for our tests. Clicking continue opens the "Tag Assistant" website.
The tag assistant is a live tool that can help tremendously with debugging your tags and/or templates.
We can see that the tag we created is in fact being fired during the initial load of the site.
Once the testing/previewing process has been sucessful, 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.
Unit tests can be written and run per template. You will find a "Tests" tab in the Template Editor where you can do so.
A sucessfully ran test-suite looks like this
You can follow this documentation to better understand unit testing for templates https://developers.google.com/tag-manager/templates/tests
And these are the Test APIs that work with GTM Sandboxed Javascript https://developers.google.com/tag-manager/templates/api#test_apis
If you need to load a template.tpl
of this repo into GTM,
-
Get a copy of this repo on your local environment.
-
Go to the "Templates" tab and click on "New"
- At the top right of the template editor menu, choose "Import"
- Navigate to the
template.tpl
file in your local environment. Click "save" and then "continue".
The template should load correctly,
Everytime the template.tpl
is updated and you would want the Community Template Gallery version to reflect those changes, the medatada.yaml
file should also be updated. The sha
value must reference the specific template.tpl
file that you want to publish. Don't forget to update this value correctly with every new version!
See https://developers.google.com/tag-manager/templates/gallery#metadatayaml
After the metadata.yaml
file has been updated, the gallery version of the template will reflect any changes within 2 to 3 days typically. The template users will be notified of said changes and they will have the option of automatically update to the latest version.
See https://developers.google.com/tag-manager/templates/gallery