@tracelog/lib 2.8.5 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- const hr = 9e5;
2
- const fr = 120, mr = 49152, gr = 100, Er = 500, pr = 200;
3
- const Sr = 1e3, Tr = 500, Ir = 1e3;
1
+ const fr = 9e5;
2
+ const mr = 120, gr = 49152, pr = 100, Er = 500, Sr = 200;
3
+ const Tr = 1e3, Ir = 500, vr = 1e3;
4
4
  const b = "data-tlog", bt = [
5
5
  "button",
6
6
  "a",
@@ -49,7 +49,7 @@ const b = "data-tlog", bt = [
49
49
  "code",
50
50
  "otp"
51
51
  ];
52
- const E = {
52
+ const p = {
53
53
  INVALID_SESSION_TIMEOUT: "Session timeout must be between 30000ms (30 seconds) and 86400000ms (24 hours)",
54
54
  INVALID_SAMPLING_RATE: "Sampling rate must be between 0 and 1",
55
55
  INVALID_ERROR_SAMPLING_RATE: "Error sampling must be between 0 and 1",
@@ -93,13 +93,13 @@ class re extends Error {
93
93
  super(e), this.name = "RateLimitError", Error.captureStackTrace && Error.captureStackTrace(this, re);
94
94
  }
95
95
  }
96
- class ie extends Error {
96
+ class ne extends Error {
97
97
  constructor(e) {
98
- super(e), this.name = "TimeoutError", Error.captureStackTrace && Error.captureStackTrace(this, ie);
98
+ super(e), this.name = "TimeoutError", Error.captureStackTrace && Error.captureStackTrace(this, ne);
99
99
  }
100
100
  }
101
- var u = /* @__PURE__ */ ((r) => (r.PAGE_VIEW = "page_view", r.CLICK = "click", r.SCROLL = "scroll", r.SESSION_START = "session_start", r.CUSTOM = "custom", r.WEB_VITALS = "web_vitals", r.ERROR = "error", r.VIEWPORT_VISIBLE = "viewport_visible", r))(u || {}), Z = /* @__PURE__ */ ((r) => (r.UP = "up", r.DOWN = "down", r))(Z || {}), B = /* @__PURE__ */ ((r) => (r.JS_ERROR = "js_error", r.PROMISE_REJECTION = "promise_rejection", r))(B || {}), ne = /* @__PURE__ */ ((r) => (r.QA = "qa", r))(ne || {});
102
- const vr = (r) => r.type === u.SCROLL && "scroll_data" in r && r.scroll_data.is_primary === !0, _r = (r) => r.type === u.SCROLL && "scroll_data" in r && r.scroll_data.is_primary === !1;
101
+ var u = /* @__PURE__ */ ((r) => (r.PAGE_VIEW = "page_view", r.CLICK = "click", r.SCROLL = "scroll", r.SESSION_START = "session_start", r.CUSTOM = "custom", r.WEB_VITALS = "web_vitals", r.ERROR = "error", r.VIEWPORT_VISIBLE = "viewport_visible", r))(u || {}), Z = /* @__PURE__ */ ((r) => (r.UP = "up", r.DOWN = "down", r))(Z || {}), B = /* @__PURE__ */ ((r) => (r.JS_ERROR = "js_error", r.PROMISE_REJECTION = "promise_rejection", r))(B || {}), ie = /* @__PURE__ */ ((r) => (r.QA = "qa", r))(ie || {});
102
+ const _r = (r) => r.type === u.SCROLL && "scroll_data" in r && r.scroll_data.is_primary === !0, yr = (r) => r.type === u.SCROLL && "scroll_data" in r && r.scroll_data.is_primary === !1;
103
103
  class j extends Error {
104
104
  constructor(e, t, s) {
105
105
  super(e), this.errorCode = t, this.layer = s, this.name = this.constructor.name, Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
@@ -127,13 +127,13 @@ class N extends j {
127
127
  super(e, "INTEGRATION_INVALID", t);
128
128
  }
129
129
  }
130
- class yr extends j {
130
+ class wr extends j {
131
131
  constructor(e, t, s = "runtime") {
132
132
  super(e, "INITIALIZATION_TIMEOUT", s), this.timeoutMs = t;
133
133
  }
134
134
  timeoutMs;
135
135
  }
136
- const it = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", nt = "background: #9e9e9e; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", Dt = "background: #d32f2f; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", kt = (r, e) => {
136
+ const nt = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", it = "background: #9e9e9e; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", Dt = "background: #d32f2f; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", kt = (r, e) => {
137
137
  if (e) {
138
138
  if (e instanceof Error) {
139
139
  const t = e.message.replace(/\s+at\s+.*$/gm, "").replace(/\s*\([^()]+:\d+:\d+\)/g, "");
@@ -161,25 +161,25 @@ const it = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8
161
161
  return !1;
162
162
  }
163
163
  }, a = (r, e, t) => {
164
- const { error: s, data: i, showToClient: n = !1, style: o, visibility: l } = t ?? {}, c = s ? kt(e, s) : `[TraceLog] ${e}`, d = r === "error" ? "error" : r === "warn" ? "warn" : "log";
165
- if (!Ut(l, n))
164
+ const { error: s, data: n, showToClient: i = !1, style: o, visibility: l } = t ?? {}, c = s ? kt(e, s) : `[TraceLog] ${e}`, d = r === "error" ? "error" : r === "warn" ? "warn" : "log";
165
+ if (!Ut(l, i))
166
166
  return;
167
- const g = Ft(l, o), I = i !== void 0 ? Ie(i) : void 0;
167
+ const g = Ft(l, o), I = n !== void 0 ? Ie(n) : void 0;
168
168
  Ht(d, c, g, I);
169
169
  }, Ut = (r, e) => r === "critical" ? !0 : r === "qa" || e ? Vt() : !1, Ft = (r, e) => e !== void 0 && e !== "" ? e : r === "critical" ? Dt : "", Ht = (r, e, t, s) => {
170
- const i = t !== void 0 && t !== "", n = i ? `%c${e}` : e;
171
- s !== void 0 ? i ? console[r](n, t, s) : console[r](n, s) : i ? console[r](n, t) : console[r](n);
170
+ const n = t !== void 0 && t !== "", i = n ? `%c${e}` : e;
171
+ s !== void 0 ? n ? console[r](i, t, s) : console[r](i, s) : n ? console[r](i, t) : console[r](i);
172
172
  }, Ie = (r) => {
173
173
  const e = {}, t = ["token", "password", "secret", "key", "apikey", "api_key", "sessionid", "session_id"];
174
- for (const [s, i] of Object.entries(r)) {
175
- const n = s.toLowerCase();
176
- if (t.some((o) => n.includes(o))) {
174
+ for (const [s, n] of Object.entries(r)) {
175
+ const i = s.toLowerCase();
176
+ if (t.some((o) => i.includes(o))) {
177
177
  e[s] = "[REDACTED]";
178
178
  continue;
179
179
  }
180
- i !== null && typeof i == "object" && !Array.isArray(i) ? e[s] = Ie(i) : Array.isArray(i) ? e[s] = i.map(
180
+ n !== null && typeof n == "object" && !Array.isArray(n) ? e[s] = Ie(n) : Array.isArray(n) ? e[s] = n.map(
181
181
  (o) => o !== null && typeof o == "object" && !Array.isArray(o) ? Ie(o) : o
182
- ) : e[s] = i;
182
+ ) : e[s] = n;
183
183
  }
184
184
  return e;
185
185
  };
@@ -201,10 +201,10 @@ const xt = () => {
201
201
  }, Bt = (r) => {
202
202
  const e = r.userAgentData?.brands;
203
203
  if (e != null && e.length > 0) {
204
- const i = e.filter((n) => !/not.?a.?brand|chromium/i.test(n.brand))[0];
205
- if (i != null) {
206
- const n = i.brand;
207
- return /google chrome/i.test(n) ? "Chrome" : /microsoft edge/i.test(n) ? "Edge" : /opera/i.test(n) ? "Opera" : n;
204
+ const n = e.filter((i) => !/not.?a.?brand|chromium/i.test(i.brand))[0];
205
+ if (n != null) {
206
+ const i = n.brand;
207
+ return /google chrome/i.test(i) ? "Chrome" : /microsoft edge/i.test(i) ? "Edge" : /opera/i.test(i) ? "Opera" : i;
208
208
  }
209
209
  }
210
210
  const t = navigator.userAgent;
@@ -217,8 +217,8 @@ const xt = () => {
217
217
  return c != null && c !== "" && /ipad|tablet/i.test(c) ? A.Tablet : r.userAgentData.mobile ? A.Mobile : A.Desktop;
218
218
  }
219
219
  xt();
220
- const e = window.innerWidth, t = ve?.matches ?? !1, s = ot?.matches ?? !1, i = "ontouchstart" in window || navigator.maxTouchPoints > 0, n = navigator.userAgent.toLowerCase(), o = /mobile|android|iphone|ipod|blackberry|iemobile|opera mini/.test(n), l = /tablet|ipad|android(?!.*mobile)/.test(n);
221
- return e <= 767 || o && i ? A.Mobile : e >= 768 && e <= 1024 || l || t && s && i ? A.Tablet : A.Desktop;
220
+ const e = window.innerWidth, t = ve?.matches ?? !1, s = ot?.matches ?? !1, n = "ontouchstart" in window || navigator.maxTouchPoints > 0, i = navigator.userAgent.toLowerCase(), o = /mobile|android|iphone|ipod|blackberry|iemobile|opera mini/.test(i), l = /tablet|ipad|android(?!.*mobile)/.test(i);
221
+ return e <= 767 || o && n ? A.Mobile : e >= 768 && e <= 1024 || l || t && s && n ? A.Tablet : A.Desktop;
222
222
  } catch (r) {
223
223
  return a("debug", "Device detection failed, defaulting to desktop", { error: r }), A.Desktop;
224
224
  }
@@ -254,7 +254,7 @@ const xt = () => {
254
254
  /:\/\/[^:/]+:([^@]+)@/gi,
255
255
  // Sensitive URL query parameters (token=, password=, auth=, secret=, api_key=, etc.)
256
256
  /[?&](token|password|passwd|auth|secret|secret_key|private_key|auth_key|api_key|apikey|access_token)=[^&\s]+/gi
257
- ], Xe = 500, Ge = 2e3, je = 5e3, ee = 50, Gt = ee * 2, lt = 1, jt = 1e3, zt = 10, ze = 5e3, Kt = 6e4, Qt = 64, wr = {
257
+ ], Xe = 500, Ge = 2e3, je = 5e3, ee = 50, Gt = ee * 2, lt = 1, jt = 1e3, Kt = 10, Ke = 5e3, zt = 6e4, Qt = 64, br = {
258
258
  LCP: 2500,
259
259
  // Good: ≤ 2.5s
260
260
  FCP: 1800,
@@ -266,7 +266,7 @@ const xt = () => {
266
266
  TTFB: 800,
267
267
  // Good: ≤ 800ms
268
268
  LONG_TASK: 50
269
- }, Ke = {
269
+ }, ze = {
270
270
  LCP: 2500,
271
271
  // Needs improvement: > 2.5s (same as good boundary)
272
272
  FCP: 1800,
@@ -296,13 +296,13 @@ const xt = () => {
296
296
  return { LCP: 0, FCP: 0, CLS: 0, INP: 0, TTFB: 0, LONG_TASK: 0 };
297
297
  // Track everything
298
298
  case "needs-improvement":
299
- return Ke;
299
+ return ze;
300
300
  case "poor":
301
301
  return Yt;
302
302
  default:
303
- return Ke;
303
+ return ze;
304
304
  }
305
- }, qt = 1e3, Jt = 50, Zt = "2.8.4", es = Zt, ct = () => typeof window < "u" && typeof sessionStorage < "u", ts = () => {
305
+ }, qt = 1e3, Jt = 50, Zt = "2.8.5", es = Zt, ct = () => typeof window < "u" && typeof sessionStorage < "u", ts = () => {
306
306
  try {
307
307
  const r = new URLSearchParams(window.location.search);
308
308
  r.delete(rt);
@@ -318,10 +318,10 @@ const xt = () => {
318
318
  let s = null;
319
319
  return e === Ue ? (s = !0, sessionStorage.setItem(X, "true"), a("info", "QA Mode ACTIVE", {
320
320
  visibility: "qa",
321
- style: it
321
+ style: nt
322
322
  })) : e === Fe && (s = !1, sessionStorage.setItem(X, "false"), a("info", "QA Mode DISABLED", {
323
323
  visibility: "qa",
324
- style: nt
324
+ style: it
325
325
  })), (e === Ue || e === Fe) && ts(), s ?? t === "true";
326
326
  } catch {
327
327
  return !1;
@@ -331,12 +331,12 @@ const xt = () => {
331
331
  try {
332
332
  sessionStorage.setItem(X, r ? "true" : "false"), a("info", r ? "QA Mode ACTIVE" : "QA Mode DISABLED", {
333
333
  visibility: "qa",
334
- style: r ? it : nt
334
+ style: r ? nt : it
335
335
  });
336
336
  } catch {
337
337
  a("debug", "Cannot set QA mode: sessionStorage unavailable");
338
338
  }
339
- }, is = [
339
+ }, ns = [
340
340
  "co.uk",
341
341
  "org.uk",
342
342
  "com.au",
@@ -353,24 +353,24 @@ const xt = () => {
353
353
  if (e.length <= 2)
354
354
  return r.toLowerCase();
355
355
  const t = e.slice(-2).join(".");
356
- return is.includes(t) ? e.slice(-3).join(".") : e.slice(-2).join(".");
357
- }, ns = (r, e) => r === e ? !0 : Ye(r) === Ye(e), me = () => {
356
+ return ns.includes(t) ? e.slice(-3).join(".") : e.slice(-2).join(".");
357
+ }, is = (r, e) => r === e ? !0 : Ye(r) === Ye(e), me = () => {
358
358
  const r = document.referrer;
359
359
  if (!r)
360
360
  return "Direct";
361
361
  try {
362
362
  const e = new URL(r).hostname.toLowerCase(), t = window.location.hostname.toLowerCase();
363
- return ns(e, t) ? "Direct" : r;
363
+ return is(e, t) ? "Direct" : r;
364
364
  } catch (e) {
365
365
  return a("debug", "Failed to parse referrer URL, using raw value", { error: e, data: { referrer: r } }), r;
366
366
  }
367
367
  }, ge = () => {
368
368
  const r = new URLSearchParams(window.location.search), e = {};
369
369
  return Lt.forEach((s) => {
370
- const i = r.get(s);
371
- if (i) {
372
- const n = s.split("utm_")[1];
373
- e[n] = i;
370
+ const n = r.get(s);
371
+ if (n) {
372
+ const i = s.split("utm_")[1];
373
+ e[i] = n;
374
374
  }
375
375
  }), Object.keys(e).length ? e : void 0;
376
376
  }, dt = () => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (r) => {
@@ -386,15 +386,15 @@ const os = () => {
386
386
  try {
387
387
  if (typeof crypto < "u" && crypto.getRandomValues) {
388
388
  const s = crypto.getRandomValues(new Uint8Array(3));
389
- s && (t = Array.from(s, (i) => i.toString(16).padStart(2, "0")).join(""));
389
+ s && (t = Array.from(s, (n) => n.toString(16).padStart(2, "0")).join(""));
390
390
  }
391
391
  } catch {
392
392
  }
393
393
  return t || (t = Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")), `${r}-${e}-${t}`;
394
394
  }, ut = (r, e = !1) => {
395
395
  try {
396
- const t = new URL(r), s = t.protocol === "https:", i = t.protocol === "http:";
397
- return s || e && i;
396
+ const t = new URL(r), s = t.protocol === "https:", n = t.protocol === "http:";
397
+ return s || e && n;
398
398
  } catch {
399
399
  return !1;
400
400
  }
@@ -412,13 +412,13 @@ const os = () => {
412
412
  throw new Error("Invalid hostname structure");
413
413
  if (s.length === 1)
414
414
  throw new Error("Single-part domain not supported for SaaS integration");
415
- let i;
416
- if (s.length === 2 ? i = s.join(".") : i = s.slice(-2).join("."), !i || i.split(".").length < 2)
415
+ let n;
416
+ if (s.length === 2 ? n = s.join(".") : n = s.slice(-2).join("."), !n || n.split(".").length < 2)
417
417
  throw new Error("Invalid domain structure for SaaS");
418
- const n = `https://${r}.${i}/collect`;
419
- if (!ut(n))
418
+ const i = `https://${r}.${n}/collect`;
419
+ if (!ut(i))
420
420
  throw new Error("Generated URL failed validation");
421
- return n;
421
+ return i;
422
422
  } catch (e) {
423
423
  throw new Error(`Invalid SaaS URL configuration: ${e instanceof Error ? e.message : String(e)}`);
424
424
  }
@@ -437,12 +437,12 @@ const os = () => {
437
437
  if (!r || typeof r != "string")
438
438
  return a("warn", "Invalid URL provided to normalizeUrl", { data: { type: typeof r } }), r || "";
439
439
  try {
440
- const t = new URL(r), s = t.searchParams, i = [.../* @__PURE__ */ new Set([...At, ...e])];
441
- let n = !1;
440
+ const t = new URL(r), s = t.searchParams, n = [.../* @__PURE__ */ new Set([...At, ...e])];
441
+ let i = !1;
442
442
  const o = [];
443
- return i.forEach((c) => {
444
- s.has(c) && (s.delete(c), n = !0, o.push(c));
445
- }), !n && r.includes("?") ? r : (t.search = s.toString(), t.toString());
443
+ return n.forEach((c) => {
444
+ s.has(c) && (s.delete(c), i = !0, o.push(c));
445
+ }), !i && r.includes("?") ? r : (t.search = s.toString(), t.toString());
446
446
  } catch (t) {
447
447
  return a("warn", "URL normalization failed, returning original", { error: t, data: { urlLength: r?.length } }), r;
448
448
  }
@@ -452,9 +452,9 @@ const os = () => {
452
452
  let e = r;
453
453
  r.length > 1e3 && (e = r.slice(0, Math.max(0, 1e3)));
454
454
  let t = 0;
455
- for (const i of Mt) {
456
- const n = e;
457
- e = e.replace(i, ""), n !== e && t++;
455
+ for (const n of Mt) {
456
+ const i = e;
457
+ e = e.replace(n, ""), i !== e && t++;
458
458
  }
459
459
  return t > 0 && a("warn", "XSS patterns detected and removed", {
460
460
  data: {
@@ -474,11 +474,11 @@ const os = () => {
474
474
  if (e > 10)
475
475
  return null;
476
476
  if (Array.isArray(r))
477
- return r.slice(0, 1e3).map((i) => we(i, e + 1)).filter((i) => i !== null);
477
+ return r.slice(0, 1e3).map((n) => we(n, e + 1)).filter((n) => n !== null);
478
478
  if (typeof r == "object") {
479
- const t = {}, i = Object.entries(r).slice(0, 200);
480
- for (const [n, o] of i) {
481
- const l = qe(n);
479
+ const t = {}, n = Object.entries(r).slice(0, 200);
480
+ for (const [i, o] of n) {
481
+ const l = qe(i);
482
482
  if (l) {
483
483
  const c = we(o, e + 1);
484
484
  c !== null && (t[l] = c);
@@ -502,41 +502,41 @@ const os = () => {
502
502
  throw new m("Configuration must be an object", "config");
503
503
  if (r) {
504
504
  if (r.sessionTimeout !== void 0 && (typeof r.sessionTimeout != "number" || r.sessionTimeout < 3e4 || r.sessionTimeout > 864e5))
505
- throw new Pt(E.INVALID_SESSION_TIMEOUT, "config");
505
+ throw new Pt(p.INVALID_SESSION_TIMEOUT, "config");
506
506
  if (r.globalMetadata !== void 0 && (typeof r.globalMetadata != "object" || r.globalMetadata === null))
507
- throw new m(E.INVALID_GLOBAL_METADATA, "config");
507
+ throw new m(p.INVALID_GLOBAL_METADATA, "config");
508
508
  if (r.integrations && hs(r.integrations), r.sensitiveQueryParams !== void 0) {
509
509
  if (!Array.isArray(r.sensitiveQueryParams))
510
- throw new m(E.INVALID_SENSITIVE_QUERY_PARAMS, "config");
510
+ throw new m(p.INVALID_SENSITIVE_QUERY_PARAMS, "config");
511
511
  for (const e of r.sensitiveQueryParams)
512
512
  if (typeof e != "string")
513
513
  throw new m("All sensitive query params must be strings", "config");
514
514
  }
515
515
  if (r.errorSampling !== void 0 && (typeof r.errorSampling != "number" || r.errorSampling < 0 || r.errorSampling > 1))
516
- throw new We(E.INVALID_ERROR_SAMPLING_RATE, "config");
516
+ throw new We(p.INVALID_ERROR_SAMPLING_RATE, "config");
517
517
  if (r.samplingRate !== void 0 && (typeof r.samplingRate != "number" || r.samplingRate < 0 || r.samplingRate > 1))
518
- throw new We(E.INVALID_SAMPLING_RATE, "config");
518
+ throw new We(p.INVALID_SAMPLING_RATE, "config");
519
519
  if (r.primaryScrollSelector !== void 0) {
520
520
  if (typeof r.primaryScrollSelector != "string" || !r.primaryScrollSelector.trim())
521
- throw new m(E.INVALID_PRIMARY_SCROLL_SELECTOR, "config");
521
+ throw new m(p.INVALID_PRIMARY_SCROLL_SELECTOR, "config");
522
522
  if (r.primaryScrollSelector !== "window")
523
523
  try {
524
524
  document.querySelector(r.primaryScrollSelector);
525
525
  } catch {
526
526
  throw new m(
527
- `${E.INVALID_PRIMARY_SCROLL_SELECTOR_SYNTAX}: "${r.primaryScrollSelector}"`,
527
+ `${p.INVALID_PRIMARY_SCROLL_SELECTOR_SYNTAX}: "${r.primaryScrollSelector}"`,
528
528
  "config"
529
529
  );
530
530
  }
531
531
  }
532
532
  if (r.pageViewThrottleMs !== void 0 && (typeof r.pageViewThrottleMs != "number" || r.pageViewThrottleMs < 0))
533
- throw new m(E.INVALID_PAGE_VIEW_THROTTLE, "config");
533
+ throw new m(p.INVALID_PAGE_VIEW_THROTTLE, "config");
534
534
  if (r.clickThrottleMs !== void 0 && (typeof r.clickThrottleMs != "number" || r.clickThrottleMs < 0))
535
- throw new m(E.INVALID_CLICK_THROTTLE, "config");
535
+ throw new m(p.INVALID_CLICK_THROTTLE, "config");
536
536
  if (r.maxSameEventPerMinute !== void 0 && (typeof r.maxSameEventPerMinute != "number" || r.maxSameEventPerMinute <= 0))
537
- throw new m(E.INVALID_MAX_SAME_EVENT_PER_MINUTE, "config");
537
+ throw new m(p.INVALID_MAX_SAME_EVENT_PER_MINUTE, "config");
538
538
  if (r.sendIntervalMs !== void 0 && (!Number.isFinite(r.sendIntervalMs) || r.sendIntervalMs < 1e3 || r.sendIntervalMs > 6e4))
539
- throw new m(E.INVALID_SEND_INTERVAL, "config");
539
+ throw new m(p.INVALID_SEND_INTERVAL, "config");
540
540
  if (r.viewport !== void 0 && us(r.viewport), r.webVitalsMode !== void 0) {
541
541
  if (typeof r.webVitalsMode != "string")
542
542
  throw new m(
@@ -570,15 +570,15 @@ const os = () => {
570
570
  }
571
571
  }, us = (r) => {
572
572
  if (typeof r != "object" || r === null)
573
- throw new m(E.INVALID_VIEWPORT_CONFIG, "config");
573
+ throw new m(p.INVALID_VIEWPORT_CONFIG, "config");
574
574
  if (!r.elements || !Array.isArray(r.elements))
575
- throw new m(E.INVALID_VIEWPORT_ELEMENTS, "config");
575
+ throw new m(p.INVALID_VIEWPORT_ELEMENTS, "config");
576
576
  if (r.elements.length === 0)
577
- throw new m(E.INVALID_VIEWPORT_ELEMENTS, "config");
577
+ throw new m(p.INVALID_VIEWPORT_ELEMENTS, "config");
578
578
  const e = /* @__PURE__ */ new Set();
579
579
  for (const t of r.elements) {
580
580
  if (!t.selector || typeof t.selector != "string" || !t.selector.trim())
581
- throw new m(E.INVALID_VIEWPORT_ELEMENT, "config");
581
+ throw new m(p.INVALID_VIEWPORT_ELEMENT, "config");
582
582
  const s = t.selector.trim();
583
583
  if (e.has(s))
584
584
  throw new m(
@@ -586,25 +586,25 @@ const os = () => {
586
586
  "config"
587
587
  );
588
588
  if (e.add(s), t.id !== void 0 && (typeof t.id != "string" || !t.id.trim()))
589
- throw new m(E.INVALID_VIEWPORT_ELEMENT_ID, "config");
589
+ throw new m(p.INVALID_VIEWPORT_ELEMENT_ID, "config");
590
590
  if (t.name !== void 0 && (typeof t.name != "string" || !t.name.trim()))
591
- throw new m(E.INVALID_VIEWPORT_ELEMENT_NAME, "config");
591
+ throw new m(p.INVALID_VIEWPORT_ELEMENT_NAME, "config");
592
592
  }
593
593
  if (r.threshold !== void 0 && (typeof r.threshold != "number" || r.threshold < 0 || r.threshold > 1))
594
- throw new m(E.INVALID_VIEWPORT_THRESHOLD, "config");
594
+ throw new m(p.INVALID_VIEWPORT_THRESHOLD, "config");
595
595
  if (r.minDwellTime !== void 0 && (typeof r.minDwellTime != "number" || r.minDwellTime < 0))
596
- throw new m(E.INVALID_VIEWPORT_MIN_DWELL_TIME, "config");
596
+ throw new m(p.INVALID_VIEWPORT_MIN_DWELL_TIME, "config");
597
597
  if (r.cooldownPeriod !== void 0 && (typeof r.cooldownPeriod != "number" || r.cooldownPeriod < 0))
598
- throw new m(E.INVALID_VIEWPORT_COOLDOWN_PERIOD, "config");
598
+ throw new m(p.INVALID_VIEWPORT_COOLDOWN_PERIOD, "config");
599
599
  if (r.maxTrackedElements !== void 0 && (typeof r.maxTrackedElements != "number" || r.maxTrackedElements <= 0))
600
- throw new m(E.INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS, "config");
600
+ throw new m(p.INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS, "config");
601
601
  }, hs = (r) => {
602
602
  if (r) {
603
603
  if (r.tracelog && (!r.tracelog.projectId || typeof r.tracelog.projectId != "string" || r.tracelog.projectId.trim() === ""))
604
- throw new N(E.INVALID_TRACELOG_PROJECT_ID, "config");
604
+ throw new N(p.INVALID_TRACELOG_PROJECT_ID, "config");
605
605
  if (r.custom) {
606
606
  if (!r.custom.collectApiUrl || typeof r.custom.collectApiUrl != "string" || r.custom.collectApiUrl.trim() === "")
607
- throw new N(E.INVALID_CUSTOM_API_URL, "config");
607
+ throw new N(p.INVALID_CUSTOM_API_URL, "config");
608
608
  if (r.custom.allowHttp !== void 0 && typeof r.custom.allowHttp != "boolean")
609
609
  throw new N("allowHttp must be a boolean", "config");
610
610
  const e = r.custom.collectApiUrl.trim();
@@ -672,49 +672,49 @@ const os = () => {
672
672
  valid: !1,
673
673
  error: "Event name cannot be a reserved word"
674
674
  } : { valid: !0 }, Je = (r, e, t) => {
675
- const s = cs(e), i = t && t === "customEvent" ? `${t} "${r}" metadata error` : `${r} metadata error`;
675
+ const s = cs(e), n = t && t === "customEvent" ? `${t} "${r}" metadata error` : `${r} metadata error`;
676
676
  if (!ms(s))
677
677
  return {
678
678
  valid: !1,
679
- error: `${i}: object has invalid types. Valid types are string, number, boolean or string arrays.`
679
+ error: `${n}: object has invalid types. Valid types are string, number, boolean or string arrays.`
680
680
  };
681
- let n;
681
+ let i;
682
682
  try {
683
- n = JSON.stringify(s);
683
+ i = JSON.stringify(s);
684
684
  } catch {
685
685
  return {
686
686
  valid: !1,
687
- error: `${i}: object contains circular references or cannot be serialized.`
687
+ error: `${n}: object contains circular references or cannot be serialized.`
688
688
  };
689
689
  }
690
- if (new TextEncoder().encode(n).byteLength > 49152)
690
+ if (new TextEncoder().encode(i).byteLength > 49152)
691
691
  return {
692
692
  valid: !1,
693
- error: `${i}: object is too large (max ${49152 / 1024} KB).`
693
+ error: `${n}: object is too large (max ${49152 / 1024} KB).`
694
694
  };
695
695
  if (Object.keys(s).length > 100)
696
696
  return {
697
697
  valid: !1,
698
- error: `${i}: object has too many keys (max 100 keys).`
698
+ error: `${n}: object has too many keys (max 100 keys).`
699
699
  };
700
700
  for (const [c, d] of Object.entries(s)) {
701
701
  if (Array.isArray(d)) {
702
702
  if (d.length > 500)
703
703
  return {
704
704
  valid: !1,
705
- error: `${i}: array property "${c}" is too large (max 500 items).`
705
+ error: `${n}: array property "${c}" is too large (max 500 items).`
706
706
  };
707
707
  for (const f of d)
708
708
  if (typeof f == "string" && f.length > 500)
709
709
  return {
710
710
  valid: !1,
711
- error: `${i}: array property "${c}" contains strings that are too long (max 500 characters).`
711
+ error: `${n}: array property "${c}" contains strings that are too long (max 500 characters).`
712
712
  };
713
713
  }
714
714
  if (typeof d == "string" && d.length > 1e3)
715
715
  return {
716
716
  valid: !1,
717
- error: `${i}: property "${c}" is too long (max 1000 characters).`
717
+ error: `${n}: property "${c}" is too long (max 1000 characters).`
718
718
  };
719
719
  }
720
720
  return {
@@ -723,19 +723,19 @@ const os = () => {
723
723
  };
724
724
  }, ft = (r, e, t) => {
725
725
  if (Array.isArray(e)) {
726
- const s = [], i = t && t === "customEvent" ? `${t} "${r}" metadata error` : `${r} metadata error`;
727
- for (let n = 0; n < e.length; n++) {
728
- const o = e[n];
726
+ const s = [], n = t && t === "customEvent" ? `${t} "${r}" metadata error` : `${r} metadata error`;
727
+ for (let i = 0; i < e.length; i++) {
728
+ const o = e[i];
729
729
  if (typeof o != "object" || o === null || Array.isArray(o))
730
730
  return {
731
731
  valid: !1,
732
- error: `${i}: array item at index ${n} must be an object.`
732
+ error: `${n}: array item at index ${i} must be an object.`
733
733
  };
734
734
  const l = Je(r, o, t);
735
735
  if (!l.valid)
736
736
  return {
737
737
  valid: !1,
738
- error: `${i}: array item at index ${n} is invalid: ${l.error}`
738
+ error: `${n}: array item at index ${i} is invalid: ${l.error}`
739
739
  };
740
740
  l.sanitizedMetadata && s.push(l.sanitizedMetadata);
741
741
  }
@@ -745,7 +745,7 @@ const os = () => {
745
745
  };
746
746
  }
747
747
  return Je(r, e, t);
748
- }, Es = (r, e) => {
748
+ }, ps = (r, e) => {
749
749
  const t = gs(r);
750
750
  if (!t.valid)
751
751
  return a("error", "Event name validation failed", {
@@ -761,7 +761,7 @@ const os = () => {
761
761
  }
762
762
  }), s;
763
763
  };
764
- class ps {
764
+ class Es {
765
765
  listeners = /* @__PURE__ */ new Map();
766
766
  /**
767
767
  * Subscribes to an event channel
@@ -814,8 +814,8 @@ class ps {
814
814
  off(e, t) {
815
815
  const s = this.listeners.get(e);
816
816
  if (s) {
817
- const i = s.indexOf(t);
818
- i > -1 && s.splice(i, 1);
817
+ const n = s.indexOf(t);
818
+ n > -1 && s.splice(n, 1);
819
819
  }
820
820
  }
821
821
  /**
@@ -848,8 +848,8 @@ class ps {
848
848
  */
849
849
  emit(e, t) {
850
850
  const s = this.listeners.get(e);
851
- s && s.forEach((i) => {
852
- i(t);
851
+ s && s.forEach((n) => {
852
+ n(t);
853
853
  });
854
854
  }
855
855
  /**
@@ -908,7 +908,7 @@ function gt(r, e, t) {
908
908
  }), r;
909
909
  }
910
910
  }
911
- const Ee = { config: {} };
911
+ const pe = { config: {} };
912
912
  class _ {
913
913
  /**
914
914
  * Retrieves a value from global state.
@@ -927,7 +927,7 @@ class _ {
927
927
  * ```
928
928
  */
929
929
  get(e) {
930
- return Ee[e];
930
+ return pe[e];
931
931
  }
932
932
  /**
933
933
  * Sets a value in global state.
@@ -947,7 +947,7 @@ class _ {
947
947
  * ```
948
948
  */
949
949
  set(e, t) {
950
- Ee[e] = t;
950
+ pe[e] = t;
951
951
  }
952
952
  /**
953
953
  * Returns an immutable snapshot of the entire global state.
@@ -964,7 +964,7 @@ class _ {
964
964
  * ```
965
965
  */
966
966
  getState() {
967
- return { ...Ee };
967
+ return { ...pe };
968
968
  }
969
969
  }
970
970
  class Ze extends _ {
@@ -1016,10 +1016,10 @@ class Ze extends _ {
1016
1016
  * @param customHeadersProvider - Optional callback for dynamic headers
1017
1017
  * @throws Error if integrationId and apiUrl are not both provided or both undefined
1018
1018
  */
1019
- constructor(e, t, s, i = {}, n = {}, o, l = "include") {
1019
+ constructor(e, t, s, n = {}, i = {}, o, l = "include") {
1020
1020
  if (super(), t && !s || !t && s)
1021
1021
  throw new Error("SenderManager: integrationId and apiUrl must either both be provided or both be undefined");
1022
- this.storeManager = e, this.integrationId = t, this.apiUrl = s, this.transformers = i, this.staticHeaders = n, this.customHeadersProvider = o, this.fetchCredentials = l, this.rateLimitedUntil = this.loadRateLimitCooldown();
1022
+ this.storeManager = e, this.integrationId = t, this.apiUrl = s, this.transformers = n, this.staticHeaders = i, this.customHeadersProvider = o, this.fetchCredentials = l, this.rateLimitedUntil = this.loadRateLimitCooldown();
1023
1023
  }
1024
1024
  /**
1025
1025
  * Get the integration ID for this sender
@@ -1100,8 +1100,8 @@ class Ze extends _ {
1100
1100
  try {
1101
1101
  const s = this.storeManager.getItem(t);
1102
1102
  if (s) {
1103
- const i = Number(s);
1104
- if (Number.isFinite(i) && i >= e)
1103
+ const n = Number(s);
1104
+ if (Number.isFinite(n) && n >= e)
1105
1105
  return;
1106
1106
  }
1107
1107
  this.storeManager.setItem(t, String(e));
@@ -1181,8 +1181,8 @@ class Ze extends _ {
1181
1181
  }
1182
1182
  }
1183
1183
  );
1184
- const t = this.ensureBatchMetadata(e), s = this.getPersistedData(), i = typeof s?.recoveryFailures == "number" && Number.isFinite(s.recoveryFailures) ? s.recoveryFailures : 0;
1185
- return this.persistEventsWithFailureCount(t, i, !0), !1;
1184
+ const t = this.ensureBatchMetadata(e), s = this.getPersistedData(), n = typeof s?.recoveryFailures == "number" && Number.isFinite(s.recoveryFailures) ? s.recoveryFailures : 0;
1185
+ return this.persistEventsWithFailureCount(t, n, !0), !1;
1186
1186
  }
1187
1187
  return this.apiUrl?.includes($.Fail) ? (a(
1188
1188
  "warn",
@@ -1231,10 +1231,10 @@ class Ze extends _ {
1231
1231
  async sendEventsQueue(e, t) {
1232
1232
  const s = this.ensureBatchMetadata(e);
1233
1233
  try {
1234
- const i = await this.send(s);
1235
- return i ? (this.clearPersistedEvents(), t?.onSuccess?.(s.events.length, s.events, s)) : (this.persistEvents(s), t?.onFailure?.()), i;
1236
- } catch (i) {
1237
- return i instanceof O ? (this.logPermanentError("Permanent error, not retrying", i), this.clearPersistedEvents(), t?.onFailure?.(), !1) : (this.persistEvents(s), t?.onFailure?.(), !1);
1234
+ const n = await this.send(s);
1235
+ return n ? (this.clearPersistedEvents(), t?.onSuccess?.(s.events.length, s.events, s)) : (this.persistEvents(s), t?.onFailure?.()), n;
1236
+ } catch (n) {
1237
+ return n instanceof O ? (this.logPermanentError("Permanent error, not retrying", n), this.clearPersistedEvents(), t?.onFailure?.(), !1) : (this.persistEvents(s), t?.onFailure?.(), !1);
1238
1238
  }
1239
1239
  }
1240
1240
  /**
@@ -1294,13 +1294,13 @@ class Ze extends _ {
1294
1294
  this.recoveryInProgress = !0;
1295
1295
  let t = null, s = 0;
1296
1296
  try {
1297
- const i = this.getPersistedData();
1298
- if (!i || !this.isDataRecent(i) || i.events.length === 0) {
1297
+ const n = this.getPersistedData();
1298
+ if (!n || !this.isDataRecent(n) || n.events.length === 0) {
1299
1299
  this.clearPersistedEvents();
1300
1300
  return;
1301
1301
  }
1302
- const n = i.recoveryFailures;
1303
- if (s = typeof n == "number" && Number.isFinite(n) && n >= 0 ? n : 0, s >= 3) {
1302
+ const i = n.recoveryFailures;
1303
+ if (s = typeof i == "number" && Number.isFinite(i) && i >= 0 ? i : 0, s >= 3) {
1304
1304
  a(
1305
1305
  "debug",
1306
1306
  `Discarding persisted events after ${s} failed recovery attempts${this.integrationId ? ` [${this.integrationId}]` : ""}`
@@ -1317,13 +1317,13 @@ class Ze extends _ {
1317
1317
  ), e?.onFailure?.();
1318
1318
  return;
1319
1319
  }
1320
- t = this.ensureBatchMetadata(this.createRecoveryBody(i)), await this.send(t) ? (this.clearPersistedEvents(), e?.onSuccess?.(i.events.length, i.events, t)) : (this.persistEventsWithFailureCount(t, s + 1, !0), e?.onFailure?.());
1321
- } catch (i) {
1322
- if (i instanceof O) {
1323
- this.logPermanentError("Permanent error during recovery, clearing persisted events", i), this.clearPersistedEvents(), e?.onFailure?.();
1320
+ t = this.ensureBatchMetadata(this.createRecoveryBody(n)), await this.send(t) ? (this.clearPersistedEvents(), e?.onSuccess?.(n.events.length, n.events, t)) : (this.persistEventsWithFailureCount(t, s + 1, !0), e?.onFailure?.());
1321
+ } catch (n) {
1322
+ if (n instanceof O) {
1323
+ this.logPermanentError("Permanent error during recovery, clearing persisted events", n), this.clearPersistedEvents(), e?.onFailure?.();
1324
1324
  return;
1325
1325
  }
1326
- a("error", "Failed to recover persisted events", { error: i }), t && this.persistEventsWithFailureCount(t, s + 1, !0), e?.onFailure?.();
1326
+ a("error", "Failed to recover persisted events", { error: n }), t && this.persistEventsWithFailureCount(t, s + 1, !0), e?.onFailure?.();
1327
1327
  } finally {
1328
1328
  this.recoveryInProgress = !1;
1329
1329
  }
@@ -1440,8 +1440,8 @@ class Ze extends _ {
1440
1440
  * @returns Promise that resolves after calculated delay
1441
1441
  */
1442
1442
  async backoffDelay(e) {
1443
- const t = 100 * Math.pow(2, e), s = Math.random() * 100, i = t + s;
1444
- return new Promise((n) => setTimeout(n, i));
1443
+ const t = 100 * Math.pow(2, e), s = Math.random() * 100, n = t + s;
1444
+ return new Promise((i) => setTimeout(i, n));
1445
1445
  }
1446
1446
  /**
1447
1447
  * Sends event queue with automatic retry logic for transient failures.
@@ -1486,20 +1486,20 @@ class Ze extends _ {
1486
1486
  const s = this.applyBeforeBatchTransformer(t);
1487
1487
  if (!s)
1488
1488
  return !0;
1489
- const i = this.ensureBatchMetadata(s, e._metadata?.idempotency_token);
1489
+ const n = this.ensureBatchMetadata(s, e._metadata?.idempotency_token);
1490
1490
  if (this.apiUrl?.includes($.Fail))
1491
1491
  return a("debug", `Fail mode: simulating network failure${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
1492
- data: { events: i.events.length }
1492
+ data: { events: n.events.length }
1493
1493
  }), !1;
1494
1494
  if (this.apiUrl?.includes($.Localhost))
1495
1495
  return a("debug", `Success mode: simulating successful send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
1496
- data: { events: i.events.length }
1496
+ data: { events: n.events.length }
1497
1497
  }), !0;
1498
1498
  if (this.isRateLimited())
1499
1499
  return a("debug", `Rate-limit cooldown active, skipping send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
1500
1500
  data: {
1501
1501
  cooldownRemainingMs: this.rateLimitedUntil - Date.now(),
1502
- events: i.events.length
1502
+ events: n.events.length
1503
1503
  }
1504
1504
  }), !1;
1505
1505
  if (this.consecutiveNetworkFailures >= 3) {
@@ -1512,15 +1512,15 @@ class Ze extends _ {
1512
1512
  }
1513
1513
  }), !1;
1514
1514
  }
1515
- const { url: n, payload: o } = this.prepareRequest(i);
1515
+ const { url: i, payload: o } = this.prepareRequest(n);
1516
1516
  let l = !0, c = !1;
1517
1517
  for (let d = 1; d <= 3; d++)
1518
1518
  try {
1519
- return (await this.sendWithTimeout(n, o)).ok ? (d > 1 && a(
1519
+ return (await this.sendWithTimeout(i, o)).ok ? (d > 1 && a(
1520
1520
  "info",
1521
1521
  `Send succeeded after ${d - 1} retry attempt(s)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
1522
1522
  {
1523
- data: { events: i.events.length, attempt: d }
1523
+ data: { events: n.events.length, attempt: d }
1524
1524
  }
1525
1525
  ), this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, !0) : !1;
1526
1526
  } catch (f) {
@@ -1533,14 +1533,14 @@ class Ze extends _ {
1533
1533
  });
1534
1534
  break;
1535
1535
  }
1536
- if (f instanceof ie || (l = !1), f instanceof TypeError || (c = !0), a(
1536
+ if (f instanceof ne || (l = !1), f instanceof TypeError || (c = !0), a(
1537
1537
  g ? "error" : "warn",
1538
1538
  `Send attempt ${d} failed${this.integrationId ? ` [${this.integrationId}]` : ""}${g ? " (all retries exhausted)" : ", will retry"}`,
1539
1539
  {
1540
1540
  error: f,
1541
1541
  data: {
1542
1542
  events: e.events.length,
1543
- url: n.replace(/\/\/[^/]+/, "//[DOMAIN]"),
1543
+ url: i.replace(/\/\/[^/]+/, "//[DOMAIN]"),
1544
1544
  attempt: d,
1545
1545
  maxAttempts: 3
1546
1546
  }
@@ -1553,7 +1553,7 @@ class Ze extends _ {
1553
1553
  "debug",
1554
1554
  `All retry attempts timed out, preserving batch for retry${this.integrationId ? ` [${this.integrationId}]` : ""}`,
1555
1555
  {
1556
- data: { events: i.events.length }
1556
+ data: { events: n.events.length }
1557
1557
  }
1558
1558
  ), !1) : (c ? (this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0) : (this.consecutiveNetworkFailures = Math.min(
1559
1559
  this.consecutiveNetworkFailures + 1,
@@ -1588,9 +1588,9 @@ class Ze extends _ {
1588
1588
  async sendWithTimeout(e, t) {
1589
1589
  const s = new AbortController();
1590
1590
  this.pendingControllers.add(s);
1591
- let i = !1;
1592
- const n = setTimeout(() => {
1593
- i = !0, s.abort();
1591
+ let n = !1;
1592
+ const i = setTimeout(() => {
1593
+ n = !0, s.abort();
1594
1594
  }, 15e3);
1595
1595
  try {
1596
1596
  const o = this.getCustomHeaders(), l = await fetch(e, {
@@ -1613,9 +1613,9 @@ class Ze extends _ {
1613
1613
  }
1614
1614
  return l;
1615
1615
  } catch (o) {
1616
- throw o instanceof O ? o : i ? new ie("Request timed out") : o;
1616
+ throw o instanceof O ? o : n ? new ne("Request timed out") : o;
1617
1617
  } finally {
1618
- clearTimeout(n), this.pendingControllers.delete(s);
1618
+ clearTimeout(i), this.pendingControllers.delete(s);
1619
1619
  }
1620
1620
  }
1621
1621
  /**
@@ -1662,10 +1662,10 @@ class Ze extends _ {
1662
1662
  const t = this.ensureBatchMetadata(e), s = this.applyBeforeSendTransformer(t);
1663
1663
  if (!s)
1664
1664
  return !0;
1665
- const i = this.applyBeforeBatchTransformer(s);
1666
- if (!i)
1665
+ const n = this.applyBeforeBatchTransformer(s);
1666
+ if (!n)
1667
1667
  return !0;
1668
- const n = this.ensureBatchMetadata(i, t._metadata?.idempotency_token), { url: o, payload: l } = this.prepareRequest(n);
1668
+ const i = this.ensureBatchMetadata(n, t._metadata?.idempotency_token), { url: o, payload: l } = this.prepareRequest(i);
1669
1669
  if (l.length > 65536)
1670
1670
  return a(
1671
1671
  "warn",
@@ -1674,7 +1674,7 @@ class Ze extends _ {
1674
1674
  data: {
1675
1675
  size: l.length,
1676
1676
  limit: 65536,
1677
- events: n.events.length
1677
+ events: i.events.length
1678
1678
  }
1679
1679
  }
1680
1680
  ), this.persistEvents(t), !1;
@@ -1756,11 +1756,11 @@ class Ze extends _ {
1756
1756
  * @private
1757
1757
  */
1758
1758
  computeContentToken(e) {
1759
- const t = e.events.map((n) => n.id).sort().join(","), s = `${e.user_id}|${e.session_id}|${t}`;
1760
- let i = 2166136261;
1761
- for (let n = 0; n < s.length; n++)
1762
- i ^= s.charCodeAt(n), i = Math.imul(i, 16777619) >>> 0;
1763
- return i.toString(16).padStart(8, "0");
1759
+ const t = e.events.map((i) => i.id).sort().join(","), s = `${e.user_id}|${e.session_id}|${t}`;
1760
+ let n = 2166136261;
1761
+ for (let i = 0; i < s.length; i++)
1762
+ n ^= s.charCodeAt(i), n = Math.imul(n, 16777619) >>> 0;
1763
+ return n.toString(16).padStart(8, "0");
1764
1764
  }
1765
1765
  /**
1766
1766
  * Retrieves persisted events from localStorage with error recovery.
@@ -1810,8 +1810,8 @@ class Ze extends _ {
1810
1810
  * @private
1811
1811
  */
1812
1812
  createRecoveryBody(e) {
1813
- const { timestamp: t, recoveryFailures: s, ...i } = e;
1814
- return i;
1813
+ const { timestamp: t, recoveryFailures: s, ...n } = e;
1814
+ return n;
1815
1815
  }
1816
1816
  /**
1817
1817
  * Persists failed events to localStorage for next-page-load recovery.
@@ -1850,9 +1850,9 @@ class Ze extends _ {
1850
1850
  */
1851
1851
  persistEventsWithFailureCount(e, t, s = !1) {
1852
1852
  try {
1853
- const i = this.getPersistedData();
1854
- if (!s && i && i.timestamp) {
1855
- const l = Date.now() - i.timestamp;
1853
+ const n = this.getPersistedData();
1854
+ if (!s && n && n.timestamp) {
1855
+ const l = Date.now() - n.timestamp;
1856
1856
  if (l < 1e3)
1857
1857
  return a(
1858
1858
  "debug",
@@ -1862,14 +1862,14 @@ class Ze extends _ {
1862
1862
  }
1863
1863
  ), !0;
1864
1864
  }
1865
- const n = {
1865
+ const i = {
1866
1866
  ...e,
1867
1867
  timestamp: Date.now(),
1868
1868
  ...t > 0 && { recoveryFailures: t }
1869
1869
  }, o = this.getQueueStorageKey();
1870
- return this.storeManager.setItem(o, JSON.stringify(n)), !!this.storeManager.getItem(o);
1871
- } catch (i) {
1872
- return a("debug", `Failed to persist events${this.integrationId ? ` [${this.integrationId}]` : ""}`, { error: i }), !1;
1870
+ return this.storeManager.setItem(o, JSON.stringify(i)), !!this.storeManager.getItem(o);
1871
+ } catch (n) {
1872
+ return a("debug", `Failed to persist events${this.integrationId ? ` [${this.integrationId}]` : ""}`, { error: n }), !1;
1873
1873
  }
1874
1874
  }
1875
1875
  clearPersistedEvents() {
@@ -1893,10 +1893,10 @@ class Ze extends _ {
1893
1893
  return typeof navigator < "u" && typeof navigator.sendBeacon == "function";
1894
1894
  }
1895
1895
  logPermanentError(e, t) {
1896
- const s = Date.now(), i = `${t.statusCode ?? "unknown"}:${t.responseCode ?? ""}`;
1897
- (!this.lastPermanentErrorLog || this.lastPermanentErrorLog.key !== i || s - this.lastPermanentErrorLog.timestamp >= Kt) && (a("error", `${e}${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
1896
+ const s = Date.now(), n = `${t.statusCode ?? "unknown"}:${t.responseCode ?? ""}`;
1897
+ (!this.lastPermanentErrorLog || this.lastPermanentErrorLog.key !== n || s - this.lastPermanentErrorLog.timestamp >= zt) && (a("error", `${e}${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
1898
1898
  data: { status: t.statusCode, code: t.responseCode, message: t.message }
1899
- }), this.lastPermanentErrorLog = { key: i, timestamp: s });
1899
+ }), this.lastPermanentErrorLog = { key: n, timestamp: s });
1900
1900
  }
1901
1901
  }
1902
1902
  class Ts extends _ {
@@ -2026,10 +2026,10 @@ class Ts extends _ {
2026
2026
  * ```
2027
2027
  */
2028
2028
  validateTimestamp(e) {
2029
- const s = this.now(), i = e - s;
2030
- return i > 12e4 ? {
2029
+ const s = this.now(), n = e - s;
2030
+ return n > 12e4 ? {
2031
2031
  valid: !1,
2032
- error: `Timestamp is ${(i / 1e3 / 60).toFixed(2)} minutes in the future (max allowed: 2 minutes)`
2032
+ error: `Timestamp is ${(n / 1e3 / 60).toFixed(2)} minutes in the future (max allowed: 2 minutes)`
2033
2033
  } : { valid: !0 };
2034
2034
  }
2035
2035
  /**
@@ -2087,7 +2087,7 @@ class vs extends _ {
2087
2087
  * @param customHeadersProvider - Optional callback for dynamic headers
2088
2088
  * @param fetchCredentials - Fetch credentials mode for custom backend. @default 'include'
2089
2089
  */
2090
- constructor(e, t = null, s = {}, i = {}, n, o = "include") {
2090
+ constructor(e, t = null, s = {}, n = {}, i, o = "include") {
2091
2091
  super(), this.emitter = t, this.transformers = s, this.timeManager = new Ts(), this.dataSenders = [];
2092
2092
  const l = this.get("collectApiUrls");
2093
2093
  l?.saas && this.dataSenders.push(new Ze(e, "saas", l.saas, s)), l?.custom && this.dataSenders.push(
@@ -2096,8 +2096,8 @@ class vs extends _ {
2096
2096
  "custom",
2097
2097
  l.custom,
2098
2098
  s,
2099
- i,
2100
2099
  n,
2100
+ i,
2101
2101
  o
2102
2102
  )
2103
2103
  ), this.saveSessionCountsDebounced = this.debounce((c) => {
@@ -2131,10 +2131,10 @@ class vs extends _ {
2131
2131
  async recoverPersistedEvents() {
2132
2132
  const e = this.dataSenders.map(
2133
2133
  async (t) => t.recoverPersistedEvents({
2134
- onSuccess: (s, i, n) => {
2135
- if (i && i.length > 0) {
2136
- const o = i.map((l) => l.id);
2137
- this.removeProcessedEvents(o), n && this.emitEventsQueue(n);
2134
+ onSuccess: (s, n, i) => {
2135
+ if (n && n.length > 0) {
2136
+ const o = n.map((l) => l.id);
2137
+ this.removeProcessedEvents(o), i && this.emitEventsQueue(i);
2138
2138
  }
2139
2139
  },
2140
2140
  onFailure: () => {
@@ -2207,8 +2207,8 @@ class vs extends _ {
2207
2207
  type: e,
2208
2208
  page_url: t,
2209
2209
  from_page_url: s,
2210
- scroll_data: i,
2211
- click_data: n,
2210
+ scroll_data: n,
2211
+ click_data: i,
2212
2212
  custom_event: o,
2213
2213
  web_vitals: l,
2214
2214
  error_data: c,
@@ -2233,8 +2233,8 @@ class vs extends _ {
2233
2233
  type: e,
2234
2234
  page_url: t,
2235
2235
  from_page_url: s,
2236
- scroll_data: i,
2237
- click_data: n,
2236
+ scroll_data: n,
2237
+ click_data: i,
2238
2238
  custom_event: o,
2239
2239
  web_vitals: l,
2240
2240
  error_data: c,
@@ -2249,25 +2249,25 @@ class vs extends _ {
2249
2249
  data: { sessionId: g }
2250
2250
  }), !I && !this.checkRateLimit())
2251
2251
  return;
2252
- const p = e;
2252
+ const E = e;
2253
2253
  if (!I) {
2254
2254
  if (this.sessionEventCounts.total >= 1e3) {
2255
2255
  a("warn", "Session event limit reached", {
2256
2256
  data: {
2257
- type: p,
2257
+ type: E,
2258
2258
  total: this.sessionEventCounts.total,
2259
2259
  limit: 1e3
2260
2260
  }
2261
2261
  });
2262
2262
  return;
2263
2263
  }
2264
- const v = this.getTypeLimitForEvent(p);
2264
+ const v = this.getTypeLimitForEvent(E);
2265
2265
  if (v) {
2266
- const he = this.sessionEventCounts[p];
2266
+ const he = this.sessionEventCounts[E];
2267
2267
  if (he !== void 0 && he >= v) {
2268
2268
  a("warn", "Session event type limit reached", {
2269
2269
  data: {
2270
- type: p,
2270
+ type: E,
2271
2271
  count: he,
2272
2272
  limit: v
2273
2273
  }
@@ -2276,17 +2276,17 @@ class vs extends _ {
2276
2276
  }
2277
2277
  }
2278
2278
  }
2279
- if (p === u.CUSTOM && o?.name) {
2279
+ if (E === u.CUSTOM && o?.name) {
2280
2280
  const v = this.get("config")?.maxSameEventPerMinute ?? 60;
2281
2281
  if (!this.checkPerEventRateLimit(o.name, v))
2282
2282
  return;
2283
2283
  }
2284
- const Ve = p === u.SESSION_START, Q = t || this.get("pageUrl"), x = this.buildEventPayload({
2285
- type: p,
2284
+ const Ve = E === u.SESSION_START, Q = t || this.get("pageUrl"), x = this.buildEventPayload({
2285
+ type: E,
2286
2286
  page_url: Q,
2287
2287
  from_page_url: s,
2288
- scroll_data: i,
2289
- click_data: n,
2288
+ scroll_data: n,
2289
+ click_data: i,
2290
2290
  custom_event: o,
2291
2291
  web_vitals: l,
2292
2292
  error_data: c,
@@ -2309,8 +2309,8 @@ class vs extends _ {
2309
2309
  this.set("hasStartSession", !0);
2310
2310
  }
2311
2311
  if (!this.isDuplicateEvent(x)) {
2312
- if (this.get("mode") === ne.QA) {
2313
- if (p === u.CUSTOM && o) {
2312
+ if (this.get("mode") === ie.QA) {
2313
+ if (E === u.CUSTOM && o) {
2314
2314
  a("info", `Custom Event: ${o.name}`, {
2315
2315
  visibility: "qa",
2316
2316
  data: {
@@ -2320,7 +2320,7 @@ class vs extends _ {
2320
2320
  }), this.emitEvent(x);
2321
2321
  return;
2322
2322
  }
2323
- if (p === u.VIEWPORT_VISIBLE && d) {
2323
+ if (E === u.VIEWPORT_VISIBLE && d) {
2324
2324
  const v = d.name || d.id || d.selector;
2325
2325
  a("info", `Viewport Visible: ${v}`, {
2326
2326
  visibility: "qa",
@@ -2336,7 +2336,7 @@ class vs extends _ {
2336
2336
  }
2337
2337
  }
2338
2338
  if (this.addToQueue(x), !I) {
2339
- this.sessionEventCounts.total++, this.sessionEventCounts[p] !== void 0 && this.sessionEventCounts[p]++;
2339
+ this.sessionEventCounts.total++, this.sessionEventCounts[E] !== void 0 && this.sessionEventCounts[E]++;
2340
2340
  const v = this.get("sessionId");
2341
2341
  v && this.saveSessionCountsDebounced && this.saveSessionCountsDebounced(v);
2342
2342
  }
@@ -2602,20 +2602,20 @@ class vs extends _ {
2602
2602
  return e ? !0 : Promise.resolve(!0);
2603
2603
  if (!e && this.sendInProgress)
2604
2604
  return a("debug", "Async flush skipped: send already in progress"), Promise.resolve(!1);
2605
- const t = this.buildEventsPayload(), s = [...this.eventsQueue], i = s.map((n) => n.id);
2605
+ const t = this.buildEventsPayload(), s = [...this.eventsQueue], n = s.map((i) => i.id);
2606
2606
  if (this.dataSenders.length === 0)
2607
- return this.removeProcessedEvents(i), this.clearSendTimeout(), this.emitEventsQueue(t), e ? !0 : Promise.resolve(!0);
2607
+ return this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t), e ? !0 : Promise.resolve(!0);
2608
2608
  if (e && this.sendInProgress)
2609
2609
  return a("debug", "Sync flush skipped: async send already in-flight, trusting fetch to deliver", {
2610
- data: { eventCount: i.length }
2610
+ data: { eventCount: n.length }
2611
2611
  }), !0;
2612
2612
  if (e) {
2613
2613
  const o = this.dataSenders.map((l) => l.sendEventsQueueSync(t)).some((l) => l);
2614
- return o ? (this.removeProcessedEvents(i), this.clearSendTimeout(), this.emitEventsQueue(t)) : (this.clearSendTimeout(), a("debug", "Sync flush complete failure, events kept in queue for retry", {
2615
- data: { eventCount: i.length }
2614
+ return o ? (this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t)) : (this.clearSendTimeout(), a("debug", "Sync flush complete failure, events kept in queue for retry", {
2615
+ data: { eventCount: n.length }
2616
2616
  })), o;
2617
2617
  } else {
2618
- const n = this.dataSenders.map(
2618
+ const i = this.dataSenders.map(
2619
2619
  async (o) => o.sendEventsQueue(t, {
2620
2620
  onSuccess: () => {
2621
2621
  },
@@ -2623,9 +2623,9 @@ class vs extends _ {
2623
2623
  }
2624
2624
  })
2625
2625
  );
2626
- return Promise.allSettled(n).then((o) => {
2626
+ return Promise.allSettled(i).then((o) => {
2627
2627
  const l = o.some((c) => this.isSuccessfulResult(c));
2628
- return l ? (this.removeProcessedEvents(i), this.clearSendTimeout(), this.emitEventsQueue(t)) : a("debug", "Async flush complete failure, events kept in queue for retry", {
2628
+ return l ? (this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t)) : a("debug", "Async flush complete failure, events kept in queue for retry", {
2629
2629
  data: { eventCount: s.length }
2630
2630
  }), l;
2631
2631
  });
@@ -2640,17 +2640,17 @@ class vs extends _ {
2640
2640
  this.emitEventsQueue(e);
2641
2641
  return;
2642
2642
  }
2643
- const t = [...this.eventsQueue], s = t.map((l) => l.id), i = this.dataSenders.map(
2643
+ const t = [...this.eventsQueue], s = t.map((l) => l.id), n = this.dataSenders.map(
2644
2644
  async (l) => l.sendEventsQueue(e, {
2645
2645
  onSuccess: () => {
2646
2646
  },
2647
2647
  onFailure: () => {
2648
2648
  }
2649
2649
  })
2650
- ), n = await Promise.allSettled(i);
2651
- if (n.some((l) => this.isSuccessfulResult(l))) {
2650
+ ), i = await Promise.allSettled(n);
2651
+ if (i.some((l) => this.isSuccessfulResult(l))) {
2652
2652
  this.consecutiveSendFailures = 0, this.removeProcessedEvents(s), this.emitEventsQueue(e);
2653
- const l = n.filter((c) => !this.isSuccessfulResult(c)).length;
2653
+ const l = i.filter((c) => !this.isSuccessfulResult(c)).length;
2654
2654
  l > 0 && a("debug", "Periodic send completed with some failures, removed from queue and persisted per-integration", {
2655
2655
  data: { eventCount: t.length, failedCount: l }
2656
2656
  });
@@ -2671,7 +2671,7 @@ class vs extends _ {
2671
2671
  e.has(d) || t.push(d), e.set(d, c);
2672
2672
  }
2673
2673
  const s = t.map((c) => e.get(c)).filter((c) => !!c).sort((c, d) => c.type === u.SESSION_START && d.type !== u.SESSION_START ? -1 : d.type === u.SESSION_START && c.type !== u.SESSION_START ? 1 : c.timestamp - d.timestamp);
2674
- let i = {
2674
+ let n = {
2675
2675
  user_id: this.get("userId"),
2676
2676
  session_id: this.get("sessionId"),
2677
2677
  device: this.get("device"),
@@ -2679,25 +2679,25 @@ class vs extends _ {
2679
2679
  ...this.get("config")?.globalMetadata && { global_metadata: this.get("config")?.globalMetadata },
2680
2680
  ...this.get("identity") && { identify: this.get("identity") }
2681
2681
  };
2682
- const n = this.get("collectApiUrls"), o = !!(n?.custom || n?.saas), l = this.transformers.beforeBatch;
2682
+ const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas), l = this.transformers.beforeBatch;
2683
2683
  if (!o && l) {
2684
- const c = gt(i, l, "EventManager");
2685
- c !== null && (i = c);
2684
+ const c = gt(n, l, "EventManager");
2685
+ c !== null && (n = c);
2686
2686
  }
2687
- return i;
2687
+ return n;
2688
2688
  }
2689
2689
  buildEventPayload(e) {
2690
- const t = e.page_url ?? this.get("pageUrl"), s = this.timeManager.now(), i = this.timeManager.validateTimestamp(s);
2691
- i.valid || a("warn", "Event timestamp validation failed", {
2692
- data: { type: e.type, error: i.error }
2690
+ const t = e.page_url ?? this.get("pageUrl"), s = this.timeManager.now(), n = this.timeManager.validateTimestamp(s);
2691
+ n.valid || a("warn", "Event timestamp validation failed", {
2692
+ data: { type: e.type, error: n.error }
2693
2693
  });
2694
- const n = this.get("sessionReferrer"), o = this.get("sessionUtm");
2694
+ const i = this.get("sessionReferrer"), o = this.get("sessionUtm");
2695
2695
  let l = {
2696
2696
  id: os(),
2697
2697
  type: e.type,
2698
2698
  page_url: t,
2699
2699
  timestamp: s,
2700
- ...n && { referrer: n },
2700
+ ...i && { referrer: i },
2701
2701
  ...e.from_page_url && { from_page_url: e.from_page_url },
2702
2702
  ...e.scroll_data && { scroll_data: e.scroll_data },
2703
2703
  ...e.click_data && { click_data: e.click_data },
@@ -2708,9 +2708,9 @@ class vs extends _ {
2708
2708
  ...e.page_view && { page_view: e.page_view },
2709
2709
  ...o && { utm: o }
2710
2710
  };
2711
- const c = this.get("collectApiUrls"), d = !!c?.custom, f = !!c?.saas, g = d || f, I = d && f, p = this.transformers.beforeSend;
2712
- if (p && (!g || d && !I)) {
2713
- const Q = mt(l, p, "EventManager");
2711
+ const c = this.get("collectApiUrls"), d = !!c?.custom, f = !!c?.saas, g = d || f, I = d && f, E = this.transformers.beforeSend;
2712
+ if (E && (!g || d && !I)) {
2713
+ const Q = mt(l, E, "EventManager");
2714
2714
  if (Q === null)
2715
2715
  return null;
2716
2716
  l = Q;
@@ -2718,15 +2718,15 @@ class vs extends _ {
2718
2718
  return l;
2719
2719
  }
2720
2720
  isDuplicateEvent(e) {
2721
- const t = Date.now(), s = this.createEventFingerprint(e), i = this.recentEventFingerprints.get(s);
2722
- return i && t - i < 1e3 ? (this.recentEventFingerprints.set(s, t), !0) : (this.recentEventFingerprints.set(s, t), this.recentEventFingerprints.size > 1500 && this.pruneOldFingerprints(), this.recentEventFingerprints.size > 3e3 && (this.recentEventFingerprints.clear(), this.recentEventFingerprints.set(s, t), a("debug", "Event fingerprint cache exceeded hard limit, cleared", {
2721
+ const t = Date.now(), s = this.createEventFingerprint(e), n = this.recentEventFingerprints.get(s);
2722
+ return n && t - n < 1e3 ? (this.recentEventFingerprints.set(s, t), !0) : (this.recentEventFingerprints.set(s, t), this.recentEventFingerprints.size > 1500 && this.pruneOldFingerprints(), this.recentEventFingerprints.size > 3e3 && (this.recentEventFingerprints.clear(), this.recentEventFingerprints.set(s, t), a("debug", "Event fingerprint cache exceeded hard limit, cleared", {
2723
2723
  data: { hardLimit: 3e3 }
2724
2724
  })), !1);
2725
2725
  }
2726
2726
  pruneOldFingerprints() {
2727
2727
  const e = Date.now(), t = 1e3 * 10;
2728
- for (const [s, i] of this.recentEventFingerprints.entries())
2729
- e - i > t && this.recentEventFingerprints.delete(s);
2728
+ for (const [s, n] of this.recentEventFingerprints.entries())
2729
+ e - n > t && this.recentEventFingerprints.delete(s);
2730
2730
  a("debug", "Pruned old event fingerprints", {
2731
2731
  data: {
2732
2732
  remaining: this.recentEventFingerprints.size,
@@ -2737,8 +2737,8 @@ class vs extends _ {
2737
2737
  createEventFingerprint(e) {
2738
2738
  let t = `${e.type}_${e.page_url}`;
2739
2739
  if (e.click_data) {
2740
- const s = Math.round((e.click_data.x || 0) / 10) * 10, i = Math.round((e.click_data.y || 0) / 10) * 10;
2741
- t += `_click_${s}_${i}`;
2740
+ const s = Math.round((e.click_data.x || 0) / 10) * 10, n = Math.round((e.click_data.y || 0) / 10) * 10;
2741
+ t += `_click_${s}_${n}`;
2742
2742
  }
2743
2743
  return e.scroll_data && (t += `_scroll_${e.scroll_data.depth}_${e.scroll_data.direction}`), e.custom_event && (t += `_custom_${e.custom_event.name}`, e.custom_event.metadata && (t += `_${this.stableStringify(e.custom_event.metadata)}`)), e.web_vitals && (t += `_vitals_${e.web_vitals.type}`), e.error_data && (t += `_error_${e.error_data.type}_${e.error_data.message}`), t;
2744
2744
  }
@@ -2747,11 +2747,11 @@ class vs extends _ {
2747
2747
  }
2748
2748
  /** Deterministic JSON string with sorted keys to ensure consistent fingerprints regardless of property insertion order */
2749
2749
  stableStringify(e) {
2750
- return JSON.stringify(e, (t, s) => s && typeof s == "object" && !Array.isArray(s) ? Object.keys(s).sort().reduce((i, n) => (i[n] = s[n], i), {}) : s);
2750
+ return JSON.stringify(e, (t, s) => s && typeof s == "object" && !Array.isArray(s) ? Object.keys(s).sort().reduce((n, i) => (n[i] = s[i], n), {}) : s);
2751
2751
  }
2752
2752
  addToQueue(e) {
2753
2753
  if (this.emitEvent(e), this.eventsQueue.push(e), this.eventsQueue.length > 100) {
2754
- const t = this.eventsQueue.findIndex((i) => i.type !== u.SESSION_START), s = t >= 0 ? this.eventsQueue.splice(t, 1)[0] : this.eventsQueue.shift();
2754
+ const t = this.eventsQueue.findIndex((n) => n.type !== u.SESSION_START), s = t >= 0 ? this.eventsQueue.splice(t, 1)[0] : this.eventsQueue.shift();
2755
2755
  a("warn", "Event queue overflow, oldest non-critical event removed", {
2756
2756
  data: {
2757
2757
  maxLength: 100,
@@ -2785,14 +2785,14 @@ class vs extends _ {
2785
2785
  return e - this.rateLimitWindowStart > 1e3 && (this.rateLimitCounter = 0, this.rateLimitWindowStart = e), this.rateLimitCounter >= 50 ? !1 : (this.rateLimitCounter++, !0);
2786
2786
  }
2787
2787
  checkPerEventRateLimit(e, t) {
2788
- const s = Date.now(), n = (this.perEventRateLimits.get(e) ?? []).filter((o) => s - o < 6e4);
2789
- return n.length >= t ? (a("warn", "Per-event rate limit exceeded for custom event", {
2788
+ const s = Date.now(), i = (this.perEventRateLimits.get(e) ?? []).filter((o) => s - o < 6e4);
2789
+ return i.length >= t ? (a("warn", "Per-event rate limit exceeded for custom event", {
2790
2790
  data: {
2791
2791
  eventName: e,
2792
2792
  limit: t,
2793
2793
  window: `${6e4 / 1e3}s`
2794
2794
  }
2795
- }), !1) : (n.push(s), this.perEventRateLimits.set(e, n), !0);
2795
+ }), !1) : (i.push(s), this.perEventRateLimits.set(e, i), !0);
2796
2796
  }
2797
2797
  getTypeLimitForEvent(e) {
2798
2798
  return {
@@ -2835,9 +2835,9 @@ class vs extends _ {
2835
2835
  */
2836
2836
  debounce(e, t) {
2837
2837
  let s = null;
2838
- return ((...i) => {
2838
+ return ((...n) => {
2839
2839
  s !== null && clearTimeout(s), s = setTimeout(() => {
2840
- e(...i), s = null;
2840
+ e(...n), s = null;
2841
2841
  }, t);
2842
2842
  });
2843
2843
  }
@@ -2889,27 +2889,27 @@ class vs extends _ {
2889
2889
  return this.getInitialCounts();
2890
2890
  const t = this.get("userId") || "anonymous", s = He(t, e);
2891
2891
  try {
2892
- const i = localStorage.getItem(s);
2893
- if (!i)
2892
+ const n = localStorage.getItem(s);
2893
+ if (!n)
2894
2894
  return this.getInitialCounts();
2895
- const n = JSON.parse(i);
2896
- return n._timestamp && Date.now() - n._timestamp > xe ? (a("debug", "Session counts expired, clearing", {
2897
- data: { sessionId: e, age: Date.now() - n._timestamp }
2898
- }), localStorage.removeItem(s), this.getInitialCounts()) : typeof n.total == "number" && typeof n[u.CLICK] == "number" && typeof n[u.PAGE_VIEW] == "number" && typeof n[u.CUSTOM] == "number" && typeof n[u.VIEWPORT_VISIBLE] == "number" && typeof n[u.SCROLL] == "number" ? {
2899
- total: n.total,
2900
- [u.CLICK]: n[u.CLICK],
2901
- [u.PAGE_VIEW]: n[u.PAGE_VIEW],
2902
- [u.CUSTOM]: n[u.CUSTOM],
2903
- [u.VIEWPORT_VISIBLE]: n[u.VIEWPORT_VISIBLE],
2904
- [u.SCROLL]: n[u.SCROLL]
2895
+ const i = JSON.parse(n);
2896
+ return i._timestamp && Date.now() - i._timestamp > xe ? (a("debug", "Session counts expired, clearing", {
2897
+ data: { sessionId: e, age: Date.now() - i._timestamp }
2898
+ }), localStorage.removeItem(s), this.getInitialCounts()) : typeof i.total == "number" && typeof i[u.CLICK] == "number" && typeof i[u.PAGE_VIEW] == "number" && typeof i[u.CUSTOM] == "number" && typeof i[u.VIEWPORT_VISIBLE] == "number" && typeof i[u.SCROLL] == "number" ? {
2899
+ total: i.total,
2900
+ [u.CLICK]: i[u.CLICK],
2901
+ [u.PAGE_VIEW]: i[u.PAGE_VIEW],
2902
+ [u.CUSTOM]: i[u.CUSTOM],
2903
+ [u.VIEWPORT_VISIBLE]: i[u.VIEWPORT_VISIBLE],
2904
+ [u.SCROLL]: i[u.SCROLL]
2905
2905
  } : (a("warn", "Invalid session counts structure in localStorage, resetting", {
2906
- data: { sessionId: e, parsed: n }
2906
+ data: { sessionId: e, parsed: i }
2907
2907
  }), localStorage.removeItem(s), a("debug", "Session counts removed due to invalid/corrupted data", {
2908
- data: { sessionId: e, parsed: n }
2908
+ data: { sessionId: e, parsed: i }
2909
2909
  }), this.getInitialCounts());
2910
- } catch (i) {
2910
+ } catch (n) {
2911
2911
  return a("warn", "Failed to load session counts from localStorage", {
2912
- error: i,
2912
+ error: n,
2913
2913
  data: { sessionId: e }
2914
2914
  }), this.getInitialCounts();
2915
2915
  }
@@ -2940,30 +2940,30 @@ class vs extends _ {
2940
2940
  try {
2941
2941
  const e = localStorage.getItem($e);
2942
2942
  if (e) {
2943
- const n = Date.now() - parseInt(e, 10);
2944
- if (n < Be) {
2943
+ const i = Date.now() - parseInt(e, 10);
2944
+ if (i < Be) {
2945
2945
  a("debug", "Skipping session counts cleanup (throttled)", {
2946
- data: { timeSinceLastCleanup: n, throttleMs: Be }
2946
+ data: { timeSinceLastCleanup: i, throttleMs: Be }
2947
2947
  });
2948
2948
  return;
2949
2949
  }
2950
2950
  }
2951
- const t = this.get("userId") || "anonymous", s = `${S}:${t}:session_counts:`, i = [];
2952
- for (let n = 0; n < localStorage.length; n++) {
2953
- const o = localStorage.key(n);
2951
+ const t = this.get("userId") || "anonymous", s = `${S}:${t}:session_counts:`, n = [];
2952
+ for (let i = 0; i < localStorage.length; i++) {
2953
+ const o = localStorage.key(i);
2954
2954
  if (o?.startsWith(s))
2955
2955
  try {
2956
2956
  const l = localStorage.getItem(o);
2957
2957
  if (l) {
2958
2958
  const c = JSON.parse(l);
2959
- c._timestamp && Date.now() - c._timestamp > xe && i.push(o);
2959
+ c._timestamp && Date.now() - c._timestamp > xe && n.push(o);
2960
2960
  }
2961
2961
  } catch {
2962
2962
  }
2963
2963
  }
2964
- i.forEach((n) => {
2965
- localStorage.removeItem(n), a("debug", "Cleaned up expired session counts", { data: { key: n } });
2966
- }), i.length > 0 && a("info", `Cleaned up ${i.length} expired session counts entries`), localStorage.setItem($e, Date.now().toString());
2964
+ n.forEach((i) => {
2965
+ localStorage.removeItem(i), a("debug", "Cleaned up expired session counts", { data: { key: i } });
2966
+ }), n.length > 0 && a("info", `Cleaned up ${n.length} expired session counts entries`), localStorage.setItem($e, Date.now().toString());
2967
2967
  } catch (e) {
2968
2968
  a("warn", "Failed to cleanup expired session counts", { error: e });
2969
2969
  }
@@ -2999,15 +2999,15 @@ class vs extends _ {
2999
2999
  saveSessionCounts(e) {
3000
3000
  const t = this.get("userId") || "anonymous", s = He(t, e);
3001
3001
  try {
3002
- const i = {
3002
+ const n = {
3003
3003
  ...this.sessionEventCounts,
3004
3004
  _timestamp: Date.now(),
3005
3005
  _version: 1
3006
3006
  };
3007
- localStorage.setItem(s, JSON.stringify(i));
3008
- } catch (i) {
3007
+ localStorage.setItem(s, JSON.stringify(n));
3008
+ } catch (n) {
3009
3009
  a("warn", "Failed to persist session counts to localStorage", {
3010
- error: i,
3010
+ error: n,
3011
3011
  data: { sessionId: e }
3012
3012
  });
3013
3013
  }
@@ -3066,8 +3066,8 @@ class ws extends _ {
3066
3066
  }
3067
3067
  const e = this.getProjectId();
3068
3068
  this.broadcastChannel = new BroadcastChannel(Ot(e)), this.broadcastChannel.onmessage = (t) => {
3069
- const { action: s, sessionId: i, timestamp: n, projectId: o } = t.data ?? {};
3070
- o === e && (s === "session_start" && i && typeof n == "number" && n > Date.now() - 5e3 ? (this.set("sessionId", i), this.persistSession(i, n), this.isTracking && this.setupSessionTimeout()) : s && s !== "session_start" && a("debug", "Ignored BroadcastChannel message with unknown action", { data: { action: s } }));
3069
+ const { action: s, sessionId: n, timestamp: i, projectId: o } = t.data ?? {};
3070
+ o === e && (s === "session_start" && n && typeof i == "number" && i > Date.now() - 5e3 ? (this.set("sessionId", n), this.persistSession(n, i), this.isTracking && this.setupSessionTimeout()) : s && s !== "session_start" && a("debug", "Ignored BroadcastChannel message with unknown action", { data: { action: s } }));
3071
3071
  };
3072
3072
  }
3073
3073
  shareSession(e) {
@@ -3092,12 +3092,12 @@ class ws extends _ {
3092
3092
  const t = this.get("config")?.sessionTimeout ?? 9e5;
3093
3093
  return Date.now() - e.lastActivity > t ? (this.clearStoredSession(), null) : e.id;
3094
3094
  }
3095
- persistSession(e, t = Date.now(), s, i) {
3095
+ persistSession(e, t = Date.now(), s, n) {
3096
3096
  this.saveStoredSession({
3097
3097
  id: e,
3098
3098
  lastActivity: t,
3099
3099
  ...s && { referrer: s },
3100
- ...i && { utm: i }
3100
+ ...n && { utm: n }
3101
3101
  });
3102
3102
  }
3103
3103
  clearStoredSession() {
@@ -3108,18 +3108,18 @@ class ws extends _ {
3108
3108
  const e = this.getSessionStorageKey(), t = this.storageManager.getItem(e);
3109
3109
  if (t !== null)
3110
3110
  try {
3111
- const i = JSON.parse(t);
3112
- if (i.id && typeof i.lastActivity == "number")
3113
- return i;
3111
+ const n = JSON.parse(t);
3112
+ if (n.id && typeof n.lastActivity == "number")
3113
+ return n;
3114
3114
  } catch {
3115
3115
  this.storageManager.removeItem(e);
3116
3116
  }
3117
3117
  const s = this.storageManager.getSessionItem(e);
3118
3118
  if (s !== null)
3119
3119
  try {
3120
- const i = JSON.parse(s);
3121
- if (i.id && typeof i.lastActivity == "number")
3122
- return i;
3120
+ const n = JSON.parse(s);
3121
+ if (n.id && typeof n.lastActivity == "number")
3122
+ return n;
3123
3123
  } catch {
3124
3124
  this.storageManager.removeSessionItem(e);
3125
3125
  }
@@ -3193,31 +3193,31 @@ class ws extends _ {
3193
3193
  return;
3194
3194
  }
3195
3195
  const e = this.recoverSession(), t = e ?? this.generateSessionId();
3196
- let s, i;
3196
+ let s, n;
3197
3197
  if (e) {
3198
- const n = this.loadStoredSession();
3199
- s = n?.referrer ?? me(), i = n?.utm ?? ge();
3198
+ const i = this.loadStoredSession();
3199
+ s = i?.referrer ?? me(), n = i?.utm ?? ge();
3200
3200
  } else
3201
- s = me(), i = ge();
3201
+ s = me(), n = ge();
3202
3202
  a("debug", "Session tracking initialized", {
3203
3203
  data: {
3204
3204
  sessionId: t,
3205
3205
  wasRecovered: !!e,
3206
3206
  willEmitSessionStart: !e,
3207
3207
  sessionReferrer: s,
3208
- hasUtm: !!i
3208
+ hasUtm: !!n
3209
3209
  }
3210
3210
  }), this.isTracking = !0;
3211
3211
  try {
3212
- this.set("sessionId", t), this.set("sessionReferrer", s), this.set("sessionUtm", i), this.persistSession(t, Date.now(), s, i), this.initCrossTabSync(), this.shareSession(t), e ? a("debug", "Session recovered, skipping SESSION_START", {
3212
+ this.set("sessionId", t), this.set("sessionReferrer", s), this.set("sessionUtm", n), this.persistSession(t, Date.now(), s, n), this.initCrossTabSync(), this.shareSession(t), e ? a("debug", "Session recovered, skipping SESSION_START", {
3213
3213
  data: { sessionId: t }
3214
3214
  }) : (a("debug", "Emitting SESSION_START event", {
3215
3215
  data: { sessionId: t }
3216
3216
  }), this.eventManager.track({
3217
3217
  type: u.SESSION_START
3218
3218
  })), this.setupSessionTimeout(), this.setupActivityListeners(), this.setupLifecycleListeners();
3219
- } catch (n) {
3220
- throw this.isTracking = !1, this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupLifecycleListeners(), this.cleanupCrossTabSync(), this.set("sessionId", null), n;
3219
+ } catch (i) {
3220
+ throw this.isTracking = !1, this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupLifecycleListeners(), this.cleanupCrossTabSync(), this.set("sessionId", null), i;
3221
3221
  }
3222
3222
  }
3223
3223
  generateSessionId() {
@@ -3501,17 +3501,17 @@ class Ls extends _ {
3501
3501
  const e = window.location.href, t = ye(e, this.get("config").sensitiveQueryParams);
3502
3502
  if (this.get("pageUrl") === t)
3503
3503
  return;
3504
- const s = Date.now(), i = this.get("config").pageViewThrottleMs ?? 1e3;
3505
- if (s - this.lastPageViewTime < i)
3504
+ const s = Date.now(), n = this.get("config").pageViewThrottleMs ?? 1e3;
3505
+ if (s - this.lastPageViewTime < n)
3506
3506
  return;
3507
3507
  this.lastPageViewTime = s, this.onTrack();
3508
- const n = this.get("pageUrl");
3508
+ const i = this.get("pageUrl");
3509
3509
  this.set("pageUrl", t);
3510
3510
  const o = this.extractPageViewData();
3511
3511
  this.eventManager.track({
3512
3512
  type: u.PAGE_VIEW,
3513
3513
  page_url: this.get("pageUrl"),
3514
- from_page_url: n,
3514
+ from_page_url: i,
3515
3515
  ...o && { page_view: o }
3516
3516
  });
3517
3517
  };
@@ -3524,10 +3524,10 @@ class Ls extends _ {
3524
3524
  }), this.onTrack();
3525
3525
  }
3526
3526
  extractPageViewData() {
3527
- const { pathname: e, search: t, hash: s } = window.location, { referrer: i } = document, { title: n } = document;
3528
- return !i && !n && !e && !t && !s ? void 0 : {
3529
- ...i && { referrer: i },
3530
- ...n && { title: n },
3527
+ const { pathname: e, search: t, hash: s } = window.location, { referrer: n } = document, { title: i } = document;
3528
+ return !n && !i && !e && !t && !s ? void 0 : {
3529
+ ...n && { referrer: n },
3530
+ ...i && { title: i },
3531
3531
  ...e && { pathname: e },
3532
3532
  ...t && { search: t },
3533
3533
  ...s && { hash: s }
@@ -3557,17 +3557,17 @@ class As extends _ {
3557
3557
  */
3558
3558
  startTracking() {
3559
3559
  this.clickHandler || (this.clickHandler = (e) => {
3560
- const t = e, s = t.target, i = typeof HTMLElement < "u" && s instanceof HTMLElement ? s : typeof HTMLElement < "u" && s instanceof Node && s.parentElement instanceof HTMLElement ? s.parentElement : null;
3561
- if (!i) {
3560
+ const t = e, s = t.target, n = typeof HTMLElement < "u" && s instanceof HTMLElement ? s : typeof HTMLElement < "u" && s instanceof Node && s.parentElement instanceof HTMLElement ? s.parentElement : null;
3561
+ if (!n) {
3562
3562
  a("debug", "Click target not found or not an element");
3563
3563
  return;
3564
3564
  }
3565
- if (this.shouldIgnoreElement(i))
3565
+ if (this.shouldIgnoreElement(n))
3566
3566
  return;
3567
- const n = this.get("config")?.clickThrottleMs ?? 300;
3568
- if (n > 0 && !this.checkClickThrottle(i, n))
3567
+ const i = this.get("config")?.clickThrottleMs ?? 300;
3568
+ if (i > 0 && !this.checkClickThrottle(n, i))
3569
3569
  return;
3570
- const o = this.findTrackingElement(i), l = this.getRelevantClickElement(i), c = this.calculateClickCoordinates(t, i);
3570
+ const o = this.findTrackingElement(n), l = this.getRelevantClickElement(n), c = this.calculateClickCoordinates(t, n);
3571
3571
  if (o) {
3572
3572
  const f = this.extractTrackingData(o);
3573
3573
  if (f) {
@@ -3581,7 +3581,7 @@ class As extends _ {
3581
3581
  });
3582
3582
  }
3583
3583
  }
3584
- const d = this.generateClickData(i, l, c);
3584
+ const d = this.generateClickData(n, l, c);
3585
3585
  this.eventManager.track({
3586
3586
  type: u.CLICK,
3587
3587
  click_data: d
@@ -3605,15 +3605,15 @@ class As extends _ {
3605
3605
  * Returns true if the click should be tracked, false if throttled
3606
3606
  */
3607
3607
  checkClickThrottle(e, t) {
3608
- const s = this.getElementSignature(e), i = Date.now();
3609
- this.pruneThrottleCache(i);
3610
- const n = this.lastClickTimes.get(s);
3611
- return n !== void 0 && i - n < t ? (a("debug", "ClickHandler: Click suppressed by throttle", {
3608
+ const s = this.getElementSignature(e), n = Date.now();
3609
+ this.pruneThrottleCache(n);
3610
+ const i = this.lastClickTimes.get(s);
3611
+ return i !== void 0 && n - i < t ? (a("debug", "ClickHandler: Click suppressed by throttle", {
3612
3612
  data: {
3613
3613
  signature: s,
3614
- throttleRemaining: t - (i - n)
3614
+ throttleRemaining: t - (n - i)
3615
3615
  }
3616
- }), !1) : (this.lastClickTimes.set(s, i), !0);
3616
+ }), !1) : (this.lastClickTimes.set(s, n), !0);
3617
3617
  }
3618
3618
  /**
3619
3619
  * Prunes stale entries from the throttle cache to prevent memory leaks
@@ -3625,15 +3625,15 @@ class As extends _ {
3625
3625
  return;
3626
3626
  this.lastPruneTime = e;
3627
3627
  const t = e - 3e5;
3628
- for (const [s, i] of this.lastClickTimes.entries())
3629
- i < t && this.lastClickTimes.delete(s);
3628
+ for (const [s, n] of this.lastClickTimes.entries())
3629
+ n < t && this.lastClickTimes.delete(s);
3630
3630
  if (this.lastClickTimes.size > 1e3) {
3631
- const s = Array.from(this.lastClickTimes.entries()).sort((o, l) => o[1] - l[1]), i = this.lastClickTimes.size - 1e3, n = s.slice(0, i);
3632
- for (const [o] of n)
3631
+ const s = Array.from(this.lastClickTimes.entries()).sort((o, l) => o[1] - l[1]), n = this.lastClickTimes.size - 1e3, i = s.slice(0, n);
3632
+ for (const [o] of i)
3633
3633
  this.lastClickTimes.delete(o);
3634
3634
  a("debug", "ClickHandler: Pruned throttle cache", {
3635
3635
  data: {
3636
- removed: n.length,
3636
+ removed: i.length,
3637
3637
  remaining: this.lastClickTimes.size
3638
3638
  }
3639
3639
  });
@@ -3659,12 +3659,12 @@ class As extends _ {
3659
3659
  const t = [];
3660
3660
  let s = e;
3661
3661
  for (; s && s !== document.body; ) {
3662
- let i = s.tagName.toLowerCase();
3662
+ let n = s.tagName.toLowerCase();
3663
3663
  if (s.className) {
3664
- const n = s.className.split(" ")[0];
3665
- n && (i += `.${n}`);
3664
+ const i = s.className.split(" ")[0];
3665
+ i && (n += `.${i}`);
3666
3666
  }
3667
- t.unshift(i), s = s.parentElement;
3667
+ t.unshift(n), s = s.parentElement;
3668
3668
  }
3669
3669
  return t.join(">") || "unknown";
3670
3670
  }
@@ -3700,8 +3700,8 @@ class As extends _ {
3700
3700
  return Math.max(0, Math.min(1, Number(e.toFixed(3))));
3701
3701
  }
3702
3702
  calculateClickCoordinates(e, t) {
3703
- const s = t.getBoundingClientRect(), i = e.clientX, n = e.clientY, o = s.width > 0 ? this.clamp((i - s.left) / s.width) : 0, l = s.height > 0 ? this.clamp((n - s.top) / s.height) : 0;
3704
- return { x: i, y: n, relativeX: o, relativeY: l };
3703
+ const s = t.getBoundingClientRect(), n = e.clientX, i = e.clientY, o = s.width > 0 ? this.clamp((n - s.left) / s.width) : 0, l = s.height > 0 ? this.clamp((i - s.top) / s.height) : 0;
3704
+ return { x: n, y: i, relativeX: o, relativeY: l };
3705
3705
  }
3706
3706
  extractTrackingData(e) {
3707
3707
  const t = e.getAttribute(`${b}-name`), s = e.getAttribute(`${b}-value`);
@@ -3713,10 +3713,10 @@ class As extends _ {
3713
3713
  };
3714
3714
  }
3715
3715
  generateClickData(e, t, s) {
3716
- const { x: i, y: n, relativeX: o, relativeY: l } = s, c = this.getRelevantText(e, t), d = this.extractElementAttributes(t);
3716
+ const { x: n, y: i, relativeX: o, relativeY: l } = s, c = this.getRelevantText(e, t), d = this.extractElementAttributes(t);
3717
3717
  return {
3718
- x: i,
3719
- y: n,
3718
+ x: n,
3719
+ y: i,
3720
3720
  relativeX: o,
3721
3721
  relativeY: l,
3722
3722
  tag: t.tagName.toLowerCase(),
@@ -3753,17 +3753,17 @@ class As extends _ {
3753
3753
  sanitizeText(e) {
3754
3754
  let t = e;
3755
3755
  for (const s of at) {
3756
- const i = new RegExp(s.source, s.flags);
3757
- t = t.replace(i, "[REDACTED]");
3756
+ const n = new RegExp(s.source, s.flags);
3757
+ t = t.replace(n, "[REDACTED]");
3758
3758
  }
3759
3759
  return t;
3760
3760
  }
3761
3761
  getRelevantText(e, t) {
3762
- const s = e.textContent?.trim() ?? "", i = t.textContent?.trim() ?? "";
3763
- if (!s && !i)
3762
+ const s = e.textContent?.trim() ?? "", n = t.textContent?.trim() ?? "";
3763
+ if (!s && !n)
3764
3764
  return "";
3765
- let n = "";
3766
- return s && s.length <= 255 ? n = s : i.length <= 255 ? n = i : n = i.slice(0, 252) + "...", this.sanitizeText(n);
3765
+ let i = "";
3766
+ return s && s.length <= 255 ? i = s : n.length <= 255 ? i = n : i = n.slice(0, 252) + "...", this.sanitizeText(i);
3767
3767
  }
3768
3768
  extractElementAttributes(e) {
3769
3769
  const t = [
@@ -3778,9 +3778,9 @@ class As extends _ {
3778
3778
  "alt",
3779
3779
  "role"
3780
3780
  ], s = {};
3781
- for (const i of t) {
3782
- const n = e.getAttribute(i);
3783
- n && (s[i] = n);
3781
+ for (const n of t) {
3782
+ const i = e.getAttribute(n);
3783
+ i && (s[n] = i);
3784
3784
  }
3785
3785
  return s;
3786
3786
  }
@@ -3838,8 +3838,8 @@ class Ms extends _ {
3838
3838
  const t = this.findScrollableElements();
3839
3839
  if (this.isWindowScrollable() && this.setupScrollContainer(window, "window"), t.length > 0) {
3840
3840
  for (const s of t) {
3841
- const i = this.getElementSelector(s);
3842
- this.setupScrollContainer(s, i);
3841
+ const n = this.getElementSelector(s);
3842
+ this.setupScrollContainer(s, n);
3843
3843
  }
3844
3844
  this.applyPrimaryScrollSelectorIfConfigured();
3845
3845
  return;
@@ -3860,18 +3860,18 @@ class Ms extends _ {
3860
3860
  if (!document.body)
3861
3861
  return [];
3862
3862
  const e = [], t = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT, {
3863
- acceptNode: (i) => {
3864
- const n = i;
3865
- if (!n.isConnected || !n.offsetParent)
3863
+ acceptNode: (n) => {
3864
+ const i = n;
3865
+ if (!i.isConnected || !i.offsetParent)
3866
3866
  return NodeFilter.FILTER_SKIP;
3867
- const o = getComputedStyle(n);
3867
+ const o = getComputedStyle(i);
3868
3868
  return o.overflowY === "auto" || o.overflowY === "scroll" || o.overflow === "auto" || o.overflow === "scroll" ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
3869
3869
  }
3870
3870
  });
3871
3871
  let s;
3872
3872
  for (; (s = t.nextNode()) && e.length < 10; ) {
3873
- const i = s;
3874
- this.isElementScrollable(i) && e.push(i);
3873
+ const n = s;
3874
+ this.isElementScrollable(n) && e.push(n);
3875
3875
  }
3876
3876
  return e;
3877
3877
  }
@@ -3882,7 +3882,7 @@ class Ms extends _ {
3882
3882
  if (t.id)
3883
3883
  return `#${t.id}`;
3884
3884
  if (t.className && typeof t.className == "string") {
3885
- const s = t.className.split(" ").filter((i) => i.trim())[0];
3885
+ const s = t.className.split(" ").filter((n) => n.trim())[0];
3886
3886
  if (s)
3887
3887
  return `.${s}`;
3888
3888
  }
@@ -3894,20 +3894,20 @@ class Ms extends _ {
3894
3894
  setupScrollContainer(e, t) {
3895
3895
  if (this.containers.some((d) => d.element === e) || e !== window && !this.isElementScrollable(e))
3896
3896
  return;
3897
- const i = this.getScrollTop(e), n = this.calculateScrollDepth(
3898
- i,
3897
+ const n = this.getScrollTop(e), i = this.calculateScrollDepth(
3898
+ n,
3899
3899
  this.getScrollHeight(e),
3900
3900
  this.getViewportHeight(e)
3901
3901
  ), o = this.determineIfPrimary(e), l = {
3902
3902
  element: e,
3903
3903
  selector: t,
3904
3904
  isPrimary: o,
3905
- lastScrollPos: i,
3906
- lastDepth: n,
3905
+ lastScrollPos: n,
3906
+ lastDepth: i,
3907
3907
  lastDirection: Z.DOWN,
3908
3908
  lastEventTime: 0,
3909
3909
  firstScrollEventTime: null,
3910
- maxDepthReached: n,
3910
+ maxDepthReached: i,
3911
3911
  debounceTimer: null,
3912
3912
  listener: null
3913
3913
  }, c = () => {
@@ -3926,8 +3926,8 @@ class Ms extends _ {
3926
3926
  if (!this.shouldEmitScrollEvent(e, t, s))
3927
3927
  return;
3928
3928
  e.lastEventTime = s, e.lastDepth = t.depth, e.lastDirection = t.direction;
3929
- const i = this.get("scrollEventCount") ?? 0;
3930
- this.set("scrollEventCount", i + 1), this.eventManager.track({
3929
+ const n = this.get("scrollEventCount") ?? 0;
3930
+ this.set("scrollEventCount", n + 1), this.eventManager.track({
3931
3931
  type: u.SCROLL,
3932
3932
  scroll_data: {
3933
3933
  ...t,
@@ -3968,21 +3968,21 @@ class Ms extends _ {
3968
3968
  calculateScrollDepth(e, t, s) {
3969
3969
  if (t <= s)
3970
3970
  return 0;
3971
- const i = t - s;
3972
- return Math.min(100, Math.max(0, Math.floor(e / i * 100)));
3971
+ const n = t - s;
3972
+ return Math.min(100, Math.max(0, Math.floor(e / n * 100)));
3973
3973
  }
3974
3974
  calculateScrollData(e) {
3975
- const { element: t, lastScrollPos: s, lastEventTime: i } = e, n = this.getScrollTop(t), o = Date.now(), l = Math.abs(n - s);
3975
+ const { element: t, lastScrollPos: s, lastEventTime: n } = e, i = this.getScrollTop(t), o = Date.now(), l = Math.abs(i - s);
3976
3976
  if (l < 10 || t === window && !this.isWindowScrollable())
3977
3977
  return null;
3978
- const c = this.getViewportHeight(t), d = this.getScrollHeight(t), f = this.getScrollDirection(n, s), g = this.calculateScrollDepth(n, d, c);
3978
+ const c = this.getViewportHeight(t), d = this.getScrollHeight(t), f = this.getScrollDirection(i, s), g = this.calculateScrollDepth(i, d, c);
3979
3979
  let I;
3980
- i > 0 ? I = o - i : e.firstScrollEventTime !== null ? I = o - e.firstScrollEventTime : I = 250;
3981
- const p = Math.round(l / I * 1e3);
3982
- return g > e.maxDepthReached && (e.maxDepthReached = g), e.lastScrollPos = n, {
3980
+ n > 0 ? I = o - n : e.firstScrollEventTime !== null ? I = o - e.firstScrollEventTime : I = 250;
3981
+ const E = Math.round(l / I * 1e3);
3982
+ return g > e.maxDepthReached && (e.maxDepthReached = g), e.lastScrollPos = i, {
3983
3983
  depth: g,
3984
3984
  direction: f,
3985
- velocity: p,
3985
+ velocity: E,
3986
3986
  max_depth_reached: e.maxDepthReached
3987
3987
  };
3988
3988
  }
@@ -3996,24 +3996,24 @@ class Ms extends _ {
3996
3996
  return e === window ? document.documentElement.scrollHeight : e.scrollHeight;
3997
3997
  }
3998
3998
  isElementScrollable(e) {
3999
- const t = getComputedStyle(e), s = t.overflowY === "auto" || t.overflowY === "scroll" || t.overflow === "auto" || t.overflow === "scroll", i = e.scrollHeight > e.clientHeight;
4000
- return s && i;
3999
+ const t = getComputedStyle(e), s = t.overflowY === "auto" || t.overflowY === "scroll" || t.overflow === "auto" || t.overflow === "scroll", n = e.scrollHeight > e.clientHeight;
4000
+ return s && n;
4001
4001
  }
4002
4002
  applyPrimaryScrollSelector(e) {
4003
4003
  let t;
4004
4004
  if (e === "window")
4005
4005
  t = window;
4006
4006
  else {
4007
- const i = document.querySelector(e);
4008
- if (!(i instanceof HTMLElement)) {
4007
+ const n = document.querySelector(e);
4008
+ if (!(n instanceof HTMLElement)) {
4009
4009
  a("debug", `Selector "${e}" did not match an HTMLElement`);
4010
4010
  return;
4011
4011
  }
4012
- t = i;
4012
+ t = n;
4013
4013
  }
4014
- this.containers.forEach((i) => {
4015
- this.updateContainerPrimary(i, i.element === t);
4016
- }), !this.containers.some((i) => i.element === t) && t instanceof HTMLElement && this.isElementScrollable(t) && this.setupScrollContainer(t, e);
4014
+ this.containers.forEach((n) => {
4015
+ this.updateContainerPrimary(n, n.element === t);
4016
+ }), !this.containers.some((n) => n.element === t) && t instanceof HTMLElement && this.isElementScrollable(t) && this.setupScrollContainer(t, e);
4017
4017
  }
4018
4018
  updateContainerPrimary(e, t) {
4019
4019
  e.isPrimary = t;
@@ -4071,8 +4071,8 @@ class Cs extends _ {
4071
4071
  let t = this.trackedElements.size;
4072
4072
  for (const s of this.config.elements)
4073
4073
  try {
4074
- const i = document.querySelectorAll(s.selector);
4075
- for (const n of Array.from(i)) {
4074
+ const n = document.querySelectorAll(s.selector);
4075
+ for (const i of Array.from(n)) {
4076
4076
  if (t >= e) {
4077
4077
  a("debug", "ViewportHandler: Maximum tracked elements reached", {
4078
4078
  data: {
@@ -4083,18 +4083,18 @@ class Cs extends _ {
4083
4083
  });
4084
4084
  return;
4085
4085
  }
4086
- n.hasAttribute(`${b}-ignore`) || this.trackedElements.has(n) || (this.trackedElements.set(n, {
4087
- element: n,
4086
+ i.hasAttribute(`${b}-ignore`) || this.trackedElements.has(i) || (this.trackedElements.set(i, {
4087
+ element: i,
4088
4088
  selector: s.selector,
4089
4089
  id: s.id,
4090
4090
  name: s.name,
4091
4091
  startTime: null,
4092
4092
  timeoutId: null,
4093
4093
  lastFiredTime: null
4094
- }), this.observer?.observe(n), t++);
4094
+ }), this.observer?.observe(i), t++);
4095
4095
  }
4096
- } catch (i) {
4097
- a("debug", `ViewportHandler: Invalid selector "${s.selector}"`, { error: i });
4096
+ } catch (n) {
4097
+ a("debug", `ViewportHandler: Invalid selector "${s.selector}"`, { error: n });
4098
4098
  }
4099
4099
  a("debug", "ViewportHandler: Elements tracked", {
4100
4100
  data: { count: t, limit: e }
@@ -4107,11 +4107,11 @@ class Cs extends _ {
4107
4107
  if (!this.config) return;
4108
4108
  const t = this.config.minDwellTime ?? 1e3;
4109
4109
  for (const s of e) {
4110
- const i = this.trackedElements.get(s.target);
4111
- i && (s.isIntersecting ? i.startTime === null && (i.startTime = performance.now(), i.timeoutId = window.setTimeout(() => {
4112
- const n = Math.round(s.intersectionRatio * 100) / 100;
4113
- this.fireViewportEvent(i, n);
4114
- }, t)) : i.startTime !== null && (i.timeoutId !== null && (window.clearTimeout(i.timeoutId), i.timeoutId = null), i.startTime = null));
4110
+ const n = this.trackedElements.get(s.target);
4111
+ n && (s.isIntersecting ? n.startTime === null && (n.startTime = performance.now(), n.timeoutId = window.setTimeout(() => {
4112
+ const i = Math.round(s.intersectionRatio * 100) / 100;
4113
+ this.fireViewportEvent(n, i);
4114
+ }, t)) : n.startTime !== null && (n.timeoutId !== null && (window.clearTimeout(n.timeoutId), n.timeoutId = null), n.startTime = null));
4115
4115
  }
4116
4116
  };
4117
4117
  /**
@@ -4122,12 +4122,12 @@ class Cs extends _ {
4122
4122
  const s = Math.round(performance.now() - e.startTime);
4123
4123
  if (e.element.hasAttribute(`${b}-ignore`))
4124
4124
  return;
4125
- const i = this.config?.cooldownPeriod ?? 6e4, n = Date.now();
4126
- if (e.lastFiredTime !== null && n - e.lastFiredTime < i) {
4125
+ const n = this.config?.cooldownPeriod ?? 6e4, i = Date.now();
4126
+ if (e.lastFiredTime !== null && i - e.lastFiredTime < n) {
4127
4127
  a("debug", "ViewportHandler: Event suppressed by cooldown period", {
4128
4128
  data: {
4129
4129
  selector: e.selector,
4130
- cooldownRemaining: i - (n - e.lastFiredTime)
4130
+ cooldownRemaining: n - (i - e.lastFiredTime)
4131
4131
  }
4132
4132
  }), e.startTime = null, e.timeoutId = null;
4133
4133
  return;
@@ -4142,7 +4142,7 @@ class Cs extends _ {
4142
4142
  this.eventManager.track({
4143
4143
  type: u.VIEWPORT_VISIBLE,
4144
4144
  viewport_data: o
4145
- }), e.startTime = null, e.timeoutId = null, e.lastFiredTime = n;
4145
+ }), e.startTime = null, e.timeoutId = null, e.lastFiredTime = i;
4146
4146
  }
4147
4147
  /**
4148
4148
  * Sets up MutationObserver to detect dynamically added elements
@@ -4172,58 +4172,75 @@ class Cs extends _ {
4172
4172
  cleanupRemovedNodes(e) {
4173
4173
  e.forEach((t) => {
4174
4174
  if (t.nodeType !== 1) return;
4175
- const s = t, i = this.trackedElements.get(s);
4176
- i && (i.timeoutId !== null && window.clearTimeout(i.timeoutId), this.observer?.unobserve(s), this.trackedElements.delete(s)), Array.from(this.trackedElements.keys()).filter((o) => s.contains(o)).forEach((o) => {
4175
+ const s = t, n = this.trackedElements.get(s);
4176
+ n && (n.timeoutId !== null && window.clearTimeout(n.timeoutId), this.observer?.unobserve(s), this.trackedElements.delete(s)), Array.from(this.trackedElements.keys()).filter((o) => s.contains(o)).forEach((o) => {
4177
4177
  const l = this.trackedElements.get(o);
4178
4178
  l && l.timeoutId !== null && window.clearTimeout(l.timeoutId), this.observer?.unobserve(o), this.trackedElements.delete(o);
4179
4179
  });
4180
4180
  });
4181
4181
  }
4182
4182
  }
4183
- const Rs = "tracelog_session_id";
4184
- class Ns extends _ {
4183
+ const Rs = "tracelog_session_id", Ns = "tracelog_user_id";
4184
+ class Os extends _ {
4185
4185
  visibilityHandler = null;
4186
- lastSyncedSessionId = null;
4186
+ pageshowHandler = null;
4187
+ lastSyncedKey = null;
4187
4188
  activate() {
4188
- this.cleanupVisibilityListener(), this.syncCartAttribute(), this.setupVisibilityListener();
4189
+ this.cleanupListeners(), this.syncCartAttribute(), this.setupListeners();
4189
4190
  }
4190
4191
  deactivate() {
4191
- this.cleanupVisibilityListener(), this.lastSyncedSessionId = null;
4192
+ this.cleanupListeners(), this.lastSyncedKey = null;
4192
4193
  }
4193
- /** Re-syncs the cart attribute when session rotates (called by App on SESSION_START). */
4194
+ /** Re-syncs cart attributes when session rotates (called by App on SESSION_START). */
4194
4195
  onSessionChange() {
4195
4196
  this.syncCartAttribute();
4196
4197
  }
4197
4198
  syncCartAttribute() {
4198
4199
  const e = this.get("sessionId");
4199
- !e || e === this.lastSyncedSessionId || (this.lastSyncedSessionId = e, this.postCartUpdate(e));
4200
+ if (!e) return;
4201
+ const t = this.get("userId"), s = typeof t == "string" && t.length > 0 ? t : "", n = `${e}|${s}`;
4202
+ n !== this.lastSyncedKey && (this.lastSyncedKey = n, this.postCartUpdate(e, s));
4200
4203
  }
4201
- postCartUpdate(e) {
4204
+ postCartUpdate(e, t) {
4205
+ const s = { [Rs]: e };
4206
+ t.length > 0 && (s[Ns] = t);
4202
4207
  try {
4203
4208
  fetch("/cart/update.js", {
4204
4209
  method: "POST",
4205
4210
  headers: { "Content-Type": "application/json" },
4206
- body: JSON.stringify({ attributes: { [Rs]: e } }),
4211
+ body: JSON.stringify({ attributes: s }),
4207
4212
  credentials: "same-origin"
4208
- }).then((t) => {
4209
- t.ok || (this.lastSyncedSessionId = null, a("debug", "Shopify cart attribute update failed", { data: { status: t.status } }));
4213
+ }).then((n) => {
4214
+ n.ok || (this.lastSyncedKey = null, a("debug", "Shopify cart attribute update failed", { data: { status: n.status } }));
4210
4215
  }).catch(() => {
4211
- this.lastSyncedSessionId = null, a("debug", "Shopify cart attribute update failed");
4216
+ this.lastSyncedKey = null, a("debug", "Shopify cart attribute update failed");
4212
4217
  });
4213
4218
  } catch {
4214
- this.lastSyncedSessionId = null, a("debug", "Shopify cart attribute update failed");
4219
+ this.lastSyncedKey = null, a("debug", "Shopify cart attribute update failed");
4215
4220
  }
4216
4221
  }
4217
- setupVisibilityListener() {
4222
+ /**
4223
+ * Sync triggers (theme-agnostic):
4224
+ * - `visibilitychange`: catches tab refocus (long sessions, OAuth round-trips).
4225
+ * - `pageshow` with `event.persisted === true`: catches bfcache restore so a
4226
+ * user returning from an external checkout / Shop Pay window picks up the
4227
+ * current sessionId before any further interaction.
4228
+ *
4229
+ * Both triggers go through `syncCartAttribute()` which dedupes by
4230
+ * `sessionId|userId`, so spurious calls cost nothing.
4231
+ */
4232
+ setupListeners() {
4218
4233
  this.visibilityHandler = () => {
4219
4234
  document.hidden || this.syncCartAttribute();
4220
- }, document.addEventListener("visibilitychange", this.visibilityHandler);
4235
+ }, document.addEventListener("visibilitychange", this.visibilityHandler), this.pageshowHandler = (e) => {
4236
+ e.persisted && this.syncCartAttribute();
4237
+ }, window.addEventListener("pageshow", this.pageshowHandler);
4221
4238
  }
4222
- cleanupVisibilityListener() {
4223
- this.visibilityHandler && (document.removeEventListener("visibilitychange", this.visibilityHandler), this.visibilityHandler = null);
4239
+ cleanupListeners() {
4240
+ this.visibilityHandler && (document.removeEventListener("visibilitychange", this.visibilityHandler), this.visibilityHandler = null), this.pageshowHandler && (window.removeEventListener("pageshow", this.pageshowHandler), this.pageshowHandler = null);
4224
4241
  }
4225
4242
  }
4226
- class Os {
4243
+ class Ps {
4227
4244
  storage;
4228
4245
  sessionStorageRef;
4229
4246
  fallbackStorage = /* @__PURE__ */ new Map();
@@ -4392,19 +4409,19 @@ class Os {
4392
4409
  return !1;
4393
4410
  try {
4394
4411
  const e = [], t = [];
4395
- for (let n = 0; n < this.storage.length; n++) {
4396
- const o = this.storage.key(n);
4412
+ for (let i = 0; i < this.storage.length; i++) {
4413
+ const o = this.storage.key(i);
4397
4414
  o?.startsWith("tracelog_") && (e.push(o), o.startsWith("tracelog_persisted_events_") && t.push(o));
4398
4415
  }
4399
4416
  if (t.length > 0)
4400
- return t.forEach((n) => {
4417
+ return t.forEach((i) => {
4401
4418
  try {
4402
- this.storage.removeItem(n);
4419
+ this.storage.removeItem(i);
4403
4420
  } catch {
4404
4421
  }
4405
4422
  }), !0;
4406
- const s = ["tracelog_session_", "tracelog_user_id", "tracelog_device_id", "tracelog_config"], i = e.filter((n) => !s.some((o) => n.startsWith(o)));
4407
- return i.length > 0 ? (i.slice(0, 5).forEach((o) => {
4423
+ const s = ["tracelog_session_", "tracelog_user_id", "tracelog_device_id", "tracelog_config"], n = e.filter((i) => !s.some((o) => i.startsWith(o)));
4424
+ return n.length > 0 ? (n.slice(0, 5).forEach((o) => {
4408
4425
  try {
4409
4426
  this.storage.removeItem(o);
4410
4427
  } catch {
@@ -4506,7 +4523,7 @@ class Os {
4506
4523
  this.fallbackSessionStorage.delete(e);
4507
4524
  }
4508
4525
  }
4509
- class Ps extends _ {
4526
+ class Ds extends _ {
4510
4527
  eventManager;
4511
4528
  reportedByNav = /* @__PURE__ */ new Map();
4512
4529
  navigationHistory = [];
@@ -4559,8 +4576,8 @@ class Ps extends _ {
4559
4576
  this.reportTTFB(), this.safeObserve(
4560
4577
  "largest-contentful-paint",
4561
4578
  (s) => {
4562
- const i = s.getEntries(), n = i[i.length - 1];
4563
- n && this.sendVital({ type: "LCP", value: Number(n.startTime.toFixed(2)) });
4579
+ const n = s.getEntries(), i = n[n.length - 1];
4580
+ i && this.sendVital({ type: "LCP", value: Number(i.startTime.toFixed(2)) });
4564
4581
  },
4565
4582
  { type: "largest-contentful-paint", buffered: !0 },
4566
4583
  !0
@@ -4569,10 +4586,10 @@ class Ps extends _ {
4569
4586
  this.safeObserve(
4570
4587
  "layout-shift",
4571
4588
  (s) => {
4572
- const i = this.getNavigationId();
4573
- i !== t && (e = 0, t = i);
4574
- const n = s.getEntries();
4575
- for (const o of n) {
4589
+ const n = this.getNavigationId();
4590
+ n !== t && (e = 0, t = n);
4591
+ const i = s.getEntries();
4592
+ for (const o of i) {
4576
4593
  if (o.hadRecentInput === !0)
4577
4594
  continue;
4578
4595
  const l = typeof o.value == "number" ? o.value : 0;
@@ -4584,32 +4601,32 @@ class Ps extends _ {
4584
4601
  ), this.safeObserve(
4585
4602
  "paint",
4586
4603
  (s) => {
4587
- for (const i of s.getEntries())
4588
- i.name === "first-contentful-paint" && this.sendVital({ type: "FCP", value: Number(i.startTime.toFixed(2)) });
4604
+ for (const n of s.getEntries())
4605
+ n.name === "first-contentful-paint" && this.sendVital({ type: "FCP", value: Number(n.startTime.toFixed(2)) });
4589
4606
  },
4590
4607
  { type: "paint", buffered: !0 },
4591
4608
  !0
4592
4609
  ), this.safeObserve(
4593
4610
  "event",
4594
4611
  (s) => {
4595
- let i = 0;
4596
- const n = s.getEntries();
4597
- for (const o of n) {
4612
+ let n = 0;
4613
+ const i = s.getEntries();
4614
+ for (const o of i) {
4598
4615
  const l = (o.processingEnd ?? 0) - (o.startTime ?? 0);
4599
- i = Math.max(i, l);
4616
+ n = Math.max(n, l);
4600
4617
  }
4601
- i > 0 && this.sendVital({ type: "INP", value: Number(i.toFixed(2)) });
4618
+ n > 0 && this.sendVital({ type: "INP", value: Number(n.toFixed(2)) });
4602
4619
  },
4603
4620
  { type: "event", buffered: !0 }
4604
4621
  );
4605
4622
  }
4606
4623
  async initWebVitals() {
4607
4624
  try {
4608
- const { onLCP: e, onCLS: t, onFCP: s, onTTFB: i, onINP: n } = await Promise.resolve().then(() => ur), o = (l) => (c) => {
4625
+ const { onLCP: e, onCLS: t, onFCP: s, onTTFB: n, onINP: i } = await Promise.resolve().then(() => hr), o = (l) => (c) => {
4609
4626
  const d = Number(c.value.toFixed(2));
4610
4627
  this.sendVital({ type: l, value: d });
4611
4628
  };
4612
- e(o("LCP"), { reportAllChanges: !1 }), t(o("CLS"), { reportAllChanges: !1 }), s(o("FCP"), { reportAllChanges: !1 }), i(o("TTFB"), { reportAllChanges: !1 }), n(o("INP"), { reportAllChanges: !1 });
4629
+ e(o("LCP"), { reportAllChanges: !1 }), t(o("CLS"), { reportAllChanges: !1 }), s(o("FCP"), { reportAllChanges: !1 }), n(o("TTFB"), { reportAllChanges: !1 }), i(o("INP"), { reportAllChanges: !1 });
4613
4630
  } catch (e) {
4614
4631
  a("debug", "Failed to load web-vitals library, using fallback", { error: e }), this.observeWebVitalsFallback();
4615
4632
  }
@@ -4631,8 +4648,8 @@ class Ps extends _ {
4631
4648
  (e) => {
4632
4649
  const t = e.getEntries();
4633
4650
  for (const s of t) {
4634
- const i = Number(s.duration.toFixed(2)), n = Date.now();
4635
- n - this.lastLongTaskSentAt >= qt && (this.shouldSendVital("LONG_TASK", i) && this.trackWebVital("LONG_TASK", i), this.lastLongTaskSentAt = n);
4651
+ const n = Number(s.duration.toFixed(2)), i = Date.now();
4652
+ i - this.lastLongTaskSentAt >= qt && (this.shouldSendVital("LONG_TASK", n) && this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = i);
4636
4653
  }
4637
4654
  },
4638
4655
  { type: "longtask", buffered: !0 }
@@ -4649,8 +4666,8 @@ class Ps extends _ {
4649
4666
  if (s)
4650
4667
  s.add(e.type);
4651
4668
  else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length > Jt) {
4652
- const n = this.navigationHistory.shift();
4653
- n && this.reportedByNav.delete(n);
4669
+ const i = this.navigationHistory.shift();
4670
+ i && this.reportedByNav.delete(i);
4654
4671
  }
4655
4672
  }
4656
4673
  this.trackWebVital(e.type, e.value);
@@ -4694,8 +4711,8 @@ class Ps extends _ {
4694
4711
  const e = performance.getEntriesByType("navigation")[0];
4695
4712
  if (!e)
4696
4713
  return null;
4697
- const t = e.startTime || performance.now(), s = ++this.navigationCounter, i = `${t.toFixed(2)}_${window.location.pathname}`;
4698
- return s > 1 ? `${i}_${s}` : i;
4714
+ const t = e.startTime || performance.now(), s = ++this.navigationCounter, n = `${t.toFixed(2)}_${window.location.pathname}`;
4715
+ return s > 1 ? `${n}_${s}` : n;
4699
4716
  } catch (e) {
4700
4717
  return a("debug", "Failed to get navigation ID", { error: e }), null;
4701
4718
  }
@@ -4705,11 +4722,11 @@ class Ps extends _ {
4705
4722
  const t = PerformanceObserver.supportedEntryTypes;
4706
4723
  return !t || t.includes(e);
4707
4724
  }
4708
- safeObserve(e, t, s, i = !1) {
4725
+ safeObserve(e, t, s, n = !1) {
4709
4726
  try {
4710
4727
  if (!this.isObserverSupported(e))
4711
4728
  return !1;
4712
- const n = new PerformanceObserver((o, l) => {
4729
+ const i = new PerformanceObserver((o, l) => {
4713
4730
  try {
4714
4731
  t(o, l);
4715
4732
  } catch (c) {
@@ -4718,16 +4735,16 @@ class Ps extends _ {
4718
4735
  data: { type: e }
4719
4736
  });
4720
4737
  }
4721
- if (i)
4738
+ if (n)
4722
4739
  try {
4723
4740
  l.disconnect();
4724
4741
  } catch {
4725
4742
  }
4726
4743
  });
4727
- return n.observe(s ?? { type: e, buffered: !0 }), i || this.observers.push(n), !0;
4728
- } catch (n) {
4744
+ return i.observe(s ?? { type: e, buffered: !0 }), n || this.observers.push(i), !0;
4745
+ } catch (i) {
4729
4746
  return a("debug", "Failed to create performance observer", {
4730
- error: n,
4747
+ error: i,
4731
4748
  data: { type: e }
4732
4749
  }), !1;
4733
4750
  }
@@ -4775,11 +4792,11 @@ class ae extends _ {
4775
4792
  const e = Date.now();
4776
4793
  if (e < this.burstBackoffUntil)
4777
4794
  return !1;
4778
- if (e - this.burstWindowStart > jt && (this.errorBurstCounter = 0, this.burstWindowStart = e), this.errorBurstCounter++, this.errorBurstCounter > zt)
4779
- return this.burstBackoffUntil = e + ze, a("debug", "Error burst detected - entering cooldown", {
4795
+ if (e - this.burstWindowStart > jt && (this.errorBurstCounter = 0, this.burstWindowStart = e), this.errorBurstCounter++, this.errorBurstCounter > Kt)
4796
+ return this.burstBackoffUntil = e + Ke, a("debug", "Error burst detected - entering cooldown", {
4780
4797
  data: {
4781
4798
  errorsInWindow: this.errorBurstCounter,
4782
- cooldownMs: ze
4799
+ cooldownMs: Ke
4783
4800
  }
4784
4801
  }), !1;
4785
4802
  const s = this.get("config").errorSampling ?? lt;
@@ -4810,13 +4827,13 @@ class ae extends _ {
4810
4827
  const t = this.extractRejectionMessage(e.reason), s = this.sanitize(t);
4811
4828
  if (this.shouldSuppressError(B.PROMISE_REJECTION, s))
4812
4829
  return;
4813
- const i = e.reason instanceof Error && typeof e.reason.stack == "string" ? this.truncateStack(e.reason.stack) : void 0;
4830
+ const n = e.reason instanceof Error && typeof e.reason.stack == "string" ? this.truncateStack(e.reason.stack) : void 0;
4814
4831
  this.eventManager.track({
4815
4832
  type: u.ERROR,
4816
4833
  error_data: {
4817
4834
  type: B.PROMISE_REJECTION,
4818
4835
  message: s,
4819
- ...i !== void 0 && { stack: i }
4836
+ ...n !== void 0 && { stack: n }
4820
4837
  }
4821
4838
  });
4822
4839
  };
@@ -4840,14 +4857,14 @@ class ae extends _ {
4840
4857
  sanitizePii(e) {
4841
4858
  let t = e;
4842
4859
  for (const s of at) {
4843
- const i = new RegExp(s.source, s.flags);
4844
- t = t.replace(i, "[REDACTED]");
4860
+ const n = new RegExp(s.source, s.flags);
4861
+ t = t.replace(n, "[REDACTED]");
4845
4862
  }
4846
4863
  return t;
4847
4864
  }
4848
4865
  shouldSuppressError(e, t) {
4849
- const s = Date.now(), i = `${e}:${t}`, n = this.recentErrors.get(i);
4850
- return n !== void 0 && s - n < je ? (this.recentErrors.set(i, s), !0) : (this.recentErrors.set(i, s), this.recentErrors.size > Gt ? (this.recentErrors.clear(), this.recentErrors.set(i, s), !1) : (this.recentErrors.size > ee && this.pruneOldErrors(), !1));
4866
+ const s = Date.now(), n = `${e}:${t}`, i = this.recentErrors.get(n);
4867
+ return i !== void 0 && s - i < je ? (this.recentErrors.set(n, s), !0) : (this.recentErrors.set(n, s), this.recentErrors.size > Gt ? (this.recentErrors.clear(), this.recentErrors.set(n, s), !1) : (this.recentErrors.size > ee && this.pruneOldErrors(), !1));
4851
4868
  }
4852
4869
  static TRUNCATION_SUFFIX = `
4853
4870
  ...truncated`;
@@ -4858,22 +4875,22 @@ class ae extends _ {
4858
4875
  }
4859
4876
  pruneOldErrors() {
4860
4877
  const e = Date.now();
4861
- for (const [i, n] of this.recentErrors.entries())
4862
- e - n > je && this.recentErrors.delete(i);
4878
+ for (const [n, i] of this.recentErrors.entries())
4879
+ e - i > je && this.recentErrors.delete(n);
4863
4880
  if (this.recentErrors.size <= ee)
4864
4881
  return;
4865
- const t = Array.from(this.recentErrors.entries()).sort((i, n) => i[1] - n[1]), s = this.recentErrors.size - ee;
4866
- for (let i = 0; i < s; i += 1) {
4867
- const n = t[i];
4868
- n && this.recentErrors.delete(n[0]);
4882
+ const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), s = this.recentErrors.size - ee;
4883
+ for (let n = 0; n < s; n += 1) {
4884
+ const i = t[n];
4885
+ i && this.recentErrors.delete(i[0]);
4869
4886
  }
4870
4887
  }
4871
4888
  }
4872
- class Ds extends _ {
4889
+ class ks extends _ {
4873
4890
  isInitialized = !1;
4874
4891
  suppressNextScrollTimer = null;
4875
4892
  pageUnloadHandler = null;
4876
- emitter = new ps();
4893
+ emitter = new Es();
4877
4894
  transformers = {};
4878
4895
  customHeadersProvider;
4879
4896
  managers = {};
@@ -4892,7 +4909,7 @@ class Ds extends _ {
4892
4909
  async init(e = {}) {
4893
4910
  if (this.isInitialized)
4894
4911
  return { sessionId: this.get("sessionId") ?? "" };
4895
- this.managers.storage = new Os();
4912
+ this.managers.storage = new Ps();
4896
4913
  try {
4897
4914
  this.setupState(e);
4898
4915
  const t = e.integrations?.custom?.headers ?? {}, s = e.integrations?.custom?.fetchCredentials ?? "include";
@@ -4903,8 +4920,8 @@ class Ds extends _ {
4903
4920
  t,
4904
4921
  this.customHeadersProvider,
4905
4922
  s
4906
- ), this.loadPersistedIdentity(), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((i) => {
4907
- a("warn", "Failed to recover persisted events", { error: i });
4923
+ ), this.loadPersistedIdentity(), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((n) => {
4924
+ a("warn", "Failed to recover persisted events", { error: n });
4908
4925
  }), this.isInitialized = !0, { sessionId: this.get("sessionId") ?? "" };
4909
4926
  } catch (t) {
4910
4927
  this.destroy(!0);
@@ -4926,11 +4943,11 @@ class Ds extends _ {
4926
4943
  }
4927
4944
  let s = t;
4928
4945
  t && typeof t == "object" && !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && (s = Object.assign({}, t));
4929
- const { valid: i, error: n, sanitizedMetadata: o } = Es(e, s);
4930
- if (!i) {
4931
- if (this.get("mode") === ne.QA)
4932
- throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${n}`);
4933
- a("warn", `Custom event "${e}" dropped: ${n}`);
4946
+ const { valid: n, error: i, sanitizedMetadata: o } = ps(e, s);
4947
+ if (!n) {
4948
+ if (this.get("mode") === ie.QA)
4949
+ throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${i}`);
4950
+ a("warn", `Custom event "${e}" dropped: ${i}`);
4934
4951
  return;
4935
4952
  }
4936
4953
  this.managers.event.track({
@@ -5000,10 +5017,10 @@ class Ds extends _ {
5000
5017
  this.set("userId", t);
5001
5018
  const s = ls(e);
5002
5019
  this.set("collectApiUrls", s);
5003
- const i = Xt();
5004
- this.set("device", i);
5005
- const n = ye(window.location.href, e.sensitiveQueryParams);
5006
- this.set("pageUrl", n), ss() && this.set("mode", ne.QA);
5020
+ const n = Xt();
5021
+ this.set("device", n);
5022
+ const i = ye(window.location.href, e.sensitiveQueryParams);
5023
+ this.set("pageUrl", i), ss() && this.set("mode", ie.QA);
5007
5024
  }
5008
5025
  /**
5009
5026
  * Returns the current configuration object.
@@ -5071,11 +5088,11 @@ class Ds extends _ {
5071
5088
  const t = this.validateGlobalMetadata(e);
5072
5089
  if (!t.valid)
5073
5090
  throw new Error(`[TraceLog] Invalid global metadata: ${t.error}`);
5074
- const i = {
5091
+ const n = {
5075
5092
  ...this.get("config"),
5076
5093
  globalMetadata: e
5077
5094
  };
5078
- this.set("config", i), a("debug", "Global metadata updated (replaced)", { data: { keys: Object.keys(e) } });
5095
+ this.set("config", n), a("debug", "Global metadata updated (replaced)", { data: { keys: Object.keys(e) } });
5079
5096
  }
5080
5097
  /**
5081
5098
  * Merges new metadata with existing global metadata.
@@ -5088,12 +5105,12 @@ class Ds extends _ {
5088
5105
  const t = this.validateGlobalMetadata(e);
5089
5106
  if (!t.valid)
5090
5107
  throw new Error(`[TraceLog] Invalid global metadata: ${t.error}`);
5091
- const s = this.get("config"), n = {
5108
+ const s = this.get("config"), i = {
5092
5109
  ...s.globalMetadata ?? {},
5093
5110
  ...e
5094
5111
  }, o = {
5095
5112
  ...s,
5096
- globalMetadata: n
5113
+ globalMetadata: i
5097
5114
  };
5098
5115
  this.set("config", o), a("debug", "Global metadata updated (merged)", { data: { keys: Object.keys(e) } });
5099
5116
  }
@@ -5121,12 +5138,12 @@ class Ds extends _ {
5121
5138
  a("warn", "identify() userId exceeds 256 characters", { data: { length: e.trim().length } });
5122
5139
  return;
5123
5140
  }
5124
- const s = e.trim(), i = ht(t), n = {
5141
+ const s = e.trim(), n = ht(t), i = {
5125
5142
  userId: s,
5126
- ...i ? { traits: i } : {}
5143
+ ...n ? { traits: n } : {}
5127
5144
  };
5128
- this.set("identity", n), this.persistIdentity(n), a("debug", "Visitor identified", {
5129
- data: { userIdLength: s.length, traitKeys: i ? Object.keys(i) : [] }
5145
+ this.set("identity", i), this.persistIdentity(i), a("debug", "Visitor identified", {
5146
+ data: { userIdLength: s.length, traitKeys: n ? Object.keys(n) : [] }
5130
5147
  });
5131
5148
  }
5132
5149
  /**
@@ -5168,14 +5185,14 @@ class Ds extends _ {
5168
5185
  loadPersistedIdentity() {
5169
5186
  const e = this.managers.storage, t = this.getProjectId(), s = fe(t);
5170
5187
  try {
5171
- const i = e.getItem(U);
5172
- if (i) {
5173
- const n = JSON.parse(i);
5174
- if (e.removeItem(U), !this.isValidIdentityData(n)) {
5188
+ const n = e.getItem(U);
5189
+ if (n) {
5190
+ const i = JSON.parse(n);
5191
+ if (e.removeItem(U), !this.isValidIdentityData(i)) {
5175
5192
  a("debug", "Invalid pending identity in localStorage, discarded");
5176
5193
  return;
5177
5194
  }
5178
- const o = { ...n, userId: n.userId.trim() };
5195
+ const o = { ...i, userId: i.userId.trim() };
5179
5196
  e.setItem(s, JSON.stringify(o)), this.set("identity", o), a("debug", "Migrated pending identity to project-scoped key");
5180
5197
  return;
5181
5198
  }
@@ -5183,14 +5200,14 @@ class Ds extends _ {
5183
5200
  e.removeItem(U);
5184
5201
  }
5185
5202
  try {
5186
- const i = e.getItem(s);
5187
- if (i) {
5188
- const n = JSON.parse(i);
5189
- if (!this.isValidIdentityData(n)) {
5203
+ const n = e.getItem(s);
5204
+ if (n) {
5205
+ const i = JSON.parse(n);
5206
+ if (!this.isValidIdentityData(i)) {
5190
5207
  e.removeItem(s), a("debug", "Invalid persisted identity in localStorage, discarded");
5191
5208
  return;
5192
5209
  }
5193
- const o = { ...n, userId: n.userId.trim() };
5210
+ const o = { ...i, userId: i.userId.trim() };
5194
5211
  this.set("identity", o), a("debug", "Loaded persisted identity");
5195
5212
  }
5196
5213
  } catch {
@@ -5207,8 +5224,8 @@ class Ds extends _ {
5207
5224
  if (typeof t != "string" || t.trim().length === 0 || t.trim().length > 256) return !1;
5208
5225
  if (s !== void 0) {
5209
5226
  if (typeof s != "object" || s === null || Array.isArray(s)) return !1;
5210
- for (const i of Object.values(s))
5211
- if (typeof i != "string") return !1;
5227
+ for (const n of Object.values(s))
5228
+ if (typeof n != "string") return !1;
5212
5229
  }
5213
5230
  return !0;
5214
5231
  }
@@ -5239,38 +5256,38 @@ class Ds extends _ {
5239
5256
  this.set("suppressNextScroll", !1);
5240
5257
  }, 500);
5241
5258
  };
5242
- if (this.handlers.pageView = new Ls(this.managers.event, t), this.handlers.pageView.startTracking(), this.handlers.click = new As(this.managers.event), this.handlers.click.startTracking(), this.handlers.scroll = new Ms(this.managers.event), this.handlers.scroll.startTracking(), this.handlers.performance = new Ps(this.managers.event), this.handlers.performance.startTracking().catch((s) => {
5259
+ if (this.handlers.pageView = new Ls(this.managers.event, t), this.handlers.pageView.startTracking(), this.handlers.click = new As(this.managers.event), this.handlers.click.startTracking(), this.handlers.scroll = new Ms(this.managers.event), this.handlers.scroll.startTracking(), this.handlers.performance = new Ds(this.managers.event), this.handlers.performance.startTracking().catch((s) => {
5243
5260
  a("warn", "Failed to start performance tracking", { error: s });
5244
5261
  }), this.handlers.error = new ae(this.managers.event), this.handlers.error.startTracking(), e.viewport && (this.handlers.viewport = new Cs(this.managers.event), this.handlers.viewport.startTracking()), e.integrations?.tracelog?.shopify) {
5245
- const s = new Ns();
5246
- s.activate(), this.integrationInstances.shopifyCartLinker = s, this.emitter.on(se.EVENT, (i) => {
5247
- i.type === u.SESSION_START && s.onSessionChange();
5262
+ const s = new Os();
5263
+ s.activate(), this.integrationInstances.shopifyCartLinker = s, this.emitter.on(se.EVENT, (n) => {
5264
+ n.type === u.SESSION_START && s.onSessionChange();
5248
5265
  });
5249
5266
  }
5250
5267
  }
5251
5268
  }
5252
5269
  const k = [], M = [];
5253
5270
  let D = null, h = null, R = !1, T = !1, P = null;
5254
- const ks = async (r) => typeof window > "u" || typeof document > "u" ? { sessionId: "" } : (T = !1, window.__traceLogDisabled === !0 ? { sessionId: "" } : h ? { sessionId: h.getSessionId() ?? "" } : (R && P || (R = !0, P = (async () => {
5271
+ const Vs = async (r) => typeof window > "u" || typeof document > "u" ? { sessionId: "" } : (T = !1, window.__traceLogDisabled === !0 ? { sessionId: "" } : h ? { sessionId: h.getSessionId() ?? "" } : (R && P || (R = !0, P = (async () => {
5255
5272
  try {
5256
- const e = fs(r ?? {}), t = new Ds();
5273
+ const e = fs(r ?? {}), t = new ks();
5257
5274
  try {
5258
5275
  k.forEach(({ event: o, callback: l }) => {
5259
5276
  t.on(o, l);
5260
5277
  }), k.length = 0, M.forEach(({ hook: o, fn: l }) => {
5261
5278
  o === "beforeSend" ? t.setTransformer("beforeSend", l) : t.setTransformer("beforeBatch", l);
5262
5279
  }), M.length = 0, D && (t.setCustomHeaders(D), D = null);
5263
- const s = t.init(e), i = new Promise((o, l) => {
5280
+ const s = t.init(e), n = new Promise((o, l) => {
5264
5281
  setTimeout(() => {
5265
5282
  l(new Error("[TraceLog] Initialization timeout after 10000ms"));
5266
5283
  }, 1e4);
5267
- }), n = await Promise.race([s, i]);
5268
- return h = t, n;
5284
+ }), i = await Promise.race([s, n]);
5285
+ return h = t, i;
5269
5286
  } catch (s) {
5270
5287
  try {
5271
5288
  t.destroy(!0);
5272
- } catch (i) {
5273
- a("error", "Failed to cleanup partially initialized app", { error: i });
5289
+ } catch (n) {
5290
+ a("error", "Failed to cleanup partially initialized app", { error: n });
5274
5291
  }
5275
5292
  throw s;
5276
5293
  }
@@ -5279,7 +5296,7 @@ const ks = async (r) => typeof window > "u" || typeof document > "u" ? { session
5279
5296
  } finally {
5280
5297
  R = !1, P = null;
5281
5298
  }
5282
- })()), P)), Vs = (r, e) => {
5299
+ })()), P)), Us = (r, e) => {
5283
5300
  if (!(typeof window > "u" || typeof document > "u")) {
5284
5301
  if (!h)
5285
5302
  throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
@@ -5287,7 +5304,7 @@ const ks = async (r) => typeof window > "u" || typeof document > "u" ? { session
5287
5304
  throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
5288
5305
  h.sendCustomEvent(r, e);
5289
5306
  }
5290
- }, Us = (r, e) => {
5307
+ }, Fs = (r, e) => {
5291
5308
  if (!(typeof window > "u" || typeof document > "u")) {
5292
5309
  if (!h || R) {
5293
5310
  k.push({ event: r, callback: e });
@@ -5295,7 +5312,7 @@ const ks = async (r) => typeof window > "u" || typeof document > "u" ? { session
5295
5312
  }
5296
5313
  h.on(r, e);
5297
5314
  }
5298
- }, Fs = (r, e) => {
5315
+ }, Hs = (r, e) => {
5299
5316
  if (!(typeof window > "u" || typeof document > "u")) {
5300
5317
  if (!h) {
5301
5318
  const t = k.findIndex((s) => s.event === r && s.callback === e);
@@ -5305,7 +5322,7 @@ const ks = async (r) => typeof window > "u" || typeof document > "u" ? { session
5305
5322
  h.off(r, e);
5306
5323
  }
5307
5324
  };
5308
- function Hs(r, e) {
5325
+ function xs(r, e) {
5309
5326
  if (!(typeof window > "u" || typeof document > "u")) {
5310
5327
  if (typeof e != "function")
5311
5328
  throw new Error(`[TraceLog] Transformer must be a function, received: ${typeof e}`);
@@ -5319,7 +5336,7 @@ function Hs(r, e) {
5319
5336
  r === "beforeSend" ? h.setTransformer("beforeSend", e) : h.setTransformer("beforeBatch", e);
5320
5337
  }
5321
5338
  }
5322
- const xs = (r) => {
5339
+ const $s = (r) => {
5323
5340
  if (!(typeof window > "u" || typeof document > "u")) {
5324
5341
  if (!h) {
5325
5342
  const e = M.findIndex((t) => t.hook === r);
@@ -5330,7 +5347,7 @@ const xs = (r) => {
5330
5347
  throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
5331
5348
  h.removeTransformer(r);
5332
5349
  }
5333
- }, $s = (r) => {
5350
+ }, Bs = (r) => {
5334
5351
  if (!(typeof window > "u" || typeof document > "u")) {
5335
5352
  if (typeof r != "function")
5336
5353
  throw new Error(`[TraceLog] Custom headers provider must be a function, received: ${typeof r}`);
@@ -5342,7 +5359,7 @@ const xs = (r) => {
5342
5359
  throw new Error("[TraceLog] Cannot set custom headers while TraceLog is being destroyed");
5343
5360
  h.setCustomHeaders(r);
5344
5361
  }
5345
- }, Bs = () => {
5362
+ }, Ws = () => {
5346
5363
  if (!(typeof window > "u" || typeof document > "u")) {
5347
5364
  if (!h) {
5348
5365
  D = null;
@@ -5352,7 +5369,7 @@ const xs = (r) => {
5352
5369
  throw new Error("[TraceLog] Cannot remove custom headers while TraceLog is being destroyed");
5353
5370
  h.removeCustomHeaders();
5354
5371
  }
5355
- }, Ws = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, Xs = () => typeof window > "u" || typeof document > "u" || !h ? null : h.getSessionId(), Gs = () => {
5372
+ }, Xs = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, Gs = () => typeof window > "u" || typeof document > "u" || !h ? null : h.getSessionId(), js = () => {
5356
5373
  if (!(typeof window > "u" || typeof document > "u")) {
5357
5374
  if (T)
5358
5375
  throw new Error("[TraceLog] Destroy operation already in progress");
@@ -5367,7 +5384,7 @@ const xs = (r) => {
5367
5384
  h = null, R = !1, P = null, k.length = 0, M.length = 0, D = null, T = !1, a("warn", "Error during destroy, forced cleanup completed", { error: r });
5368
5385
  }
5369
5386
  }
5370
- }, js = (r) => {
5387
+ }, Ks = (r) => {
5371
5388
  typeof window > "u" || typeof document > "u" || rs(r);
5372
5389
  }, zs = (r) => {
5373
5390
  if (!(typeof window > "u" || typeof document > "u")) {
@@ -5377,7 +5394,7 @@ const xs = (r) => {
5377
5394
  throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
5378
5395
  h.updateGlobalMetadata(r);
5379
5396
  }
5380
- }, Ks = (r) => {
5397
+ }, Qs = (r) => {
5381
5398
  if (!(typeof window > "u" || typeof document > "u")) {
5382
5399
  if (!h)
5383
5400
  throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
@@ -5385,7 +5402,7 @@ const xs = (r) => {
5385
5402
  throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
5386
5403
  h.mergeGlobalMetadata(r);
5387
5404
  }
5388
- }, Qs = (r, e) => {
5405
+ }, Ys = (r, e) => {
5389
5406
  if (!(typeof window > "u" || typeof document > "u")) {
5390
5407
  if (!r || typeof r != "string" || r.trim().length === 0) {
5391
5408
  a("warn", "identify() called with invalid userId");
@@ -5413,7 +5430,7 @@ const xs = (r) => {
5413
5430
  a("debug", "Failed to persist pre-init identity");
5414
5431
  }
5415
5432
  }
5416
- }, Ys = async () => {
5433
+ }, qs = async () => {
5417
5434
  if (!(typeof window > "u" || typeof document > "u")) {
5418
5435
  if (!h) {
5419
5436
  try {
@@ -5426,27 +5443,27 @@ const xs = (r) => {
5426
5443
  throw new Error("[TraceLog] Cannot reset identity while TraceLog is being destroyed");
5427
5444
  await h.resetIdentity();
5428
5445
  }
5429
- }, br = {
5430
- init: ks,
5431
- event: Vs,
5432
- on: Us,
5433
- off: Fs,
5434
- setTransformer: Hs,
5435
- removeTransformer: xs,
5436
- setCustomHeaders: $s,
5437
- removeCustomHeaders: Bs,
5438
- isInitialized: Ws,
5439
- getSessionId: Xs,
5440
- destroy: Gs,
5441
- setQaMode: js,
5446
+ }, Lr = {
5447
+ init: Vs,
5448
+ event: Us,
5449
+ on: Fs,
5450
+ off: Hs,
5451
+ setTransformer: xs,
5452
+ removeTransformer: $s,
5453
+ setCustomHeaders: Bs,
5454
+ removeCustomHeaders: Ws,
5455
+ isInitialized: Xs,
5456
+ getSessionId: Gs,
5457
+ destroy: js,
5458
+ setQaMode: Ks,
5442
5459
  updateGlobalMetadata: zs,
5443
- mergeGlobalMetadata: Ks,
5444
- identify: Qs,
5445
- resetIdentity: Ys
5460
+ mergeGlobalMetadata: Qs,
5461
+ identify: Ys,
5462
+ resetIdentity: qs
5446
5463
  };
5447
- var Le, C, G, Et, le, pt = -1, V = function(r) {
5464
+ var Le, C, G, pt, le, Et = -1, V = function(r) {
5448
5465
  addEventListener("pageshow", (function(e) {
5449
- e.persisted && (pt = e.timeStamp, r(e));
5466
+ e.persisted && (Et = e.timeStamp, r(e));
5450
5467
  }), !0);
5451
5468
  }, Pe = function() {
5452
5469
  var r = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
@@ -5456,13 +5473,13 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
5456
5473
  return r && r.activationStart || 0;
5457
5474
  }, y = function(r, e) {
5458
5475
  var t = Pe(), s = "navigate";
5459
- return pt >= 0 ? s = "back-forward-cache" : t && (document.prerendering || de() > 0 ? s = "prerender" : document.wasDiscarded ? s = "restore" : t.type && (s = t.type.replace(/_/g, "-"))), { name: r, value: e === void 0 ? -1 : e, rating: "good", delta: 0, entries: [], id: "v4-".concat(Date.now(), "-").concat(Math.floor(8999999999999 * Math.random()) + 1e12), navigationType: s };
5476
+ return Et >= 0 ? s = "back-forward-cache" : t && (document.prerendering || de() > 0 ? s = "prerender" : document.wasDiscarded ? s = "restore" : t.type && (s = t.type.replace(/_/g, "-"))), { name: r, value: e === void 0 ? -1 : e, rating: "good", delta: 0, entries: [], id: "v4-".concat(Date.now(), "-").concat(Math.floor(8999999999999 * Math.random()) + 1e12), navigationType: s };
5460
5477
  }, H = function(r, e, t) {
5461
5478
  try {
5462
5479
  if (PerformanceObserver.supportedEntryTypes.includes(r)) {
5463
- var s = new PerformanceObserver((function(i) {
5480
+ var s = new PerformanceObserver((function(n) {
5464
5481
  Promise.resolve().then((function() {
5465
- e(i.getEntries());
5482
+ e(n.getEntries());
5466
5483
  }));
5467
5484
  }));
5468
5485
  return s.observe(Object.assign({ type: r, buffered: !0 }, t || {})), s;
@@ -5470,9 +5487,9 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
5470
5487
  } catch {
5471
5488
  }
5472
5489
  }, w = function(r, e, t, s) {
5473
- var i, n;
5490
+ var n, i;
5474
5491
  return function(o) {
5475
- e.value >= 0 && (o || s) && ((n = e.value - (i || 0)) || i === void 0) && (i = e.value, e.delta = n, e.rating = (function(l, c) {
5492
+ e.value >= 0 && (o || s) && ((i = e.value - (n || 0)) || n === void 0) && (n = e.value, e.delta = i, e.rating = (function(l, c) {
5476
5493
  return l > c[1] ? "poor" : l > c[0] ? "needs-improvement" : "good";
5477
5494
  })(e.value, t), r(e));
5478
5495
  };
@@ -5482,7 +5499,7 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
5482
5499
  return r();
5483
5500
  }));
5484
5501
  }));
5485
- }, z = function(r) {
5502
+ }, K = function(r) {
5486
5503
  document.addEventListener("visibilitychange", (function() {
5487
5504
  document.visibilityState === "hidden" && r();
5488
5505
  }));
@@ -5494,10 +5511,10 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
5494
5511
  }, F = -1, et = function() {
5495
5512
  return document.visibilityState !== "hidden" || document.prerendering ? 1 / 0 : 0;
5496
5513
  }, ce = function(r) {
5497
- document.visibilityState === "hidden" && F > -1 && (F = r.type === "visibilitychange" ? r.timeStamp : 0, qs());
5514
+ document.visibilityState === "hidden" && F > -1 && (F = r.type === "visibilitychange" ? r.timeStamp : 0, Js());
5498
5515
  }, tt = function() {
5499
5516
  addEventListener("visibilitychange", ce, !0), addEventListener("prerenderingchange", ce, !0);
5500
- }, qs = function() {
5517
+ }, Js = function() {
5501
5518
  removeEventListener("visibilitychange", ce, !0), removeEventListener("prerenderingchange", ce, !0);
5502
5519
  }, ke = function() {
5503
5520
  return F < 0 && (F = et(), tt(), V((function() {
@@ -5507,55 +5524,55 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
5507
5524
  }))), { get firstHiddenTime() {
5508
5525
  return F;
5509
5526
  } };
5510
- }, K = function(r) {
5527
+ }, z = function(r) {
5511
5528
  document.prerendering ? addEventListener("prerenderingchange", (function() {
5512
5529
  return r();
5513
5530
  }), !0) : r();
5514
5531
  }, Ae = [1800, 3e3], St = function(r, e) {
5515
- e = e || {}, K((function() {
5516
- var t, s = ke(), i = y("FCP"), n = H("paint", (function(o) {
5532
+ e = e || {}, z((function() {
5533
+ var t, s = ke(), n = y("FCP"), i = H("paint", (function(o) {
5517
5534
  o.forEach((function(l) {
5518
- l.name === "first-contentful-paint" && (n.disconnect(), l.startTime < s.firstHiddenTime && (i.value = Math.max(l.startTime - de(), 0), i.entries.push(l), t(!0)));
5535
+ l.name === "first-contentful-paint" && (i.disconnect(), l.startTime < s.firstHiddenTime && (n.value = Math.max(l.startTime - de(), 0), n.entries.push(l), t(!0)));
5519
5536
  }));
5520
5537
  }));
5521
- n && (t = w(r, i, Ae, e.reportAllChanges), V((function(o) {
5522
- i = y("FCP"), t = w(r, i, Ae, e.reportAllChanges), De((function() {
5523
- i.value = performance.now() - o.timeStamp, t(!0);
5538
+ i && (t = w(r, n, Ae, e.reportAllChanges), V((function(o) {
5539
+ n = y("FCP"), t = w(r, n, Ae, e.reportAllChanges), De((function() {
5540
+ n.value = performance.now() - o.timeStamp, t(!0);
5524
5541
  }));
5525
5542
  })));
5526
5543
  }));
5527
- }, Me = [0.1, 0.25], Js = function(r, e) {
5544
+ }, Me = [0.1, 0.25], Zs = function(r, e) {
5528
5545
  e = e || {}, St(ue((function() {
5529
- var t, s = y("CLS", 0), i = 0, n = [], o = function(c) {
5546
+ var t, s = y("CLS", 0), n = 0, i = [], o = function(c) {
5530
5547
  c.forEach((function(d) {
5531
5548
  if (!d.hadRecentInput) {
5532
- var f = n[0], g = n[n.length - 1];
5533
- i && d.startTime - g.startTime < 1e3 && d.startTime - f.startTime < 5e3 ? (i += d.value, n.push(d)) : (i = d.value, n = [d]);
5549
+ var f = i[0], g = i[i.length - 1];
5550
+ n && d.startTime - g.startTime < 1e3 && d.startTime - f.startTime < 5e3 ? (n += d.value, i.push(d)) : (n = d.value, i = [d]);
5534
5551
  }
5535
- })), i > s.value && (s.value = i, s.entries = n, t());
5552
+ })), n > s.value && (s.value = n, s.entries = i, t());
5536
5553
  }, l = H("layout-shift", o);
5537
- l && (t = w(r, s, Me, e.reportAllChanges), z((function() {
5554
+ l && (t = w(r, s, Me, e.reportAllChanges), K((function() {
5538
5555
  o(l.takeRecords()), t(!0);
5539
5556
  })), V((function() {
5540
- i = 0, s = y("CLS", 0), t = w(r, s, Me, e.reportAllChanges), De((function() {
5557
+ n = 0, s = y("CLS", 0), t = w(r, s, Me, e.reportAllChanges), De((function() {
5541
5558
  return t();
5542
5559
  }));
5543
5560
  })), setTimeout(t, 0));
5544
5561
  })));
5545
- }, Tt = 0, pe = 1 / 0, J = 0, Zs = function(r) {
5562
+ }, Tt = 0, Ee = 1 / 0, J = 0, er = function(r) {
5546
5563
  r.forEach((function(e) {
5547
- e.interactionId && (pe = Math.min(pe, e.interactionId), J = Math.max(J, e.interactionId), Tt = J ? (J - pe) / 7 + 1 : 0);
5564
+ e.interactionId && (Ee = Math.min(Ee, e.interactionId), J = Math.max(J, e.interactionId), Tt = J ? (J - Ee) / 7 + 1 : 0);
5548
5565
  }));
5549
5566
  }, It = function() {
5550
5567
  return Le ? Tt : performance.interactionCount || 0;
5551
- }, er = function() {
5552
- "interactionCount" in performance || Le || (Le = H("event", Zs, { type: "event", buffered: !0, durationThreshold: 0 }));
5553
- }, L = [], te = /* @__PURE__ */ new Map(), vt = 0, tr = function() {
5568
+ }, tr = function() {
5569
+ "interactionCount" in performance || Le || (Le = H("event", er, { type: "event", buffered: !0, durationThreshold: 0 }));
5570
+ }, L = [], te = /* @__PURE__ */ new Map(), vt = 0, sr = function() {
5554
5571
  var r = Math.min(L.length - 1, Math.floor((It() - vt) / 50));
5555
5572
  return L[r];
5556
- }, sr = [], rr = function(r) {
5557
- if (sr.forEach((function(i) {
5558
- return i(r);
5573
+ }, rr = [], nr = function(r) {
5574
+ if (rr.forEach((function(n) {
5575
+ return n(r);
5559
5576
  })), r.interactionId || r.entryType === "first-input") {
5560
5577
  var e = L[L.length - 1], t = te.get(r.interactionId);
5561
5578
  if (t || L.length < 10 || r.duration > e.latency) {
@@ -5564,114 +5581,114 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
5564
5581
  var s = { id: r.interactionId, latency: r.duration, entries: [r] };
5565
5582
  te.set(s.id, s), L.push(s);
5566
5583
  }
5567
- L.sort((function(i, n) {
5568
- return n.latency - i.latency;
5569
- })), L.length > 10 && L.splice(10).forEach((function(i) {
5570
- return te.delete(i.id);
5584
+ L.sort((function(n, i) {
5585
+ return i.latency - n.latency;
5586
+ })), L.length > 10 && L.splice(10).forEach((function(n) {
5587
+ return te.delete(n.id);
5571
5588
  }));
5572
5589
  }
5573
5590
  }
5574
5591
  }, _t = function(r) {
5575
5592
  var e = self.requestIdleCallback || self.setTimeout, t = -1;
5576
- return r = ue(r), document.visibilityState === "hidden" ? r() : (t = e(r), z(r)), t;
5593
+ return r = ue(r), document.visibilityState === "hidden" ? r() : (t = e(r), K(r)), t;
5577
5594
  }, Ce = [200, 500], ir = function(r, e) {
5578
- "PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, K((function() {
5595
+ "PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, z((function() {
5579
5596
  var t;
5580
- er();
5581
- var s, i = y("INP"), n = function(l) {
5597
+ tr();
5598
+ var s, n = y("INP"), i = function(l) {
5582
5599
  _t((function() {
5583
- l.forEach(rr);
5584
- var c = tr();
5585
- c && c.latency !== i.value && (i.value = c.latency, i.entries = c.entries, s());
5600
+ l.forEach(nr);
5601
+ var c = sr();
5602
+ c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, s());
5586
5603
  }));
5587
- }, o = H("event", n, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
5588
- s = w(r, i, Ce, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), z((function() {
5589
- n(o.takeRecords()), s(!0);
5604
+ }, o = H("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
5605
+ s = w(r, n, Ce, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), K((function() {
5606
+ i(o.takeRecords()), s(!0);
5590
5607
  })), V((function() {
5591
- vt = It(), L.length = 0, te.clear(), i = y("INP"), s = w(r, i, Ce, e.reportAllChanges);
5608
+ vt = It(), L.length = 0, te.clear(), n = y("INP"), s = w(r, n, Ce, e.reportAllChanges);
5592
5609
  })));
5593
5610
  })));
5594
- }, Re = [2500, 4e3], Se = {}, nr = function(r, e) {
5595
- e = e || {}, K((function() {
5596
- var t, s = ke(), i = y("LCP"), n = function(c) {
5611
+ }, Re = [2500, 4e3], Se = {}, or = function(r, e) {
5612
+ e = e || {}, z((function() {
5613
+ var t, s = ke(), n = y("LCP"), i = function(c) {
5597
5614
  e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(d) {
5598
- d.startTime < s.firstHiddenTime && (i.value = Math.max(d.startTime - de(), 0), i.entries = [d], t());
5615
+ d.startTime < s.firstHiddenTime && (n.value = Math.max(d.startTime - de(), 0), n.entries = [d], t());
5599
5616
  }));
5600
- }, o = H("largest-contentful-paint", n);
5617
+ }, o = H("largest-contentful-paint", i);
5601
5618
  if (o) {
5602
- t = w(r, i, Re, e.reportAllChanges);
5619
+ t = w(r, n, Re, e.reportAllChanges);
5603
5620
  var l = ue((function() {
5604
- Se[i.id] || (n(o.takeRecords()), o.disconnect(), Se[i.id] = !0, t(!0));
5621
+ Se[n.id] || (i(o.takeRecords()), o.disconnect(), Se[n.id] = !0, t(!0));
5605
5622
  }));
5606
5623
  ["keydown", "click"].forEach((function(c) {
5607
5624
  addEventListener(c, (function() {
5608
5625
  return _t(l);
5609
5626
  }), { once: !0, capture: !0 });
5610
- })), z(l), V((function(c) {
5611
- i = y("LCP"), t = w(r, i, Re, e.reportAllChanges), De((function() {
5612
- i.value = performance.now() - c.timeStamp, Se[i.id] = !0, t(!0);
5627
+ })), K(l), V((function(c) {
5628
+ n = y("LCP"), t = w(r, n, Re, e.reportAllChanges), De((function() {
5629
+ n.value = performance.now() - c.timeStamp, Se[n.id] = !0, t(!0);
5613
5630
  }));
5614
5631
  }));
5615
5632
  }
5616
5633
  }));
5617
- }, Ne = [800, 1800], or = function r(e) {
5618
- document.prerendering ? K((function() {
5634
+ }, Ne = [800, 1800], ar = function r(e) {
5635
+ document.prerendering ? z((function() {
5619
5636
  return r(e);
5620
5637
  })) : document.readyState !== "complete" ? addEventListener("load", (function() {
5621
5638
  return r(e);
5622
5639
  }), !0) : setTimeout(e, 0);
5623
- }, ar = function(r, e) {
5640
+ }, lr = function(r, e) {
5624
5641
  e = e || {};
5625
5642
  var t = y("TTFB"), s = w(r, t, Ne, e.reportAllChanges);
5626
- or((function() {
5627
- var i = Pe();
5628
- i && (t.value = Math.max(i.responseStart - de(), 0), t.entries = [i], s(!0), V((function() {
5643
+ ar((function() {
5644
+ var n = Pe();
5645
+ n && (t.value = Math.max(n.responseStart - de(), 0), t.entries = [n], s(!0), V((function() {
5629
5646
  t = y("TTFB", 0), (s = w(r, t, Ne, e.reportAllChanges))(!0);
5630
5647
  })));
5631
5648
  }));
5632
- }, W = { passive: !0, capture: !0 }, lr = /* @__PURE__ */ new Date(), st = function(r, e) {
5633
- C || (C = e, G = r, Et = /* @__PURE__ */ new Date(), wt(removeEventListener), yt());
5649
+ }, W = { passive: !0, capture: !0 }, cr = /* @__PURE__ */ new Date(), st = function(r, e) {
5650
+ C || (C = e, G = r, pt = /* @__PURE__ */ new Date(), wt(removeEventListener), yt());
5634
5651
  }, yt = function() {
5635
- if (G >= 0 && G < Et - lr) {
5652
+ if (G >= 0 && G < pt - cr) {
5636
5653
  var r = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp + G };
5637
5654
  le.forEach((function(e) {
5638
5655
  e(r);
5639
5656
  })), le = [];
5640
5657
  }
5641
- }, cr = function(r) {
5658
+ }, dr = function(r) {
5642
5659
  if (r.cancelable) {
5643
5660
  var e = (r.timeStamp > 1e12 ? /* @__PURE__ */ new Date() : performance.now()) - r.timeStamp;
5644
5661
  r.type == "pointerdown" ? (function(t, s) {
5645
- var i = function() {
5662
+ var n = function() {
5646
5663
  st(t, s), o();
5647
- }, n = function() {
5664
+ }, i = function() {
5648
5665
  o();
5649
5666
  }, o = function() {
5650
- removeEventListener("pointerup", i, W), removeEventListener("pointercancel", n, W);
5667
+ removeEventListener("pointerup", n, W), removeEventListener("pointercancel", i, W);
5651
5668
  };
5652
- addEventListener("pointerup", i, W), addEventListener("pointercancel", n, W);
5669
+ addEventListener("pointerup", n, W), addEventListener("pointercancel", i, W);
5653
5670
  })(e, r) : st(e, r);
5654
5671
  }
5655
5672
  }, wt = function(r) {
5656
5673
  ["mousedown", "keydown", "touchstart", "pointerdown"].forEach((function(e) {
5657
- return r(e, cr, W);
5674
+ return r(e, dr, W);
5658
5675
  }));
5659
- }, Oe = [100, 300], dr = function(r, e) {
5660
- e = e || {}, K((function() {
5661
- var t, s = ke(), i = y("FID"), n = function(c) {
5662
- c.startTime < s.firstHiddenTime && (i.value = c.processingStart - c.startTime, i.entries.push(c), t(!0));
5676
+ }, Oe = [100, 300], ur = function(r, e) {
5677
+ e = e || {}, z((function() {
5678
+ var t, s = ke(), n = y("FID"), i = function(c) {
5679
+ c.startTime < s.firstHiddenTime && (n.value = c.processingStart - c.startTime, n.entries.push(c), t(!0));
5663
5680
  }, o = function(c) {
5664
- c.forEach(n);
5681
+ c.forEach(i);
5665
5682
  }, l = H("first-input", o);
5666
- t = w(r, i, Oe, e.reportAllChanges), l && (z(ue((function() {
5683
+ t = w(r, n, Oe, e.reportAllChanges), l && (K(ue((function() {
5667
5684
  o(l.takeRecords()), l.disconnect();
5668
5685
  }))), V((function() {
5669
5686
  var c;
5670
- i = y("FID"), t = w(r, i, Oe, e.reportAllChanges), le = [], G = -1, C = null, wt(addEventListener), c = n, le.push(c), yt();
5687
+ n = y("FID"), t = w(r, n, Oe, e.reportAllChanges), le = [], G = -1, C = null, wt(addEventListener), c = i, le.push(c), yt();
5671
5688
  })));
5672
5689
  }));
5673
5690
  };
5674
- const ur = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5691
+ const hr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5675
5692
  __proto__: null,
5676
5693
  CLSThresholds: Me,
5677
5694
  FCPThresholds: Ae,
@@ -5679,32 +5696,32 @@ const ur = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5679
5696
  INPThresholds: Ce,
5680
5697
  LCPThresholds: Re,
5681
5698
  TTFBThresholds: Ne,
5682
- onCLS: Js,
5699
+ onCLS: Zs,
5683
5700
  onFCP: St,
5684
- onFID: dr,
5701
+ onFID: ur,
5685
5702
  onINP: ir,
5686
- onLCP: nr,
5687
- onTTFB: ar
5703
+ onLCP: or,
5704
+ onTTFB: lr
5688
5705
  }, Symbol.toStringTag, { value: "Module" }));
5689
5706
  export {
5690
5707
  m as AppConfigValidationError,
5691
- hr as DEFAULT_SESSION_TIMEOUT,
5708
+ fr as DEFAULT_SESSION_TIMEOUT,
5692
5709
  _e as DEFAULT_WEB_VITALS_MODE,
5693
5710
  A as DeviceType,
5694
5711
  se as EmitterEvent,
5695
5712
  B as ErrorType,
5696
5713
  u as EventType,
5697
- yr as InitializationTimeoutError,
5714
+ wr as InitializationTimeoutError,
5698
5715
  N as IntegrationValidationError,
5699
- Ir as MAX_ARRAY_LENGTH,
5716
+ vr as MAX_ARRAY_LENGTH,
5700
5717
  Er as MAX_CUSTOM_EVENT_ARRAY_SIZE,
5701
- gr as MAX_CUSTOM_EVENT_KEYS,
5702
- fr as MAX_CUSTOM_EVENT_NAME_LENGTH,
5703
- mr as MAX_CUSTOM_EVENT_STRING_SIZE,
5704
- pr as MAX_NESTED_OBJECT_KEYS,
5705
- Sr as MAX_STRING_LENGTH,
5706
- Tr as MAX_STRING_LENGTH_IN_ARRAY,
5707
- ne as Mode,
5718
+ pr as MAX_CUSTOM_EVENT_KEYS,
5719
+ mr as MAX_CUSTOM_EVENT_NAME_LENGTH,
5720
+ gr as MAX_CUSTOM_EVENT_STRING_SIZE,
5721
+ Sr as MAX_NESTED_OBJECT_KEYS,
5722
+ Tr as MAX_STRING_LENGTH,
5723
+ Ir as MAX_STRING_LENGTH_IN_ARRAY,
5724
+ ie as Mode,
5708
5725
  at as PII_PATTERNS,
5709
5726
  O as PermanentError,
5710
5727
  re as RateLimitError,
@@ -5712,13 +5729,13 @@ export {
5712
5729
  Z as ScrollDirection,
5713
5730
  Pt as SessionTimeoutValidationError,
5714
5731
  $ as SpecialApiUrl,
5715
- ie as TimeoutError,
5732
+ ne as TimeoutError,
5716
5733
  j as TraceLogValidationError,
5717
- wr as WEB_VITALS_GOOD_THRESHOLDS,
5718
- Ke as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
5734
+ br as WEB_VITALS_GOOD_THRESHOLDS,
5735
+ ze as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
5719
5736
  Yt as WEB_VITALS_POOR_THRESHOLDS,
5720
5737
  Qe as getWebVitalsThresholds,
5721
- vr as isPrimaryScrollEvent,
5722
- _r as isSecondaryScrollEvent,
5723
- br as tracelog
5738
+ _r as isPrimaryScrollEvent,
5739
+ yr as isSecondaryScrollEvent,
5740
+ Lr as tracelog
5724
5741
  };