Where do javascript variables in the data layer show up on the page?

Silver Contributor
Silver Contributor
I've added a javascript variable to my data layer and set it to all tags. Let's say my variable is called "doWork". I set that variable using an extension. When I publish, I'm expecting to see window.doWork set to some value. However, that is not the case. I'm seeing utag.data["js_page.doWork"] set. This doesn't make much sense to me since we are definitely reading JS variables set by my site's code using the Javascript Object data layer function. What am I missing?
3 REPLIES 3

Where do javascript variables in the data layer show up on the page?

Employee Emeritus

Hi Chris, thanks for the question. The Javascript Variable data source type is meant for JS variables that are

 

  1. already instantiated at page load and
  2. are not part of the utag_data object.

 

So what's happening here based on your description is:

 

  1. You've defined a new data source called 'doWork' and set the type to 'JavaScript variable'
  2. doWork does not exist until utag.js runs because
  3. the variable is being defined and populated via a Tealium Extension

 

Any variable that is created and populated via a Tealium extension will default to be part of the utag.data object (and gets a 'js_page' prefix because that's the type you've defined in the Data Source definition) unless we do some specific work to scope it window outside of utag.data.

 

As a best practice, when you are creating and populating a data source via a Tealium extension then the data source type should be left as UDO variable. Hope that helps

Where do javascript variables in the data layer show up on the page?

Tealium Employee
Referencing the page javascript variable in this manner allows you to pull in javascript variable's value into TIQ for use in drop downs in extensions and tags. When I need to set a global variable for use by a tag I intend to load, I will include the initialization in the top of the template for that tag. window.doWork = 'somevalue'; If you want to use an extension, you can also use a 'custom javascript extension' with the same code.

Where do javascript variables in the data layer show up on the page?

Silver Contributor
Silver Contributor
Well that certainly helps. A combo of the two answers will work for me. Looks like I can either define it myself or use a custom extension to set it and get the desired results.
Public