Cookie Callback Function for Google Consent Mode.

Cookie Callback Function for Google Consent Mode

Instructions

Step 1:

Turn on Google Consent mode in admin settings of Google Tag Manger

Step 2:

Replace the first script of the TRUENDO Tag (The one without the Site-ID) with the script below.

Step 3:

Set the Trigger for the TRUENDO Tag to Consent Initiation.

Step 4:

Tags must trigger at least as late as dom DOMready (So a for ex. All pages trigger have to be changed to DOMready Triggers)

Note: While the default google categories of ad_storage –> Marketing and analytics_storage –> Statistics are mapped the other google categories are not (at least not in way that makes sense). TRUENDO has also added custom categories that can be applied to tags.
Important: Google Consent Mode does not work with the TRUENDO auto-blocking feature. Please adjust the TRUENDO script id from id="truendoAutoBlock" to id="truendoPrivacyPanel". See link for more details.

Find more Information in the Google Consent Mode Documentation:
Google Consent Mode (Beta) Docs
Manage user Privacy
Adjust tag behavior based on consent\

Callback example

<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
  dataLayer.push(arguments);
}

// set „denied' as default for both ad and analytics storage,
gtag("consent", "default", {
  ad_storage: "denied",
  analytics_storage: "denied",
  preferences: "denied",
  social_content: "denied",
  social_sharing: "denied",
  wait_for_update: 2000, // milliseconds to wait for update
});

// Enable ads data redaction by default [optional]
gtag("set", "ads_data_redaction", true);

// Get Cookie as object
let truCookie;

function TruendoCookieControlCallback(cookieObj) {
  if (cookieObj.preferences) {
    dataLayer.push({ event: "truendo_cc_preferences" });
    gtag("consent", "update", {
      preferences: "granted",
    });
  } else {
    gtag("consent", "update", {
      preferences: "denied",
    });
  }
  if (cookieObj.marketing) {
    dataLayer.push({ event: "truendo_cc_marketing" });
    gtag("consent", "update", {
      ad_storage: "granted",
    });
  } else {
    gtag("consent", "update", {
      ad_storage: "denied",
    });
  }
  if (cookieObj.statistics) {
    dataLayer.push({ event: "truendo_cc_statistics" });
    gtag("consent", "update", {
      analytics_storage: "granted",
    });
  } else {
    gtag("consent", "update", {
      analytics_storage: "denied",
    });
  }
  if (cookieObj.social_content) {
    dataLayer.push({ event: "truendo_cc_social_content" });
    gtag("consent", "update", {
      social_content: "granted",
    });
  } else {
    gtag("consent", "update", {
      social_content: "denied",
    });
  }
  if (cookieObj.social_sharing) {
    dataLayer.push({ event: "truendo_cc_social_sharing" });
    gtag("consent", "update", {
      social_sharing: "granted",
    });
  } else {
    gtag("consent", "update", {
      social_sharing: "denied",
    });
  }
}
</script>