@tracelog/lib 2.8.5-rc.106.9 → 2.9.0-rc.107.4

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
1
  const fr = 9e5;
2
2
  const mr = 120, gr = 49152, pr = 100, Er = 500, Sr = 200;
3
- const Tr = 1e3, Ir = 500, vr = 1e3;
3
+ const Tr = 1e3, Ir = 500, _r = 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 p = {
52
+ const S = {
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",
@@ -79,7 +79,7 @@ const p = {
79
79
  /<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
80
80
  /<embed\b[^>]*>/gi,
81
81
  /<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi
82
- ], S = "tlog", X = `${S}:qa_mode`, Te = `${S}:uid`, rt = "tlog_mode", Ue = "qa", Fe = "qa_off", Ct = (r) => r ? `${S}:${r}:queue` : `${S}:queue`, Rt = (r) => r ? `${S}:${r}:rate_limit` : `${S}:rate_limit`, Nt = (r) => r ? `${S}:${r}:session` : `${S}:session`, Ot = (r) => r ? `${S}:${r}:broadcast` : `${S}:broadcast`, He = (r, e) => `${S}:${r}:session_counts:${e}`, xe = 10080 * 60 * 1e3, $e = `${S}:session_counts_last_cleanup`, Be = 3600 * 1e3, fe = (r) => r ? `${S}:${r}:identity` : `${S}:identity`, U = `${S}:pending_identity`;
82
+ ], I = "tlog", G = `${I}:qa_mode`, Ie = `${I}:uid`, rt = "tlog_mode", Ue = "qa", Fe = "qa_off", Ct = (r) => r ? `${I}:${r}:queue` : `${I}:queue`, Rt = (r) => r ? `${I}:${r}:rate_limit` : `${I}:rate_limit`, Nt = (r) => r ? `${I}:${r}:session` : `${I}:session`, Ot = (r) => r ? `${I}:${r}:broadcast` : `${I}:broadcast`, He = (r, e) => `${I}:${r}:session_counts:${e}`, xe = 10080 * 60 * 1e3, $e = `${I}:session_counts_last_cleanup`, Be = 3600 * 1e3, me = (r) => r ? `${I}:${r}:identity` : `${I}:identity`, F = `${I}:pending_identity`;
83
83
  var $ = /* @__PURE__ */ ((r) => (r.Localhost = "localhost:8080", r.Fail = "localhost:9999", r))($ || {}), A = /* @__PURE__ */ ((r) => (r.Mobile = "mobile", r.Tablet = "tablet", r.Desktop = "desktop", r.Unknown = "unknown", r))(A || {}), se = /* @__PURE__ */ ((r) => (r.EVENT = "event", r.QUEUE = "queue", r))(se || {});
84
84
  class O extends Error {
85
85
  constructor(e, t, s) {
@@ -99,7 +99,7 @@ class ne extends Error {
99
99
  }
100
100
  }
101
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;
102
+ const vr = (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);
@@ -107,7 +107,7 @@ class j extends Error {
107
107
  errorCode;
108
108
  layer;
109
109
  }
110
- class m extends j {
110
+ class p extends j {
111
111
  constructor(e, t = "config") {
112
112
  super(e, "APP_CONFIG_INVALID", t);
113
113
  }
@@ -156,20 +156,20 @@ const nt = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8
156
156
  if (typeof window > "u" || typeof sessionStorage > "u")
157
157
  return !1;
158
158
  try {
159
- return sessionStorage.getItem(X) === "true";
159
+ return sessionStorage.getItem(G) === "true";
160
160
  } catch {
161
161
  return !1;
162
162
  }
163
163
  }, a = (r, e, t) => {
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";
164
+ const { error: s, data: n, showToClient: i = !1, style: o, visibility: l } = t ?? {}, d = s ? kt(e, s) : `[TraceLog] ${e}`, c = r === "error" ? "error" : r === "warn" ? "warn" : "log";
165
165
  if (!Ut(l, i))
166
166
  return;
167
- const g = Ft(l, o), I = n !== void 0 ? Ie(n) : void 0;
168
- Ht(d, c, g, I);
167
+ const g = Ft(l, o), m = n !== void 0 ? _e(n) : void 0;
168
+ Ht(c, d, g, m);
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
170
  const n = t !== void 0 && t !== "", i = n ? `%c${e}` : e;
171
171
  s !== void 0 ? n ? console[r](i, t, s) : console[r](i, s) : n ? console[r](i, t) : console[r](i);
172
- }, Ie = (r) => {
172
+ }, _e = (r) => {
173
173
  const e = {}, t = ["token", "password", "secret", "key", "apikey", "api_key", "sessionid", "session_id"];
174
174
  for (const [s, n] of Object.entries(r)) {
175
175
  const i = s.toLowerCase();
@@ -177,8 +177,8 @@ const nt = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8
177
177
  e[s] = "[REDACTED]";
178
178
  continue;
179
179
  }
180
- n !== null && typeof n == "object" && !Array.isArray(n) ? e[s] = Ie(n) : Array.isArray(n) ? e[s] = n.map(
181
- (o) => o !== null && typeof o == "object" && !Array.isArray(o) ? Ie(o) : o
180
+ n !== null && typeof n == "object" && !Array.isArray(n) ? e[s] = _e(n) : Array.isArray(n) ? e[s] = n.map(
181
+ (o) => o !== null && typeof o == "object" && !Array.isArray(o) ? _e(o) : o
182
182
  ) : e[s] = n;
183
183
  }
184
184
  return e;
@@ -213,8 +213,8 @@ const xt = () => {
213
213
  try {
214
214
  const r = navigator;
215
215
  if (r.userAgentData != null && typeof r.userAgentData.mobile == "boolean") {
216
- const c = r.userAgentData.platform;
217
- return c != null && c !== "" && /ipad|tablet/i.test(c) ? A.Tablet : r.userAgentData.mobile ? A.Mobile : A.Desktop;
216
+ const d = r.userAgentData.platform;
217
+ return d != null && d !== "" && /ipad|tablet/i.test(d) ? A.Tablet : r.userAgentData.mobile ? A.Mobile : A.Desktop;
218
218
  }
219
219
  xt();
220
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);
@@ -222,7 +222,7 @@ const xt = () => {
222
222
  } catch (r) {
223
223
  return a("debug", "Device detection failed, defaulting to desktop", { error: r }), A.Desktop;
224
224
  }
225
- }, Xt = () => {
225
+ }, Gt = () => {
226
226
  try {
227
227
  const r = navigator;
228
228
  return {
@@ -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, Kt = 10, Ke = 5e3, zt = 6e4, Qt = 64, br = {
257
+ ], Ge = 500, Xe = 2e3, je = 5e3, ee = 50, Xt = 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,
@@ -290,7 +290,7 @@ const xt = () => {
290
290
  TTFB: 1800,
291
291
  // Poor: > 1800ms
292
292
  LONG_TASK: 50
293
- }, _e = "needs-improvement", Qe = (r = _e) => {
293
+ }, ye = "needs-improvement", Qe = (r = ye) => {
294
294
  switch (r) {
295
295
  case "all":
296
296
  return { LCP: 0, FCP: 0, CLS: 0, INP: 0, TTFB: 0, LONG_TASK: 0 };
@@ -302,7 +302,7 @@ const xt = () => {
302
302
  default:
303
303
  return ze;
304
304
  }
305
- }, qt = 1e3, Jt = 50, Zt = "2.8.5", es = Zt, ct = () => typeof window < "u" && typeof sessionStorage < "u", ts = () => {
305
+ }, qt = 1e3, Jt = 50, Zt = "2.9.0", 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);
@@ -314,12 +314,12 @@ const xt = () => {
314
314
  if (!ct())
315
315
  return !1;
316
316
  try {
317
- const e = new URLSearchParams(window.location.search).get(rt), t = sessionStorage.getItem(X);
317
+ const e = new URLSearchParams(window.location.search).get(rt), t = sessionStorage.getItem(G);
318
318
  let s = null;
319
- return e === Ue ? (s = !0, sessionStorage.setItem(X, "true"), a("info", "QA Mode ACTIVE", {
319
+ return e === Ue ? (s = !0, sessionStorage.setItem(G, "true"), a("info", "QA Mode ACTIVE", {
320
320
  visibility: "qa",
321
321
  style: nt
322
- })) : e === Fe && (s = !1, sessionStorage.setItem(X, "false"), a("info", "QA Mode DISABLED", {
322
+ })) : e === Fe && (s = !1, sessionStorage.setItem(G, "false"), a("info", "QA Mode DISABLED", {
323
323
  visibility: "qa",
324
324
  style: it
325
325
  })), (e === Ue || e === Fe) && ts(), s ?? t === "true";
@@ -329,7 +329,7 @@ const xt = () => {
329
329
  }, rs = (r) => {
330
330
  if (ct())
331
331
  try {
332
- sessionStorage.setItem(X, r ? "true" : "false"), a("info", r ? "QA Mode ACTIVE" : "QA Mode DISABLED", {
332
+ sessionStorage.setItem(G, r ? "true" : "false"), a("info", r ? "QA Mode ACTIVE" : "QA Mode DISABLED", {
333
333
  visibility: "qa",
334
334
  style: r ? nt : it
335
335
  });
@@ -354,7 +354,7 @@ const xt = () => {
354
354
  return r.toLowerCase();
355
355
  const t = e.slice(-2).join(".");
356
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 = () => {
357
+ }, is = (r, e) => r === e ? !0 : Ye(r) === Ye(e), ge = () => {
358
358
  const r = document.referrer;
359
359
  if (!r)
360
360
  return "Direct";
@@ -364,7 +364,7 @@ const xt = () => {
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
- }, ge = () => {
367
+ }, pe = () => {
368
368
  const r = new URLSearchParams(window.location.search), e = {};
369
369
  return Lt.forEach((s) => {
370
370
  const n = r.get(s);
@@ -433,15 +433,15 @@ const os = () => {
433
433
  e.custom = t;
434
434
  }
435
435
  return e;
436
- }, ye = (r, e = []) => {
436
+ }, we = (r, e = []) => {
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
440
  const t = new URL(r), s = t.searchParams, n = [.../* @__PURE__ */ new Set([...At, ...e])];
441
441
  let i = !1;
442
442
  const o = [];
443
- return n.forEach((c) => {
444
- s.has(c) && (s.delete(c), i = !0, o.push(c));
443
+ return n.forEach((d) => {
444
+ s.has(d) && (s.delete(d), i = !0, o.push(d));
445
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;
@@ -462,7 +462,7 @@ const os = () => {
462
462
  valueLength: r.length
463
463
  }
464
464
  }), e.trim();
465
- }, we = (r, e = 0) => {
465
+ }, be = (r, e = 0) => {
466
466
  if (r == null)
467
467
  return null;
468
468
  if (typeof r == "string")
@@ -474,14 +474,14 @@ const os = () => {
474
474
  if (e > 10)
475
475
  return null;
476
476
  if (Array.isArray(r))
477
- return r.slice(0, 1e3).map((n) => we(n, e + 1)).filter((n) => n !== null);
477
+ return r.slice(0, 1e3).map((n) => be(n, e + 1)).filter((n) => n !== null);
478
478
  if (typeof r == "object") {
479
479
  const t = {}, n = Object.entries(r).slice(0, 200);
480
480
  for (const [i, o] of n) {
481
481
  const l = qe(i);
482
482
  if (l) {
483
- const c = we(o, e + 1);
484
- c !== null && (t[l] = c);
483
+ const d = be(o, e + 1);
484
+ d !== null && (t[l] = d);
485
485
  }
486
486
  }
487
487
  return t;
@@ -491,7 +491,7 @@ const os = () => {
491
491
  if (typeof r != "object" || r === null)
492
492
  return {};
493
493
  try {
494
- const e = we(r);
494
+ const e = be(r);
495
495
  return typeof e == "object" && e !== null ? e : {};
496
496
  } catch (e) {
497
497
  const t = e instanceof Error ? e.message : String(e);
@@ -499,69 +499,69 @@ const os = () => {
499
499
  }
500
500
  }, ds = (r) => {
501
501
  if (r !== void 0 && (r === null || typeof r != "object"))
502
- throw new m("Configuration must be an object", "config");
502
+ throw new p("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(p.INVALID_SESSION_TIMEOUT, "config");
505
+ throw new Pt(S.INVALID_SESSION_TIMEOUT, "config");
506
506
  if (r.globalMetadata !== void 0 && (typeof r.globalMetadata != "object" || r.globalMetadata === null))
507
- throw new m(p.INVALID_GLOBAL_METADATA, "config");
507
+ throw new p(S.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(p.INVALID_SENSITIVE_QUERY_PARAMS, "config");
510
+ throw new p(S.INVALID_SENSITIVE_QUERY_PARAMS, "config");
511
511
  for (const e of r.sensitiveQueryParams)
512
512
  if (typeof e != "string")
513
- throw new m("All sensitive query params must be strings", "config");
513
+ throw new p("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(p.INVALID_ERROR_SAMPLING_RATE, "config");
516
+ throw new We(S.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(p.INVALID_SAMPLING_RATE, "config");
518
+ throw new We(S.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(p.INVALID_PRIMARY_SCROLL_SELECTOR, "config");
521
+ throw new p(S.INVALID_PRIMARY_SCROLL_SELECTOR, "config");
522
522
  if (r.primaryScrollSelector !== "window")
523
523
  try {
524
524
  document.querySelector(r.primaryScrollSelector);
525
525
  } catch {
526
- throw new m(
527
- `${p.INVALID_PRIMARY_SCROLL_SELECTOR_SYNTAX}: "${r.primaryScrollSelector}"`,
526
+ throw new p(
527
+ `${S.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(p.INVALID_PAGE_VIEW_THROTTLE, "config");
533
+ throw new p(S.INVALID_PAGE_VIEW_THROTTLE, "config");
534
534
  if (r.clickThrottleMs !== void 0 && (typeof r.clickThrottleMs != "number" || r.clickThrottleMs < 0))
535
- throw new m(p.INVALID_CLICK_THROTTLE, "config");
535
+ throw new p(S.INVALID_CLICK_THROTTLE, "config");
536
536
  if (r.maxSameEventPerMinute !== void 0 && (typeof r.maxSameEventPerMinute != "number" || r.maxSameEventPerMinute <= 0))
537
- throw new m(p.INVALID_MAX_SAME_EVENT_PER_MINUTE, "config");
537
+ throw new p(S.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(p.INVALID_SEND_INTERVAL, "config");
539
+ throw new p(S.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
- throw new m(
542
+ throw new p(
543
543
  `Invalid webVitalsMode type: ${typeof r.webVitalsMode}. Must be a string`,
544
544
  "config"
545
545
  );
546
546
  const e = ["all", "needs-improvement", "poor"];
547
547
  if (!e.includes(r.webVitalsMode))
548
- throw new m(
548
+ throw new p(
549
549
  `Invalid webVitalsMode: "${r.webVitalsMode}". Must be one of: ${e.join(", ")}`,
550
550
  "config"
551
551
  );
552
552
  }
553
553
  if (r.webVitalsThresholds !== void 0) {
554
554
  if (typeof r.webVitalsThresholds != "object" || r.webVitalsThresholds === null || Array.isArray(r.webVitalsThresholds))
555
- throw new m("webVitalsThresholds must be an object", "config");
555
+ throw new p("webVitalsThresholds must be an object", "config");
556
556
  const e = ["LCP", "FCP", "CLS", "INP", "TTFB", "LONG_TASK"];
557
557
  for (const [t, s] of Object.entries(r.webVitalsThresholds)) {
558
558
  if (!e.includes(t))
559
- throw new m(
559
+ throw new p(
560
560
  `Invalid Web Vitals threshold key: "${t}". Must be one of: ${e.join(", ")}`,
561
561
  "config"
562
562
  );
563
563
  if (typeof s != "number" || !Number.isFinite(s) || s < 0)
564
- throw new m(
564
+ throw new p(
565
565
  `Invalid Web Vitals threshold value for ${t}: ${s}. Must be a non-negative finite number`,
566
566
  "config"
567
567
  );
@@ -570,41 +570,41 @@ const os = () => {
570
570
  }
571
571
  }, us = (r) => {
572
572
  if (typeof r != "object" || r === null)
573
- throw new m(p.INVALID_VIEWPORT_CONFIG, "config");
573
+ throw new p(S.INVALID_VIEWPORT_CONFIG, "config");
574
574
  if (!r.elements || !Array.isArray(r.elements))
575
- throw new m(p.INVALID_VIEWPORT_ELEMENTS, "config");
575
+ throw new p(S.INVALID_VIEWPORT_ELEMENTS, "config");
576
576
  if (r.elements.length === 0)
577
- throw new m(p.INVALID_VIEWPORT_ELEMENTS, "config");
577
+ throw new p(S.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(p.INVALID_VIEWPORT_ELEMENT, "config");
581
+ throw new p(S.INVALID_VIEWPORT_ELEMENT, "config");
582
582
  const s = t.selector.trim();
583
583
  if (e.has(s))
584
- throw new m(
584
+ throw new p(
585
585
  `Duplicate viewport selector found: "${s}". Each selector should appear only once.`,
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(p.INVALID_VIEWPORT_ELEMENT_ID, "config");
589
+ throw new p(S.INVALID_VIEWPORT_ELEMENT_ID, "config");
590
590
  if (t.name !== void 0 && (typeof t.name != "string" || !t.name.trim()))
591
- throw new m(p.INVALID_VIEWPORT_ELEMENT_NAME, "config");
591
+ throw new p(S.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(p.INVALID_VIEWPORT_THRESHOLD, "config");
594
+ throw new p(S.INVALID_VIEWPORT_THRESHOLD, "config");
595
595
  if (r.minDwellTime !== void 0 && (typeof r.minDwellTime != "number" || r.minDwellTime < 0))
596
- throw new m(p.INVALID_VIEWPORT_MIN_DWELL_TIME, "config");
596
+ throw new p(S.INVALID_VIEWPORT_MIN_DWELL_TIME, "config");
597
597
  if (r.cooldownPeriod !== void 0 && (typeof r.cooldownPeriod != "number" || r.cooldownPeriod < 0))
598
- throw new m(p.INVALID_VIEWPORT_COOLDOWN_PERIOD, "config");
598
+ throw new p(S.INVALID_VIEWPORT_COOLDOWN_PERIOD, "config");
599
599
  if (r.maxTrackedElements !== void 0 && (typeof r.maxTrackedElements != "number" || r.maxTrackedElements <= 0))
600
- throw new m(p.INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS, "config");
600
+ throw new p(S.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(p.INVALID_TRACELOG_PROJECT_ID, "config");
604
+ throw new N(S.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(p.INVALID_CUSTOM_API_URL, "config");
607
+ throw new N(S.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();
@@ -645,12 +645,12 @@ const os = () => {
645
645
  cooldownPeriod: e.viewport.cooldownPeriod ?? 6e4,
646
646
  maxTrackedElements: e.viewport.maxTrackedElements ?? 100
647
647
  }), e;
648
- }, be = (r, e = /* @__PURE__ */ new Set()) => {
648
+ }, Le = (r, e = /* @__PURE__ */ new Set()) => {
649
649
  if (r == null)
650
650
  return !0;
651
651
  const t = typeof r;
652
- return t === "string" || t === "number" || t === "boolean" ? !0 : t === "function" || t === "symbol" || t === "bigint" || e.has(r) ? !1 : (e.add(r), Array.isArray(r) ? r.every((s) => be(s, e)) : t === "object" ? Object.values(r).every((s) => be(s, e)) : !1);
653
- }, ms = (r) => typeof r != "object" || r === null ? !1 : be(r), ht = (r) => {
652
+ return t === "string" || t === "number" || t === "boolean" ? !0 : t === "function" || t === "symbol" || t === "bigint" || e.has(r) ? !1 : (e.add(r), Array.isArray(r) ? r.every((s) => Le(s, e)) : t === "object" ? Object.values(r).every((s) => Le(s, e)) : !1);
653
+ }, ms = (r) => typeof r != "object" || r === null ? !1 : Le(r), ht = (r) => {
654
654
  if (typeof r != "object" || r === null || Array.isArray(r)) return;
655
655
  const e = {};
656
656
  for (const [t, s] of Object.entries(r))
@@ -697,24 +697,24 @@ const os = () => {
697
697
  valid: !1,
698
698
  error: `${n}: object has too many keys (max 100 keys).`
699
699
  };
700
- for (const [c, d] of Object.entries(s)) {
701
- if (Array.isArray(d)) {
702
- if (d.length > 500)
700
+ for (const [d, c] of Object.entries(s)) {
701
+ if (Array.isArray(c)) {
702
+ if (c.length > 500)
703
703
  return {
704
704
  valid: !1,
705
- error: `${n}: array property "${c}" is too large (max 500 items).`
705
+ error: `${n}: array property "${d}" is too large (max 500 items).`
706
706
  };
707
- for (const f of d)
707
+ for (const f of c)
708
708
  if (typeof f == "string" && f.length > 500)
709
709
  return {
710
710
  valid: !1,
711
- error: `${n}: array property "${c}" contains strings that are too long (max 500 characters).`
711
+ error: `${n}: array property "${d}" contains strings that are too long (max 500 characters).`
712
712
  };
713
713
  }
714
- if (typeof d == "string" && d.length > 1e3)
714
+ if (typeof c == "string" && c.length > 1e3)
715
715
  return {
716
716
  valid: !1,
717
- error: `${n}: property "${c}" is too long (max 1000 characters).`
717
+ error: `${n}: property "${d}" is too long (max 1000 characters).`
718
718
  };
719
719
  }
720
720
  return {
@@ -908,8 +908,8 @@ function gt(r, e, t) {
908
908
  }), r;
909
909
  }
910
910
  }
911
- const pe = { config: {} };
912
- class _ {
911
+ const Ee = { config: {} };
912
+ class v {
913
913
  /**
914
914
  * Retrieves a value from global state.
915
915
  *
@@ -927,7 +927,7 @@ class _ {
927
927
  * ```
928
928
  */
929
929
  get(e) {
930
- return pe[e];
930
+ return Ee[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
- pe[e] = t;
950
+ Ee[e] = t;
951
951
  }
952
952
  /**
953
953
  * Returns an immutable snapshot of the entire global state.
@@ -964,10 +964,10 @@ class _ {
964
964
  * ```
965
965
  */
966
966
  getState() {
967
- return { ...pe };
967
+ return { ...Ee };
968
968
  }
969
969
  }
970
- class Ze extends _ {
970
+ class Ze extends v {
971
971
  storeManager;
972
972
  integrationId;
973
973
  apiUrl;
@@ -1503,50 +1503,50 @@ class Ze extends _ {
1503
1503
  }
1504
1504
  }), !1;
1505
1505
  if (this.consecutiveNetworkFailures >= 3) {
1506
- const d = Date.now() - this.circuitOpenedAt;
1507
- if (d < 12e4)
1506
+ const c = Date.now() - this.circuitOpenedAt;
1507
+ if (c < 12e4)
1508
1508
  return a("debug", `Network circuit open, skipping send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
1509
1509
  data: {
1510
1510
  consecutiveNetworkFailures: this.consecutiveNetworkFailures,
1511
- cooldownRemainingMs: 12e4 - d
1511
+ cooldownRemainingMs: 12e4 - c
1512
1512
  }
1513
1513
  }), !1;
1514
1514
  }
1515
1515
  const { url: i, payload: o } = this.prepareRequest(n);
1516
- let l = !0, c = !1;
1517
- for (let d = 1; d <= 3; d++)
1516
+ let l = !0, d = !1;
1517
+ for (let c = 1; c <= 3; c++)
1518
1518
  try {
1519
- return (await this.sendWithTimeout(i, o)).ok ? (d > 1 && a(
1519
+ return (await this.sendWithTimeout(i, o)).ok ? (c > 1 && a(
1520
1520
  "info",
1521
- `Send succeeded after ${d - 1} retry attempt(s)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
1521
+ `Send succeeded after ${c - 1} retry attempt(s)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
1522
1522
  {
1523
- data: { events: n.events.length, attempt: d }
1523
+ data: { events: n.events.length, attempt: c }
1524
1524
  }
1525
1525
  ), this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, !0) : !1;
1526
1526
  } catch (f) {
1527
- const g = d === 3;
1527
+ const g = c === 3;
1528
1528
  if (f instanceof O)
1529
1529
  throw this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, f;
1530
1530
  if (f instanceof re) {
1531
- this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, l = !1, c = !0, this.armRateLimitCooldown(Date.now() + 6e4), a("warn", `Rate limited, skipping retries${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
1532
- data: { events: e.events.length, attempt: d, cooldownMs: 6e4 }
1531
+ this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, l = !1, d = !0, this.armRateLimitCooldown(Date.now() + 6e4), a("warn", `Rate limited, skipping retries${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
1532
+ data: { events: e.events.length, attempt: c, cooldownMs: 6e4 }
1533
1533
  });
1534
1534
  break;
1535
1535
  }
1536
- if (f instanceof ne || (l = !1), f instanceof TypeError || (c = !0), a(
1536
+ if (f instanceof ne || (l = !1), f instanceof TypeError || (d = !0), a(
1537
1537
  g ? "error" : "warn",
1538
- `Send attempt ${d} failed${this.integrationId ? ` [${this.integrationId}]` : ""}${g ? " (all retries exhausted)" : ", will retry"}`,
1538
+ `Send attempt ${c} 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
1543
  url: i.replace(/\/\/[^/]+/, "//[DOMAIN]"),
1544
- attempt: d,
1544
+ attempt: c,
1545
1545
  maxAttempts: 3
1546
1546
  }
1547
1547
  }
1548
1548
  ), !g) {
1549
- await this.backoffDelay(d);
1549
+ await this.backoffDelay(c);
1550
1550
  continue;
1551
1551
  }
1552
1552
  return l ? (a(
@@ -1555,7 +1555,7 @@ class Ze extends _ {
1555
1555
  {
1556
1556
  data: { events: n.events.length }
1557
1557
  }
1558
- ), !1) : (c ? (this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0) : (this.consecutiveNetworkFailures = Math.min(
1558
+ ), !1) : (d ? (this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0) : (this.consecutiveNetworkFailures = Math.min(
1559
1559
  this.consecutiveNetworkFailures + 1,
1560
1560
  3
1561
1561
  ), this.consecutiveNetworkFailures >= 3 && (this.circuitOpenedAt = Date.now())), !1);
@@ -1606,8 +1606,8 @@ class Ze extends _ {
1606
1606
  });
1607
1607
  if (!l.ok) {
1608
1608
  if (l.status >= 400 && l.status < 500 && l.status !== 408 && l.status !== 429) {
1609
- const d = await this.readTraceLogErrorCode(l), f = d ? `HTTP ${l.status}: ${l.statusText} (${d})` : `HTTP ${l.status}: ${l.statusText}`;
1610
- throw new O(f, l.status, d);
1609
+ const c = await this.readTraceLogErrorCode(l), f = c ? `HTTP ${l.status}: ${l.statusText} (${c})` : `HTTP ${l.status}: ${l.statusText}`;
1610
+ throw new O(f, l.status, c);
1611
1611
  }
1612
1612
  throw l.status === 429 ? new re(`HTTP 429: ${l.statusText}`) : new Error(`HTTP ${l.status}: ${l.statusText}`);
1613
1613
  }
@@ -1678,17 +1678,17 @@ class Ze extends _ {
1678
1678
  }
1679
1679
  }
1680
1680
  ), this.persistEvents(t), !1;
1681
- const c = new Blob([l], { type: "application/json" });
1681
+ const d = new Blob([l], { type: "application/json" });
1682
1682
  if (!this.isSendBeaconAvailable())
1683
1683
  return a(
1684
1684
  "warn",
1685
1685
  `sendBeacon not available, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
1686
1686
  ), this.persistEvents(t), !1;
1687
- const d = navigator.sendBeacon(o, c);
1688
- return d || (a(
1687
+ const c = navigator.sendBeacon(o, d);
1688
+ return c || (a(
1689
1689
  "warn",
1690
1690
  `sendBeacon rejected request, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
1691
- ), this.persistEvents(t)), d;
1691
+ ), this.persistEvents(t)), c;
1692
1692
  }
1693
1693
  /**
1694
1694
  * Prepares request by enriching payload with metadata and serializing to JSON.
@@ -1899,7 +1899,7 @@ class Ze extends _ {
1899
1899
  }), this.lastPermanentErrorLog = { key: n, timestamp: s });
1900
1900
  }
1901
1901
  }
1902
- class Ts extends _ {
1902
+ class Ts extends v {
1903
1903
  bootTime;
1904
1904
  bootTimestamp;
1905
1905
  hasPerformanceNow;
@@ -2049,7 +2049,7 @@ class Ts extends _ {
2049
2049
  }
2050
2050
  }
2051
2051
  const Is = new Set(Object.values(u));
2052
- class vs extends _ {
2052
+ class _s extends v {
2053
2053
  dataSenders;
2054
2054
  emitter;
2055
2055
  transformers;
@@ -2100,8 +2100,8 @@ class vs extends _ {
2100
2100
  i,
2101
2101
  o
2102
2102
  )
2103
- ), this.saveSessionCountsDebounced = this.debounce((c) => {
2104
- this.saveSessionCounts(c);
2103
+ ), this.saveSessionCountsDebounced = this.debounce((d) => {
2104
+ this.saveSessionCounts(d);
2105
2105
  }, 500), this.cleanupExpiredSessionCounts();
2106
2106
  }
2107
2107
  /**
@@ -2211,8 +2211,8 @@ class vs extends _ {
2211
2211
  click_data: i,
2212
2212
  custom_event: o,
2213
2213
  web_vitals: l,
2214
- error_data: c,
2215
- viewport_data: d,
2214
+ error_data: d,
2215
+ viewport_data: c,
2216
2216
  page_view: f
2217
2217
  }) {
2218
2218
  if (!e) {
@@ -2237,20 +2237,20 @@ class vs extends _ {
2237
2237
  click_data: i,
2238
2238
  custom_event: o,
2239
2239
  web_vitals: l,
2240
- error_data: c,
2241
- viewport_data: d,
2240
+ error_data: d,
2241
+ viewport_data: c,
2242
2242
  page_view: f
2243
2243
  });
2244
2244
  return;
2245
2245
  }
2246
2246
  this.lastSessionId !== g && (this.lastSessionId = g, this.sessionEventCounts = this.loadSessionCounts(g));
2247
- const I = e === u.SESSION_START;
2248
- if (I && a("debug", "Processing SESSION_START event", {
2247
+ const m = e === u.SESSION_START;
2248
+ if (m && a("debug", "Processing SESSION_START event", {
2249
2249
  data: { sessionId: g }
2250
- }), !I && !this.checkRateLimit())
2250
+ }), !m && !this.checkRateLimit())
2251
2251
  return;
2252
2252
  const E = e;
2253
- if (!I) {
2253
+ if (!m) {
2254
2254
  if (this.sessionEventCounts.total >= 1e3) {
2255
2255
  a("warn", "Session event limit reached", {
2256
2256
  data: {
@@ -2261,15 +2261,15 @@ class vs extends _ {
2261
2261
  });
2262
2262
  return;
2263
2263
  }
2264
- const v = this.getTypeLimitForEvent(E);
2265
- if (v) {
2266
- const he = this.sessionEventCounts[E];
2267
- if (he !== void 0 && he >= v) {
2264
+ const T = this.getTypeLimitForEvent(E);
2265
+ if (T) {
2266
+ const fe = this.sessionEventCounts[E];
2267
+ if (fe !== void 0 && fe >= T) {
2268
2268
  a("warn", "Session event type limit reached", {
2269
2269
  data: {
2270
2270
  type: E,
2271
- count: he,
2272
- limit: v
2271
+ count: fe,
2272
+ limit: T
2273
2273
  }
2274
2274
  });
2275
2275
  return;
@@ -2277,11 +2277,11 @@ class vs extends _ {
2277
2277
  }
2278
2278
  }
2279
2279
  if (E === u.CUSTOM && o?.name) {
2280
- const v = this.get("config")?.maxSameEventPerMinute ?? 60;
2281
- if (!this.checkPerEventRateLimit(o.name, v))
2280
+ const T = this.get("config")?.maxSameEventPerMinute ?? 60;
2281
+ if (!this.checkPerEventRateLimit(o.name, T))
2282
2282
  return;
2283
2283
  }
2284
- const Ve = E === u.SESSION_START, Q = t || this.get("pageUrl"), x = this.buildEventPayload({
2284
+ const he = E === u.SESSION_START, Q = t || this.get("pageUrl"), U = this.buildEventPayload({
2285
2285
  type: E,
2286
2286
  page_url: Q,
2287
2287
  from_page_url: s,
@@ -2289,26 +2289,26 @@ class vs extends _ {
2289
2289
  click_data: i,
2290
2290
  custom_event: o,
2291
2291
  web_vitals: l,
2292
- error_data: c,
2293
- viewport_data: d,
2292
+ error_data: d,
2293
+ viewport_data: c,
2294
2294
  page_view: f
2295
2295
  });
2296
- if (x && !(!I && !this.shouldSample())) {
2297
- if (Ve) {
2298
- const v = this.get("sessionId");
2299
- if (!v) {
2296
+ if (U && !(!m && !this.shouldSample())) {
2297
+ if (he) {
2298
+ const T = this.get("sessionId");
2299
+ if (!T) {
2300
2300
  a("error", "Session start event requires sessionId - event will be ignored");
2301
2301
  return;
2302
2302
  }
2303
2303
  if (this.get("hasStartSession")) {
2304
2304
  a("debug", "Duplicate session_start detected", {
2305
- data: { sessionId: v }
2305
+ data: { sessionId: T }
2306
2306
  });
2307
2307
  return;
2308
2308
  }
2309
2309
  this.set("hasStartSession", !0);
2310
2310
  }
2311
- if (!this.isDuplicateEvent(x)) {
2311
+ if (!this.isDuplicateEvent(U)) {
2312
2312
  if (this.get("mode") === ie.QA) {
2313
2313
  if (E === u.CUSTOM && o) {
2314
2314
  a("info", `Custom Event: ${o.name}`, {
@@ -2317,28 +2317,28 @@ class vs extends _ {
2317
2317
  name: o.name,
2318
2318
  ...o.metadata && { metadata: o.metadata }
2319
2319
  }
2320
- }), this.emitEvent(x);
2320
+ }), this.emitEvent(U);
2321
2321
  return;
2322
2322
  }
2323
- if (E === u.VIEWPORT_VISIBLE && d) {
2324
- const v = d.name || d.id || d.selector;
2325
- a("info", `Viewport Visible: ${v}`, {
2323
+ if (E === u.VIEWPORT_VISIBLE && c) {
2324
+ const T = c.name || c.id || c.selector;
2325
+ a("info", `Viewport Visible: ${T}`, {
2326
2326
  visibility: "qa",
2327
2327
  data: {
2328
- selector: d.selector,
2329
- ...d.name && { name: d.name },
2330
- ...d.id && { id: d.id },
2331
- visibilityRatio: d.visibilityRatio,
2332
- dwellTime: d.dwellTime
2328
+ selector: c.selector,
2329
+ ...c.name && { name: c.name },
2330
+ ...c.id && { id: c.id },
2331
+ visibilityRatio: c.visibilityRatio,
2332
+ dwellTime: c.dwellTime
2333
2333
  }
2334
- }), this.emitEvent(x);
2334
+ }), this.emitEvent(U);
2335
2335
  return;
2336
2336
  }
2337
2337
  }
2338
- if (this.addToQueue(x), !I) {
2338
+ if (this.addToQueue(U), !m) {
2339
2339
  this.sessionEventCounts.total++, this.sessionEventCounts[E] !== void 0 && this.sessionEventCounts[E]++;
2340
- const v = this.get("sessionId");
2341
- v && this.saveSessionCountsDebounced && this.saveSessionCountsDebounced(v);
2340
+ const T = this.get("sessionId");
2341
+ T && this.saveSessionCountsDebounced && this.saveSessionCountsDebounced(T);
2342
2342
  }
2343
2343
  }
2344
2344
  }
@@ -2514,7 +2514,7 @@ class vs extends _ {
2514
2514
  * @internal Used by test-bridge.ts for test inspection
2515
2515
  */
2516
2516
  getQueueEvents() {
2517
- return [...this.eventsQueue];
2517
+ return this.eventsQueue.map(({ _session_id: e, ...t }) => t);
2518
2518
  }
2519
2519
  /**
2520
2520
  * Triggers immediate queue flush (test utility).
@@ -2597,107 +2597,191 @@ class vs extends _ {
2597
2597
  isSuccessfulResult(e) {
2598
2598
  return e.status === "fulfilled" && e.value === !0;
2599
2599
  }
2600
+ /**
2601
+ * Groups the queue by frozen `_session_id`, preserving insertion order.
2602
+ * Single pass — `buildBatchesWithIds()` builds one batch + one eventIds list
2603
+ * per group, so the grouping cost is O(N) per flush regardless of session
2604
+ * count.
2605
+ *
2606
+ * **Self-heal**: any entry missing `_session_id` (an internal invariant
2607
+ * violation — `buildEventPayload` always stamps it) is removed from the
2608
+ * queue rather than left behind, otherwise a single corrupted entry would
2609
+ * keep `eventsQueue.length > 0` forever and re-trigger periodic sends.
2610
+ */
2611
+ groupQueuedEventsBySession() {
2612
+ const e = /* @__PURE__ */ new Map(), t = [];
2613
+ for (const s of this.eventsQueue) {
2614
+ if (!s._session_id) {
2615
+ a("debug", "Queued event missing _session_id, dropping", {
2616
+ data: { eventId: s.id, type: s.type }
2617
+ }), t.push(s.id);
2618
+ continue;
2619
+ }
2620
+ const n = e.get(s._session_id);
2621
+ n ? n.push(s) : e.set(s._session_id, [s]);
2622
+ }
2623
+ return t.length > 0 && this.removeProcessedEvents(t), e;
2624
+ }
2625
+ /**
2626
+ * Builds a parallel list of `(batch, eventIds)` for sending. The eventIds are
2627
+ * the original `_session_id`-tagged event IDs in the queue that map to this
2628
+ * batch — used for optimistic removal. We can't read them off the wrapper's
2629
+ * `events[]` because dedup may have removed some signatures.
2630
+ */
2631
+ buildBatchesWithIds() {
2632
+ const e = this.groupQueuedEventsBySession();
2633
+ if (e.size === 0) return [];
2634
+ const t = [];
2635
+ for (const [s, n] of e)
2636
+ t.push({
2637
+ batch: this.buildBatchFromGroup(s, n),
2638
+ eventIds: n.map((i) => i.id)
2639
+ });
2640
+ return t;
2641
+ }
2600
2642
  flushEvents(e) {
2601
2643
  if (this.eventsQueue.length === 0)
2602
2644
  return e ? !0 : Promise.resolve(!0);
2603
2645
  if (!e && this.sendInProgress)
2604
2646
  return a("debug", "Async flush skipped: send already in progress"), Promise.resolve(!1);
2605
- const t = this.buildEventsPayload(), s = [...this.eventsQueue], n = s.map((i) => i.id);
2606
- if (this.dataSenders.length === 0)
2607
- return this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t), e ? !0 : Promise.resolve(!0);
2608
- if (e && this.sendInProgress)
2647
+ const t = this.buildBatchesWithIds();
2648
+ if (t.length === 0)
2649
+ return e ? !0 : Promise.resolve(!0);
2650
+ if (this.dataSenders.length === 0) {
2651
+ for (const { batch: s, eventIds: n } of t)
2652
+ this.removeProcessedEvents(n), this.emitEventsQueue(s);
2653
+ return this.clearSendTimeout(), e ? !0 : Promise.resolve(!0);
2654
+ }
2655
+ if (e && this.sendInProgress) {
2656
+ const s = t.reduce((n, i) => n + i.eventIds.length, 0);
2609
2657
  return a("debug", "Sync flush skipped: async send already in-flight, trusting fetch to deliver", {
2610
- data: { eventCount: n.length }
2658
+ data: { eventCount: s }
2611
2659
  }), !0;
2660
+ }
2612
2661
  if (e) {
2613
- const o = this.dataSenders.map((l) => l.sendEventsQueueSync(t)).some((l) => l);
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
- })), o;
2617
- } else {
2618
- const i = this.dataSenders.map(
2619
- async (o) => o.sendEventsQueue(t, {
2620
- onSuccess: () => {
2621
- },
2622
- onFailure: () => {
2623
- }
2624
- })
2662
+ const s = t.map(({ batch: n, eventIds: i }) => this.sendBatchSync(n, i));
2663
+ return this.clearSendTimeout(), s.some(Boolean);
2664
+ }
2665
+ return (async () => {
2666
+ const s = await Promise.all(
2667
+ t.map(async ({ batch: n, eventIds: i }) => this.sendBatchAsync(n, i))
2625
2668
  );
2626
- return Promise.allSettled(i).then((o) => {
2627
- const l = o.some((c) => this.isSuccessfulResult(c));
2628
- return l ? (this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t)) : a("debug", "Async flush complete failure, events kept in queue for retry", {
2629
- data: { eventCount: s.length }
2630
- }), l;
2669
+ return this.clearSendTimeout(), s.some(Boolean);
2670
+ })();
2671
+ }
2672
+ /**
2673
+ * Sends one batch synchronously across all integrations (sendBeacon path).
2674
+ * Optimistic removal: if any integration succeeds, we remove the batch's
2675
+ * events from the queue and emit it locally. Failures persist per-integration.
2676
+ */
2677
+ sendBatchSync(e, t) {
2678
+ const n = this.dataSenders.map((i) => i.sendEventsQueueSync(e)).some((i) => i);
2679
+ return n ? (this.removeProcessedEvents(t), this.emitEventsQueue(e)) : a("debug", "Sync send complete failure, events kept in queue for retry", {
2680
+ data: { eventCount: t.length, sessionId: e.session_id }
2681
+ }), n;
2682
+ }
2683
+ /**
2684
+ * Sends one batch asynchronously across all integrations (fetch path).
2685
+ */
2686
+ async sendBatchAsync(e, t) {
2687
+ const s = this.dataSenders.map(
2688
+ async (o) => o.sendEventsQueue(e, {
2689
+ onSuccess: () => {
2690
+ },
2691
+ onFailure: () => {
2692
+ }
2693
+ })
2694
+ ), n = await Promise.allSettled(s), i = n.some((o) => this.isSuccessfulResult(o));
2695
+ if (i) {
2696
+ this.removeProcessedEvents(t), this.emitEventsQueue(e);
2697
+ const o = n.filter((l) => !this.isSuccessfulResult(l)).length;
2698
+ o > 0 && a("debug", "Async send completed with some failures, removed from queue and persisted per-integration", {
2699
+ data: { eventCount: t.length, failedCount: o, sessionId: e.session_id }
2631
2700
  });
2632
- }
2701
+ } else
2702
+ a("debug", "Async send complete failure, events kept in queue for retry", {
2703
+ data: { eventCount: t.length, sessionId: e.session_id }
2704
+ });
2705
+ return i;
2633
2706
  }
2634
2707
  async sendEventsQueue() {
2635
- if (!(!this.get("sessionId") || this.eventsQueue.length === 0 || this.sendInProgress)) {
2708
+ if (!(this.eventsQueue.length === 0 || this.sendInProgress)) {
2636
2709
  this.sendInProgress = !0;
2637
2710
  try {
2638
- const e = this.buildEventsPayload();
2711
+ const e = this.buildBatchesWithIds();
2712
+ if (e.length === 0) return;
2639
2713
  if (this.dataSenders.length === 0) {
2640
- this.emitEventsQueue(e);
2714
+ for (const { batch: n } of e)
2715
+ this.emitEventsQueue(n);
2641
2716
  return;
2642
2717
  }
2643
- const t = [...this.eventsQueue], s = t.map((l) => l.id), n = this.dataSenders.map(
2644
- async (l) => l.sendEventsQueue(e, {
2645
- onSuccess: () => {
2646
- },
2647
- onFailure: () => {
2648
- }
2649
- })
2650
- ), i = await Promise.allSettled(n);
2651
- if (i.some((l) => this.isSuccessfulResult(l))) {
2652
- this.consecutiveSendFailures = 0, this.removeProcessedEvents(s), this.emitEventsQueue(e);
2653
- const l = i.filter((c) => !this.isSuccessfulResult(c)).length;
2654
- l > 0 && a("debug", "Periodic send completed with some failures, removed from queue and persisted per-integration", {
2655
- data: { eventCount: t.length, failedCount: l }
2656
- });
2657
- } else
2658
- this.consecutiveSendFailures = Math.min(this.consecutiveSendFailures + 1, 5), a("debug", "Periodic send complete failure, events kept in queue for retry", {
2659
- data: { eventCount: t.length }
2660
- });
2661
- this.eventsQueue.length === 0 ? this.clearSendTimeout() : this.scheduleSendTimeout();
2718
+ (await Promise.all(
2719
+ e.map(async ({ batch: n, eventIds: i }) => this.sendBatchAsync(n, i))
2720
+ )).some(Boolean) ? this.consecutiveSendFailures = 0 : this.consecutiveSendFailures = Math.min(this.consecutiveSendFailures + 1, 5), this.eventsQueue.length === 0 ? this.clearSendTimeout() : this.scheduleSendTimeout();
2662
2721
  } finally {
2663
2722
  this.sendInProgress = !1;
2664
2723
  }
2665
2724
  }
2666
2725
  }
2667
- buildEventsPayload() {
2668
- const e = /* @__PURE__ */ new Map(), t = [];
2669
- for (const c of this.eventsQueue) {
2670
- const d = this.createEventSignature(c);
2671
- e.has(d) || t.push(d), e.set(d, c);
2726
+ /**
2727
+ * Builds a single batch from a per-session group: dedup by signature,
2728
+ * SESSION_START first, then timestamp order, strip `_session_id`, apply
2729
+ * `beforeBatch` transformer when running standalone.
2730
+ *
2731
+ * **Why N batches per flush**: events freeze their `_session_id` at `track()`
2732
+ * time. If the session was renewed (idle timeout) between two `track()`
2733
+ * calls, the queue contains events from multiple sessions. `buildBatchesWithIds()`
2734
+ * emits one batch per session so the backend's `EventsQueueDto.session_id`
2735
+ * remains the single source of truth and stays consistent with the events it
2736
+ * carries.
2737
+ *
2738
+ * **Strip**: `_session_id` is removed from each event in the wrapper's
2739
+ * `events[]` because the backend uses `forbidNonWhitelisted: true` and would
2740
+ * reject the batch if the field leaked through.
2741
+ *
2742
+ * **Transformer note**: `beforeBatch` is invoked **once per session-batch**,
2743
+ * not once per flush. A queue spanning N sessions triggers N invocations.
2744
+ */
2745
+ buildBatchFromGroup(e, t) {
2746
+ const s = /* @__PURE__ */ new Map(), n = [];
2747
+ for (const m of t) {
2748
+ const E = this.createEventSignature(m);
2749
+ s.has(E) || n.push(E), s.set(E, m);
2672
2750
  }
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 n = {
2751
+ const i = n.map((m) => s.get(m)).filter((m) => !!m).sort((m, E) => m.type === u.SESSION_START && E.type !== u.SESSION_START ? -1 : E.type === u.SESSION_START && m.type !== u.SESSION_START ? 1 : m.timestamp - E.timestamp).map(({ _session_id: m, ...E }) => E), o = this.get("config")?.globalMetadata, l = this.get("identity");
2752
+ let d = {
2675
2753
  user_id: this.get("userId"),
2676
- session_id: this.get("sessionId"),
2754
+ session_id: e,
2677
2755
  device: this.get("device"),
2678
- events: s,
2679
- ...this.get("config")?.globalMetadata && { global_metadata: this.get("config")?.globalMetadata },
2680
- ...this.get("identity") && { identify: this.get("identity") }
2756
+ events: i,
2757
+ ...o && { global_metadata: o },
2758
+ ...l && { identify: l }
2681
2759
  };
2682
- const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas), l = this.transformers.beforeBatch;
2683
- if (!o && l) {
2684
- const c = gt(n, l, "EventManager");
2685
- c !== null && (n = c);
2760
+ const c = this.get("collectApiUrls"), f = !!(c?.custom || c?.saas), g = this.transformers.beforeBatch;
2761
+ if (!f && g) {
2762
+ const m = gt(d, g, "EventManager");
2763
+ m !== null && (d = m);
2686
2764
  }
2687
- return n;
2765
+ return d;
2688
2766
  }
2689
2767
  buildEventPayload(e) {
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 }
2768
+ const t = this.get("sessionId");
2769
+ if (!t)
2770
+ return a("error", "buildEventPayload reached without sessionId — event dropped", {
2771
+ data: { type: e.type },
2772
+ visibility: "critical"
2773
+ }), null;
2774
+ const s = e.page_url ?? this.get("pageUrl"), n = typeof s == "string" && s.length > 0 ? s : "unknown", i = this.timeManager.now(), o = this.timeManager.validateTimestamp(i);
2775
+ o.valid || a("warn", "Event timestamp validation failed", {
2776
+ data: { type: e.type, error: o.error }
2693
2777
  });
2694
- const i = this.get("sessionReferrer"), o = this.get("sessionUtm");
2695
- let l = {
2778
+ const l = this.get("sessionReferrer"), d = this.get("sessionUtm");
2779
+ let c = {
2696
2780
  id: os(),
2697
2781
  type: e.type,
2698
- page_url: t,
2699
- timestamp: s,
2700
- ...i && { referrer: i },
2782
+ page_url: n,
2783
+ timestamp: i,
2784
+ ...l && { referrer: l },
2701
2785
  ...e.from_page_url && { from_page_url: e.from_page_url },
2702
2786
  ...e.scroll_data && { scroll_data: e.scroll_data },
2703
2787
  ...e.click_data && { click_data: e.click_data },
@@ -2706,16 +2790,16 @@ class vs extends _ {
2706
2790
  ...e.error_data && { error_data: e.error_data },
2707
2791
  ...e.viewport_data && { viewport_data: e.viewport_data },
2708
2792
  ...e.page_view && { page_view: e.page_view },
2709
- ...o && { utm: o }
2793
+ ...d && { utm: d }
2710
2794
  };
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
- if (Q === null)
2795
+ const f = this.get("collectApiUrls"), g = !!f?.custom, m = !!f?.saas, E = g || m, he = g && m, Q = this.transformers.beforeSend;
2796
+ if (Q && (!E || g && !he)) {
2797
+ const T = mt(c, Q, "EventManager");
2798
+ if (T === null)
2715
2799
  return null;
2716
- l = Q;
2800
+ c = T;
2717
2801
  }
2718
- return l;
2802
+ return { ...c, _session_id: t };
2719
2803
  }
2720
2804
  isDuplicateEvent(e) {
2721
2805
  const t = Date.now(), s = this.createEventFingerprint(e), n = this.recentEventFingerprints.get(s);
@@ -2808,7 +2892,10 @@ class vs extends _ {
2808
2892
  this.eventsQueue = this.eventsQueue.filter((s) => !t.has(s.id));
2809
2893
  }
2810
2894
  emitEvent(e) {
2811
- this.emitter && this.emitter.emit(se.EVENT, e);
2895
+ if (this.emitter) {
2896
+ const { _session_id: t, ...s } = e;
2897
+ this.emitter.emit(se.EVENT, s);
2898
+ }
2812
2899
  }
2813
2900
  emitEventsQueue(e) {
2814
2901
  this.emitter && this.emitter.emit(se.QUEUE, e);
@@ -2948,15 +3035,15 @@ class vs extends _ {
2948
3035
  return;
2949
3036
  }
2950
3037
  }
2951
- const t = this.get("userId") || "anonymous", s = `${S}:${t}:session_counts:`, n = [];
3038
+ const t = this.get("userId") || "anonymous", s = `${I}:${t}:session_counts:`, n = [];
2952
3039
  for (let i = 0; i < localStorage.length; i++) {
2953
3040
  const o = localStorage.key(i);
2954
3041
  if (o?.startsWith(s))
2955
3042
  try {
2956
3043
  const l = localStorage.getItem(o);
2957
3044
  if (l) {
2958
- const c = JSON.parse(l);
2959
- c._timestamp && Date.now() - c._timestamp > xe && n.push(o);
3045
+ const d = JSON.parse(l);
3046
+ d._timestamp && Date.now() - d._timestamp > xe && n.push(o);
2960
3047
  }
2961
3048
  } catch {
2962
3049
  }
@@ -3013,7 +3100,7 @@ class vs extends _ {
3013
3100
  }
3014
3101
  }
3015
3102
  }
3016
- class _s {
3103
+ class vs {
3017
3104
  /**
3018
3105
  * Gets or creates a unique user ID.
3019
3106
  *
@@ -3031,15 +3118,15 @@ class _s {
3031
3118
  * @returns Persistent unique user ID (UUID v4 format)
3032
3119
  */
3033
3120
  static getId(e) {
3034
- const t = e.getItem(Te);
3121
+ const t = e.getItem(Ie);
3035
3122
  if (t)
3036
3123
  return t;
3037
3124
  const s = dt();
3038
- return e.setItem(Te, s), s;
3125
+ return e.setItem(Ie, s), s;
3039
3126
  }
3040
3127
  }
3041
3128
  const ys = /^\d{13}-[a-z0-9]{9}$/;
3042
- class ws extends _ {
3129
+ class ws extends v {
3043
3130
  storageManager;
3044
3131
  eventManager;
3045
3132
  projectId;
@@ -3196,9 +3283,9 @@ class ws extends _ {
3196
3283
  let s, n;
3197
3284
  if (e) {
3198
3285
  const i = this.loadStoredSession();
3199
- s = i?.referrer ?? me(), n = i?.utm ?? ge();
3286
+ s = i?.referrer ?? ge(), n = i?.utm ?? pe();
3200
3287
  } else
3201
- s = me(), n = ge();
3288
+ s = ge(), n = pe();
3202
3289
  a("debug", "Session tracking initialized", {
3203
3290
  data: {
3204
3291
  sessionId: t,
@@ -3249,7 +3336,7 @@ class ws extends _ {
3249
3336
  */
3250
3337
  renewSession() {
3251
3338
  this.needsRenewal = !1;
3252
- const e = this.generateSessionId(), t = me(), s = ge();
3339
+ const e = this.generateSessionId(), t = ge(), s = pe();
3253
3340
  a("debug", "Renewing session after timeout", {
3254
3341
  data: { newSessionId: e }
3255
3342
  }), this.set("sessionId", e), this.set("sessionReferrer", t), this.set("sessionUtm", s), this.persistSession(e, Date.now(), t, s), this.cleanupCrossTabSync(), this.initCrossTabSync(), this.shareSession(e), this.eventManager.track({
@@ -3370,7 +3457,7 @@ class ws extends _ {
3370
3457
  this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupCrossTabSync(), this.cleanupLifecycleListeners(), this.isTracking = !1, this.needsRenewal = !1, this.set("hasStartSession", !1);
3371
3458
  }
3372
3459
  }
3373
- class bs extends _ {
3460
+ class bs extends v {
3374
3461
  eventManager;
3375
3462
  storageManager;
3376
3463
  sessionManager = null;
@@ -3458,7 +3545,7 @@ class bs extends _ {
3458
3545
  this.destroyed || (this.sessionManager && (this.sessionManager.destroy(), this.sessionManager = null), this.destroyed = !0);
3459
3546
  }
3460
3547
  }
3461
- class Ls extends _ {
3548
+ class Ls extends v {
3462
3549
  eventManager;
3463
3550
  onTrack;
3464
3551
  originalPushState;
@@ -3498,7 +3585,7 @@ class Ls extends _ {
3498
3585
  };
3499
3586
  }
3500
3587
  trackCurrentPage = () => {
3501
- const e = window.location.href, t = ye(e, this.get("config").sensitiveQueryParams);
3588
+ const e = window.location.href, t = we(e, this.get("config").sensitiveQueryParams);
3502
3589
  if (this.get("pageUrl") === t)
3503
3590
  return;
3504
3591
  const s = Date.now(), n = this.get("config").pageViewThrottleMs ?? 1e3;
@@ -3516,7 +3603,7 @@ class Ls extends _ {
3516
3603
  });
3517
3604
  };
3518
3605
  trackInitialPageView() {
3519
- const e = ye(window.location.href, this.get("config").sensitiveQueryParams), t = this.extractPageViewData();
3606
+ const e = we(window.location.href, this.get("config").sensitiveQueryParams), t = this.extractPageViewData();
3520
3607
  this.lastPageViewTime = Date.now(), this.eventManager.track({
3521
3608
  type: u.PAGE_VIEW,
3522
3609
  page_url: e,
@@ -3534,7 +3621,7 @@ class Ls extends _ {
3534
3621
  };
3535
3622
  }
3536
3623
  }
3537
- class As extends _ {
3624
+ class As extends v {
3538
3625
  eventManager;
3539
3626
  lastClickTimes = /* @__PURE__ */ new Map();
3540
3627
  clickHandler;
@@ -3567,7 +3654,7 @@ class As extends _ {
3567
3654
  const i = this.get("config")?.clickThrottleMs ?? 300;
3568
3655
  if (i > 0 && !this.checkClickThrottle(n, i))
3569
3656
  return;
3570
- const o = this.findTrackingElement(n), l = this.getRelevantClickElement(n), c = this.calculateClickCoordinates(t, n);
3657
+ const o = this.findTrackingElement(n), l = this.getRelevantClickElement(n), d = this.calculateClickCoordinates(t, n);
3571
3658
  if (o) {
3572
3659
  const f = this.extractTrackingData(o);
3573
3660
  if (f) {
@@ -3581,10 +3668,14 @@ class As extends _ {
3581
3668
  });
3582
3669
  }
3583
3670
  }
3584
- const d = this.generateClickData(n, l, c);
3671
+ if (!d) {
3672
+ a("debug", "Click skipped: invalid coordinates (likely synthetic)");
3673
+ return;
3674
+ }
3675
+ const c = this.generateClickData(n, l, d);
3585
3676
  this.eventManager.track({
3586
3677
  type: u.CLICK,
3587
- click_data: d
3678
+ click_data: c
3588
3679
  });
3589
3680
  }, window.addEventListener("click", this.clickHandler, !0));
3590
3681
  }
@@ -3700,8 +3791,11 @@ class As extends _ {
3700
3791
  return Math.max(0, Math.min(1, Number(e.toFixed(3))));
3701
3792
  }
3702
3793
  calculateClickCoordinates(e, t) {
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 };
3794
+ const s = e.clientX, n = e.clientY;
3795
+ if (typeof s != "number" || typeof n != "number" || !Number.isFinite(s) || !Number.isFinite(n) || s === 0 && n === 0 && !e.isTrusted)
3796
+ return null;
3797
+ const i = t.getBoundingClientRect(), o = i.width > 0 ? this.clamp((s - i.left) / i.width) : 0, l = i.height > 0 ? this.clamp((n - i.top) / i.height) : 0;
3798
+ return { x: s, y: n, relativeX: o, relativeY: l };
3705
3799
  }
3706
3800
  extractTrackingData(e) {
3707
3801
  const t = e.getAttribute(`${b}-name`), s = e.getAttribute(`${b}-value`);
@@ -3713,7 +3807,7 @@ class As extends _ {
3713
3807
  };
3714
3808
  }
3715
3809
  generateClickData(e, t, s) {
3716
- const { x: n, y: i, relativeX: o, relativeY: l } = s, c = this.getRelevantText(e, t), d = this.extractElementAttributes(t);
3810
+ const { x: n, y: i, relativeX: o, relativeY: l } = s, d = this.getRelevantText(e, t), c = this.extractElementAttributes(t);
3717
3811
  return {
3718
3812
  x: n,
3719
3813
  y: i,
@@ -3722,13 +3816,13 @@ class As extends _ {
3722
3816
  tag: t.tagName.toLowerCase(),
3723
3817
  ...t.id && { id: t.id },
3724
3818
  ...t.className && { class: t.className },
3725
- ...c && { text: c },
3726
- ...d.href && { href: d.href },
3727
- ...d.title && { title: d.title },
3728
- ...d.alt && { alt: d.alt },
3729
- ...d.role && { role: d.role },
3730
- ...d["aria-label"] && { ariaLabel: d["aria-label"] },
3731
- ...Object.keys(d).length > 0 && { dataAttributes: d }
3819
+ ...d && { text: d },
3820
+ ...c.href && { href: c.href },
3821
+ ...c.title && { title: c.title },
3822
+ ...c.alt && { alt: c.alt },
3823
+ ...c.role && { role: c.role },
3824
+ ...c["aria-label"] && { ariaLabel: c["aria-label"] },
3825
+ ...Object.keys(c).length > 0 && { dataAttributes: c }
3732
3826
  };
3733
3827
  }
3734
3828
  /**
@@ -3791,7 +3885,7 @@ class As extends _ {
3791
3885
  };
3792
3886
  }
3793
3887
  }
3794
- class Ms extends _ {
3888
+ class Ms extends v {
3795
3889
  eventManager;
3796
3890
  containers = [];
3797
3891
  limitWarningLogged = !1;
@@ -3892,7 +3986,7 @@ class Ms extends _ {
3892
3986
  return this.isWindowScrollable() ? e === window : this.containers.length === 0;
3893
3987
  }
3894
3988
  setupScrollContainer(e, t) {
3895
- if (this.containers.some((d) => d.element === e) || e !== window && !this.isElementScrollable(e))
3989
+ if (this.containers.some((c) => c.element === e) || e !== window && !this.isElementScrollable(e))
3896
3990
  return;
3897
3991
  const n = this.getScrollTop(e), i = this.calculateScrollDepth(
3898
3992
  n,
@@ -3910,17 +4004,17 @@ class Ms extends _ {
3910
4004
  maxDepthReached: i,
3911
4005
  debounceTimer: null,
3912
4006
  listener: null
3913
- }, c = () => {
4007
+ }, d = () => {
3914
4008
  this.get("suppressNextScroll") || (l.firstScrollEventTime === null && (l.firstScrollEventTime = Date.now()), this.clearContainerTimer(l), l.debounceTimer = window.setTimeout(() => {
3915
- const d = this.calculateScrollData(l);
3916
- if (d) {
4009
+ const c = this.calculateScrollData(l);
4010
+ if (c) {
3917
4011
  const f = Date.now();
3918
- this.processScrollEvent(l, d, f);
4012
+ this.processScrollEvent(l, c, f);
3919
4013
  }
3920
4014
  l.debounceTimer = null;
3921
4015
  }, 250));
3922
4016
  };
3923
- l.listener = c, this.containers.push(l), e === window ? window.addEventListener("scroll", c, { passive: !0 }) : e.addEventListener("scroll", c, { passive: !0 });
4017
+ l.listener = d, this.containers.push(l), e === window ? window.addEventListener("scroll", d, { passive: !0 }) : e.addEventListener("scroll", d, { passive: !0 });
3924
4018
  }
3925
4019
  processScrollEvent(e, t, s) {
3926
4020
  if (!this.shouldEmitScrollEvent(e, t, s))
@@ -3975,10 +4069,10 @@ class Ms extends _ {
3975
4069
  const { element: t, lastScrollPos: s, lastEventTime: n } = e, i = this.getScrollTop(t), o = Date.now(), l = Math.abs(i - s);
3976
4070
  if (l < 10 || t === window && !this.isWindowScrollable())
3977
4071
  return null;
3978
- const c = this.getViewportHeight(t), d = this.getScrollHeight(t), f = this.getScrollDirection(i, s), g = this.calculateScrollDepth(i, d, c);
3979
- let I;
3980
- n > 0 ? I = o - n : e.firstScrollEventTime !== null ? I = o - e.firstScrollEventTime : I = 250;
3981
- const E = Math.round(l / I * 1e3);
4072
+ const d = this.getViewportHeight(t), c = this.getScrollHeight(t), f = this.getScrollDirection(i, s), g = this.calculateScrollDepth(i, c, d);
4073
+ let m;
4074
+ n > 0 ? m = o - n : e.firstScrollEventTime !== null ? m = o - e.firstScrollEventTime : m = 250;
4075
+ const E = Math.round(l / m * 1e3);
3982
4076
  return g > e.maxDepthReached && (e.maxDepthReached = g), e.lastScrollPos = i, {
3983
4077
  depth: g,
3984
4078
  direction: f,
@@ -4019,7 +4113,7 @@ class Ms extends _ {
4019
4113
  e.isPrimary = t;
4020
4114
  }
4021
4115
  }
4022
- class Cs extends _ {
4116
+ class Cs extends v {
4023
4117
  eventManager;
4024
4118
  trackedElements = /* @__PURE__ */ new Map();
4025
4119
  observer = null;
@@ -4181,7 +4275,7 @@ class Cs extends _ {
4181
4275
  }
4182
4276
  }
4183
4277
  const Rs = "tracelog_session_id", Ns = "tracelog_user_id";
4184
- class Os extends _ {
4278
+ class Os extends v {
4185
4279
  visibilityHandler = null;
4186
4280
  pageshowHandler = null;
4187
4281
  lastSyncedKey = null;
@@ -4523,7 +4617,7 @@ class Ps {
4523
4617
  this.fallbackSessionStorage.delete(e);
4524
4618
  }
4525
4619
  }
4526
- class Ds extends _ {
4620
+ class Ds extends v {
4527
4621
  eventManager;
4528
4622
  reportedByNav = /* @__PURE__ */ new Map();
4529
4623
  navigationHistory = [];
@@ -4534,7 +4628,7 @@ class Ds extends _ {
4534
4628
  navigationCounter = 0;
4535
4629
  // Counter for handling simultaneous navigations edge case
4536
4630
  constructor(e) {
4537
- super(), this.eventManager = e, this.vitalThresholds = Qe(_e);
4631
+ super(), this.eventManager = e, this.vitalThresholds = Qe(ye);
4538
4632
  }
4539
4633
  /**
4540
4634
  * Starts tracking Web Vitals and performance metrics.
@@ -4551,7 +4645,7 @@ class Ds extends _ {
4551
4645
  * @returns Promise that resolves when tracking is initialized
4552
4646
  */
4553
4647
  async startTracking() {
4554
- const e = this.get("config"), t = e?.webVitalsMode ?? _e;
4648
+ const e = this.get("config"), t = e?.webVitalsMode ?? ye;
4555
4649
  this.vitalThresholds = Qe(t), e?.webVitalsThresholds && (this.vitalThresholds = { ...this.vitalThresholds, ...e.webVitalsThresholds }), await this.initWebVitals(), this.observeLongTasks();
4556
4650
  }
4557
4651
  /**
@@ -4622,9 +4716,9 @@ class Ds extends _ {
4622
4716
  }
4623
4717
  async initWebVitals() {
4624
4718
  try {
4625
- const { onLCP: e, onCLS: t, onFCP: s, onTTFB: n, onINP: i } = await Promise.resolve().then(() => hr), o = (l) => (c) => {
4626
- const d = Number(c.value.toFixed(2));
4627
- this.sendVital({ type: l, value: d });
4719
+ const { onLCP: e, onCLS: t, onFCP: s, onTTFB: n, onINP: i } = await Promise.resolve().then(() => hr), o = (l) => (d) => {
4720
+ const c = Number(d.value.toFixed(2));
4721
+ this.sendVital({ type: l, value: c });
4628
4722
  };
4629
4723
  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 });
4630
4724
  } catch (e) {
@@ -4729,9 +4823,9 @@ class Ds extends _ {
4729
4823
  const i = new PerformanceObserver((o, l) => {
4730
4824
  try {
4731
4825
  t(o, l);
4732
- } catch (c) {
4826
+ } catch (d) {
4733
4827
  a("debug", "Observer callback failed", {
4734
- error: c,
4828
+ error: d,
4735
4829
  data: { type: e }
4736
4830
  });
4737
4831
  }
@@ -4756,7 +4850,7 @@ class Ds extends _ {
4756
4850
  return !(typeof s == "number" && t <= s);
4757
4851
  }
4758
4852
  }
4759
- class ae extends _ {
4853
+ class ae extends v {
4760
4854
  eventManager;
4761
4855
  recentErrors = /* @__PURE__ */ new Map();
4762
4856
  errorBurstCounter = 0;
@@ -4851,7 +4945,7 @@ class ae extends _ {
4851
4945
  }
4852
4946
  }
4853
4947
  sanitize(e) {
4854
- const t = e.length > Xe ? e.slice(0, Xe) + "..." : e;
4948
+ const t = e.length > Ge ? e.slice(0, Ge) + "..." : e;
4855
4949
  return this.sanitizePii(t);
4856
4950
  }
4857
4951
  sanitizePii(e) {
@@ -4864,13 +4958,13 @@ class ae extends _ {
4864
4958
  }
4865
4959
  shouldSuppressError(e, t) {
4866
4960
  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));
4961
+ return i !== void 0 && s - i < je ? (this.recentErrors.set(n, s), !0) : (this.recentErrors.set(n, s), this.recentErrors.size > Xt ? (this.recentErrors.clear(), this.recentErrors.set(n, s), !1) : (this.recentErrors.size > ee && this.pruneOldErrors(), !1));
4868
4962
  }
4869
4963
  static TRUNCATION_SUFFIX = `
4870
4964
  ...truncated`;
4871
4965
  truncateStack(e) {
4872
- if (e.length <= Ge) return this.sanitizePii(e);
4873
- const t = Ge - ae.TRUNCATION_SUFFIX.length, s = e.slice(0, t) + ae.TRUNCATION_SUFFIX;
4966
+ if (e.length <= Xe) return this.sanitizePii(e);
4967
+ const t = Xe - ae.TRUNCATION_SUFFIX.length, s = e.slice(0, t) + ae.TRUNCATION_SUFFIX;
4874
4968
  return this.sanitizePii(s);
4875
4969
  }
4876
4970
  pruneOldErrors() {
@@ -4886,7 +4980,7 @@ class ae extends _ {
4886
4980
  }
4887
4981
  }
4888
4982
  }
4889
- class ks extends _ {
4983
+ class ks extends v {
4890
4984
  isInitialized = !1;
4891
4985
  suppressNextScrollTimer = null;
4892
4986
  pageUnloadHandler = null;
@@ -4913,7 +5007,7 @@ class ks extends _ {
4913
5007
  try {
4914
5008
  this.setupState(e);
4915
5009
  const t = e.integrations?.custom?.headers ?? {}, s = e.integrations?.custom?.fetchCredentials ?? "include";
4916
- return this.managers.event = new vs(
5010
+ return this.managers.event = new _s(
4917
5011
  this.managers.storage,
4918
5012
  this.emitter,
4919
5013
  this.transformers,
@@ -5013,13 +5107,13 @@ class ks extends _ {
5013
5107
  }
5014
5108
  setupState(e = {}) {
5015
5109
  this.set("config", e);
5016
- const t = _s.getId(this.managers.storage);
5110
+ const t = vs.getId(this.managers.storage);
5017
5111
  this.set("userId", t);
5018
5112
  const s = ls(e);
5019
5113
  this.set("collectApiUrls", s);
5020
- const n = Xt();
5114
+ const n = Gt();
5021
5115
  this.set("device", n);
5022
- const i = ye(window.location.href, e.sensitiveQueryParams);
5116
+ const i = we(window.location.href, e.sensitiveQueryParams);
5023
5117
  this.set("pageUrl", i), ss() && this.set("mode", ie.QA);
5024
5118
  }
5025
5119
  /**
@@ -5158,7 +5252,7 @@ class ks extends _ {
5158
5252
  async resetIdentity() {
5159
5253
  await this.managers.event?.flushImmediately(), this.set("identity", void 0), this.clearPersistedIdentity();
5160
5254
  const e = dt();
5161
- this.managers.storage.setItem(Te, e), this.set("userId", e), this.set("hasStartSession", !1), this.set("sessionId", null), this.handlers.session?.stopTracking(), this.handlers.session?.startTracking(), a("debug", "Identity reset, new UUID generated");
5255
+ this.managers.storage.setItem(Ie, e), this.set("userId", e), this.set("hasStartSession", !1), this.set("sessionId", null), this.handlers.session?.stopTracking(), this.handlers.session?.startTracking(), a("debug", "Identity reset, new UUID generated");
5162
5256
  }
5163
5257
  /**
5164
5258
  * Returns the project ID used for identity storage scoping.
@@ -5172,7 +5266,7 @@ class ks extends _ {
5172
5266
  */
5173
5267
  persistIdentity(e) {
5174
5268
  try {
5175
- const t = this.getProjectId(), s = fe(t);
5269
+ const t = this.getProjectId(), s = me(t);
5176
5270
  this.managers.storage.setItem(s, JSON.stringify(e));
5177
5271
  } catch {
5178
5272
  a("debug", "Failed to persist identity to localStorage");
@@ -5183,12 +5277,12 @@ class ks extends _ {
5183
5277
  * Also migrates pending identity (set before init) to the project-scoped key.
5184
5278
  */
5185
5279
  loadPersistedIdentity() {
5186
- const e = this.managers.storage, t = this.getProjectId(), s = fe(t);
5280
+ const e = this.managers.storage, t = this.getProjectId(), s = me(t);
5187
5281
  try {
5188
- const n = e.getItem(U);
5282
+ const n = e.getItem(F);
5189
5283
  if (n) {
5190
5284
  const i = JSON.parse(n);
5191
- if (e.removeItem(U), !this.isValidIdentityData(i)) {
5285
+ if (e.removeItem(F), !this.isValidIdentityData(i)) {
5192
5286
  a("debug", "Invalid pending identity in localStorage, discarded");
5193
5287
  return;
5194
5288
  }
@@ -5197,7 +5291,7 @@ class ks extends _ {
5197
5291
  return;
5198
5292
  }
5199
5293
  } catch {
5200
- e.removeItem(U);
5294
+ e.removeItem(F);
5201
5295
  }
5202
5296
  try {
5203
5297
  const n = e.getItem(s);
@@ -5235,7 +5329,7 @@ class ks extends _ {
5235
5329
  clearPersistedIdentity() {
5236
5330
  try {
5237
5331
  const e = this.managers.storage, t = this.getProjectId();
5238
- e.removeItem(fe(t)), e.removeItem(U);
5332
+ e.removeItem(me(t)), e.removeItem(F);
5239
5333
  } catch {
5240
5334
  a("debug", "Failed to clear persisted identity");
5241
5335
  }
@@ -5267,8 +5361,8 @@ class ks extends _ {
5267
5361
  }
5268
5362
  }
5269
5363
  const k = [], M = [];
5270
- let D = null, h = null, R = !1, T = !1, P = null;
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 () => {
5364
+ let D = null, h = null, R = !1, _ = !1, P = null;
5365
+ const Vs = async (r) => typeof window > "u" || typeof document > "u" ? { sessionId: "" } : (_ = !1, window.__traceLogDisabled === !0 ? { sessionId: "" } : h ? { sessionId: h.getSessionId() ?? "" } : (R && P || (R = !0, P = (async () => {
5272
5366
  try {
5273
5367
  const e = fs(r ?? {}), t = new ks();
5274
5368
  try {
@@ -5300,7 +5394,7 @@ const Vs = async (r) => typeof window > "u" || typeof document > "u" ? { session
5300
5394
  if (!(typeof window > "u" || typeof document > "u")) {
5301
5395
  if (!h)
5302
5396
  throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
5303
- if (T)
5397
+ if (_)
5304
5398
  throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
5305
5399
  h.sendCustomEvent(r, e);
5306
5400
  }
@@ -5331,7 +5425,7 @@ function xs(r, e) {
5331
5425
  t !== -1 && M.splice(t, 1), M.push({ hook: r, fn: e });
5332
5426
  return;
5333
5427
  }
5334
- if (T)
5428
+ if (_)
5335
5429
  throw new Error("[TraceLog] Cannot set transformers while TraceLog is being destroyed");
5336
5430
  r === "beforeSend" ? h.setTransformer("beforeSend", e) : h.setTransformer("beforeBatch", e);
5337
5431
  }
@@ -5343,7 +5437,7 @@ const $s = (r) => {
5343
5437
  e !== -1 && M.splice(e, 1);
5344
5438
  return;
5345
5439
  }
5346
- if (T)
5440
+ if (_)
5347
5441
  throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
5348
5442
  h.removeTransformer(r);
5349
5443
  }
@@ -5355,7 +5449,7 @@ const $s = (r) => {
5355
5449
  D = r;
5356
5450
  return;
5357
5451
  }
5358
- if (T)
5452
+ if (_)
5359
5453
  throw new Error("[TraceLog] Cannot set custom headers while TraceLog is being destroyed");
5360
5454
  h.setCustomHeaders(r);
5361
5455
  }
@@ -5365,23 +5459,23 @@ const $s = (r) => {
5365
5459
  D = null;
5366
5460
  return;
5367
5461
  }
5368
- if (T)
5462
+ if (_)
5369
5463
  throw new Error("[TraceLog] Cannot remove custom headers while TraceLog is being destroyed");
5370
5464
  h.removeCustomHeaders();
5371
5465
  }
5372
- }, Xs = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, Gs = () => typeof window > "u" || typeof document > "u" || !h ? null : h.getSessionId(), js = () => {
5466
+ }, Gs = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, Xs = () => typeof window > "u" || typeof document > "u" || !h ? null : h.getSessionId(), js = () => {
5373
5467
  if (!(typeof window > "u" || typeof document > "u")) {
5374
- if (T)
5468
+ if (_)
5375
5469
  throw new Error("[TraceLog] Destroy operation already in progress");
5376
5470
  if (!h) {
5377
- T = !1;
5471
+ _ = !1;
5378
5472
  return;
5379
5473
  }
5380
- T = !0;
5474
+ _ = !0;
5381
5475
  try {
5382
- h.destroy(), h = null, R = !1, P = null, k.length = 0, M.length = 0, D = null, T = !1;
5476
+ h.destroy(), h = null, R = !1, P = null, k.length = 0, M.length = 0, D = null, _ = !1;
5383
5477
  } catch (r) {
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 });
5478
+ h = null, R = !1, P = null, k.length = 0, M.length = 0, D = null, _ = !1, a("warn", "Error during destroy, forced cleanup completed", { error: r });
5385
5479
  }
5386
5480
  }
5387
5481
  }, Ks = (r) => {
@@ -5390,7 +5484,7 @@ const $s = (r) => {
5390
5484
  if (!(typeof window > "u" || typeof document > "u")) {
5391
5485
  if (!h)
5392
5486
  throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
5393
- if (T)
5487
+ if (_)
5394
5488
  throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
5395
5489
  h.updateGlobalMetadata(r);
5396
5490
  }
@@ -5398,7 +5492,7 @@ const $s = (r) => {
5398
5492
  if (!(typeof window > "u" || typeof document > "u")) {
5399
5493
  if (!h)
5400
5494
  throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
5401
- if (T)
5495
+ if (_)
5402
5496
  throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
5403
5497
  h.mergeGlobalMetadata(r);
5404
5498
  }
@@ -5412,7 +5506,7 @@ const $s = (r) => {
5412
5506
  a("warn", "identify() userId exceeds 256 characters");
5413
5507
  return;
5414
5508
  }
5415
- if (T) {
5509
+ if (_) {
5416
5510
  a("warn", "Cannot identify while TraceLog is being destroyed");
5417
5511
  return;
5418
5512
  }
@@ -5425,7 +5519,7 @@ const $s = (r) => {
5425
5519
  userId: r.trim(),
5426
5520
  ...t ? { traits: t } : {}
5427
5521
  };
5428
- localStorage.setItem(U, JSON.stringify(s)), a("debug", "Identity persisted pre-init (will be applied on init)");
5522
+ localStorage.setItem(F, JSON.stringify(s)), a("debug", "Identity persisted pre-init (will be applied on init)");
5429
5523
  } catch {
5430
5524
  a("debug", "Failed to persist pre-init identity");
5431
5525
  }
@@ -5434,12 +5528,12 @@ const $s = (r) => {
5434
5528
  if (!(typeof window > "u" || typeof document > "u")) {
5435
5529
  if (!h) {
5436
5530
  try {
5437
- localStorage.removeItem(U);
5531
+ localStorage.removeItem(F);
5438
5532
  } catch {
5439
5533
  }
5440
5534
  return;
5441
5535
  }
5442
- if (T)
5536
+ if (_)
5443
5537
  throw new Error("[TraceLog] Cannot reset identity while TraceLog is being destroyed");
5444
5538
  await h.resetIdentity();
5445
5539
  }
@@ -5452,8 +5546,8 @@ const $s = (r) => {
5452
5546
  removeTransformer: $s,
5453
5547
  setCustomHeaders: Bs,
5454
5548
  removeCustomHeaders: Ws,
5455
- isInitialized: Xs,
5456
- getSessionId: Gs,
5549
+ isInitialized: Gs,
5550
+ getSessionId: Xs,
5457
5551
  destroy: js,
5458
5552
  setQaMode: Ks,
5459
5553
  updateGlobalMetadata: zs,
@@ -5461,20 +5555,20 @@ const $s = (r) => {
5461
5555
  identify: Ys,
5462
5556
  resetIdentity: qs
5463
5557
  };
5464
- var Le, C, G, pt, le, Et = -1, V = function(r) {
5558
+ var Ae, C, X, pt, le, Et = -1, V = function(r) {
5465
5559
  addEventListener("pageshow", (function(e) {
5466
5560
  e.persisted && (Et = e.timeStamp, r(e));
5467
5561
  }), !0);
5468
- }, Pe = function() {
5562
+ }, De = function() {
5469
5563
  var r = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
5470
5564
  if (r && r.responseStart > 0 && r.responseStart < performance.now()) return r;
5471
5565
  }, de = function() {
5472
- var r = Pe();
5566
+ var r = De();
5473
5567
  return r && r.activationStart || 0;
5474
5568
  }, y = function(r, e) {
5475
- var t = Pe(), s = "navigate";
5569
+ var t = De(), s = "navigate";
5476
5570
  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 };
5477
- }, H = function(r, e, t) {
5571
+ }, x = function(r, e, t) {
5478
5572
  try {
5479
5573
  if (PerformanceObserver.supportedEntryTypes.includes(r)) {
5480
5574
  var s = new PerformanceObserver((function(n) {
@@ -5489,11 +5583,11 @@ var Le, C, G, pt, le, Et = -1, V = function(r) {
5489
5583
  }, w = function(r, e, t, s) {
5490
5584
  var n, i;
5491
5585
  return function(o) {
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) {
5493
- return l > c[1] ? "poor" : l > c[0] ? "needs-improvement" : "good";
5586
+ e.value >= 0 && (o || s) && ((i = e.value - (n || 0)) || n === void 0) && (n = e.value, e.delta = i, e.rating = (function(l, d) {
5587
+ return l > d[1] ? "poor" : l > d[0] ? "needs-improvement" : "good";
5494
5588
  })(e.value, t), r(e));
5495
5589
  };
5496
- }, De = function(r) {
5590
+ }, ke = function(r) {
5497
5591
  requestAnimationFrame((function() {
5498
5592
  return requestAnimationFrame((function() {
5499
5593
  return r();
@@ -5508,67 +5602,67 @@ var Le, C, G, pt, le, Et = -1, V = function(r) {
5508
5602
  return function() {
5509
5603
  e || (r(), e = !0);
5510
5604
  };
5511
- }, F = -1, et = function() {
5605
+ }, H = -1, et = function() {
5512
5606
  return document.visibilityState !== "hidden" || document.prerendering ? 1 / 0 : 0;
5513
5607
  }, ce = function(r) {
5514
- document.visibilityState === "hidden" && F > -1 && (F = r.type === "visibilitychange" ? r.timeStamp : 0, Js());
5608
+ document.visibilityState === "hidden" && H > -1 && (H = r.type === "visibilitychange" ? r.timeStamp : 0, Js());
5515
5609
  }, tt = function() {
5516
5610
  addEventListener("visibilitychange", ce, !0), addEventListener("prerenderingchange", ce, !0);
5517
5611
  }, Js = function() {
5518
5612
  removeEventListener("visibilitychange", ce, !0), removeEventListener("prerenderingchange", ce, !0);
5519
- }, ke = function() {
5520
- return F < 0 && (F = et(), tt(), V((function() {
5613
+ }, Ve = function() {
5614
+ return H < 0 && (H = et(), tt(), V((function() {
5521
5615
  setTimeout((function() {
5522
- F = et(), tt();
5616
+ H = et(), tt();
5523
5617
  }), 0);
5524
5618
  }))), { get firstHiddenTime() {
5525
- return F;
5619
+ return H;
5526
5620
  } };
5527
5621
  }, z = function(r) {
5528
5622
  document.prerendering ? addEventListener("prerenderingchange", (function() {
5529
5623
  return r();
5530
5624
  }), !0) : r();
5531
- }, Ae = [1800, 3e3], St = function(r, e) {
5625
+ }, Me = [1800, 3e3], St = function(r, e) {
5532
5626
  e = e || {}, z((function() {
5533
- var t, s = ke(), n = y("FCP"), i = H("paint", (function(o) {
5627
+ var t, s = Ve(), n = y("FCP"), i = x("paint", (function(o) {
5534
5628
  o.forEach((function(l) {
5535
5629
  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)));
5536
5630
  }));
5537
5631
  }));
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() {
5632
+ i && (t = w(r, n, Me, e.reportAllChanges), V((function(o) {
5633
+ n = y("FCP"), t = w(r, n, Me, e.reportAllChanges), ke((function() {
5540
5634
  n.value = performance.now() - o.timeStamp, t(!0);
5541
5635
  }));
5542
5636
  })));
5543
5637
  }));
5544
- }, Me = [0.1, 0.25], Zs = function(r, e) {
5638
+ }, Ce = [0.1, 0.25], Zs = function(r, e) {
5545
5639
  e = e || {}, St(ue((function() {
5546
- var t, s = y("CLS", 0), n = 0, i = [], o = function(c) {
5547
- c.forEach((function(d) {
5548
- if (!d.hadRecentInput) {
5640
+ var t, s = y("CLS", 0), n = 0, i = [], o = function(d) {
5641
+ d.forEach((function(c) {
5642
+ if (!c.hadRecentInput) {
5549
5643
  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]);
5644
+ n && c.startTime - g.startTime < 1e3 && c.startTime - f.startTime < 5e3 ? (n += c.value, i.push(c)) : (n = c.value, i = [c]);
5551
5645
  }
5552
5646
  })), n > s.value && (s.value = n, s.entries = i, t());
5553
- }, l = H("layout-shift", o);
5554
- l && (t = w(r, s, Me, e.reportAllChanges), K((function() {
5647
+ }, l = x("layout-shift", o);
5648
+ l && (t = w(r, s, Ce, e.reportAllChanges), K((function() {
5555
5649
  o(l.takeRecords()), t(!0);
5556
5650
  })), V((function() {
5557
- n = 0, s = y("CLS", 0), t = w(r, s, Me, e.reportAllChanges), De((function() {
5651
+ n = 0, s = y("CLS", 0), t = w(r, s, Ce, e.reportAllChanges), ke((function() {
5558
5652
  return t();
5559
5653
  }));
5560
5654
  })), setTimeout(t, 0));
5561
5655
  })));
5562
- }, Tt = 0, Ee = 1 / 0, J = 0, er = function(r) {
5656
+ }, Tt = 0, Se = 1 / 0, J = 0, er = function(r) {
5563
5657
  r.forEach((function(e) {
5564
- e.interactionId && (Ee = Math.min(Ee, e.interactionId), J = Math.max(J, e.interactionId), Tt = J ? (J - Ee) / 7 + 1 : 0);
5658
+ e.interactionId && (Se = Math.min(Se, e.interactionId), J = Math.max(J, e.interactionId), Tt = J ? (J - Se) / 7 + 1 : 0);
5565
5659
  }));
5566
5660
  }, It = function() {
5567
- return Le ? Tt : performance.interactionCount || 0;
5661
+ return Ae ? Tt : performance.interactionCount || 0;
5568
5662
  }, 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() {
5571
- var r = Math.min(L.length - 1, Math.floor((It() - vt) / 50));
5663
+ "interactionCount" in performance || Ae || (Ae = x("event", er, { type: "event", buffered: !0, durationThreshold: 0 }));
5664
+ }, L = [], te = /* @__PURE__ */ new Map(), _t = 0, sr = function() {
5665
+ var r = Math.min(L.length - 1, Math.floor((It() - _t) / 50));
5572
5666
  return L[r];
5573
5667
  }, rr = [], nr = function(r) {
5574
5668
  if (rr.forEach((function(n) {
@@ -5588,50 +5682,50 @@ var Le, C, G, pt, le, Et = -1, V = function(r) {
5588
5682
  }));
5589
5683
  }
5590
5684
  }
5591
- }, _t = function(r) {
5685
+ }, vt = function(r) {
5592
5686
  var e = self.requestIdleCallback || self.setTimeout, t = -1;
5593
5687
  return r = ue(r), document.visibilityState === "hidden" ? r() : (t = e(r), K(r)), t;
5594
- }, Ce = [200, 500], ir = function(r, e) {
5688
+ }, Re = [200, 500], ir = function(r, e) {
5595
5689
  "PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, z((function() {
5596
5690
  var t;
5597
5691
  tr();
5598
5692
  var s, n = y("INP"), i = function(l) {
5599
- _t((function() {
5693
+ vt((function() {
5600
5694
  l.forEach(nr);
5601
- var c = sr();
5602
- c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, s());
5695
+ var d = sr();
5696
+ d && d.latency !== n.value && (n.value = d.latency, n.entries = d.entries, s());
5603
5697
  }));
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() {
5698
+ }, o = x("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
5699
+ s = w(r, n, Re, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), K((function() {
5606
5700
  i(o.takeRecords()), s(!0);
5607
5701
  })), V((function() {
5608
- vt = It(), L.length = 0, te.clear(), n = y("INP"), s = w(r, n, Ce, e.reportAllChanges);
5702
+ _t = It(), L.length = 0, te.clear(), n = y("INP"), s = w(r, n, Re, e.reportAllChanges);
5609
5703
  })));
5610
5704
  })));
5611
- }, Re = [2500, 4e3], Se = {}, or = function(r, e) {
5705
+ }, Ne = [2500, 4e3], Te = {}, or = function(r, e) {
5612
5706
  e = e || {}, z((function() {
5613
- var t, s = ke(), n = y("LCP"), i = function(c) {
5614
- e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(d) {
5615
- d.startTime < s.firstHiddenTime && (n.value = Math.max(d.startTime - de(), 0), n.entries = [d], t());
5707
+ var t, s = Ve(), n = y("LCP"), i = function(d) {
5708
+ e.reportAllChanges || (d = d.slice(-1)), d.forEach((function(c) {
5709
+ c.startTime < s.firstHiddenTime && (n.value = Math.max(c.startTime - de(), 0), n.entries = [c], t());
5616
5710
  }));
5617
- }, o = H("largest-contentful-paint", i);
5711
+ }, o = x("largest-contentful-paint", i);
5618
5712
  if (o) {
5619
- t = w(r, n, Re, e.reportAllChanges);
5713
+ t = w(r, n, Ne, e.reportAllChanges);
5620
5714
  var l = ue((function() {
5621
- Se[n.id] || (i(o.takeRecords()), o.disconnect(), Se[n.id] = !0, t(!0));
5715
+ Te[n.id] || (i(o.takeRecords()), o.disconnect(), Te[n.id] = !0, t(!0));
5622
5716
  }));
5623
- ["keydown", "click"].forEach((function(c) {
5624
- addEventListener(c, (function() {
5625
- return _t(l);
5717
+ ["keydown", "click"].forEach((function(d) {
5718
+ addEventListener(d, (function() {
5719
+ return vt(l);
5626
5720
  }), { once: !0, capture: !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);
5721
+ })), K(l), V((function(d) {
5722
+ n = y("LCP"), t = w(r, n, Ne, e.reportAllChanges), ke((function() {
5723
+ n.value = performance.now() - d.timeStamp, Te[n.id] = !0, t(!0);
5630
5724
  }));
5631
5725
  }));
5632
5726
  }
5633
5727
  }));
5634
- }, Ne = [800, 1800], ar = function r(e) {
5728
+ }, Oe = [800, 1800], ar = function r(e) {
5635
5729
  document.prerendering ? z((function() {
5636
5730
  return r(e);
5637
5731
  })) : document.readyState !== "complete" ? addEventListener("load", (function() {
@@ -5639,18 +5733,18 @@ var Le, C, G, pt, le, Et = -1, V = function(r) {
5639
5733
  }), !0) : setTimeout(e, 0);
5640
5734
  }, lr = function(r, e) {
5641
5735
  e = e || {};
5642
- var t = y("TTFB"), s = w(r, t, Ne, e.reportAllChanges);
5736
+ var t = y("TTFB"), s = w(r, t, Oe, e.reportAllChanges);
5643
5737
  ar((function() {
5644
- var n = Pe();
5738
+ var n = De();
5645
5739
  n && (t.value = Math.max(n.responseStart - de(), 0), t.entries = [n], s(!0), V((function() {
5646
- t = y("TTFB", 0), (s = w(r, t, Ne, e.reportAllChanges))(!0);
5740
+ t = y("TTFB", 0), (s = w(r, t, Oe, e.reportAllChanges))(!0);
5647
5741
  })));
5648
5742
  }));
5649
5743
  }, 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());
5744
+ C || (C = e, X = r, pt = /* @__PURE__ */ new Date(), wt(removeEventListener), yt());
5651
5745
  }, yt = function() {
5652
- if (G >= 0 && G < pt - cr) {
5653
- var r = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp + G };
5746
+ if (X >= 0 && X < pt - cr) {
5747
+ var r = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp + X };
5654
5748
  le.forEach((function(e) {
5655
5749
  e(r);
5656
5750
  })), le = [];
@@ -5673,29 +5767,29 @@ var Le, C, G, pt, le, Et = -1, V = function(r) {
5673
5767
  ["mousedown", "keydown", "touchstart", "pointerdown"].forEach((function(e) {
5674
5768
  return r(e, dr, W);
5675
5769
  }));
5676
- }, Oe = [100, 300], ur = function(r, e) {
5770
+ }, Pe = [100, 300], ur = function(r, e) {
5677
5771
  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));
5680
- }, o = function(c) {
5681
- c.forEach(i);
5682
- }, l = H("first-input", o);
5683
- t = w(r, n, Oe, e.reportAllChanges), l && (K(ue((function() {
5772
+ var t, s = Ve(), n = y("FID"), i = function(d) {
5773
+ d.startTime < s.firstHiddenTime && (n.value = d.processingStart - d.startTime, n.entries.push(d), t(!0));
5774
+ }, o = function(d) {
5775
+ d.forEach(i);
5776
+ }, l = x("first-input", o);
5777
+ t = w(r, n, Pe, e.reportAllChanges), l && (K(ue((function() {
5684
5778
  o(l.takeRecords()), l.disconnect();
5685
5779
  }))), V((function() {
5686
- var c;
5687
- n = y("FID"), t = w(r, n, Oe, e.reportAllChanges), le = [], G = -1, C = null, wt(addEventListener), c = i, le.push(c), yt();
5780
+ var d;
5781
+ n = y("FID"), t = w(r, n, Pe, e.reportAllChanges), le = [], X = -1, C = null, wt(addEventListener), d = i, le.push(d), yt();
5688
5782
  })));
5689
5783
  }));
5690
5784
  };
5691
5785
  const hr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5692
5786
  __proto__: null,
5693
- CLSThresholds: Me,
5694
- FCPThresholds: Ae,
5695
- FIDThresholds: Oe,
5696
- INPThresholds: Ce,
5697
- LCPThresholds: Re,
5698
- TTFBThresholds: Ne,
5787
+ CLSThresholds: Ce,
5788
+ FCPThresholds: Me,
5789
+ FIDThresholds: Pe,
5790
+ INPThresholds: Re,
5791
+ LCPThresholds: Ne,
5792
+ TTFBThresholds: Oe,
5699
5793
  onCLS: Zs,
5700
5794
  onFCP: St,
5701
5795
  onFID: ur,
@@ -5704,16 +5798,16 @@ const hr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5704
5798
  onTTFB: lr
5705
5799
  }, Symbol.toStringTag, { value: "Module" }));
5706
5800
  export {
5707
- m as AppConfigValidationError,
5801
+ p as AppConfigValidationError,
5708
5802
  fr as DEFAULT_SESSION_TIMEOUT,
5709
- _e as DEFAULT_WEB_VITALS_MODE,
5803
+ ye as DEFAULT_WEB_VITALS_MODE,
5710
5804
  A as DeviceType,
5711
5805
  se as EmitterEvent,
5712
5806
  B as ErrorType,
5713
5807
  u as EventType,
5714
5808
  wr as InitializationTimeoutError,
5715
5809
  N as IntegrationValidationError,
5716
- vr as MAX_ARRAY_LENGTH,
5810
+ _r as MAX_ARRAY_LENGTH,
5717
5811
  Er as MAX_CUSTOM_EVENT_ARRAY_SIZE,
5718
5812
  pr as MAX_CUSTOM_EVENT_KEYS,
5719
5813
  mr as MAX_CUSTOM_EVENT_NAME_LENGTH,
@@ -5735,7 +5829,7 @@ export {
5735
5829
  ze as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
5736
5830
  Yt as WEB_VITALS_POOR_THRESHOLDS,
5737
5831
  Qe as getWebVitalsThresholds,
5738
- _r as isPrimaryScrollEvent,
5832
+ vr as isPrimaryScrollEvent,
5739
5833
  yr as isSecondaryScrollEvent,
5740
5834
  Lr as tracelog
5741
5835
  };