Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
building a data element to store info in a cookie on the root domain
/**
* Steps:
* 1. Create a data element to retrieve the query parameter; set storage to "none"
* 2. Create a second data element that sets the cookie on your domain's root
* 3. Reference the second data element on load of every page (it won't fire if it's not referenced)
* 4. When you need the info in the cookie, pull it from the data element created in step 2
*/
// check for the query param first (this always overrides a saved value)
var retval = _satellite.getVar("qsp:ex_id");
var cookieName = "launch_ex_id";
var cookieOptions = {
domain: '.YOURDOMAIN.COM' // be sure to specify your domain/subdomain
}
if (retval) { // if a value was found in the url, set/update the cookie
_satellite.cookie.set(cookieName, retval, cookieOptions);
} else { // if no value in the url, check for the cookie
retval = _satellite.cookie.get(cookieName);
}
// return the value
return retval;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment