Skip to content

Instantly share code, notes, and snippets.

@ju1
Created June 10, 2018 20:33
Show Gist options
  • Save ju1/a6265b250908b3544be2a4565b767599 to your computer and use it in GitHub Desktop.
Save ju1/a6265b250908b3544be2a4565b767599 to your computer and use it in GitHub Desktop.
A script which sets the cookie
<script>
var cookieName = "visitorFromAdwords"; // Name of your cookie
var cookieValue = "true"; // Value of your cookie
var expirationTime = 2592000; // One month in seconds
expirationTime = expirationTime * 1000; // Converts expirationtime to milliseconds
var date = new Date();
var dateTimeNow = date.getTime();
date.setTime(dateTimeNow + expirationTime); // Sets expiration time (Time now + one month)
var expirationTime = date.toUTCString(); // Converts milliseconds to UTC time string
document.cookie = cookieName+"="+cookieValue+"; expires="+expirationTime+"; path=/; domain=." + location.hostname.replace(/^www\./i, ""); // Sets cookie for all subdomains
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment