Need JS help retrieving multiple values from a cookie.

Gold Contributor
Gold Contributor
I want to set 5 name/value pairs in one cookie and pull them down to five variables. Setting the cookie is easy enough (I think, see below), but I'd like to have one JS function to pull the values down, and I'm not a coder. From there I can do the extension to set the variables. I can do this using a whole lot of extensions, but I'd rather minimize them. Regarding the cookie-setting functionality, if I have 5 extensions each setting values in one cookie, will I wind up with 5 name/value pairs or is each name/value overwritten by the function? Thanks.
1 REPLY 1

Need JS help retrieving multiple values from a cookie.

Tealium Employee
Hi, There are basically two parts to this. First, setting the cookie: If you use 5 persist data value extensions, each will overwrite the value of the previous one. What you need to do is build a string in a variable using the Set Data Values extension, and then pass that variable to the cookie. If you use a set data values extension to set a UDO variable to "JS Code" containing "value1:"+utag.data['value1']+"%24" + "value2:"+utag.data['value2'] and keep going adding your keys in quotes, then a plus, then the utag.data variable (or other data) that you want to add to that key, then another plus, then "%24" which is the URI encoded version of $ (used as a separator) Once you have set that up, create a Persist Data Values extension, and make sure you call the cookie "utag_xxxx" where xxxx is whatever you want to name it. The utag_ prefix will mean that when the cookie is read back, it will automatically be read back into the data layer as it's individual components, so cp.utag_xxxx_value1, cp.utag_xxxx_value2 etc. I hope that helps Steve Lake
Connecting data systems since the 1980s.
Public