Multilingual support when using GTM




  • 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 root domain, while German to be displayed on my de, subdomain?

    Kind regards,

    Comment actions Permalink
  • Avatar
    Stephen Greis


    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...


    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.



    Comment actions Permalink

Please sign in to leave a comment.