- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
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!
Solved! Go to Solution.
09-11-2017 09:53 AM - last edited on 09-11-2017 10:20 AM by kathleen_jo
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
09-11-2017 06:25 PM
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!
09-12-2017 07:05 AM
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
09-13-2017 08:35 AM - last edited on 09-13-2017 09:18 AM by kathleen_jo
Copyright All Rights Reserved © 2008-2023