adding variables to existing datalayer

Gold Contributor
Gold Contributor

beginner question : if i have already declared utag_data variables on a page, can i still add new set of variables in future without overwriting the existing datalayer or editing the existing code on the page ? how do i do that ?  thanks!

4 REPLIES 4

adding variables to existing datalayer

Tealium Expert
Tealium Expert

Hello @hcerus,

 

If i understand the question correctly, you are trying to add a new variable to utag_data Javascript object that already exists on the web page.

 

utag_data on page acts like any other javascript object variable on web pages. So you can add new variables directly as part of definition as below

var utag_data = {var1: "val1", newvariable:"value"};

 

or 

var utag_data = {var1"val1"};

utag_data.newvariable = "value";

or

var utag_data = {var1"val1"};

utag_data["newvariable"] = "value";

 

Here is a link i could find more details about utag_data object

https://community.tealiumiq.com/t5/JavaScript-utag-js/How-utag-data-works/ta-p/15369

 

Hope this helps.

 

Thanks

Abraham

Thanks & Regards
--------------------------------------------------
Abraham Easo
Principal Consultant
Numeric Analytics, LLC
Bartlett, IL (CST)
m: 980-422-2044
Abraham.Easo@numericanalytics.com | http://www.numericanalytics.com
Adobe Analytics Architect/Tealium Expert/Ensighten/Google Analytics Certified

adding variables to existing datalayer

Gold Contributor
Gold Contributor

Thank you Abraham,

 

That certainly answers the question. Just out of curiosity :

is there any difference or practical implication or best practice that I should be aware of when choosing one of the method above versus the other two suggested?

I am planing the implementation of the data layer and this will be good to know.thanks!

 

 

adding variables to existing datalayer

Tealium Expert
Tealium Expert

Hello @hcerus,

 

I would prefer to use first approach, if we have the new variables data available as part of utag_data variable definition. This would help ensure, all variables are defined together at one place and before utag.js is loaded.

var utag_data = {var1: "val1", newvariable:"value"};

 

If it is like, you would like to append new variables to an existing data layer thats already defined, then we could use approach 2 or 3.

utag_data.newvariable = "value";

or 

utag_data["newvariable"] = "value";

 

I havent seen any disadvantages on the earlier provided approaches so far, looks like JavaScript's flexible syntax allows to have variables set in different ways.:)

 

Here is some additional note that might be helpful: The UDO(utag_data) can be updated with additional values outside of the declaration block, as long as the data gets set prior to loading utag.js. UDO variables set after loading utag.js will be ignored.

 

Thanks

Abraham 

Thanks & Regards
--------------------------------------------------
Abraham Easo
Principal Consultant
Numeric Analytics, LLC
Bartlett, IL (CST)
m: 980-422-2044
Abraham.Easo@numericanalytics.com | http://www.numericanalytics.com
Adobe Analytics Architect/Tealium Expert/Ensighten/Google Analytics Certified

adding variables to existing datalayer

Gold Contributor
Gold Contributor

Thanks @abrahameaso, it is crystal clear now :)

Public