how to get language & locale with get.header('accept-language') - how to debug

gylesf73140248

03-10-2017

Hello,

I am trying to do something similar, but with language and locale.

What exactly does the user.header('accept-language') get?  usually the accept language has locale and factor weighting included.  Accept-Language - HTTP | MDN

for example if i wanted to create a profile script differentiating england from united states for english, i would need to parse the language and locale.   would the user.header("accept-language") give me "en-gb" or "en-us"?

Does using console.log work for debugging these scripts?  It is difficult to use the built in target parameters without know exactly what it provides.

any help would be much appreciated!

Gyles Fohl

Accepted Solutions (1)

Accepted Solutions (1)

Amelia_Waliany

Employee

11-10-2017

Hi Gyles,

Thanks for your questions! Using console.log is not an option because this is not js that gets executed in the page, it is js that is executed server side, when the mbox call comes in. The user.header ("accept-language") would give you "en-gb" or "en-us" because it captures whatever the browser sends as its language header. In most cases you should get the en-gb or en-us coming though.

Warmly,

Amelia

Answers (7)

Answers (7)

Amelia_Waliany

Employee

12-10-2017

Hi Gyles,

There is no way to debug profile scripts, though you can try to write out the value of the profile script in an Offer using token replace and then view the value of the profile script, which may be helpful. 

Warmly,

Amelia

yogil76910810

20-11-2019

Running into the same issue we solved that by using the Accept language setting in Adobe target

Site Pages: HTTP Header Accept-Language startsWith

zh

above to target all Chinese language packages. This will also trigger with zh_TW, zh, zh-CN,... a.s.o
however this method seems to be not able to take the preferred language weighting into account (so the `startsWith` is  not really respected and behaves like `contains`)

gylesf73140248

28-11-2017

Just a warning to anyone using the language rules when creating audiences:

When you choose Browser - English for example, it won't consider US English to be English, because it doesn't include locale settings when determining language.

So, setting browser - english only works for "EN", but not for "EN-US" or "EN-GB", which basically makes it useless.

Gyles

Amelia_Waliany

Employee

20-10-2017

Hi Gyles,

Thanks for sharing this experience with the community - appreciate this suggestion! The good thing about discussing it here is that you're probably not the only one that might be interested in this!

To that end, would you mind posting this as a "New Idea" using the "Submit an Idea" link on the right of the page (orange lightbub icon)? This way, other community members can vote up on this idea, and it can then be suggested to the product team.

Thanks again!

Warmly,

Amelia

gylesf73140248

20-10-2017

Hello,

This does not address the original question unfortunately.  I had tried going this route originally but because those options are so limited it was of not helpful.

There are only about 10 languages, for example there is no Italian or traditional chinese.   Also, the language options do not distinguish locale, which accept-header does.   from original post: "en-gb" or "en-us".

I would recommend adding more languages and options for locale.

Thanks!

Amelia_Waliany

Employee

20-10-2017

Hi Gyles,

Just to follow up on an alternative (and new best practice) for getting visitor language --

Using user.header('accept-language') is no longer best practice now that Browser->Language and Site Pages->HTTP Header->Accept-Language are both UI options in the Audience builder:

Pasted image at 2017_10_04 10_25 AM.png

Pasted image at 2017_10_04 10_25 AM (1).png

User.header('accept-language') = the latter, and could do the same differentiation. User.header('accept-language') is no longer necessary, except for maybe in a token replace.

Hope this was helpful!