1// Gclid submit form 2function saveGclidCookie() { 3 const url = window.location.href; 4 const searchParams = new URLSearchParams(url.split('?')[1]); 5 6 const gclid = searchParams.get('gclid'); 7 8 const storedGclid = getCookie('gclid'); 9 if (storedGclid) { 10 const { 11 value: gclidValue, 12 expiration: gclidExpiration 13 } = JSON.parse(storedGclid); 14 15 if (new Date().getTime() <= gclidExpiration) { 16 return { 17 gclid: gclidValue 18 }; 19 } else { 20 deleteCookie('gclid'); 21 } 22 } 23 24 if (gclid) { 25 const expirationTime = new Date().getTime() + (3 * 24 * 60 * 60 * 1000); // 30 phút 26 27 const gclidObject = { 28 value: gclid, 29 expiration: expirationTime 30 }; 31 32 setCookieForm('gclid', JSON.stringify(gclidObject)); 33 return { 34 gclid: gclid 35 }; 36 } 37 38 return { 39 gclid: '' 40 }; 41} 42 43function setCookieForm(name, value, days = 365) { 44 const expirationDate = new Date(); 45 expirationDate.setTime(expirationDate.getTime() + (3 * 24 * 60 * 60 * 1000)); 46 const expires = "expires=" + expirationDate.toUTCString(); 47 document.cookie = name + "=" + value + ";" + expires + ";path=/"; 48} 49 50function getCookie(name) { 51 const cookieName = name + "="; 52 const cookies = document.cookie.split(';'); 53 for (let i = 0; i < cookies.length; i++) { 54 let cookie = cookies[i]; 55 while (cookie.charAt(0) === ' ') { 56 cookie = cookie.substring(1); 57 } 58 if (cookie.indexOf(cookieName) === 0) { 59 return decodeURIComponent(cookie.substring(cookieName.length, cookie.length)); 60 } 61 } 62 return null; 63} 64 65function deleteCookie(name) { 66 setCookieForm(name, '', -1); 67} 68saveGclidCookie();
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.