- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
Hi
I'm placing a cookie using the utag.loader.SC("utag_mycookie", {"mycookie1": "value;exp-session"}).
It places a seperate cookie than utag_main, which is what we want.
However, utag.loader.RC("utag_mycookie").mycookie1, is returning undefined.
I have created a dataLayer as utag_mycookie, too.
Can someone clarify where am I going wrong?
We want to set two seperate cookies and read it back in an extension.
Thanks
Samrat D'souza
Solved! Go to Solution.
02-17-2016
10:26 AM
- last edited on
03-08-2018
04:30 PM
by
TealiumJustin
The method you are using only works when adding cookies to the utag_main cookie. What I would recommend as a solution for you is the Persist Data Values extension in TiQ.
Here is a community article that can explain more: Persist Data Value extension
You can persist text or an existing data layer variable and you can create multiple extensions. Then, when you need to "read" that cookie, you can do so in a set data values extension mycookie1(cp) or JS code extension utag.data['cp.mycookie1'].
Let me know if this doesn't work for you, or you have any other questions.
02-17-2016 11:43 PM - edited 02-17-2016 11:44 PM
Well, wouldn't work in my scenario, as it's to be bolted into a functoinality written through an extension itself.
However, utag.loader.SC, does set a cookie but "utag.loader.RC" doesn't read it, would this be considered a bug?
Thanks
Sam
Hi @samrat_dsouza,
@christina_schel FYI
To use the
;exp-session
You need to also include a timestamp ("_st" property) of when the session expires.
For example using the utag_main time out value:
utag.loader.SC("utag_mycookie", {"mycookie1": "value;exp-session", "_st" : utag.data["cp.utag_main__st"]});
Or if you would like to set the session timeout period from when you set the cookie you can use:
utag.loader.SC("utag_mycookie", {"mycookie1": "value;exp-session", "_st" : ((new Date()).getTime() + parseInt(utag.cfg.session_timeout))})
utag.cfg.session_timeout, is by default 30 mins, which can be changed via the Publish Config Setting in TiQ.
Adrian
02-18-2016 04:53 AM - edited 02-18-2016 05:57 AM
Thanks for the tip, however utag.loader.RC("utag_mycookie").mycookie1 doesn't work, for a similar cookie below:
It does work for utag_main cookie, but for nothing other than that.
Should it be declare as a dataLayer, if yes then in what syntax?
Any tips?
Thanks
Sam
@samrat_dsouza I'm afraid your picture didn't upload.
To help try and explain, here is what I am doing.
(I have included some document.cookie statements to show what is in the cookie)
Adrian
02-18-2016 06:04 AM - edited 02-18-2016 06:07 AM
Hi
Thanks, I realised that, as I wasn't using the "_st"; utag.loader.SC worked but utag.loader.RC didn't.
Now, utag.loader.RC works fine.
Quick one before we close this thread:
Is there a exp-session setting which expires the cookie when the window is closed?
Cheers
Sam
03-14-2016 04:52 AM - edited 03-14-2016 04:53 AM
I'm using the solution to set and read cookies to utag_main. However, i'm facing the below issue:
Have a variable decarled with the cookie key name "variableName".
var abc = "variableName";
The following works in chrome, firefox and IE edge.
utag.loader.SC("utag_main", {[abc]: "start;exp-session"});
which is actually the below, but using a variable with dynamic value set, for different situations:
utag.loader.SC("utag_main", {"variableName": "start;exp-session"});
This, on IE 11 and lower versions, throws an error: "unexpected string".
Is this a bug or is there a better way to do it?
Thanks
Samrat D'souza
So what you have come across is IE not liking defining a key name inline of an object declartaion.
https://kangax.github.io/compat-table/es6/#test-object_literal_extensions_computed_properties
Baically IE11 doesn't support ES6 Object Initializer.
The bit that is failing is:
{[abc]: "start;exp-session"};
The best way to do this would be to create an object first, then assign the key you want.
var abc = "variableName", tempObj = {}; tempObj[abc] = "start;exp-session"; utag.loader.SC("utag_main", tempObj);
Adrian
Copyright All Rights Reserved © 2008-2023