brandonmcpeak
11/27/2019 - 8:59 PM

From: https://www.analyticsmania.com/post/cookies-with-google-tag-manager/

// use <script> tags when embedding in HTML or adding as GTM tag
 var cookieName = "visitorFromAdwords"; // Name of your cookie
 var cookieValue = "true"; // Value of your cookie - if using GTM, it's ideal to store the email as a GTM variable
 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 date = date.toUTCString(); // Converts milliseconds to UTC time string
 document.cookie = cookieName+"="+cookieValue+"; expires="+date+"; path=/; domain=." + location.hostname.replace(/^www\./i, ""); // Sets cookie for all subdomains