Multilingual support when using Google Tag Manager

When you operate a multilingual website and would like to have the cookie banner displayed in the same language as your website (E.g. English for “mywebsite.com/en” and Spanish for “mywebsite.com/es”) you can use the data-culture attribute.

While this can be achieved in multiple ways, you may for example create a Custom JavaScript Variable named “Current Language” that returns a two-letter ISO language code based on custom logic. In this example, the language is set to either French or Spanish and will default to English, depending on the path of the URL that the user is currently visiting on your website:

<script>
var CookieConsentScriptContainer = document.getElementsByTagName('script')[0];
var CookieConsentScript = document.createElement("script");
CookieConsentScript.type = "text/javascript";
CookieConsentScript.id = "CookieConsent";
CookieConsentScript.src = "https://consent.cookiebot.com/uc.js?cbid=00000000-0000-0000-0000-000000000000";

var currentUserPagePathname = location.pathname.toLowerCase();
var currentUserPageCulture = "en";  //default to english

if (currentUserPagePathname.indexOf("/fr")==0)
{
currentUserPageCulture = "fr";
}
else if (currentUserPagePathname.indexOf("/es")==0)
{
currentUserPageCulture = "es";
}

CookieConsentScript.setAttribute("data-culture", currentUserPageCulture);
CookieConsentScriptContainer.parentNode.insertBefore(CookieConsentScript, CookieConsentScriptContainer);

function CookieConsentCallback_OnAccept() {
if (CookieConsent.consent.preferences)
dataLayer.push({'event':'cookieconsent_preferences'});
if (CookieConsent.consent.statistics)
dataLayer.push({'event':'cookieconsent_statistics'});
if (CookieConsent.consent.marketing)
dataLayer.push({'event':'cookieconsent_marketing'});
}
</script>

Don’t forget to replace cbid=00000000-0000-0000-0000-000000000000 with your own code.

30 day free trial Cookiebot

Cookie scanner, cookie banner, cookie declaration en cookie consent in one solution.

  • Use cookies on your website compliant with GDPR, ePrivacy and cookie legislation
  • Cookie management completely automated
  • Cookie banner based on your corporate identity
  • Automatic composed cookie declaration, always up to date

The Cookiebot solution runs on 500,000+ websites, manages 13 billion User Consents and supports 40+ languages.