Cookie Consent language depending on page content language

Rookie Contributor

We need the Cookie Consent Banner content to be either in German, French, Italian or English depending on what version of the page the user is on—not depending on the browser's language. For example if my primary browser language is English, but I'm on the French version of the site, I want the French version of the banner content shown, not the English one. Can this be achieved in any way?


Cookie Consent language depending on page content language

Bronze Contributor
Bronze Contributor


yes this can be achieved.

Tealium consent has a method utag.gdpr.getLanguage which is used to determine language of the site (by default it's a browser language).


To override default behaviour you have to do next:

1. Create a Javascript Extension with scope All Tags and Execution value Before Load Rules

2. Insert custom code so that language corresponds to the site language

    The example below is detecting language from the URL but it can be adjusted to use a cookie instead.

/*URL based Consent Language */
utag.gdpr.getLanguage = function(promptData) {
  var url = window.location.href;

  var langMappingURLToTealium = {
    'pl': 'pl', 
    'ru': 'ru'
  var langArray = ['en', 'cz', 'de', 'it', 'si', 'sk', 'fr', 'hr', 'pl', 'ru'];
  var urlLang = url.split('#')[0].split('/');
  /* index depends on the URL structure */
  if (urlLang.length >= 4 && langArray.indexOf(urlLang[3]) != -1) {
    return langMappingURLToTealium[urlLang[3]];
  /* default behaviour */
  var lang = navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage;
  lang = (lang || "").split("-")[0];
  return promptData.languages[lang] ? lang : promptData.defaultLang;

Hope this is the answer you've been looking.