Highlighted

how to override language preferences in GDPR modals based on page lang

Rookie Contributor

Hello,

I am trying, for the GDPR "Explicit Consent Prompt" and "Consent Preferences Dialog" to override the user's browser's language preferences with the page HTML's lang attribute (accessible via JS:

document.documentElement.lang

and I see in the docs we should use this script to override the language preference:

window.utag_cfg_ovrd = window.utag_cfg_ovrd || {}; 
window.utag_cfg_ovrd.gdprDLRef = "<some data layer var e.g. meta.lang/page_lang>";


it, unfortunately, doesn't seem to work for me.


So far I have tried:

window.utag_cfg_ovrd = window.utag_cfg_ovrd || {};
window.utag_cfg_ovrd.gdprDLRef = document.documentElement.lang;


but also:

window.utag_cfg_ovrd = window.utag_cfg_ovrd || {};
window.utag_cfg_ovrd.gdprDLRef = "fr";


or:

window.utag_cfg_ovrd = window.utag_cfg_ovrd || {};
window.utag_cfg_ovrd.gdprDLRef = '<html lang="fr">';



none seem to be working for me, what am I missing?
I am thinking I am maybe adding it to the wrong place? So far I was adding it to the Explicit Consent Prompt JS.

Thanks!

4 REPLIES 4
Highlighted

how to override language preferences in GDPR modals based on page lang

Tealium Employee

Hi @raphaelF 

So the gdprDLRef  actually refers to a data layer property name.

So in your data layer you would have:

utag_data = {
......
page_lang: document.documentElement.lang
};

Then you would set the override like so (in a preloader extension):

window.utag_cfg_ovrd = window.utag_cfg_ovrd || {}; 
window.utag_cfg_ovrd.gdprDLRef = "page_lang";

When the consent modals appear they will then look at utag.data[utag_cfg_ovrd.gdprDLRef] which would then give back the language to use.

Adrian

Ask me anything Tealium related or Javascript, or NodeJS.
Please remember to mark solutions as accepted for future searchers.
Highlighted

how to override language preferences in GDPR modals based on page lang

Rookie Contributor
Hello @adrian_browning and thanks a lot for your answer !
I have a stupid question but:
- to edit the data layer should I do it via the "IQ Tag Management > Data Layer > Variables" ? and in there add an UDO variable ? or should I add it directly in my HTML to the var utag_data = {...} I add via script ?
Highlighted

how to override language preferences in GDPR modals based on page lang

Tealium Employee

Hi @raphaelF 

So you can go down the route of updating your page utag_data object.
However, if you can't or don't want to go down that route, I would suggest using a preloader extension to add it into the datalayer object.

So something like:

window.utag_data = window.utag_data || {};
window.utag_data.page_lang = document.documentElement.lang;

I would suggest to also add page_lang to the data sources tab in iQ so that others now of its existence.

Adrian

Ask me anything Tealium related or Javascript, or NodeJS.
Please remember to mark solutions as accepted for future searchers.
Highlighted

how to override language preferences in GDPR modals based on page lang

Rookie Contributor

Hey @adrian_browning,
Thanks a lot again for your answers ! Turned out my issue was I forgot to turn my extension as "Pre Load" scope.
For future reference, this is the way I fixed it:
- In IQ Tag Management > create an extension, set its scope as "Pre Load", and paste this code:

window.utag_cfg_ovrd = window.utag_cfg_ovrd || {};
window.utag_cfg_ovrd.gdprDLRef = "page_lang";

- in the script added directly to my HTML pages, I added the object property:

page_lang: document.documentElement.lang

it now works perfectly.
Thanks again !