Pass Cookie Value in Tealium Variable

Bronze Contributor
Bronze Contributor

Hi Team,

I am new to tealium. I have to do one activity i.e need to pass LILO cookie value( non-tealium cookie, first party) into variable(prop 27) user_hashedID. Here mapping is already done in global page load rule. So, how I can populate that cookie value in variable i.e through extension or creating new variable.

For now user_hashID is empty and I have to pass cookie value whien we find hashID is empty.

3 REPLIES 3

Pass Cookie Value in Tealium Variable

Tealium Employee

All first-party cookies are read by the utag.js script and added to the data layer using the "cp." prefix. If your cookie is set before Tealium executes, you should see it show in the data layer as "cp.LILO". You'll still need to add it as a UDO variable in Tealium IQ to be able to use it in mappings. You can go to the data layer tab, click on the blue "Add Variable" button, then enter "LILO" in the variable name box. Please ensure the type is set to "First Party Cookie". Once you have added the variable in the data layer tab, you can use it in your Adobe tag to map to "prop27".

You can have multiple variables mapped to the same prop, however, know that mappings are set from top to bottom, so if you have two, the bottom value is what will be used.

If you want to use the cookie as a fallback, you can use a Set Data Values extension to set "user_hashedID" to the cookie value if the variable "user_hashedID" is not defined. You would then map "user_hashedID" to "prop27" in the Adobe tag.

I hope this helps.

Jen Kaye
Senior Premium Success Engineer | Tealium, Inc.

Pass Cookie Value in Tealium Variable

Bronze Contributor
Bronze Contributor
if sample_cookie is available: how to set the rules in tealium ?










Pass Cookie Value in Tealium Variable

Gold Contributor
Gold Contributor

Hello,

To achieve this, you can create a new JavaScript Code extension in Tealium iQ Tag Management to read the LILO cookie value and set it as the user_hashedID in your data layer. Here's how you can do it:

In Tealium iQ, navigate to the "Extensions" tab and click on the "Add Extension" button.
Select the "JavaScript Code" extension.
In the configuration panel, set the scope to "Pre Loader" to ensure that the cookie value is read before the tags are loaded.
Add the following JavaScript code to read the LILO cookie value and set it as the user_hashedID in the data layer:

function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}

var liloCookieValue = getCookie("LILO");
if (liloCookieValue) {
utag_data["user_hashedID"] = liloCookieValue;
}
Replace "LILO" in the getCookie function call with the actual name of the LILO cookie if it's different.

Save and publish your changes.
This extension will read the LILO cookie value and set it as the user_hashedID in the data layer when the user_hashedID is empty. Since you mentioned that the mapping is already done in the global page load rule, the prop27 variable should now receive the LILO cookie value.

I hope this helps! Let me know if you have any questions or need further assistance.

shivam joshi
Public