Reply
Highlighted
Visitor
Posts: 1
Registered: ‎11-15-2018

Cookie Consent language depending on page content language

[ Edited ]

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?

Reply
0 Kudos
Visitor
Posts: 2
Registered: ‎05-21-2018

Re: Cookie Consent language depending on page content language

Hi,

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 = {
    'en':'en', 
    'cz':'cs', 
    'de':'de', 
    'it':'it', 
    'si':'sl', 
    'sk':'sk', 
    'fr':'fr', 
    'hr':'hr', 
    '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.

 

 

 

Reply
0 Kudos