1const { initZendesk } = ThirdPartyHelpers; 2const { initGtag, initAmplitude } = AnalyticsHelpers; 3 4window.getCookie = (cname) => { 5 let name = cname + "="; 6 let decodedCookie = decodeURIComponent(document.cookie); 7 let ca = decodedCookie.split(";"); 8 for (let i = 0; i < ca.length; i++) { 9 let c = ca[i]; 10 while (c.charAt(0) == " ") { 11 c = c.substring(1); 12 } 13 if (c.indexOf(name) == 0) { 14 return c.substring(name.length, c.length); 15 } 16 } 17 return ""; 18}; 19 20window.setCookie = (cname, cvalue, exdays) => { 21 let expires = ""; 22 if (exdays) { 23 const d = new Date(); 24 d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000); 25 expires = "; expires=" + d.toUTCString(); 26 } 27 document.cookie = 28 cname + 29 "=" + 30 cvalue + 31 expires + 32 ";path=/;domain=.krisp.ai;SameSite=None; secure"; 33}; 34 35const sanitizer = (string) => { 36 return string.replace(/[;\s].*/, ""); 37}; 38 39const forbiddenStrings = ["constructor", "__proto__"]; 40 41const checkString = (string) => { 42 return forbiddenStrings.every( 43 (forbiddenString) => !string.includes(forbiddenString), 44 ) 45 ? string 46 : false; 47}; 48 49const generateuuidv4 = () => { 50 return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) => 51 ( 52 c ^ 53 (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4))) 54 ).toString(16), 55 ); 56}; 57 58let anonymousId; 59let userId = getCookie("userId") || 0; 60let url = new URL(window.location.href); 61 62const setAnonymousCookie = () => { 63 anonymousId = getCookie("anonymousId"); 64 if (!anonymousId) { 65 anonymousId = generateuuidv4(); 66 } 67 setCookie("anonymousId", anonymousId, 2555); 68}; 69 70const setSessionIdCookie = (userId) => { 71 let sessionId = getCookie("krispSessionId"); 72 if (!sessionId) { 73 sessionId = generateuuidv4(); 74 } 75 setCookie("krispSessionId", sessionId); 76 window.dataLayer = window.dataLayer || []; 77 window.dataLayer.push({ 78 event: "sessionIDs", 79 sessionIDs: sessionId + "," + userId + "," + anonymousId, 80 }); 81}; 82 83const setExpAllowedCookie = () => { 84 let expCookie = getCookie("_expAllowed"); 85 if (!expCookie) { 86 setCookie("_expAllowed", "true", 365); 87 } 88}; 89 90const setAffiliateCookie = (affiliateParam) => { 91 let sanitizedParam = sanitizer(affiliateParam); 92 let affiliateParamValue = checkString(sanitizedParam); 93 if (affiliateParamValue) { 94 setCookie("refSource", affiliateParamValue, 30); 95 } 96}; 97 98const UTM_STORAGE_KEYS = [ 99 "utm_source", 100 "utm_medium", 101 "utm_campaign", 102 "utm_term", 103 "utm_content", 104 "utm_id", 105]; 106 107const UTM_COOKIE_DAYS = 90; 108 109// Persist UTM params as cookies (90 days), but only when OneTrust targeting 110// consent (C0002) is present. The cookie is overwritten whenever a new value is 111// present in the URL, so the most recent campaign always wins. 112const captureUtmsInCookies = () => { 113 if ( 114 !window.OnetrustActiveGroups || 115 !window.OnetrustActiveGroups.includes("C0002") 116 ) { 117 return; 118 } 119 try { 120 const params = new URL(window.location.href).searchParams; 121 UTM_STORAGE_KEYS.forEach((key) => { 122 const raw = params.get(key); 123 if (!raw) return; 124 const safe = checkString(sanitizer(raw)); 125 if (!safe) return; 126 setCookie(key, safe, UTM_COOKIE_DAYS); 127 }); 128 } catch (e) {} 129}; 130 131const initTapfiliate = (affiliateParam) => { 132 if (!affiliateParam || affiliateParam > 2000) return; 133 let tap_script = document.createElement("script"); 134 document.getElementsByTagName("head")[0].appendChild(tap_script); 135 tap_script.src = "https://script.tapfiliate.com/tapfiliate.js"; 136 tap_script.id = "Tapfillate"; 137 tap_script.async = true; 138 (function (t, a, p) { 139 t.TapfiliateObject = a; 140 t[a] = 141 t[a] || 142 function () { 143 (t[a].q = t[a].q || []).push(arguments); 144 }; 145 })(window, "tap"); 146 tap("create", "10671-17f705", { integration: "javascript" }); 147 tap("click", { referral_code: affiliateParam }); 148 setAffiliateCookie(affiliateParam); 149}; 150 151const affiliateParam = new URL(window.location.href).searchParams.get("ref"); 152 153const impactAffiliateRef = new URL(window.location.href).searchParams.get( 154 "im_ref", 155); 156 157const impactPartnerId = new URL(window.location.href).searchParams.get("irpid"); 158 159if (impactAffiliateRef && impactAffiliateRef !== null) { 160 let impactParam = sanitizer(impactAffiliateRef); 161 let impactParamValue = checkString(impactParam); 162 if (impactParamValue) {
163 setCookie("impact_im_ref", impactParamValue, 90); 164 } 165} 166 167// Always capture the Impact partner id (irpid) when present, independent of im_ref. 168if (impactPartnerId) { 169 setCookie("impact_partner_id", sanitizer(impactPartnerId), 90); 170} 171 172if (affiliateParam && affiliateParam !== null) { 173 initTapfiliate(affiliateParam); 174} 175 176let krispCookiesAvailable = false; 177let isAccessiBeLoaded = false; 178 179function setKrispCookies() { 180 if (krispCookiesAvailable) return; 181 if ( 182 !window.OnetrustActiveGroups || 183 window.OnetrustActiveGroups.includes("C0002") 184 ) { 185 krispCookiesAvailable = true; 186 setAnonymousCookie(); 187 setSessionIdCookie(userId); 188 setExpAllowedCookie(); 189 } 190} 191 192function loadLazyScripts() { 193 const pathname = window.location.pathname.toLowerCase(); 194 const isExcluded = 195 pathname === "/contact-center/" || 196 pathname.startsWith("/contact-center/") || 197 pathname === "/ai-accent-conversion/listener/"; 198 199 if (isExcluded) return; 200 201 $(window).one("keydown mouseover touchmove touchstart", function () { 202 //initZendesk(); 203 }); 204} 205 206function loadGtag() { 207 if ( 208 !window.OnetrustActiveGroups || 209 window.OnetrustActiveGroups.includes("C0002") 210 ) { 211 initGtag(); 212 } 213} 214 215function loadAmplitude() { 216 if ( 217 typeof window.OnetrustActiveGroups === "string" && 218 window.OnetrustActiveGroups.includes("C0002") 219 ) { 220 initAmplitude(); 221 } 222} 223 224let onConsentChangedBound = false; 225 226// Called by the OptanonWrapper declared in the head, either when OneTrust fires 227// it or right below if it already fired before this file ran. 228window.__otRun = function () { 229 setKrispCookies(); 230 loadLazyScripts(); 231 loadGtag(); 232 loadAmplitude(); 233 captureUtmsInCookies(); 234 235 // OneTrust can call the wrapper more than once; binding twice would run every 236 // handler twice on each consent change. 237 if (!onConsentChangedBound && window.Optanon) { 238 onConsentChangedBound = true; 239 Optanon.OnConsentChanged(function () { 240 setKrispCookies(); 241 loadLazyScripts(); 242 loadGtag(); 243 loadAmplitude(); 244 captureUtmsInCookies(); 245 }); 246 } 247}; 248 249if (window.__otFired) window.__otRun();
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.