Other tag managers

This section explains how to integrate Didomi with any tag manager that we do not have a direct integration with. This allows you to to use consent information in rules when deciding whether a tag can be loaded or not directly from your tag manager.

Events and variables are detailed in this documentation.

Overview

Didomi stores variables on the window.didomiState object with the consent information from the user. A custom tag manager integration requires passing that consent information to the data layer of the tag manager, to be able to create tag-loading rules based on the user consent status.

With this guide, you will:

  • Pass consent information from Didomi to the data layer of your tag manager

  • Create rules in your tag manager to only load tags when consent is granted

  • Delay loading of your tag manager and/or tags that require consent

Configure the integration

Step 1 - Website configuration

Option A - Dynamic data layer - Update the data layer on your website

If your tag manager supports dynamically passing variables to the data layer after page load, this is the best option to leverage as you will not need to delay your tag manager initialization.

The Didomi SDK stores a copy of the user consent status in variables on the window.didomiState object. To get started, update the data layer on your website to pass variables from Didomi to your tag manager after the Didomi SDK is ready:

<script type="text/javascript">
window.didomiOnReady = window.didomiOnReady || [];
window.didomiOnReady.push(function (Didomi) {
    window.updateDataLayer({      
      // Didomi variables  
      didomiRegulationName: window.didomiState.didomiRegulationName,
      didomiVendorsEnabled: window.didomiState.didomiVendorsEnabled,
      didomiVendorsDisabled: window.didomiState.didomiVendorsDisabled,
      didomiVendorsUnknown: window.didomiState.didomiVendorsUnknown,
      didomiPurposesEnabled: window.didomiState.didomiPurposesEnabled,
      didomiPurposesDisabled: window.didomiState.didomiPurposesDisabled,
      didomiExperimentId: window.didomiState.didomiExperimentId,
      didomiExperimentUserGroup: window.didomiState.didomiExperimentUserGroup,
      didomiGDPRApplies: window.didomiState.didomiGDPRApplies,
      didomiIABConsent: window.didomiState.didomiIABConsent,
      
    };
});
</script>

updateDataLayer is an example function name. Your tag manager will have its own way of passing custom variables to the data layer dynamically.

Notice how the data layer is updated in a didomiOnReady handler. This guarantees that the Didomi consent status is available in the didomi* variables when the data layer for your tag manager gets updated.

Option 2 - Static data layer - Update the data layer on your website

Some tag managers load variables into the data layer only on page load and do not have an option to dynamically pass variables later in the page lifecycle. As a result, you will need to update your website configuration to delay loading the tag manager and set the dataLayer variable only after Didomi is loaded on the page.

The Didomi SDK stores a copy of the user consent status in variables on the window.didomiState object. To get started, update your dataLayer JavaScript on your website to pass variables from Didomi to your tag manager after the Didomi SDK is ready:

<script type="text/javascript">
window.didomiOnReady = window.didomiOnReady || [];
window.didomiOnReady.push(function (Didomi) {
    window.dataLayer = {
      // Keep your existing variables here
      firstVariable: 'content',
      secondVariable: 'content',
      ...
      
      // Add Didomi variables
      didomiRegulationName: window.didomiState.didomiRegulationName,
      didomiVendorsEnabled: window.didomiState.didomiVendorsEnabled,
      didomiVendorsDisabled: window.didomiState.didomiVendorsDisabled,
      didomiVendorsUnknown: window.didomiState.didomiVendorsUnknown,
      didomiPurposesEnabled: window.didomiState.didomiPurposesEnabled,
      didomiPurposesDisabled: window.didomiState.didomiPurposesDisabled,
      didomiExperimentId: window.didomiState.didomiExperimentId,
      didomiExperimentUserGroup: window.didomiState.didomiExperimentUserGroup,
      didomiGDPRApplies: window.didomiState.didomiGDPRApplies,
      didomiIABConsent: window.didomiState.didomiIABConsent,
    };
});
</script>

dataLayer is an example variable name. Your tag manager will have its own naming for data layer variables.

Notice how the dataLayer variable is defined in a didomiOnReady handler. This guarantees that the Didomi consent status is available in the didomi* variables when the external variables for your tag manager get registered.

Step 2 - Delay initializing your tag manager

If you are using a static data layer, you will need to delay the initialization of your tag manager to make sure that the user consent status is available in the data layer when tags get evaluated and loaded.

If you are using a dynamic data layer, you usually do not need to implemented this step.

Didomi creates the window.didomi* variable when the SDK is done loading. You must delay your tag manager until Didomi is ready or the variables holding the consent status will be undefined.

To delay your tag manager, update your <script> tags that load your tag manager to execute after Didomi is loaded. For instance:

<script type="text/javascript" src="/path/to/tagmanager.js"></script>

becomes:

<script type="didomi/javascript" src="/path/to/tc_script.js"></script>

Notice how we replaced the script type text/javascript with didomi/javascript. This will ensure that your tag manager only gets included after Didomi is ready.

Read our documentation for more information on this feature.

Step 3 - Create rules in your tag manager

Now that your data layer is setup, you are able to access the user consent status collected by Didomi in your tag manager.

You need to create rules on your tags that require consent to only load after consent is given by the user. How to do that depends on your tag manager and we can only provide a generic outline of the setup.

Generally, you will create rules that depend on the didomiVendorsEnabled and that constrain a tag to be loaded only if that variables contains a specific value indicating that the user has given consent for that vendor.

For instance, if you want to load Google Ads only if the user has given consent to the vendor Google, you will create a rule that only embeds ads into the page if the didomiVendorsEnabled data layer variable contains "google,".

Last updated