title: Set Cloudflare Cookie Based on GET Parameter
body: <p>I am attempting to set the cloudflare cookie based on the GET Parameter. In this scenario, the GET Parameter is utm_source. Demo URL (worker is currently live): <a href="https://ellasbubbles.com/product/cultured-marble-trench-drain-shower-base-36x60-and-30x60/?utm_source=test" rel="nofollow noreferrer">https://ellasbubbles.com/product/cultured-marble-trench-drain-shower-base-36x60-and-30x60/?utm_source=test</a></p>
  <p>I was able to get a head start with this documentation, but cannot seem to get this to work properly. I am using inspect element on chrome to search for cookie and it is unfound - <a href="https://www.mikestreety.co.uk/blog/using-cloudflare-workers-to-set-a-cookie-based-on-a-get-parameter-or-path/" rel="nofollow noreferrer">https://www.mikestreety.co.uk/blog/using-cloudflare-workers-to-set-a-cookie-based-on-a-get-parameter-or-path/</a></p>
  <pre><code>addEventListener('fetch', event =&gt; {
      event.respondWith(fetchAndApply(event.request))
  })
  
  async function fetchAndApply(request) {
      let response = await fetch(request);
  
      let url = new URL(request.url),
          refer = url.searchParams.get('utm_source');
  
      response = new Response(response.body, response);
  
      if(refer) {
          let partnerCookie = `source=${refer}; path=/; domain=https://ellasbubbles.com; secure; HttpOnly; SameSite=None`;
          response.headers.set('Set-Cookie', partnerCookie);
      }
  
      return response;
  }
  </code></pre>