1(function(){ 2 function setCookie(name, value, days){ 3 var d=new Date(); d.setTime(d.getTime()+days*864e5); 4 document.cookie=name+"="+encodeURIComponent(value)+"; expires="+d.toUTCString()+"; path=/; SameSite=Lax"; 5 } 6 function getCookie(name){ 7 var m=document.cookie.match(new RegExp('(^| )'+name+'=([^;]+)')); 8 return m?decodeURIComponent(m[2]):""; 9 } 10 function getParam(name){ 11 return (new URL(location.href)).searchParams.get(name)||""; 12 } 13 14 function getOrCreateUserId(){ 15 var k = "id_user_id"; 16 var v = localStorage.getItem(k); 17 if(!v){ v = uuidv4(); localStorage.setItem(k, v); } 18 return v; 19} 20 21 // Save first-touch landing and referrer 22 if (!localStorage.getItem("first_landing_url")) localStorage.setItem("first_landing_url", location.href); 23 if (!localStorage.getItem("first_referrer")) localStorage.setItem("first_referrer", document.referrer || ""); 24 25 // Capture click IDs from URL into cookies 26 var clickParams = [ 27 "fbclid","gclid","wbraid","gbraid","msclkid","ttclid","twclid","li_fat_id","sccid","epik" 28 ]; 29 clickParams.forEach(function(p){ 30 var v=getParam(p); 31 if (v) setCookie(p, v, 90); 32 }); 33 34 35 var fbclidParam = getParam("fbclid"); 36 if (fbclidParam) setCookie("fbclid", fbclidParam, 90); 37 38 // Ensure _fbc from fbclid if missing 39 if (!getCookie("_fbc")) { 40 var fbclid = fbclidParam || getCookie("fbclid"); 41 if (fbclid) setCookie("_fbc", "fb.1."+Date.now()+"."+fbclid, 90); 42} 43 44 function getGaClientId(){ 45 var ga=getCookie("_ga"); 46 if(!ga) return ""; 47 var parts=ga.split("."); 48 if(parts.length<4) return ""; 49 return parts[2]+"."+parts[3]; 50 } 51 52 function getGaSessionInfo(){ 53 // GA4 cookie looks like: _ga_MEASID=GS1.1.1700000000.1.1.1700000500.0.0.0 54 // We canât know MEASID here, so we scan cookies. 55 var cookies=document.cookie.split(";").map(c=>c.trim()); 56 var ga4=cookies.find(c=>c.startsWith("_ga_")); 57 if(!ga4) return { ga_session_id:"", ga_session_number:"" }; 58 var val=decodeURIComponent(ga4.split("=").slice(1).join("=")); 59 var parts=val.split("."); 60 // GS1.1.<session_id>.<session_number>.... 61 return { 62 ga_session_id: parts[2] || "", 63 ga_session_number: parts[3] || "" 64 }; 65 } 66 67 function uuidv4(){ 68 if (crypto && crypto.randomUUID) return crypto.randomUUID(); 69 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,function(c){ 70 var r=Math.random()*16|0,v=c=='x'?r:(r&0x3|0x8); return v.toString(16); 71 }); 72 } 73 74 window.buildTrackingPayload = function(extra){ 75 var eventId = localStorage.getItem("fs_event_id"); 76 if(!eventId){ eventId=uuidv4(); localStorage.setItem("fs_event_id", eventId); } 77 78 var sess = getGaSessionInfo(); 79 80 var payload = { 81 event_id: eventId, 82 user_id: getOrCreateUserId(), 83 // URLs 84 page_url: location.href, 85 page_path: location.pathname, 86 first_landing_url: localStorage.getItem("first_landing_url") || "", 87 first_referrer: localStorage.getItem("first_referrer") || "", 88 referrer: document.referrer || "", 89 90 // UTM 91 utm_source: getParam("utm_source") || "", 92 utm_medium: getParam("utm_medium") || "", 93 utm_campaign: getParam("utm_campaign") || "", 94 utm_term: getParam("utm_term") || "", 95 utm_content: getParam("utm_content") || "", 96 97 // Meta cookies 98 fbp: getCookie("_fbp"), 99 fbc: getCookie("_fbc"), 100 fbclid: getCookie("fbclid"), 101 102 // Google / other click IDs 103 gclid: getCookie("gclid"), 104 wbraid: getCookie("wbraid"), 105 gbraid: getCookie("gbraid"), 106 msclkid: getCookie("msclkid"), 107 ttclid: getCookie("ttclid"), 108 twclid: getCookie("twclid"), 109 li_fat_id: getCookie("li_fat_id"), 110 sccid: getCookie("sccid"), 111 epik: getCookie("epik"), 112 113 // GA identifiers 114 ga_client_id: getGaClientId(), 115 ga_session_id: sess.ga_session_id, 116 ga_session_number: sess.ga_session_number, 117 118 119 // Device 120 user_agent: navigator.userAgent, 121 language: navigator.language || "", 122 123 ipAddress: (window.__client_ip || "") 124 }; 125 126 if (extra && typeof extra === "object") {
127 Object.keys(extra).forEach(k => payload[k] = extra[k]); 128 } 129 130 return payload; 131 }; 132})();
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.