Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
hitGovernor
/
launchCookieStorageDataElement.js
Created
Dec 3, 2020
Star
0
Fork
0
Star
Code
Revisions
1
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
building a data element to store info in a cookie on the root domain
Raw
launchCookieStorageDataElement.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
/**
* 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
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.