Link to home
Start Free TrialLog in
Avatar of Jon Imms
Jon ImmsFlag for United States of America

asked on

Google Tag Manager Cookie being stripped.

Hey there,  We have a cookie, setup in Google Tag Manager, which is supposed to follow a user through the site, and expire after 1 month.  

I.e  user clicks on an add,  goes to https://buildertrend.com/?source=dev-test.  Source Tag fires.
user then goes to any other page on the site, we lose the cookie value. Not sure why it is stripping the value ?


<script>
  
  //Get value from URL parameter "source"
  
 function getParameterByName(name) {
     name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
     var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
         results = regex.exec(location.search);
     return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
 }
  
 // Set Cookie
 
 var cookieName = "sourcetag"; // Name of your cookie
 var source = getParameterByName('source'); // 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 date = date.toUTCString(); // Converts milliseconds to UTC time string
 document.cookie = cookieName+"="+source+"; expires="+date+"; path=/; domain=." + location.hostname.replace(/^www\./i, ""); // Sets cookie for all subdomains

</script>

Open in new window

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

The current version of Firefox is blocking tracking cookies.  Chrome will also do that soon.
ASKER CERTIFIED SOLUTION
Avatar of Dr. Klahn
Dr. Klahn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial