Google Tag Manager (GTM)

Steps to implement TrustCommander with Google Tag Manager.

TrustCommander provides a plug-in to integrate with Google Tag Manager. The setup requires technical installation steps.

⚠️ This method to integrate GTM is outdated. See the page “Consent Mode in GTM” for a smoother integration.

Setup

Following you will find the required steps to implement a standard TrustCommander setup.

  1. Choose the default account configuration mode for your account (see Options).

  2. Setup your TrustCommander categories & vendors (see Manage Categories).

  3. Create one or multiple banner templates (see Manage Banner)

  4. Deploy your TrustCommander banner templates to the Commanders Act CDN or on premise target (see Deploy Banner).

  5. Install TrustCommander tag (see below)

  6. Manage GTM tags with TrustCommander (see below).

Install TrustCommander tag

To install TrustCommander with Google Tag Manager you need to add following JavaScript tag to your website. This snippet can be added in the <head> of the website or via a custom HTML tag in Google Tag Manager.

<script type="text/javascript">
    var tCPrivacyTagManager = "gtm";
</script>
<script type="text/javascript" src="{{ privacy_tag_url }}"></script>

tCPrivacyTagManager hast to be set to "gtm". This variable allows TrustCommander to send privacy settings to GTM. It will push a tcConsentChanged event to the GTM data layer that includes the privacy settings of a visitor in the tcCategoriesConsent variable. The event is pushed as soon as TrustCommander loads on a page and in case a visitor updates his privacy settings.

{{ privacy_tag_url }} has to be replaced with your privacy JavaScript tag URL. This URL can be found in the GENERATE & DEPLOY tab of each privacy banner.

Manage GTM tags with TrustCommander

Add tag triggers in Google Tag Manager

Field

Value

Variable name

Label that the consent variable has in the GTM interface (recommended: tcCategoriesConsent)

Variable Type

Data Layer Variable

Data Layer Variable Name

tcCategoriesConsent

Data Layer version

Choose the latest data layer version available

Create a new Trigger for each TrustCommander category and sub-category. These trigger can then be used to only fire your tags when a visitor accepts a certain TrustCommander category. Create each trigger with following settings:

Field

Value

Trigger name

Label of the Trigger in the GTM interface (recommended to use TrustCommander category name like "Retargeting category").

Trigger Type

Custom Event

Event name

tcConsentChanged

This trigger fires on

Some Custom Events

Fire this trigger when an Event occurs and all of these conditions are true

tcCategoriesConsent containsID of the related TrustCommander category.

Call the Privacy banner

Visitors will be able to activate or deactivate only sub-categories and not the main category in the banner. In case a category has sub-categories then you have to use the sub-category ID instead of the category ID to play out tags.

There are 4 steps to add triggers to tags in Google Tag Manager (GTM).

In the GTM interface, "Variables" tab, create a custom variable to calculate the status of the consent given by the user: no consent, optout, optin or partially optin. Create a "User Defined" variable.

  • Variable name: tcCategoriesConsent (the name that will appear in your interface, so you can choose another name)

  • Variable Type: "Data Layer Variable"

  • Data Layer Variable Name: tcCategoriesConsent (the variable used by Commanders Act Privacy when you add tCPrivacyTagManager = "gtm" in the website’s source code)

  • Data Layer version: choose the latest data layer version available

function(){
    if (typeof tC.privacy == "undefined") {

        var cookieName = "TC_PRIVACY=";
        var cookieSeparator = "@"

        var privacyCookie = "";
        var cookieCategoryName = cookieName+"_CENTER=";
        var cookieData = null;
        var categories = null;
        var decodedCookie = decodeURIComponent(document.cookie);
        var ca = decodedCookie.split(';');

        for (var i = 0; i <ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(cookieName) == 0) {
                privacyCookie = c.substring(cookieName.length, c.length);
            } else if (c.indexOf(cookieCategoryName) == 0) {
                categories = c.substring(cookieCategoryName.length, c.length);
            }
        }

        if (privacyCookie === "") {
            return "no_consent";
        } else if (privacyCookie) {
            cookieData = privacyCookie.split(cookieSeparator);
        } else {
            cookieData = [];
        }

        var optType = parseInt(cookieData[0] || 0);

        if (categories == "ALL") {
            if (optType === 1) {
                return "optout";
            } else {
                return "all_consent";
            }
        }

        return optType === 0 && categories != -1 ? categories : "optout";
    }

    if (tC.getCookie(tC.privacy.getCN()) === "")  {
        return "no_consent";
    } else if (tC.privacy.getOptinCategories().join(",") === ""){
        return "optout";
    } else {
        return tC.privacy.getOptinCategories().join(",");
    }
}

Important: to facilitate the implementation of Privacy rules on your tags that may already have other triggers in place, we recommend that you work with an "exception" logic and follow the implementation process explained below. The logic is to create rules that will not trigger the tag if the category is denied rather than rules that will trigger it if the category is valid.

Configure the trigger as follows:

  • Trigger name: Retargeting category (this name depends on the category names that you create and the name that you want to be displayed on your interface)

  • Trigger Type: "Custom Event"

  • Event name: tcConsentChanged (this is the event sent by the Commanders Act Privacy when you use tCPrivacyTagManager = "gtm" in your website’s source code)

  • This trigger fires on: "Some Custom Events"

  • Fire this trigger when an Event occurs and all of these conditions are true: pick the tcCategoriesConsent variable created in the previous step, the operator “equals” (or “contains”), and the name of the category as you declared it in the Commanders Act Privacy interface.

Be careful when you create sub-categories associated to a category: you have to enter the sub-category ID and not the category ID in the Trust commander values, as the user will be able to activate or deactivate only sub-categories and not the main category in the banner:

Be careful in case you use more then 9 categories and sub-categories. In this case there can be a confusion between e.g. category "2" and category "12" as "2" is included in "12". In this case we recommend to only use category IDs above 10. We are working on an improvement to resolve this.

  • Name of the trigger: "trust_commander".

  • Trigger Type: "Custom Event"

  • Event name: "trust_commander"

  • This trigger fires on: "All Custom Events"

In the "Triggers" section, start by creating the following trigger that allows you to not activate the tags if the user has not yet given his consent :

If you want your site to be in "default optout" mode (blocking of tags when the visitor arrives on your site, in accordance with the General Data Protection Regulations, the GDPR), you must also make the following configuration.

Then create a custom tag that you will trigger on all pages (this is the TrustCommander event listener) in the "Tags" section:

  • Name of the tag: "Trust commander event listener"

  • Trigger Type: "Custom HTML"

  • HTML: copy and paste the following code :

<script>
//No choice expressed by the user yet
if({{Trust commander values}} === "no_consent"){
window.tc_closePrivacyButton = window.tc_closePrivacyButton || function (){
window.dataLayer.push({"event":"trust_commander"});  
}
window.tc_closePrivacyCenter = window.tc_closePrivacyCenter || function (close_type){
if(close_type !== "cross"){  
window.dataLayer.push({"event":"trust_commander"});  
}  
}
} 
//Choice already expressed
else{

}
</script>  
  • Triggering : "All pages"

In the GTM interface, in the Tags section, assign the previously created trigger to your tags to fire them based on the TrustCommander categories. These triggers will replace your normal "pageview" trigger.

Last updated