1// from packages/web-lib/src/tracking/leadSource.tracking.ts 2const n = { 3 invalidObject: "ERROR | INVALID LOCALSTORAGE OBJECT", 4 parseFailed: "ERROR | PARSING LOCALSTORAGE FAILED", 5 accessBlocked: "ERROR | LOCALSTORAGE ACCESS BLOCKED", 6 }, 7 i = "adSourceData", 8 a = { 9 savedFlag: "ilds", 10 savedValue: "1", 11 campaignId: "hsa_cam", 12 adGroupId: "hsa_grp", 13 source: "utm_source", 14 searchTerm: "utm_term", 15 }, 16 t = { complete: "complete", partial: "partial", empty: "empty", error: "error" }, 17 o = { google: "google", bing: "bing", none: "", unknown: (e) => `unknown | ${e}` }; 18function l(e) { 19 return ( 20 typeof e == "object" && 21 e !== null && 22 "unixTime" in e && 23 typeof e.unixTime == "number" && 24 "campaignId" in e && 25 typeof e.campaignId == "string" && 26 "adGroupId" in e && 27 typeof e.adGroupId == "string" && 28 "channel" in e && 29 typeof e.channel == "string" && 30 "searchTerm" in e && 31 typeof e.searchTerm == "string" 32 ); 33} 34function m(e) { 35 return ( 36 typeof e == "object" && 37 e !== null && 38 "numAdClicks" in e && 39 typeof e.numAdClicks == "number" && 40 "firstVisit" in e && 41 l(e.firstVisit) && 42 "lastVisit" in e && 43 l(e.lastVisit) 44 ); 45} 46export function getStoredLeadData() { 47 try { 48 const e = localStorage.getItem(i); 49 if (!e) return { ok: !0, hasData: !1 }; 50 const r = JSON.parse(e); 51 return m(r) 52 ? { ok: !0, hasData: !0, data: r } 53 : (console.error("Invalid lead data format:", r), d(), { ok: !1, error: n.invalidObject }); 54 } catch (e) { 55 const r = e instanceof DOMException && e.name === "SecurityError" ? n.accessBlocked : n.parseFailed; 56 return (console.error("Error getting lead data:", r, e), r !== n.accessBlocked && d(), { ok: !1, error: r }); 57 } 58} 59function c(e) { 60 try { 61 (localStorage.setItem(i, JSON.stringify(e)), p()); 62 } catch (r) { 63 console.error("Failed to save lead data to localStorage:", r); 64 } 65} 66function d() { 67 try { 68 localStorage.removeItem(i); 69 } catch (e) { 70 console.error("Failed to clear lead data from localStorage:", e); 71 } 72} 73function p() { 74 const e = new URL(window.location.href); 75 (e.searchParams.set(a.savedFlag, a.savedValue), window.history.pushState(null, "", e.toString())); 76} 77function f(e) { 78 const r = e.get(a.source); 79 switch (r) { 80 case null: 81 case "": 82 return o.none; 83 case "adwords": 84 case "google": 85 return o.google; 86 case "bing": 87 return o.bing; 88 default: 89 return o.unknown(r); 90 } 91} 92function h() { 93 let e; 94 try { 95 e = new URLSearchParams(window.location.search); 96 } catch (u) { 97 return (console.error("Error parsing URL search params:", u), { dataState: t.error }); 98 } 99 const r = { 100 unixTime: Date.now(), 101 campaignId: e.get(a.campaignId) ?? "", 102 adGroupId: e.get(a.adGroupId) ?? "", 103 channel: f(e), 104 searchTerm: e.get(a.searchTerm) ?? "", 105 }; 106 let s = t.empty; 107 return ( 108 (r.campaignId || r.adGroupId || r.channel || r.searchTerm) && (s = t.partial), 109 r.campaignId && r.adGroupId && r.channel && r.searchTerm && (s = t.complete), 110 { wasSaved: e.get(a.savedFlag) === a.savedValue, dataState: s, data: r } 111 ); 112} 113function S() { 114 const e = h(); 115 if (e.dataState === t.error || e.dataState === t.empty || e.wasSaved) return; 116 const r = getStoredLeadData(); 117 if (!r.ok) { 118 if (r.error === n.accessBlocked) return; 119 c({ 120 numAdClicks: 2, 121 firstVisit: { 122 campaignId: r.error, 123 adGroupId: r.error, 124 channel: r.error, 125 searchTerm: r.error, 126 unixTime: 0, 127 }, 128 lastVisit: e.data, 129 }); 130 return; 131 } 132 if (!r.hasData) { 133 c({ numAdClicks: 1, firstVisit: e.data, lastVisit: e.data }); 134 return; 135 } 136 c({ numAdClicks: r.data.numAdClicks + 1, firstVisit: r.data.firstVisit, lastVisit: e.data }); 137} 138S();
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.