1function saveUTM() { 2 var utmParams = ["gclid", "utm_source", "utm_medium", "utm_term", "utm_content", "utm_campaign", "fbclid", "ad_id", "adset_id", "campaign_id", "ad_name", "adset_name", "campaign_name", "placement", "site_source_name"]; 3 var queryParams = new URLSearchParams(window.location.search); 4// document.cookie = "aan_utm_1=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/"; 5 var urlUTM = ''; 6 7// dl Kyes with empty values should not be counted in. 8 utmParams.forEach(function(param) { 9 if (queryParams.has(param) && queryParams.get(param).length > 0) { 10 urlUTM += '&'+ param +'='+ queryParams.get(param); 11 } 12 }); 13 14 var re = /^&/; 15 urlUTM = urlUTM.replace(re, ''); 16 17 // Save timestamp and URL in cookie if UTM parameters exist 18 if (urlUTM.length > 0) { 19 let cookieValues = getCookies("aan_utm"), 20 timestamp = new Date().toISOString(), 21 no = 1, 22 addCookie = true; 23// dl If several utf strings in the same cookie - whey will expie all togethr 24 25 if (cookieValues.length > 0) { 26 cookieValues.map((cookieValue) => { 27 no ++; 28 if (cookieValue.indexOf(urlUTM) > -1) 29 addCookie = false; 30 }); 31// dl Limit 5 cookies 32 no = no > 5 ? 1 : no; 33 } 34 35 if (addCookie) 36 setCookie("aan_utm_"+ no, timestamp + "," + urlUTM, 14); 37 } 38 39 // console.log(getCookies("aan_utm")); 40} 41// Helper function to get cookie value 42function getCookies(name) { 43 var cookieValues = []; 44 var cookies = document.cookie.split(';'); 45 cookies.forEach(function(cookie) { 46 cookie = cookie.trim(); 47 if (cookie.startsWith(name)) 48 cookieValues.push(cookie); 49 }); 50 return cookieValues; 51} 52// Helper function to set cookie value 53function setCookie(name, value, days) { 54 var expires = ""; 55 if (days) { 56 var date = new Date(); 57 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 58 expires = "; expires=" + date.toUTCString(); 59 } 60 document.cookie = name + "=" + value + expires + "; path=/"; 61} 62// Call saveUTM function on every page load 63saveUTM();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.