Reading a cookie into the Data Layer, Tealium Tools Web Companion

Gold Contributor
Gold Contributor

Hey guys,

 

I was just trying to write a little extension that shall display a message at the top of our web page when the environment of the utag.js gets changed in the Tealium Tools Webcompanion extension (Chrome).

 

My initial approach was to add a property to the data layer, using the cookie name the Webcompanion writes.

Settings are

  • Source utag_env_mycompany_main
  • Type First Party Cookie
  • Alias some alias

The problem is that when I set the environment to let's say "dev", Tealium does not seem to properly generate/populate this datalayer value. Instead the propertey name seems to get the actual value appended to it, leaving the value unset.

 

cp.utag_env_mycompany_main_//tags.tiqcdn.com/utag/mycompany/main/dev/utag.js : "undefined"

 

Any idea, what's wrong here?

 

Cheers, Bjoern

2 REPLIES 2

Reading a cookie into the Data Layer, Tealium Tools Web Companion

Employee Emeritus

@bjoern_koth

Seems like the cookie is not getting parsed correctly into the datalayer. 

 

There is a built in feature in since version 4.36 of utag.js which has the environment already in the data layer: 

 

https://community.tealiumiq.com/t5/uTag/utag-js-Versions-4-33-through-4-40-Release-Notes/ta-p/11909

 

In Tealium iQ, you can add these "Tealium Built-in Data" Data Sources via the "Add Common Data Sources" in the "Data Layer" tab. 

 

With this approach, you can look at:

utag.data['ut.env']

 

Or you can pull the value of the cookie using the following:

webCompaionVersion = (function (sKey) {
    if (!sKey) { return null; }
    return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
}('utag_env_'+utag.data['ut.account']+'_'+utag.data['ut.profile']))

 

 

Reading a cookie into the Data Layer, Tealium Tools Web Companion

Gold Contributor
Gold Contributor
Awesome, works!

Thanks a lot, Brian
Public