- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
11-22-2018 03:55 AM - edited 11-22-2018 03:58 AM
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?
12-20-2018 04:07 AM
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.
Copyright All Rights Reserved © 2008-2023