cookie
The _satellite.cookie object contains methods that allow you to write, edit, or delete cookies that your tag rules can reference. It is a partial copy of js-cookie, containing many core features of that library.
cookie.set()
The set() method writes a cookie that your tag property can reference.
_satellite.cookie.set(name: string, value: string, attributes?: {
expires?: number | Date;
path?: string;
domain?: string;
secure?: boolean;
sameSite?: 'Strict' | 'Lax' | 'None';
}): string
The following method parameters are available:
namestringvaluestringattributesobjectThe attributes object supports the following properties:
expiresnumber or Datepathstringdomainstringsecurebooleanhttps://). If omitted, there is no secure protocol requirement.sameSite'Strict' | 'Lax' | 'None'sameSite attribute. If you set sameSite to None, you must also set secure to true.// Sets a cookie valid across the entire site, expires on session close
_satellite.cookie.set('simple_session_cookie', 'value');
// Sets a cookie that expires 7 days from now, valid across the entire site
_satellite.cookie.set('seven_day_cookie', 'value', { expires: 7 });
// Sets a cookie that expires 14 days from now, valid only on the current page
_satellite.cookie.set('page_specific_cookie', 'value', { expires: 14, path: '/' });
// Cross-site compatible cookie (requires HTTPS)
_satellite.cookie.set('cross_site_cookie', 'value', { secure: true, sameSite: 'None' });
Invoking this method writes the desired cookie and returns the serialized cookie string that was written. This string is primarily used for debugging or logging purposes.
'written_cookie=value; path=/'
_satellite.setCookie(). The setCookie() method is deprecated in favor of _satellite.cookie.set().cookie.get()
The get() method returns a cookie value.
_satellite.cookie.get(name: string): string | undefined;
namestringIf the cookie name exists, returns the cookie value. If the cookie name does not exist, returns undefined.
_satellite.getCookie(). The getCookie() method is deprecated in favor of _satellite.cookie.get().cookie.remove()
The remove() method deletes a cookie that you have set.
_satellite.cookie.remove(name: string, attributes?: {
path?: string;
domain?: string;
}): void
namestringattributesobjectpath or domain attributes, include those same attributes when removing the cookie. Failure to include these attributes does not remove the cookie.// Creates a session cookie
_satellite.cookie.set('session_cookie', 'Cookie value');
// Removes the above cookie
_satellite.cookie.remove('session_cookie');
// Creates a cookie that is only visible on the current page
_satellite.cookie.set('page_specific_cookie', 'value', { path: '/' });
// This remove method does nothing because it does not match the path and domain attributes of the cookie set
_satellite.cookie.remove('page_specific_cookie');
// This remove method works correctly for the page-specific cookie
_satellite.cookie.remove('page_specific_cookie', { path: '/' });
_satellite.removeCookie(). The removeCookie() method is deprecated in favor of _satellite.cookie.remove().