- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
03-25-2019 01:34 PM
Hi,
I want to add an additional key and value to the utag_data object or the b object (since they are meant to be the same) but make sure it persists throughout the life of the tealium session or visitor id remains persistent also.
I won't be able to provide the data upfront and add it to the utag_data object before utag.js loads (as explained in the docs) because I am making an HTTP request to see if the data I am trying to store in tealium exists in my DB and if not generate the data and add it into tealium's data_layer (I believe) then store in my DB.
Based on what I have read, one way to go is to make an extension, call the HTTP endpoint there and store the results in the b object e.g. b.foo = "bar" where it the docs suggest the data will persist from then on.
Is this correct? or is there another or better method?
Thanks
03-26-2019 02:12 PM
Update:
created an extention to add data to
b.foo = "bar"
however through once its added. it get replaced each time I refresh the page, which means it does not persist on the same object. I wonder if I should check utag_data or utag.data instead of checking b.foo to see if the data has persisted?
03-27-2019 02:26 AM
Hi @okbrown ,
if you want to persist the data from pageview to pageview, adding it to the UDO won't be enough. utag_data
and utag.data
are just window-scoped JS objects, so they only last the life of the page. b
is even more short-lived.
You need to set a cookie (or use local/sessionStorage).
The easiest way to do that in TiQ will be to set a cookie using the Persist Data Value Extension.
So you might:
u.callback = function (response) {That callback will fire a utag.link event with the data from the response (obviously just illustration code).
if (typeof response !== "string") response = "bar";
utag.link({
"event_name" : "data_callback",
"foo" : response
});
}
foo
to a cookie like utag_main_foo
(you'll need to add both those through the Data Layer tab). You can set that up with a condition so that it's only set on 'data_callback' events. I'd suggest using a utag_main
subcookie to make sure that the session recognition is consistent (some browsers handle that strangely, better to let TiQ's session logic handle it).cp.utag_main_foo
) isn't already set to make sure it only fires once per session.That's off the top of my head and I haven't tested it through specifically, but those are the building blocks I'd suggest using.
Hope that helps?
Best
Caleb
03-27-2019 05:10 AM
03-27-2019 05:38 AM - edited 03-27-2019 05:42 AM
I do have one question, where can I find documentation for utag.link() how do i know that
utag.link({ "event_name" : "data_callback", "foo" : response });
this will add data to utag_main_foo cookie?
Edit: I need to get foo as a variable to the persisted data value.
03-27-2019 05:44 AM
Here's some documentation on utag.link() - it's basically just a way to send a non-pageview event through TiQ's logic.
It's just an event, and as such doesn't set a cookie. But it allows you to set up the Persist Data Values extension to set a cookie on qualifying events using the 'Conditions' at the bottom of that extension.
Does that make sense?
03-27-2019 05:52 AM
Thanks for your time,
It makes sense a little...
I can create the cookie, but how does the persisted data value know where foo is in the first place?
its not like it expecting an event called foo? dont i need to create a variable? so that I when i select "Persist" dropdown I can then select what it is going to persist to.
Feels like something is missing in the flow of it.
03-27-2019 06:06 AM
Here's how I would configure the Persist Data Values extension here:
I created 3 variables:
So if the 'event_name' is 'data_callback' on an incoming event (either utag.view or utag.link as I've configured it here, you could limit it further to only respond to links), the value of 'foo' will be persisted for the Session duration in a subcookie called 'foo' within the 'utag_main' cookie.
That 'utag_main_foo' cookie could be used in the Load Rule for your Generic Tag, to only get that value if you haven't already gotten it within the same session.
03-27-2019 06:47 AM
03-27-2019 01:09 PM - edited 03-27-2019 01:10 PM
Unfortunately the sub cookie does not store on the utag_main as utag_main_foo.
I have tried using a different variable other than event_name e.g. foo_event_name just in case there is another tags and extensions using it.
However no joy. could you give me a break down of execution steps or point to the correct part of the documentation that explains it when using;
My understanding would be the
I am pretty sure there is an order of execution issue here.
03-28-2019 02:53 AM - edited 03-28-2019 04:28 AM
Hi,
I think the order of execution here is the tricky part. Let me explain what I think is happening here.
Persist Data Value Extension is wating on the Javascript Code Extension on Generic Tag load which fires the callback utag_main.link({}) ?
Therefore:
Correct?
Edit: could the issue be because it needs version 4.38?
Trying other things...
03-28-2019 01:01 PM
04-01-2019 01:51 AM
Sorry for the confusion, you're right that my initial suggestion doesn't work. The problem is that the callback to the Generic Tag doesn't include the response as an argument.
I've just set up a successful test:
/* Start Tag Sending Code */No other changes are needed to that template.
// could add mapping to make this more generalized, hardcoding for now as POC
var xhr = new XMLHttpRequest();
var apiResource = 'https://putsreq.com/JTBXYfs30pQvioNwgV2Y'
xhr.open('GET', apiResource);
xhr.onload = function() {
if (xhr.status === 200) {
var data = {};
data.event_name = "data_callback";
data.foo = xhr.responseText;
utag.link(data);
}
else {
utag.DB('XHR API Request failed. Returned status of ' + xhr.status);
}
};
xhr.send();
/* End Tag Sending Code */
Sorry for all the back-and-forth on this one, let me know if that works for you.
Best
Caleb
Copyright All Rights Reserved © 2008-2023