Cookiebot multilingual support in combination with 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.