Advertisement
flycat

utm_source view

Sep 26th, 2023 (edited)
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const queryString = window.location.search;
  2. const urlParams = new URLSearchParams(queryString);
  3. const utm = urlParams.get('utm_source');
  4. if (utm) {
  5.   var myVar = utm;
  6. }
  7.  
  8. function getCookie(cname) {
  9.   let name = cname + "=";
  10.   let decodedCookie = decodeURIComponent(document.cookie);
  11.   let ca = decodedCookie.split(';');
  12.   for(let i = 0; i <ca.length; i++) {
  13.     let c = ca[i];
  14.     while (c.charAt(0) == ' ') {
  15.       c = c.substring(1);
  16.     }
  17.     if (c.indexOf(name) == 0) {
  18.       return c.substring(name.length, c.length);
  19.     }
  20.   }
  21.   return "";
  22. }
  23. zztop = getCookie('_shopify_sa_p');
  24. const zz = new URLSearchParams(zztop);
  25. var cook_utm = zz.get('utm_source');
  26. if (cook_utm) {
  27.   var myVar = cook_utm;
  28. }
  29.  
  30. console.error('utm myVar = '+myVar);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement