Skip to content

Instantly share code, notes, and snippets.

@hitGovernor
Created December 3, 2020 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitGovernor/cecf482ffb3e36c514c7ffddf957007d to your computer and use it in GitHub Desktop.
Save hitGovernor/cecf482ffb3e36c514c7ffddf957007d to your computer and use it in GitHub Desktop.
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