Michal
Michal

Reputation: 132

How to get specific element from page to variable in Google Tag Manager

I have this kind of cookie in code on page. I would like to get language out of it.

I mean how could I this function return in this example "en" in GTM variable:

function() {return ...}

Code in page looks like:

<script type="text/javascript" id="wtml-cookie-js-extra">
var wtml_cookies = {"wp-wtml_current_language":{"value":"en","expires":1,"path":"\/"}};
var wtml_cookies = {"wp-wtml_current_language":{"value":"en","expires":1,"path":"\/"}};</script>

Upvotes: 0

Views: 885

Answers (1)

Ben Larson
Ben Larson

Reputation: 475

Global variables like that are accessible in the window object. This code should do it:

function() {
  return window.wtml_cookies["wp-wtml_current_language"]["value"];
}

Upvotes: 1

Related Questions