title: What is the best way to create a custom cookie using Google Tag Manager?
body: <p>I am trying to set personalized cookies in Google Tag Manager for the first time. Searching the web, I have found different Javascript functions and I was wondering which one I should use, as I am not a developer and I don't really know how "good code" looks like :)  </p>
  
  <p>The first function is the following : </p>
  
  <pre><code>&lt;script&gt;
    function createCookie(name,value,days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; domain=insérernomdedomaineici";
    }
  
    createCookie("lead_magnet_getresponse_devis","devis",60);
  &lt;/script&gt;
  
  </code></pre>
  
  <p>The second one is this one : </p>
  
  <pre><code>&lt;script&gt;
  
   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 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
  
  &lt;/script&gt;
  </code></pre>