Highlighted

How to define utag.data variable in JS pre loader extension?

Rookie Contributor
in "all tags" JS extension I can do this - utag.data["variable"]. However, this doesn't work in pre loader JS extension. How do I do it?
7 REPLIES 7
Highlighted

How to define utag.data variable in JS pre loader extension?

Tealium Employee

Hi Tomas,

You can use the 'Javascript Code' Extension scoped to 'Pre-Loader' to achieve this functionality.

utag_data.name_of_new_variable_1 = "variable value";
utag_data.name_of_new_variable_2 = ["variable value 1", "variable value 2"];

You can set the variable value to be a string or array.

Highlighted

How to define utag.data variable in JS pre loader extension?

Employee Emeritus

Hey Tomas,

The utag.data object does not exist when the PreLoader extensions run. The utag.data object gets defined within the utag.js file. Because the Pre Loader extensions run before anything else in the utag.js file the utag.data and the "b" object are not defined at that time.

To do this you will need to use "utag_data" like so:

utag_data["variable"]

Highlighted

How to define utag.data variable in JS pre loader extension?

Rookie Contributor

hm, doesn't work either:
utag_data["variable"] = "variable value";
utag_data.name_of_new_variable_1 = "variable value";

could there be something else?

Highlighted

How to define utag.data variable in JS pre loader extension?

Employee Emeritus

If utag_data isn't defined on the page then this won't work because you can't set a variable in an object that doesn't exist.

You will need something like:

if(typeof utag_data=="undefined"){
utag_data = {}
}

utag_data["variable"] = "variable value";

Highlighted

How to define utag.data variable in JS pre loader extension?

Rookie Contributor

Thanks Jared.

Different question - why does Tealium fail silently on dev and qa? Debugging JS in Tealium with console.log is very inconvenient.

DEV and QA environments should spit out all the Tealium related errors and warnings into console.

Highlighted

How to define utag.data variable in JS pre loader extension?

Employee Emeritus

Tealium has a built in debugging function within it's library. You can follow one of the options for Method 2 in this post:
https://community.tealiumiq.com/t5/uTag/Debugging-utag-view-and-utag-link/ta-p/13695

This will output various logs into the console as the tags load and fire. It will also log errors that are found in JS Code Extensions.

All JavaScript Code Extensions are wrapped in a Try/Catch statement that when the utagDB cookie is set it will output the error and the path to the error.

It will output something like:

All Tags EXTENSIONS utag.js?a234asdf234:422
e:fail is not defined , s://tags.tiqcdn.com/utag/jaredtest/test/dev/utag.js , l:5 , t:ge

e= Error Message
s= File that threw the error
l= Extension number
t= Just logging that this came from an extension

NOTE: This will not work for JavaScript Code Extensions Scoped to PreLoader because the utag.DB function has not loaded by then. At this point you will need to use your own kind of logging for debugging.

Highlighted

How to define utag.data variable in JS pre loader extension?

Rookie Contributor
Thanks Jared. This will make things easier.