Hello everyone,
I am setting a cookie with _satellite.cookie.set(digitalData,digitalData); Basically I am thinking of storing the digitalData in th cookie, ONLY for authenticated users and re-use it where I need, by using _satellite.cookie.get. My question is, how to read the digitalData json ? For instance, how can i read digitalData.user.customerId from the json cookie?
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
Cookie values can only be strings. I haven't personally tried storing non-text values in cookies using _satellite.cookie.set(), but if it's working for you, then that means Launch is able to stringify the object before storing it as a JSON value in the cookie.
_satellite.cookie.get() would return the cookie's value as-is, i.e. as a string. To convert it back to its original type, use `JSON.parse()`.
E.g.
var digitalDataString = _satellite.cookie.get("digitalData");
var digitalData = JSON.parse(digitalDataString); // this is what you want
// you should now be able to get digitalData.customerId
Cookie values can only be strings. I haven't personally tried storing non-text values in cookies using _satellite.cookie.set(), but if it's working for you, then that means Launch is able to stringify the object before storing it as a JSON value in the cookie.
_satellite.cookie.get() would return the cookie's value as-is, i.e. as a string. To convert it back to its original type, use `JSON.parse()`.
E.g.
var digitalDataString = _satellite.cookie.get("digitalData");
var digitalData = JSON.parse(digitalDataString); // this is what you want
// you should now be able to get digitalData.customerId