Multilingual support when using GTM

Follow

Comments

3 comments

  • Avatar
    Stephen Greis

    Hi,

    you don't have to write custom javascript for that. Simply do the following steps:

    • In GTM create a new variable of type "javascript variable" and name it "Current Language".
    • Set as name of the global variable: document.documentElement.lang
    • Save the GTM variable
    • Edit the Cookiebot Tag
    • As "Language" set "By GTM variable"
    • As "Language variable" set: {{Current Language}}
    • Save the Tag

    That's it...

     

    0
    Comment actions Permalink
  • Avatar
    Ilya Averyanov

    Hi Jacob,

    Thank you for your documentation!

    What should I write in currentUserPagePathname.indexOf(" ") if I want English to be displayed on my mydomain.com root domain, while German to be displayed on my de,mydomain.com subdomain?

    Kind regards,
    Ilya

    0
    Comment actions Permalink
  • Avatar
    Richard van der Velde

    Hi Stephen,

    Thanks for the tip. It's definitely useful, but probably not quite enough by it self.
    For example on this page, this property returns "en-US". We would have to trim off the "-US" part to make this work. Using this instead should do the trick: document.documentElement.lang.substring(0,2)

    This requires that the lang attribute is set and actually reflects the preferred language though.

     

     

    0
    Comment actions Permalink

Please sign in to leave a comment.