Cookie Functions
Reference guide for cookie functions provided by Tealium for JavaScript.
utag.loader.SC()
This function sets and deletes multi-value cookies inside the namespace utag_
. It is commonly used to set utag_main
subcookies to avoid adding extra cookies.
To minimize the number of cookies on your domain, we recommended setting a multi-value cookie object. A multi-value cookie stores several values, as key-value pairs, within one cookie namespace. The function is commonly used to set utag_main
This is the same function used by the Persist Data Value extension.
The following format demonstrates how to set a cookie by identifying the cookie’s namespace, name, value, optional expiration time, and optional flag for specifying additional functionality:
utag.loader.SC(namespace, {"name": "value;exp-expiry"}, flag);
Parameter | Type | Description | Example |
---|---|---|---|
namespace |
String |
The namespace of the cookie, which must start with utag_ . |
"utag_multi" |
name:value |
Object |
An object of key-value pairs representing a multi-value cookie. | {"uid": "012345689", "aff": "SiteAff1;exp-7d"} |
expiry |
String |
(Optional) The expiration of the cookie, which must start with exp- . |
exp-12h |
flag |
String |
(Optional) A flag to delete one or more cookies. | "d" |
Expiry Options
The following cookie expiry options are available:
Expiry unit | Description | Example |
---|---|---|
#d |
Expiry time in days (default unit, if none provided) | exp-7d or exp-7 (7 days) |
#h |
Expiry time in hours | "exp-8h" (8 hours) |
#u |
Expiry time at Unix timestamp | "exp-1549271521u" (Midnight (GMT) on Dec 22, 2022) |
session |
Expiry time at end of session (default session timeout: 30 minutes) | "exp-session" |
Timestamp-based expiration, such as "exp-1549271521u"
, has a trailing u
indicates Unix timestamp. Do not confuse it with the value set in the cookie itself such as "exp-1549271521"
If no expiry option is set, then the default behavior is based on the version of utag.js
:
- 4.27+ - default expiry is 1 year after the creation of the cookie.
- 4.26 or older - default expiry is the year 2099.
Set a Cookie
To set a multi-value cookie, pass an object of key-value pairs of to the value
parameter.
The following example creates a multi-value cookie named utag_multi
:
utag.loader.SC("utag_multi", {
"uid" : "012345689", // default expiry
"test_seg" : "groupA;exp-12h", // 12 hour expiry
"aff" : "SiteAff1;exp-7d" // 7 day expiry
});
Delete a Cookie
To delete one or more cookie values, use the optional flag
parameter.
Delete one or more values from a multi-value cookie. Each key-value pair specified is deleted:
utag.loader.SC("utag_multicookie", {"test_seg":"", "aff":""}, "d");
Delete all values from a multi-value cookie:
utag.loader.SC("utag_multicookie", {}, "da");
This page was last updated: January 7, 2023