Notification

The Google Analytics: GA4 Configuration tag is now the Google tag. GA4 Configuration tags in a web container will be automatically migrated starting in September. There are no changes to your existing measurement and there is no action required from you. Learn more

Set up TrustArc to obtain user consent

To capture valuable insights while protecting user privacy, you need to collect consent from your website users. We recommend you use a Consent Management Platform (CMP) or work with your Content Management System (CMS) to collect consent and send it to Google.

Step 1: Set up a consent banner

  1. If you have CCM Advanced (Managed Service), your Technical Account Manager (TAM) will set up your banner following your requirements and style guidelines.
  2. If you have CCM Pro (Self-Service CMP), TrustArc will provide you with the URL to sign in to the portal and configure your banner using the predefined templates in the wizard.
  3. Ensure that your banner complies with the requirements in the Google EU User Consent Policy (EUUCP). For more details on TrustArc banner setup, see the Getting Started section in our User Guide.
  4. Include the <div> elements, responsible for rendering the banner and the CMP link, in your website code or via Google tag manager.

Step 2: Set up consent mode

Using Google Tag Manager

  1. Open Tag Manager and navigate to your container.
  2. In “Tags”, click New, and name the tag.
  3. Click Tag Configuration, then click Discover more tag types in the Community Template Gallery. From the gallery, search for “ TrustArc CMP (Consent Mode)”, then install “TrustArc CMP (Consent Mode)” by TrustArc.
  4. Configure the default settings you would like to use under “Default Consent Mode settings”.
  5. Select the Deploy CMP Script using the template option.
    1. In the CMP ID field, enter the instance ID available in Step 4. Copy Code Snippet of the CCM Pro portal. If you have a CCM Advanced, the TAM can provide you with that information.
    2. In the Additional parameters field, enter additional settings for your instance. This configuration is used to override the backend configurations like language, geo detection, privacy policy links, etc.
  6. Set up the Google Consent Mode Integration by enabling the Integrate CMP with Google Consent Mode option.
  7. Inform the mapping for the consent types and the user’s preferences according to your settings. For each consent type you are using, map to the corresponding ID of the cookie consent bucket (Required, Functional, Advertising). In the Preferences Cookie field, map a first-party cookie for cmapi_cookie_privacy. In the Behavior Cookie field, map a first-party cookie for notice_behavior.
  8. Click Triggering > Consent Initialization - All Pages > Save.
  9. Test your container by clicking Preview in the top right corner (see the testing instructions below).
  10. Publish your container.

Using Other Platforms or Directly Editing Website Code 

  1. Log in to the TrustArc Support portal, open the TrustArc Google Consent Mode Implementation Guide from this link, then follow the instructions in the Integrating the Consent Mode Using JavaScript​​ section.
  2. If you use a website builder, review their documentation to find out how to implement the code in the head tag of each page. Otherwise, skip to step 3.
  3. If you are using the CCM Advanced version, please follow this step. Otherwise, skip to step 4. In the head tag of each page (refer to step 2 if you use a website builder), copy and paste the code below, followed by the CMP script you copied in step 1 at the very top of the head tag. Note that this is critical in order to ensure the CMP functions properly.

    <script>

    window.dataLayer = window.dataLayer || [];

    function gtag(){dataLayer.push(arguments);}

     

    gtag('js', new Date());

    gtag('config', 'AW-YYYYYY');

     

    // Default consent types to 'denied' as a placeholder

    // Determine actual values based on your own requirements

    // Please omit consent types not being used

    gtag('consent', 'default', {

    'ad_storage': 'denied',

    'ad_user_data': 'denied',

    'ad_personalization': 'denied',

    'analytics_storage': 'denied',

    'functionality_storage': 'denied',

    'personalization_storage': 'denied',

    'security_storage': 'denied',

    'wait_for_update': 500

    });

    gtag('set', 'ads_data_redaction', true);

    gtag('set', 'developer_id.dNTIxZG', true);

    </script>

    <!--Banner script here!-->

  4. If you are using the CCM Pro version, please follow this step. In the head tag of each page (refer to step 2 if you use a website builder), copy and paste the code below, followed by the CMP script you copied in step 1 at the very top of the head tag. Note that this is critical in order to ensure the CMP functions properly. Please make sure to adjust the association between the CMP buckets and the consent types.

    window.dataLayer = window.dataLayer || [];

    function gtag() { dataLayer.push(arguments); }

    gtag('js', new Date());

    gtag('config', 'GA_MEASUREMENT_ID');

    gtag('set', 'developer_id.dNTIxZG', true);

    // TODO: Can be changed according to customer's need and according to the configuration

    gtag('set', 'ads_data_redaction', true);

    gtag('set', 'url_passthrough', true);

    //Consent Mode Status

    const ConsentType = {

    DENIED: 'denied',

    GRANTED: 'granted',

    };

     

    const convertBooleanToGrantedOrDenied = (boolean) => boolean ? ConsentType.GRANTED : ConsentType.DENIED;

     

    /*

    TODO: This is where you can configure the Google Consent Mode, map the CMP categorisation and the default values for the consent initialization

    Google recommends commenting our consent types that you are not going to use.

    */

    const domain = 'your_domain.com'; // TODO: update

    // Bucket Mapping

    const REQUIRED = 1;

    const FUNCTIONAL = 2;

    const ADVERTISING = 3;

    const consentTypesMapped = {

    'ad_storage': ADVERTISING,

    'ad_user_data': ADVERTISING,

    'ad_personalization': FUNCTIONAL,

    'analytics_storage': FUNCTIONAL,

    'functionality_storage': FUNCTIONAL,

    'personalization_storage': FUNCTIONAL,

    'security_storage': REQUIRED

    }

    const getConsentState = (prefCookie) => {

    var consentStates = {};

    var noticeBehavior = window.truste.util.readCookie("notice_behavior");

    /*

    TODO: Can be changed according to customer's need and according to the configuration

    */

    var impliedLocation = noticeBehavior && noticeBehavior.includes("na");

    for (const consentType in consentTypesMapped) {

    var id = consentTypesMapped[consentType];

     

    if(prefCookie && !prefCookie.includes(0)) {

    console.log("Existing consent..");

    consentStates[consentType] = convertBooleanToGrantedOrDenied(prefCookie && prefCookie.includes(id));

    } else {

    console.log("Non Existing consent..");

    consentStates[consentType] = convertBooleanToGrantedOrDenied(impliedLocation);

    ;}

    ;}

    consentStates['wait_for_update'] = 500;

    console.log(consentStates);

    return consentStates;

    };

    /*

    Helper function to submit a GCM event based on user's preferences on TrustArc's Script

    consent: The consent object will be an array of values [1, 2, 3, n] as 1 being if the user consented to required, 2 to function, ... etc

    This function needs to be customized according to the customer's needed mapping. Ex: 'ad_storage': returnGrantedOrDenied(advertisingAccepted) is being mapped to advertising. if we were to map it to functional instead, we just need to change the bucket variable it's looking at. 

    */

     

    var runOnceGCM = 0;

    function handleConsentDecisionForGCM(consent) {

    //This code initializes the consent mode

    const consentStates = getConsentState(consent.consentDecision);

    var defaultOrUpdate;

    if (runOnceGCM == 0) {

    defaultOrUpdate = 'default';

    runOnceGCM++;

    } else {

    console.log('consent is being updated');

    defaultOrUpdate = 'update';

    }

    console.log(consentStates);

    //Once consent is changed, we will send an update 

    gtag('consent', defaultOrUpdate, {

    consentStates

    });

    }

     

    // This code is responsible for listening to any consent changes trough TrustArc's CCM Instance

    // And pushing the consent changes to the dataLayer according to the customer's consent mapping

    // This is for the intial load. If the user has a consent different from the default values, this is to push an update to the datalayer 

    // Once the CCM loads. 

    var interval = setInterval(() => {

    if (window.truste) {

    var consentDecision = truste.cma.callApi("getGDPRConsentDecision", domain);

    handleConsentDecisionForGCM(consentDecision);

    clearInterval(interval);

    console.log("running once...");

    }

    }, 100);

     

    // Start listening to when users submit their preferences  

    window.addEventListener("message", (event) => {

    let eventDataJson = null;

    // We only care about TrustArc Events at this point. And TrustArc's even it encoded in JSON

    try {

    eventDataJson = JSON.parse(event.data);

    } catch {

    // Some other event that is not JSON. 

    // TrustArc encodes the data as JSON

    // console.log(event.data);

    }

     

    // Safeguard to make sure we are only getting events from TrustArc

    if (eventDataJson && eventDataJson.source === "preference_manager") {

    // Means that the user has submited their preferences

    if (eventDataJson.message === "submit_preferences") {

    console.log("Event Data: ", eventDataJson);

    // Waiting half a second to make sure user's preferences are reflected. 

    setTimeout(() => {

    var consentDecision = truste.cma.callApi("getGDPRConsentDecision", domain);

    console.log("Consent Decision: ", consentDecision);

    handleConsentDecisionForGCM(consentDecision);

    }, 500);

    }

    }

    }, false);

    <!--Banner script here!-->

Testing using Tag Assistant

Learn more about how to Troubleshoot consent mode with Google Tag Manager.

Was this helpful?

How can we improve it?
Search
Clear search
Close search
Main menu
15831114289437338429
true
Search Help Center
true
true
true
true
true
102259
false
false