@tracelog/lib 2.8.5-rc.106.7 → 2.8.5-rc.106.8
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.
- package/dist/browser/tracelog.esm.js +559 -539
- package/dist/browser/tracelog.esm.js.map +1 -1
- package/dist/browser/tracelog.js +1 -1
- package/dist/browser/tracelog.js.map +1 -1
- package/dist/public-api.cjs +2 -2
- package/dist/public-api.cjs.map +1 -1
- package/dist/public-api.js +2 -2
- package/dist/public-api.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const fr = 9e5;
|
|
2
|
-
const mr = 120, gr = 49152,
|
|
2
|
+
const mr = 120, gr = 49152, pr = 100, Er = 500, Sr = 200;
|
|
3
3
|
const Tr = 1e3, Ir = 500, vr = 1e3;
|
|
4
4
|
const b = "data-tlog", bt = [
|
|
5
5
|
"button",
|
|
@@ -49,7 +49,7 @@ const b = "data-tlog", bt = [
|
|
|
49
49
|
"code",
|
|
50
50
|
"otp"
|
|
51
51
|
];
|
|
52
|
-
const
|
|
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",
|
|
@@ -79,7 +79,7 @@ const E = {
|
|
|
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",
|
|
82
|
+
], S = "tlog", X = `${S}:qa_mode`, Te = `${S}:uid`, rt = "tlog_mode", Ue = "qa", He = "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`, Fe = (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`;
|
|
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) {
|
|
@@ -93,12 +93,12 @@ class re extends Error {
|
|
|
93
93
|
super(e), this.name = "RateLimitError", Error.captureStackTrace && Error.captureStackTrace(this, re);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
class
|
|
96
|
+
class ne extends Error {
|
|
97
97
|
constructor(e) {
|
|
98
|
-
super(e), this.name = "TimeoutError", Error.captureStackTrace && Error.captureStackTrace(this,
|
|
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 || {}),
|
|
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
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) {
|
|
@@ -133,7 +133,7 @@ class wr extends j {
|
|
|
133
133
|
}
|
|
134
134
|
timeoutMs;
|
|
135
135
|
}
|
|
136
|
-
const
|
|
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:
|
|
165
|
-
if (!Ut(l,
|
|
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 =
|
|
168
|
-
|
|
169
|
-
}, Ut = (r, e) => r === "critical" ? !0 : r === "qa" || e ? Vt() : !1,
|
|
170
|
-
const
|
|
171
|
-
s !== void 0 ?
|
|
167
|
+
const g = Ht(l, o), I = n !== void 0 ? Ie(n) : void 0;
|
|
168
|
+
Ft(d, c, g, I);
|
|
169
|
+
}, Ut = (r, e) => r === "critical" ? !0 : r === "qa" || e ? Vt() : !1, Ht = (r, e) => e !== void 0 && e !== "" ? e : r === "critical" ? Dt : "", Ft = (r, e, t, s) => {
|
|
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,
|
|
175
|
-
const
|
|
176
|
-
if (t.some((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
|
-
|
|
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] =
|
|
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
|
|
205
|
-
if (
|
|
206
|
-
const
|
|
207
|
-
return /google chrome/i.test(
|
|
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,
|
|
221
|
-
return e <= 767 || o &&
|
|
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
|
}
|
|
@@ -317,12 +317,12 @@ const xt = () => {
|
|
|
317
317
|
const e = new URLSearchParams(window.location.search).get(rt), t = sessionStorage.getItem(X);
|
|
318
318
|
let s = null;
|
|
319
319
|
return e === Ue ? (s = !0, sessionStorage.setItem(X, "true"), a("info", "QA Mode ACTIVE", {
|
|
320
|
-
visibility: "qa",
|
|
321
|
-
style: it
|
|
322
|
-
})) : e === Fe && (s = !1, sessionStorage.setItem(X, "false"), a("info", "QA Mode DISABLED", {
|
|
323
320
|
visibility: "qa",
|
|
324
321
|
style: nt
|
|
325
|
-
}))
|
|
322
|
+
})) : e === He && (s = !1, sessionStorage.setItem(X, "false"), a("info", "QA Mode DISABLED", {
|
|
323
|
+
visibility: "qa",
|
|
324
|
+
style: it
|
|
325
|
+
})), (e === Ue || e === He) && ts(), s ?? t === "true";
|
|
326
326
|
} catch {
|
|
327
327
|
return !1;
|
|
328
328
|
}
|
|
@@ -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 ?
|
|
334
|
+
style: r ? nt : it
|
|
335
335
|
});
|
|
336
336
|
} catch {
|
|
337
337
|
a("debug", "Cannot set QA mode: sessionStorage unavailable");
|
|
338
338
|
}
|
|
339
|
-
},
|
|
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
|
|
357
|
-
},
|
|
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
|
|
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
|
|
371
|
-
if (
|
|
372
|
-
const
|
|
373
|
-
e[
|
|
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, (
|
|
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:",
|
|
397
|
-
return s || e &&
|
|
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
|
|
416
|
-
if (s.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
|
|
419
|
-
if (!ut(
|
|
418
|
+
const i = `https://${r}.${n}/collect`;
|
|
419
|
+
if (!ut(i))
|
|
420
420
|
throw new Error("Generated URL failed validation");
|
|
421
|
-
return
|
|
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,
|
|
441
|
-
let
|
|
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
|
|
444
|
-
s.has(c) && (s.delete(c),
|
|
445
|
-
}), !
|
|
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
|
|
456
|
-
const
|
|
457
|
-
e = e.replace(
|
|
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((
|
|
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 = {},
|
|
480
|
-
for (const [
|
|
481
|
-
const l = qe(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
`${
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
573
|
+
throw new m(p.INVALID_VIEWPORT_CONFIG, "config");
|
|
574
574
|
if (!r.elements || !Array.isArray(r.elements))
|
|
575
|
-
throw new m(
|
|
575
|
+
throw new m(p.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
576
576
|
if (r.elements.length === 0)
|
|
577
|
-
throw new m(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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),
|
|
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: `${
|
|
679
|
+
error: `${n}: object has invalid types. Valid types are string, number, boolean or string arrays.`
|
|
680
680
|
};
|
|
681
|
-
let
|
|
681
|
+
let i;
|
|
682
682
|
try {
|
|
683
|
-
|
|
683
|
+
i = JSON.stringify(s);
|
|
684
684
|
} catch {
|
|
685
685
|
return {
|
|
686
686
|
valid: !1,
|
|
687
|
-
error: `${
|
|
687
|
+
error: `${n}: object contains circular references or cannot be serialized.`
|
|
688
688
|
};
|
|
689
689
|
}
|
|
690
|
-
if (new TextEncoder().encode(
|
|
690
|
+
if (new TextEncoder().encode(i).byteLength > 49152)
|
|
691
691
|
return {
|
|
692
692
|
valid: !1,
|
|
693
|
-
error: `${
|
|
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: `${
|
|
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: `${
|
|
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: `${
|
|
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: `${
|
|
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 = [],
|
|
727
|
-
for (let
|
|
728
|
-
const o = e[
|
|
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: `${
|
|
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: `${
|
|
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
|
-
},
|
|
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
|
|
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
|
|
818
|
-
|
|
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((
|
|
852
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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 { ...
|
|
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,
|
|
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 =
|
|
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
|
|
1104
|
-
if (Number.isFinite(
|
|
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(),
|
|
1185
|
-
return this.persistEventsWithFailureCount(t,
|
|
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
|
|
1235
|
-
return
|
|
1236
|
-
} catch (
|
|
1237
|
-
return
|
|
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
|
|
1298
|
-
if (!
|
|
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
|
|
1303
|
-
if (s = typeof
|
|
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(
|
|
1321
|
-
} catch (
|
|
1322
|
-
if (
|
|
1323
|
-
this.logPermanentError("Permanent error during recovery, clearing persisted events",
|
|
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:
|
|
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,
|
|
1444
|
-
return new Promise((
|
|
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
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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(
|
|
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:
|
|
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
|
|
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:
|
|
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:
|
|
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
|
|
1592
|
-
const
|
|
1593
|
-
|
|
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 :
|
|
1616
|
+
throw o instanceof O ? o : n ? new ne("Request timed out") : o;
|
|
1617
1617
|
} finally {
|
|
1618
|
-
clearTimeout(
|
|
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
|
|
1666
|
-
if (!
|
|
1665
|
+
const n = this.applyBeforeBatchTransformer(s);
|
|
1666
|
+
if (!n)
|
|
1667
1667
|
return !0;
|
|
1668
|
-
const
|
|
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:
|
|
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((
|
|
1760
|
-
let
|
|
1761
|
-
for (let
|
|
1762
|
-
|
|
1763
|
-
return
|
|
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, ...
|
|
1814
|
-
return
|
|
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
|
|
1854
|
-
if (!s &&
|
|
1855
|
-
const l = Date.now() -
|
|
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
|
|
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(
|
|
1871
|
-
} catch (
|
|
1872
|
-
return a("debug", `Failed to persist events${this.integrationId ? ` [${this.integrationId}]` : ""}`, { error:
|
|
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(),
|
|
1897
|
-
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.key !==
|
|
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:
|
|
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(),
|
|
2030
|
-
return
|
|
2029
|
+
const s = this.now(), n = e - s;
|
|
2030
|
+
return n > 12e4 ? {
|
|
2031
2031
|
valid: !1,
|
|
2032
|
-
error: `Timestamp is ${(
|
|
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 = {},
|
|
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,
|
|
2135
|
-
if (
|
|
2136
|
-
const o =
|
|
2137
|
-
this.removeProcessedEvents(o),
|
|
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:
|
|
2211
|
-
click_data:
|
|
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:
|
|
2237
|
-
click_data:
|
|
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
|
|
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:
|
|
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(
|
|
2264
|
+
const v = this.getTypeLimitForEvent(E);
|
|
2265
2265
|
if (v) {
|
|
2266
|
-
const he = this.sessionEventCounts[
|
|
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:
|
|
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 (
|
|
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 =
|
|
2285
|
-
type:
|
|
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:
|
|
2289
|
-
click_data:
|
|
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") ===
|
|
2313
|
-
if (
|
|
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 (
|
|
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[
|
|
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],
|
|
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(
|
|
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:
|
|
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(
|
|
2615
|
-
data: { eventCount:
|
|
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
|
|
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(
|
|
2626
|
+
return Promise.allSettled(i).then((o) => {
|
|
2627
2627
|
const l = o.some((c) => this.isSuccessfulResult(c));
|
|
2628
|
-
return l ? (this.removeProcessedEvents(
|
|
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),
|
|
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
|
-
),
|
|
2651
|
-
if (
|
|
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 =
|
|
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
|
|
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
|
|
2682
|
+
const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas), l = this.transformers.beforeBatch;
|
|
2683
2683
|
if (!o && l) {
|
|
2684
|
-
const c = gt(
|
|
2685
|
-
c !== null && (
|
|
2684
|
+
const c = gt(n, l, "EventManager");
|
|
2685
|
+
c !== null && (n = c);
|
|
2686
2686
|
}
|
|
2687
|
-
return
|
|
2687
|
+
return n;
|
|
2688
2688
|
}
|
|
2689
2689
|
buildEventPayload(e) {
|
|
2690
|
-
const t = e.page_url ?? this.get("pageUrl"), s = this.timeManager.now(),
|
|
2691
|
-
|
|
2692
|
-
data: { type: e.type, 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
|
|
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
|
-
...
|
|
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,
|
|
2712
|
-
if (
|
|
2713
|
-
const Q = mt(l,
|
|
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),
|
|
2722
|
-
return
|
|
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,
|
|
2729
|
-
e -
|
|
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,
|
|
2741
|
-
t += `_click_${s}_${
|
|
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((
|
|
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((
|
|
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(),
|
|
2789
|
-
return
|
|
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) : (
|
|
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 ((...
|
|
2838
|
+
return ((...n) => {
|
|
2839
2839
|
s !== null && clearTimeout(s), s = setTimeout(() => {
|
|
2840
|
-
e(...
|
|
2840
|
+
e(...n), s = null;
|
|
2841
2841
|
}, t);
|
|
2842
2842
|
});
|
|
2843
2843
|
}
|
|
@@ -2887,29 +2887,29 @@ class vs extends _ {
|
|
|
2887
2887
|
loadSessionCounts(e) {
|
|
2888
2888
|
if (typeof window > "u" || typeof localStorage > "u")
|
|
2889
2889
|
return this.getInitialCounts();
|
|
2890
|
-
const t = this.get("userId") || "anonymous", s =
|
|
2890
|
+
const t = this.get("userId") || "anonymous", s = Fe(t, e);
|
|
2891
2891
|
try {
|
|
2892
|
-
const
|
|
2893
|
-
if (!
|
|
2892
|
+
const n = localStorage.getItem(s);
|
|
2893
|
+
if (!n)
|
|
2894
2894
|
return this.getInitialCounts();
|
|
2895
|
-
const
|
|
2896
|
-
return
|
|
2897
|
-
data: { sessionId: e, age: Date.now() -
|
|
2898
|
-
}), localStorage.removeItem(s), this.getInitialCounts()) : typeof
|
|
2899
|
-
total:
|
|
2900
|
-
[u.CLICK]:
|
|
2901
|
-
[u.PAGE_VIEW]:
|
|
2902
|
-
[u.CUSTOM]:
|
|
2903
|
-
[u.VIEWPORT_VISIBLE]:
|
|
2904
|
-
[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:
|
|
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:
|
|
2908
|
+
data: { sessionId: e, parsed: i }
|
|
2909
2909
|
}), this.getInitialCounts());
|
|
2910
|
-
} catch (
|
|
2910
|
+
} catch (n) {
|
|
2911
2911
|
return a("warn", "Failed to load session counts from localStorage", {
|
|
2912
|
-
error:
|
|
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
|
|
2944
|
-
if (
|
|
2943
|
+
const i = Date.now() - parseInt(e, 10);
|
|
2944
|
+
if (i < Be) {
|
|
2945
2945
|
a("debug", "Skipping session counts cleanup (throttled)", {
|
|
2946
|
-
data: { timeSinceLastCleanup:
|
|
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:`,
|
|
2952
|
-
for (let
|
|
2953
|
-
const o = localStorage.key(
|
|
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 &&
|
|
2959
|
+
c._timestamp && Date.now() - c._timestamp > xe && n.push(o);
|
|
2960
2960
|
}
|
|
2961
2961
|
} catch {
|
|
2962
2962
|
}
|
|
2963
2963
|
}
|
|
2964
|
-
|
|
2965
|
-
localStorage.removeItem(
|
|
2966
|
-
}),
|
|
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
|
}
|
|
@@ -2997,17 +2997,17 @@ class vs extends _ {
|
|
|
2997
2997
|
* @internal
|
|
2998
2998
|
*/
|
|
2999
2999
|
saveSessionCounts(e) {
|
|
3000
|
-
const t = this.get("userId") || "anonymous", s =
|
|
3000
|
+
const t = this.get("userId") || "anonymous", s = Fe(t, e);
|
|
3001
3001
|
try {
|
|
3002
|
-
const
|
|
3002
|
+
const n = {
|
|
3003
3003
|
...this.sessionEventCounts,
|
|
3004
3004
|
_timestamp: Date.now(),
|
|
3005
3005
|
_version: 1
|
|
3006
3006
|
};
|
|
3007
|
-
localStorage.setItem(s, JSON.stringify(
|
|
3008
|
-
} catch (
|
|
3007
|
+
localStorage.setItem(s, JSON.stringify(n));
|
|
3008
|
+
} catch (n) {
|
|
3009
3009
|
a("warn", "Failed to persist session counts to localStorage", {
|
|
3010
|
-
error:
|
|
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:
|
|
3070
|
-
o === e && (s === "session_start" &&
|
|
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,
|
|
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
|
-
...
|
|
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
|
|
3112
|
-
if (
|
|
3113
|
-
return
|
|
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
|
|
3121
|
-
if (
|
|
3122
|
-
return
|
|
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,
|
|
3196
|
+
let s, n;
|
|
3197
3197
|
if (e) {
|
|
3198
|
-
const
|
|
3199
|
-
s =
|
|
3198
|
+
const i = this.loadStoredSession();
|
|
3199
|
+
s = i?.referrer ?? me(), n = i?.utm ?? ge();
|
|
3200
3200
|
} else
|
|
3201
|
-
s = me(),
|
|
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: !!
|
|
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",
|
|
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 (
|
|
3220
|
-
throw this.isTracking = !1, this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupLifecycleListeners(), this.cleanupCrossTabSync(), this.set("sessionId", null),
|
|
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(),
|
|
3505
|
-
if (s - this.lastPageViewTime <
|
|
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
|
|
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:
|
|
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:
|
|
3528
|
-
return !
|
|
3529
|
-
...
|
|
3530
|
-
...
|
|
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,
|
|
3561
|
-
if (!
|
|
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(
|
|
3565
|
+
if (this.shouldIgnoreElement(n))
|
|
3566
3566
|
return;
|
|
3567
|
-
const
|
|
3568
|
-
if (
|
|
3567
|
+
const i = this.get("config")?.clickThrottleMs ?? 300;
|
|
3568
|
+
if (i > 0 && !this.checkClickThrottle(n, i))
|
|
3569
3569
|
return;
|
|
3570
|
-
const o = this.findTrackingElement(
|
|
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(
|
|
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),
|
|
3609
|
-
this.pruneThrottleCache(
|
|
3610
|
-
const
|
|
3611
|
-
return
|
|
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 - (
|
|
3614
|
+
throttleRemaining: t - (n - i)
|
|
3615
3615
|
}
|
|
3616
|
-
}), !1) : (this.lastClickTimes.set(s,
|
|
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,
|
|
3629
|
-
|
|
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]),
|
|
3632
|
-
for (const [o] of
|
|
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:
|
|
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
|
|
3662
|
+
let n = s.tagName.toLowerCase();
|
|
3663
3663
|
if (s.className) {
|
|
3664
|
-
const
|
|
3665
|
-
|
|
3664
|
+
const i = s.className.split(" ")[0];
|
|
3665
|
+
i && (n += `.${i}`);
|
|
3666
3666
|
}
|
|
3667
|
-
t.unshift(
|
|
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(),
|
|
3704
|
-
return { x:
|
|
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:
|
|
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:
|
|
3719
|
-
y:
|
|
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
|
|
3757
|
-
t = t.replace(
|
|
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() ?? "",
|
|
3763
|
-
if (!s && !
|
|
3762
|
+
const s = e.textContent?.trim() ?? "", n = t.textContent?.trim() ?? "";
|
|
3763
|
+
if (!s && !n)
|
|
3764
3764
|
return "";
|
|
3765
|
-
let
|
|
3766
|
-
return s && s.length <= 255 ?
|
|
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
|
|
3782
|
-
const
|
|
3783
|
-
|
|
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
|
|
3842
|
-
this.setupScrollContainer(s,
|
|
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: (
|
|
3864
|
-
const
|
|
3865
|
-
if (!
|
|
3863
|
+
acceptNode: (n) => {
|
|
3864
|
+
const i = n;
|
|
3865
|
+
if (!i.isConnected || !i.offsetParent)
|
|
3866
3866
|
return NodeFilter.FILTER_SKIP;
|
|
3867
|
-
const o = getComputedStyle(
|
|
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
|
|
3874
|
-
this.isElementScrollable(
|
|
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((
|
|
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
|
|
3898
|
-
|
|
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:
|
|
3906
|
-
lastDepth:
|
|
3905
|
+
lastScrollPos: n,
|
|
3906
|
+
lastDepth: i,
|
|
3907
3907
|
lastDirection: Z.DOWN,
|
|
3908
3908
|
lastEventTime: 0,
|
|
3909
3909
|
firstScrollEventTime: null,
|
|
3910
|
-
maxDepthReached:
|
|
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
|
|
3930
|
-
this.set("scrollEventCount",
|
|
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
|
|
3972
|
-
return Math.min(100, Math.max(0, Math.floor(e /
|
|
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:
|
|
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(
|
|
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
|
-
|
|
3981
|
-
const
|
|
3982
|
-
return g > e.maxDepthReached && (e.maxDepthReached = g), e.lastScrollPos =
|
|
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:
|
|
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",
|
|
4000
|
-
return s &&
|
|
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
|
|
4008
|
-
if (!(
|
|
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 =
|
|
4012
|
+
t = n;
|
|
4013
4013
|
}
|
|
4014
|
-
this.containers.forEach((
|
|
4015
|
-
this.updateContainerPrimary(
|
|
4016
|
-
}), !this.containers.some((
|
|
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
|
|
4075
|
-
for (const
|
|
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
|
-
|
|
4087
|
-
element:
|
|
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(
|
|
4094
|
+
}), this.observer?.observe(i), t++);
|
|
4095
4095
|
}
|
|
4096
|
-
} catch (
|
|
4097
|
-
a("debug", `ViewportHandler: Invalid selector "${s.selector}"`, { error:
|
|
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
|
|
4111
|
-
|
|
4112
|
-
const
|
|
4113
|
-
this.fireViewportEvent(
|
|
4114
|
-
}, t)) :
|
|
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
|
|
4126
|
-
if (e.lastFiredTime !== null &&
|
|
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:
|
|
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 =
|
|
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,8 +4172,8 @@ class Cs extends _ {
|
|
|
4172
4172
|
cleanupRemovedNodes(e) {
|
|
4173
4173
|
e.forEach((t) => {
|
|
4174
4174
|
if (t.nodeType !== 1) return;
|
|
4175
|
-
const s = t,
|
|
4176
|
-
|
|
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
|
});
|
|
@@ -4183,12 +4183,14 @@ class Cs extends _ {
|
|
|
4183
4183
|
const Rs = "tracelog_session_id", Ns = "tracelog_user_id";
|
|
4184
4184
|
class Os extends _ {
|
|
4185
4185
|
visibilityHandler = null;
|
|
4186
|
+
pageshowHandler = null;
|
|
4187
|
+
submitHandler = null;
|
|
4186
4188
|
lastSyncedKey = null;
|
|
4187
4189
|
activate() {
|
|
4188
|
-
this.
|
|
4190
|
+
this.cleanupListeners(), this.syncCartAttribute(), this.setupListeners();
|
|
4189
4191
|
}
|
|
4190
4192
|
deactivate() {
|
|
4191
|
-
this.
|
|
4193
|
+
this.cleanupListeners(), this.lastSyncedKey = null;
|
|
4192
4194
|
}
|
|
4193
4195
|
/** Re-syncs cart attributes when session rotates (called by App on SESSION_START). */
|
|
4194
4196
|
onSessionChange() {
|
|
@@ -4197,8 +4199,8 @@ class Os extends _ {
|
|
|
4197
4199
|
syncCartAttribute() {
|
|
4198
4200
|
const e = this.get("sessionId");
|
|
4199
4201
|
if (!e) return;
|
|
4200
|
-
const t = this.get("userId"), s = typeof t == "string" && t.length > 0 ? t : "",
|
|
4201
|
-
|
|
4202
|
+
const t = this.get("userId"), s = typeof t == "string" && t.length > 0 ? t : "", n = `${e}|${s}`;
|
|
4203
|
+
n !== this.lastSyncedKey && (this.lastSyncedKey = n, this.postCartUpdate(e, s));
|
|
4202
4204
|
}
|
|
4203
4205
|
postCartUpdate(e, t) {
|
|
4204
4206
|
const s = { [Rs]: e };
|
|
@@ -4209,8 +4211,8 @@ class Os extends _ {
|
|
|
4209
4211
|
headers: { "Content-Type": "application/json" },
|
|
4210
4212
|
body: JSON.stringify({ attributes: s }),
|
|
4211
4213
|
credentials: "same-origin"
|
|
4212
|
-
}).then((
|
|
4213
|
-
|
|
4214
|
+
}).then((n) => {
|
|
4215
|
+
n.ok || (this.lastSyncedKey = null, a("debug", "Shopify cart attribute update failed", { data: { status: n.status } }));
|
|
4214
4216
|
}).catch(() => {
|
|
4215
4217
|
this.lastSyncedKey = null, a("debug", "Shopify cart attribute update failed");
|
|
4216
4218
|
});
|
|
@@ -4218,13 +4220,31 @@ class Os extends _ {
|
|
|
4218
4220
|
this.lastSyncedKey = null, a("debug", "Shopify cart attribute update failed");
|
|
4219
4221
|
}
|
|
4220
4222
|
}
|
|
4221
|
-
|
|
4223
|
+
/**
|
|
4224
|
+
* Sync triggers (theme-agnostic, no monkey-patching):
|
|
4225
|
+
*
|
|
4226
|
+
* - `visibilitychange`: catches tab refocus (long sessions, OAuth round-trips).
|
|
4227
|
+
* - `pageshow`: catches bfcache restore — Shopify's "Buy It Now" redirects keep
|
|
4228
|
+
* the original product page in bfcache; on back-navigation Shopify may reuse
|
|
4229
|
+
* the cart without re-running scripts.
|
|
4230
|
+
* - `submit` (capture-phase, document-level): fires before any product form
|
|
4231
|
+
* submission (add-to-cart, buy-now). This maximizes the chance that the cart
|
|
4232
|
+
* attribute write completes before the page navigates to /cart or /checkout.
|
|
4233
|
+
*
|
|
4234
|
+
* All triggers go through `syncCartAttribute()` which dedupes by
|
|
4235
|
+
* `sessionId|userId`, so spurious calls are cheap (early-return).
|
|
4236
|
+
*/
|
|
4237
|
+
setupListeners() {
|
|
4222
4238
|
this.visibilityHandler = () => {
|
|
4223
4239
|
document.hidden || this.syncCartAttribute();
|
|
4224
|
-
}, document.addEventListener("visibilitychange", this.visibilityHandler)
|
|
4240
|
+
}, document.addEventListener("visibilitychange", this.visibilityHandler), this.pageshowHandler = (e) => {
|
|
4241
|
+
e.persisted && this.syncCartAttribute();
|
|
4242
|
+
}, window.addEventListener("pageshow", this.pageshowHandler), this.submitHandler = () => {
|
|
4243
|
+
this.syncCartAttribute();
|
|
4244
|
+
}, document.addEventListener("submit", this.submitHandler, !0);
|
|
4225
4245
|
}
|
|
4226
|
-
|
|
4227
|
-
this.visibilityHandler && (document.removeEventListener("visibilitychange", this.visibilityHandler), this.visibilityHandler = null);
|
|
4246
|
+
cleanupListeners() {
|
|
4247
|
+
this.visibilityHandler && (document.removeEventListener("visibilitychange", this.visibilityHandler), this.visibilityHandler = null), this.pageshowHandler && (window.removeEventListener("pageshow", this.pageshowHandler), this.pageshowHandler = null), this.submitHandler && (document.removeEventListener("submit", this.submitHandler, !0), this.submitHandler = null);
|
|
4228
4248
|
}
|
|
4229
4249
|
}
|
|
4230
4250
|
class Ps {
|
|
@@ -4396,19 +4416,19 @@ class Ps {
|
|
|
4396
4416
|
return !1;
|
|
4397
4417
|
try {
|
|
4398
4418
|
const e = [], t = [];
|
|
4399
|
-
for (let
|
|
4400
|
-
const o = this.storage.key(
|
|
4419
|
+
for (let i = 0; i < this.storage.length; i++) {
|
|
4420
|
+
const o = this.storage.key(i);
|
|
4401
4421
|
o?.startsWith("tracelog_") && (e.push(o), o.startsWith("tracelog_persisted_events_") && t.push(o));
|
|
4402
4422
|
}
|
|
4403
4423
|
if (t.length > 0)
|
|
4404
|
-
return t.forEach((
|
|
4424
|
+
return t.forEach((i) => {
|
|
4405
4425
|
try {
|
|
4406
|
-
this.storage.removeItem(
|
|
4426
|
+
this.storage.removeItem(i);
|
|
4407
4427
|
} catch {
|
|
4408
4428
|
}
|
|
4409
4429
|
}), !0;
|
|
4410
|
-
const s = ["tracelog_session_", "tracelog_user_id", "tracelog_device_id", "tracelog_config"],
|
|
4411
|
-
return
|
|
4430
|
+
const s = ["tracelog_session_", "tracelog_user_id", "tracelog_device_id", "tracelog_config"], n = e.filter((i) => !s.some((o) => i.startsWith(o)));
|
|
4431
|
+
return n.length > 0 ? (n.slice(0, 5).forEach((o) => {
|
|
4412
4432
|
try {
|
|
4413
4433
|
this.storage.removeItem(o);
|
|
4414
4434
|
} catch {
|
|
@@ -4563,8 +4583,8 @@ class Ds extends _ {
|
|
|
4563
4583
|
this.reportTTFB(), this.safeObserve(
|
|
4564
4584
|
"largest-contentful-paint",
|
|
4565
4585
|
(s) => {
|
|
4566
|
-
const
|
|
4567
|
-
|
|
4586
|
+
const n = s.getEntries(), i = n[n.length - 1];
|
|
4587
|
+
i && this.sendVital({ type: "LCP", value: Number(i.startTime.toFixed(2)) });
|
|
4568
4588
|
},
|
|
4569
4589
|
{ type: "largest-contentful-paint", buffered: !0 },
|
|
4570
4590
|
!0
|
|
@@ -4573,10 +4593,10 @@ class Ds extends _ {
|
|
|
4573
4593
|
this.safeObserve(
|
|
4574
4594
|
"layout-shift",
|
|
4575
4595
|
(s) => {
|
|
4576
|
-
const
|
|
4577
|
-
|
|
4578
|
-
const
|
|
4579
|
-
for (const o of
|
|
4596
|
+
const n = this.getNavigationId();
|
|
4597
|
+
n !== t && (e = 0, t = n);
|
|
4598
|
+
const i = s.getEntries();
|
|
4599
|
+
for (const o of i) {
|
|
4580
4600
|
if (o.hadRecentInput === !0)
|
|
4581
4601
|
continue;
|
|
4582
4602
|
const l = typeof o.value == "number" ? o.value : 0;
|
|
@@ -4588,32 +4608,32 @@ class Ds extends _ {
|
|
|
4588
4608
|
), this.safeObserve(
|
|
4589
4609
|
"paint",
|
|
4590
4610
|
(s) => {
|
|
4591
|
-
for (const
|
|
4592
|
-
|
|
4611
|
+
for (const n of s.getEntries())
|
|
4612
|
+
n.name === "first-contentful-paint" && this.sendVital({ type: "FCP", value: Number(n.startTime.toFixed(2)) });
|
|
4593
4613
|
},
|
|
4594
4614
|
{ type: "paint", buffered: !0 },
|
|
4595
4615
|
!0
|
|
4596
4616
|
), this.safeObserve(
|
|
4597
4617
|
"event",
|
|
4598
4618
|
(s) => {
|
|
4599
|
-
let
|
|
4600
|
-
const
|
|
4601
|
-
for (const o of
|
|
4619
|
+
let n = 0;
|
|
4620
|
+
const i = s.getEntries();
|
|
4621
|
+
for (const o of i) {
|
|
4602
4622
|
const l = (o.processingEnd ?? 0) - (o.startTime ?? 0);
|
|
4603
|
-
|
|
4623
|
+
n = Math.max(n, l);
|
|
4604
4624
|
}
|
|
4605
|
-
|
|
4625
|
+
n > 0 && this.sendVital({ type: "INP", value: Number(n.toFixed(2)) });
|
|
4606
4626
|
},
|
|
4607
4627
|
{ type: "event", buffered: !0 }
|
|
4608
4628
|
);
|
|
4609
4629
|
}
|
|
4610
4630
|
async initWebVitals() {
|
|
4611
4631
|
try {
|
|
4612
|
-
const { onLCP: e, onCLS: t, onFCP: s, onTTFB:
|
|
4632
|
+
const { onLCP: e, onCLS: t, onFCP: s, onTTFB: n, onINP: i } = await Promise.resolve().then(() => hr), o = (l) => (c) => {
|
|
4613
4633
|
const d = Number(c.value.toFixed(2));
|
|
4614
4634
|
this.sendVital({ type: l, value: d });
|
|
4615
4635
|
};
|
|
4616
|
-
e(o("LCP"), { reportAllChanges: !1 }), t(o("CLS"), { reportAllChanges: !1 }), s(o("FCP"), { reportAllChanges: !1 }),
|
|
4636
|
+
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 });
|
|
4617
4637
|
} catch (e) {
|
|
4618
4638
|
a("debug", "Failed to load web-vitals library, using fallback", { error: e }), this.observeWebVitalsFallback();
|
|
4619
4639
|
}
|
|
@@ -4635,8 +4655,8 @@ class Ds extends _ {
|
|
|
4635
4655
|
(e) => {
|
|
4636
4656
|
const t = e.getEntries();
|
|
4637
4657
|
for (const s of t) {
|
|
4638
|
-
const
|
|
4639
|
-
|
|
4658
|
+
const n = Number(s.duration.toFixed(2)), i = Date.now();
|
|
4659
|
+
i - this.lastLongTaskSentAt >= qt && (this.shouldSendVital("LONG_TASK", n) && this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = i);
|
|
4640
4660
|
}
|
|
4641
4661
|
},
|
|
4642
4662
|
{ type: "longtask", buffered: !0 }
|
|
@@ -4653,8 +4673,8 @@ class Ds extends _ {
|
|
|
4653
4673
|
if (s)
|
|
4654
4674
|
s.add(e.type);
|
|
4655
4675
|
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length > Jt) {
|
|
4656
|
-
const
|
|
4657
|
-
|
|
4676
|
+
const i = this.navigationHistory.shift();
|
|
4677
|
+
i && this.reportedByNav.delete(i);
|
|
4658
4678
|
}
|
|
4659
4679
|
}
|
|
4660
4680
|
this.trackWebVital(e.type, e.value);
|
|
@@ -4698,8 +4718,8 @@ class Ds extends _ {
|
|
|
4698
4718
|
const e = performance.getEntriesByType("navigation")[0];
|
|
4699
4719
|
if (!e)
|
|
4700
4720
|
return null;
|
|
4701
|
-
const t = e.startTime || performance.now(), s = ++this.navigationCounter,
|
|
4702
|
-
return s > 1 ? `${
|
|
4721
|
+
const t = e.startTime || performance.now(), s = ++this.navigationCounter, n = `${t.toFixed(2)}_${window.location.pathname}`;
|
|
4722
|
+
return s > 1 ? `${n}_${s}` : n;
|
|
4703
4723
|
} catch (e) {
|
|
4704
4724
|
return a("debug", "Failed to get navigation ID", { error: e }), null;
|
|
4705
4725
|
}
|
|
@@ -4709,11 +4729,11 @@ class Ds extends _ {
|
|
|
4709
4729
|
const t = PerformanceObserver.supportedEntryTypes;
|
|
4710
4730
|
return !t || t.includes(e);
|
|
4711
4731
|
}
|
|
4712
|
-
safeObserve(e, t, s,
|
|
4732
|
+
safeObserve(e, t, s, n = !1) {
|
|
4713
4733
|
try {
|
|
4714
4734
|
if (!this.isObserverSupported(e))
|
|
4715
4735
|
return !1;
|
|
4716
|
-
const
|
|
4736
|
+
const i = new PerformanceObserver((o, l) => {
|
|
4717
4737
|
try {
|
|
4718
4738
|
t(o, l);
|
|
4719
4739
|
} catch (c) {
|
|
@@ -4722,16 +4742,16 @@ class Ds extends _ {
|
|
|
4722
4742
|
data: { type: e }
|
|
4723
4743
|
});
|
|
4724
4744
|
}
|
|
4725
|
-
if (
|
|
4745
|
+
if (n)
|
|
4726
4746
|
try {
|
|
4727
4747
|
l.disconnect();
|
|
4728
4748
|
} catch {
|
|
4729
4749
|
}
|
|
4730
4750
|
});
|
|
4731
|
-
return
|
|
4732
|
-
} catch (
|
|
4751
|
+
return i.observe(s ?? { type: e, buffered: !0 }), n || this.observers.push(i), !0;
|
|
4752
|
+
} catch (i) {
|
|
4733
4753
|
return a("debug", "Failed to create performance observer", {
|
|
4734
|
-
error:
|
|
4754
|
+
error: i,
|
|
4735
4755
|
data: { type: e }
|
|
4736
4756
|
}), !1;
|
|
4737
4757
|
}
|
|
@@ -4814,13 +4834,13 @@ class ae extends _ {
|
|
|
4814
4834
|
const t = this.extractRejectionMessage(e.reason), s = this.sanitize(t);
|
|
4815
4835
|
if (this.shouldSuppressError(B.PROMISE_REJECTION, s))
|
|
4816
4836
|
return;
|
|
4817
|
-
const
|
|
4837
|
+
const n = e.reason instanceof Error && typeof e.reason.stack == "string" ? this.truncateStack(e.reason.stack) : void 0;
|
|
4818
4838
|
this.eventManager.track({
|
|
4819
4839
|
type: u.ERROR,
|
|
4820
4840
|
error_data: {
|
|
4821
4841
|
type: B.PROMISE_REJECTION,
|
|
4822
4842
|
message: s,
|
|
4823
|
-
...
|
|
4843
|
+
...n !== void 0 && { stack: n }
|
|
4824
4844
|
}
|
|
4825
4845
|
});
|
|
4826
4846
|
};
|
|
@@ -4844,14 +4864,14 @@ class ae extends _ {
|
|
|
4844
4864
|
sanitizePii(e) {
|
|
4845
4865
|
let t = e;
|
|
4846
4866
|
for (const s of at) {
|
|
4847
|
-
const
|
|
4848
|
-
t = t.replace(
|
|
4867
|
+
const n = new RegExp(s.source, s.flags);
|
|
4868
|
+
t = t.replace(n, "[REDACTED]");
|
|
4849
4869
|
}
|
|
4850
4870
|
return t;
|
|
4851
4871
|
}
|
|
4852
4872
|
shouldSuppressError(e, t) {
|
|
4853
|
-
const s = Date.now(),
|
|
4854
|
-
return
|
|
4873
|
+
const s = Date.now(), n = `${e}:${t}`, i = this.recentErrors.get(n);
|
|
4874
|
+
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));
|
|
4855
4875
|
}
|
|
4856
4876
|
static TRUNCATION_SUFFIX = `
|
|
4857
4877
|
...truncated`;
|
|
@@ -4862,14 +4882,14 @@ class ae extends _ {
|
|
|
4862
4882
|
}
|
|
4863
4883
|
pruneOldErrors() {
|
|
4864
4884
|
const e = Date.now();
|
|
4865
|
-
for (const [
|
|
4866
|
-
e -
|
|
4885
|
+
for (const [n, i] of this.recentErrors.entries())
|
|
4886
|
+
e - i > je && this.recentErrors.delete(n);
|
|
4867
4887
|
if (this.recentErrors.size <= ee)
|
|
4868
4888
|
return;
|
|
4869
|
-
const t = Array.from(this.recentErrors.entries()).sort((
|
|
4870
|
-
for (let
|
|
4871
|
-
const
|
|
4872
|
-
|
|
4889
|
+
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), s = this.recentErrors.size - ee;
|
|
4890
|
+
for (let n = 0; n < s; n += 1) {
|
|
4891
|
+
const i = t[n];
|
|
4892
|
+
i && this.recentErrors.delete(i[0]);
|
|
4873
4893
|
}
|
|
4874
4894
|
}
|
|
4875
4895
|
}
|
|
@@ -4877,7 +4897,7 @@ class ks extends _ {
|
|
|
4877
4897
|
isInitialized = !1;
|
|
4878
4898
|
suppressNextScrollTimer = null;
|
|
4879
4899
|
pageUnloadHandler = null;
|
|
4880
|
-
emitter = new
|
|
4900
|
+
emitter = new Es();
|
|
4881
4901
|
transformers = {};
|
|
4882
4902
|
customHeadersProvider;
|
|
4883
4903
|
managers = {};
|
|
@@ -4907,8 +4927,8 @@ class ks extends _ {
|
|
|
4907
4927
|
t,
|
|
4908
4928
|
this.customHeadersProvider,
|
|
4909
4929
|
s
|
|
4910
|
-
), this.loadPersistedIdentity(), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((
|
|
4911
|
-
a("warn", "Failed to recover persisted events", { error:
|
|
4930
|
+
), this.loadPersistedIdentity(), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((n) => {
|
|
4931
|
+
a("warn", "Failed to recover persisted events", { error: n });
|
|
4912
4932
|
}), this.isInitialized = !0, { sessionId: this.get("sessionId") ?? "" };
|
|
4913
4933
|
} catch (t) {
|
|
4914
4934
|
this.destroy(!0);
|
|
@@ -4930,11 +4950,11 @@ class ks extends _ {
|
|
|
4930
4950
|
}
|
|
4931
4951
|
let s = t;
|
|
4932
4952
|
t && typeof t == "object" && !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && (s = Object.assign({}, t));
|
|
4933
|
-
const { valid:
|
|
4934
|
-
if (!
|
|
4935
|
-
if (this.get("mode") ===
|
|
4936
|
-
throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${
|
|
4937
|
-
a("warn", `Custom event "${e}" dropped: ${
|
|
4953
|
+
const { valid: n, error: i, sanitizedMetadata: o } = ps(e, s);
|
|
4954
|
+
if (!n) {
|
|
4955
|
+
if (this.get("mode") === ie.QA)
|
|
4956
|
+
throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${i}`);
|
|
4957
|
+
a("warn", `Custom event "${e}" dropped: ${i}`);
|
|
4938
4958
|
return;
|
|
4939
4959
|
}
|
|
4940
4960
|
this.managers.event.track({
|
|
@@ -5004,10 +5024,10 @@ class ks extends _ {
|
|
|
5004
5024
|
this.set("userId", t);
|
|
5005
5025
|
const s = ls(e);
|
|
5006
5026
|
this.set("collectApiUrls", s);
|
|
5007
|
-
const
|
|
5008
|
-
this.set("device",
|
|
5009
|
-
const
|
|
5010
|
-
this.set("pageUrl",
|
|
5027
|
+
const n = Xt();
|
|
5028
|
+
this.set("device", n);
|
|
5029
|
+
const i = ye(window.location.href, e.sensitiveQueryParams);
|
|
5030
|
+
this.set("pageUrl", i), ss() && this.set("mode", ie.QA);
|
|
5011
5031
|
}
|
|
5012
5032
|
/**
|
|
5013
5033
|
* Returns the current configuration object.
|
|
@@ -5075,11 +5095,11 @@ class ks extends _ {
|
|
|
5075
5095
|
const t = this.validateGlobalMetadata(e);
|
|
5076
5096
|
if (!t.valid)
|
|
5077
5097
|
throw new Error(`[TraceLog] Invalid global metadata: ${t.error}`);
|
|
5078
|
-
const
|
|
5098
|
+
const n = {
|
|
5079
5099
|
...this.get("config"),
|
|
5080
5100
|
globalMetadata: e
|
|
5081
5101
|
};
|
|
5082
|
-
this.set("config",
|
|
5102
|
+
this.set("config", n), a("debug", "Global metadata updated (replaced)", { data: { keys: Object.keys(e) } });
|
|
5083
5103
|
}
|
|
5084
5104
|
/**
|
|
5085
5105
|
* Merges new metadata with existing global metadata.
|
|
@@ -5092,12 +5112,12 @@ class ks extends _ {
|
|
|
5092
5112
|
const t = this.validateGlobalMetadata(e);
|
|
5093
5113
|
if (!t.valid)
|
|
5094
5114
|
throw new Error(`[TraceLog] Invalid global metadata: ${t.error}`);
|
|
5095
|
-
const s = this.get("config"),
|
|
5115
|
+
const s = this.get("config"), i = {
|
|
5096
5116
|
...s.globalMetadata ?? {},
|
|
5097
5117
|
...e
|
|
5098
5118
|
}, o = {
|
|
5099
5119
|
...s,
|
|
5100
|
-
globalMetadata:
|
|
5120
|
+
globalMetadata: i
|
|
5101
5121
|
};
|
|
5102
5122
|
this.set("config", o), a("debug", "Global metadata updated (merged)", { data: { keys: Object.keys(e) } });
|
|
5103
5123
|
}
|
|
@@ -5125,12 +5145,12 @@ class ks extends _ {
|
|
|
5125
5145
|
a("warn", "identify() userId exceeds 256 characters", { data: { length: e.trim().length } });
|
|
5126
5146
|
return;
|
|
5127
5147
|
}
|
|
5128
|
-
const s = e.trim(),
|
|
5148
|
+
const s = e.trim(), n = ht(t), i = {
|
|
5129
5149
|
userId: s,
|
|
5130
|
-
...
|
|
5150
|
+
...n ? { traits: n } : {}
|
|
5131
5151
|
};
|
|
5132
|
-
this.set("identity",
|
|
5133
|
-
data: { userIdLength: s.length, traitKeys:
|
|
5152
|
+
this.set("identity", i), this.persistIdentity(i), a("debug", "Visitor identified", {
|
|
5153
|
+
data: { userIdLength: s.length, traitKeys: n ? Object.keys(n) : [] }
|
|
5134
5154
|
});
|
|
5135
5155
|
}
|
|
5136
5156
|
/**
|
|
@@ -5172,14 +5192,14 @@ class ks extends _ {
|
|
|
5172
5192
|
loadPersistedIdentity() {
|
|
5173
5193
|
const e = this.managers.storage, t = this.getProjectId(), s = fe(t);
|
|
5174
5194
|
try {
|
|
5175
|
-
const
|
|
5176
|
-
if (
|
|
5177
|
-
const
|
|
5178
|
-
if (e.removeItem(U), !this.isValidIdentityData(
|
|
5195
|
+
const n = e.getItem(U);
|
|
5196
|
+
if (n) {
|
|
5197
|
+
const i = JSON.parse(n);
|
|
5198
|
+
if (e.removeItem(U), !this.isValidIdentityData(i)) {
|
|
5179
5199
|
a("debug", "Invalid pending identity in localStorage, discarded");
|
|
5180
5200
|
return;
|
|
5181
5201
|
}
|
|
5182
|
-
const o = { ...
|
|
5202
|
+
const o = { ...i, userId: i.userId.trim() };
|
|
5183
5203
|
e.setItem(s, JSON.stringify(o)), this.set("identity", o), a("debug", "Migrated pending identity to project-scoped key");
|
|
5184
5204
|
return;
|
|
5185
5205
|
}
|
|
@@ -5187,14 +5207,14 @@ class ks extends _ {
|
|
|
5187
5207
|
e.removeItem(U);
|
|
5188
5208
|
}
|
|
5189
5209
|
try {
|
|
5190
|
-
const
|
|
5191
|
-
if (
|
|
5192
|
-
const
|
|
5193
|
-
if (!this.isValidIdentityData(
|
|
5210
|
+
const n = e.getItem(s);
|
|
5211
|
+
if (n) {
|
|
5212
|
+
const i = JSON.parse(n);
|
|
5213
|
+
if (!this.isValidIdentityData(i)) {
|
|
5194
5214
|
e.removeItem(s), a("debug", "Invalid persisted identity in localStorage, discarded");
|
|
5195
5215
|
return;
|
|
5196
5216
|
}
|
|
5197
|
-
const o = { ...
|
|
5217
|
+
const o = { ...i, userId: i.userId.trim() };
|
|
5198
5218
|
this.set("identity", o), a("debug", "Loaded persisted identity");
|
|
5199
5219
|
}
|
|
5200
5220
|
} catch {
|
|
@@ -5211,8 +5231,8 @@ class ks extends _ {
|
|
|
5211
5231
|
if (typeof t != "string" || t.trim().length === 0 || t.trim().length > 256) return !1;
|
|
5212
5232
|
if (s !== void 0) {
|
|
5213
5233
|
if (typeof s != "object" || s === null || Array.isArray(s)) return !1;
|
|
5214
|
-
for (const
|
|
5215
|
-
if (typeof
|
|
5234
|
+
for (const n of Object.values(s))
|
|
5235
|
+
if (typeof n != "string") return !1;
|
|
5216
5236
|
}
|
|
5217
5237
|
return !0;
|
|
5218
5238
|
}
|
|
@@ -5247,8 +5267,8 @@ class ks extends _ {
|
|
|
5247
5267
|
a("warn", "Failed to start performance tracking", { error: s });
|
|
5248
5268
|
}), 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) {
|
|
5249
5269
|
const s = new Os();
|
|
5250
|
-
s.activate(), this.integrationInstances.shopifyCartLinker = s, this.emitter.on(se.EVENT, (
|
|
5251
|
-
|
|
5270
|
+
s.activate(), this.integrationInstances.shopifyCartLinker = s, this.emitter.on(se.EVENT, (n) => {
|
|
5271
|
+
n.type === u.SESSION_START && s.onSessionChange();
|
|
5252
5272
|
});
|
|
5253
5273
|
}
|
|
5254
5274
|
}
|
|
@@ -5264,17 +5284,17 @@ const Vs = async (r) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
5264
5284
|
}), k.length = 0, M.forEach(({ hook: o, fn: l }) => {
|
|
5265
5285
|
o === "beforeSend" ? t.setTransformer("beforeSend", l) : t.setTransformer("beforeBatch", l);
|
|
5266
5286
|
}), M.length = 0, D && (t.setCustomHeaders(D), D = null);
|
|
5267
|
-
const s = t.init(e),
|
|
5287
|
+
const s = t.init(e), n = new Promise((o, l) => {
|
|
5268
5288
|
setTimeout(() => {
|
|
5269
5289
|
l(new Error("[TraceLog] Initialization timeout after 10000ms"));
|
|
5270
5290
|
}, 1e4);
|
|
5271
|
-
}),
|
|
5272
|
-
return h = t,
|
|
5291
|
+
}), i = await Promise.race([s, n]);
|
|
5292
|
+
return h = t, i;
|
|
5273
5293
|
} catch (s) {
|
|
5274
5294
|
try {
|
|
5275
5295
|
t.destroy(!0);
|
|
5276
|
-
} catch (
|
|
5277
|
-
a("error", "Failed to cleanup partially initialized app", { error:
|
|
5296
|
+
} catch (n) {
|
|
5297
|
+
a("error", "Failed to cleanup partially initialized app", { error: n });
|
|
5278
5298
|
}
|
|
5279
5299
|
throw s;
|
|
5280
5300
|
}
|
|
@@ -5291,7 +5311,7 @@ const Vs = async (r) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
5291
5311
|
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
5292
5312
|
h.sendCustomEvent(r, e);
|
|
5293
5313
|
}
|
|
5294
|
-
},
|
|
5314
|
+
}, Hs = (r, e) => {
|
|
5295
5315
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5296
5316
|
if (!h || R) {
|
|
5297
5317
|
k.push({ event: r, callback: e });
|
|
@@ -5299,7 +5319,7 @@ const Vs = async (r) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
5299
5319
|
}
|
|
5300
5320
|
h.on(r, e);
|
|
5301
5321
|
}
|
|
5302
|
-
},
|
|
5322
|
+
}, Fs = (r, e) => {
|
|
5303
5323
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5304
5324
|
if (!h) {
|
|
5305
5325
|
const t = k.findIndex((s) => s.event === r && s.callback === e);
|
|
@@ -5433,8 +5453,8 @@ const $s = (r) => {
|
|
|
5433
5453
|
}, Lr = {
|
|
5434
5454
|
init: Vs,
|
|
5435
5455
|
event: Us,
|
|
5436
|
-
on:
|
|
5437
|
-
off:
|
|
5456
|
+
on: Hs,
|
|
5457
|
+
off: Fs,
|
|
5438
5458
|
setTransformer: xs,
|
|
5439
5459
|
removeTransformer: $s,
|
|
5440
5460
|
setCustomHeaders: Bs,
|
|
@@ -5448,9 +5468,9 @@ const $s = (r) => {
|
|
|
5448
5468
|
identify: Ys,
|
|
5449
5469
|
resetIdentity: qs
|
|
5450
5470
|
};
|
|
5451
|
-
var Le, C, G,
|
|
5471
|
+
var Le, C, G, pt, le, Et = -1, V = function(r) {
|
|
5452
5472
|
addEventListener("pageshow", (function(e) {
|
|
5453
|
-
e.persisted && (
|
|
5473
|
+
e.persisted && (Et = e.timeStamp, r(e));
|
|
5454
5474
|
}), !0);
|
|
5455
5475
|
}, Pe = function() {
|
|
5456
5476
|
var r = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
|
|
@@ -5460,13 +5480,13 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
|
|
|
5460
5480
|
return r && r.activationStart || 0;
|
|
5461
5481
|
}, y = function(r, e) {
|
|
5462
5482
|
var t = Pe(), s = "navigate";
|
|
5463
|
-
return
|
|
5464
|
-
},
|
|
5483
|
+
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 };
|
|
5484
|
+
}, F = function(r, e, t) {
|
|
5465
5485
|
try {
|
|
5466
5486
|
if (PerformanceObserver.supportedEntryTypes.includes(r)) {
|
|
5467
|
-
var s = new PerformanceObserver((function(
|
|
5487
|
+
var s = new PerformanceObserver((function(n) {
|
|
5468
5488
|
Promise.resolve().then((function() {
|
|
5469
|
-
e(
|
|
5489
|
+
e(n.getEntries());
|
|
5470
5490
|
}));
|
|
5471
5491
|
}));
|
|
5472
5492
|
return s.observe(Object.assign({ type: r, buffered: !0 }, t || {})), s;
|
|
@@ -5474,9 +5494,9 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
|
|
|
5474
5494
|
} catch {
|
|
5475
5495
|
}
|
|
5476
5496
|
}, w = function(r, e, t, s) {
|
|
5477
|
-
var
|
|
5497
|
+
var n, i;
|
|
5478
5498
|
return function(o) {
|
|
5479
|
-
e.value >= 0 && (o || s) && ((
|
|
5499
|
+
e.value >= 0 && (o || s) && ((i = e.value - (n || 0)) || n === void 0) && (n = e.value, e.delta = i, e.rating = (function(l, c) {
|
|
5480
5500
|
return l > c[1] ? "poor" : l > c[0] ? "needs-improvement" : "good";
|
|
5481
5501
|
})(e.value, t), r(e));
|
|
5482
5502
|
};
|
|
@@ -5495,21 +5515,21 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
|
|
|
5495
5515
|
return function() {
|
|
5496
5516
|
e || (r(), e = !0);
|
|
5497
5517
|
};
|
|
5498
|
-
},
|
|
5518
|
+
}, H = -1, et = function() {
|
|
5499
5519
|
return document.visibilityState !== "hidden" || document.prerendering ? 1 / 0 : 0;
|
|
5500
5520
|
}, ce = function(r) {
|
|
5501
|
-
document.visibilityState === "hidden" &&
|
|
5521
|
+
document.visibilityState === "hidden" && H > -1 && (H = r.type === "visibilitychange" ? r.timeStamp : 0, Js());
|
|
5502
5522
|
}, tt = function() {
|
|
5503
5523
|
addEventListener("visibilitychange", ce, !0), addEventListener("prerenderingchange", ce, !0);
|
|
5504
5524
|
}, Js = function() {
|
|
5505
5525
|
removeEventListener("visibilitychange", ce, !0), removeEventListener("prerenderingchange", ce, !0);
|
|
5506
5526
|
}, ke = function() {
|
|
5507
|
-
return
|
|
5527
|
+
return H < 0 && (H = et(), tt(), V((function() {
|
|
5508
5528
|
setTimeout((function() {
|
|
5509
|
-
|
|
5529
|
+
H = et(), tt();
|
|
5510
5530
|
}), 0);
|
|
5511
5531
|
}))), { get firstHiddenTime() {
|
|
5512
|
-
return
|
|
5532
|
+
return H;
|
|
5513
5533
|
} };
|
|
5514
5534
|
}, z = function(r) {
|
|
5515
5535
|
document.prerendering ? addEventListener("prerenderingchange", (function() {
|
|
@@ -5517,49 +5537,49 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
|
|
|
5517
5537
|
}), !0) : r();
|
|
5518
5538
|
}, Ae = [1800, 3e3], St = function(r, e) {
|
|
5519
5539
|
e = e || {}, z((function() {
|
|
5520
|
-
var t, s = ke(),
|
|
5540
|
+
var t, s = ke(), n = y("FCP"), i = F("paint", (function(o) {
|
|
5521
5541
|
o.forEach((function(l) {
|
|
5522
|
-
l.name === "first-contentful-paint" && (
|
|
5542
|
+
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)));
|
|
5523
5543
|
}));
|
|
5524
5544
|
}));
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5545
|
+
i && (t = w(r, n, Ae, e.reportAllChanges), V((function(o) {
|
|
5546
|
+
n = y("FCP"), t = w(r, n, Ae, e.reportAllChanges), De((function() {
|
|
5547
|
+
n.value = performance.now() - o.timeStamp, t(!0);
|
|
5528
5548
|
}));
|
|
5529
5549
|
})));
|
|
5530
5550
|
}));
|
|
5531
5551
|
}, Me = [0.1, 0.25], Zs = function(r, e) {
|
|
5532
5552
|
e = e || {}, St(ue((function() {
|
|
5533
|
-
var t, s = y("CLS", 0),
|
|
5553
|
+
var t, s = y("CLS", 0), n = 0, i = [], o = function(c) {
|
|
5534
5554
|
c.forEach((function(d) {
|
|
5535
5555
|
if (!d.hadRecentInput) {
|
|
5536
|
-
var f =
|
|
5537
|
-
|
|
5556
|
+
var f = i[0], g = i[i.length - 1];
|
|
5557
|
+
n && d.startTime - g.startTime < 1e3 && d.startTime - f.startTime < 5e3 ? (n += d.value, i.push(d)) : (n = d.value, i = [d]);
|
|
5538
5558
|
}
|
|
5539
|
-
})),
|
|
5540
|
-
}, l =
|
|
5559
|
+
})), n > s.value && (s.value = n, s.entries = i, t());
|
|
5560
|
+
}, l = F("layout-shift", o);
|
|
5541
5561
|
l && (t = w(r, s, Me, e.reportAllChanges), K((function() {
|
|
5542
5562
|
o(l.takeRecords()), t(!0);
|
|
5543
5563
|
})), V((function() {
|
|
5544
|
-
|
|
5564
|
+
n = 0, s = y("CLS", 0), t = w(r, s, Me, e.reportAllChanges), De((function() {
|
|
5545
5565
|
return t();
|
|
5546
5566
|
}));
|
|
5547
5567
|
})), setTimeout(t, 0));
|
|
5548
5568
|
})));
|
|
5549
|
-
}, Tt = 0,
|
|
5569
|
+
}, Tt = 0, Ee = 1 / 0, J = 0, er = function(r) {
|
|
5550
5570
|
r.forEach((function(e) {
|
|
5551
|
-
e.interactionId && (
|
|
5571
|
+
e.interactionId && (Ee = Math.min(Ee, e.interactionId), J = Math.max(J, e.interactionId), Tt = J ? (J - Ee) / 7 + 1 : 0);
|
|
5552
5572
|
}));
|
|
5553
5573
|
}, It = function() {
|
|
5554
5574
|
return Le ? Tt : performance.interactionCount || 0;
|
|
5555
5575
|
}, tr = function() {
|
|
5556
|
-
"interactionCount" in performance || Le || (Le =
|
|
5576
|
+
"interactionCount" in performance || Le || (Le = F("event", er, { type: "event", buffered: !0, durationThreshold: 0 }));
|
|
5557
5577
|
}, L = [], te = /* @__PURE__ */ new Map(), vt = 0, sr = function() {
|
|
5558
5578
|
var r = Math.min(L.length - 1, Math.floor((It() - vt) / 50));
|
|
5559
5579
|
return L[r];
|
|
5560
|
-
}, rr = [],
|
|
5561
|
-
if (rr.forEach((function(
|
|
5562
|
-
return
|
|
5580
|
+
}, rr = [], nr = function(r) {
|
|
5581
|
+
if (rr.forEach((function(n) {
|
|
5582
|
+
return n(r);
|
|
5563
5583
|
})), r.interactionId || r.entryType === "first-input") {
|
|
5564
5584
|
var e = L[L.length - 1], t = te.get(r.interactionId);
|
|
5565
5585
|
if (t || L.length < 10 || r.duration > e.latency) {
|
|
@@ -5568,52 +5588,52 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
|
|
|
5568
5588
|
var s = { id: r.interactionId, latency: r.duration, entries: [r] };
|
|
5569
5589
|
te.set(s.id, s), L.push(s);
|
|
5570
5590
|
}
|
|
5571
|
-
L.sort((function(
|
|
5572
|
-
return
|
|
5573
|
-
})), L.length > 10 && L.splice(10).forEach((function(
|
|
5574
|
-
return te.delete(
|
|
5591
|
+
L.sort((function(n, i) {
|
|
5592
|
+
return i.latency - n.latency;
|
|
5593
|
+
})), L.length > 10 && L.splice(10).forEach((function(n) {
|
|
5594
|
+
return te.delete(n.id);
|
|
5575
5595
|
}));
|
|
5576
5596
|
}
|
|
5577
5597
|
}
|
|
5578
5598
|
}, _t = function(r) {
|
|
5579
5599
|
var e = self.requestIdleCallback || self.setTimeout, t = -1;
|
|
5580
5600
|
return r = ue(r), document.visibilityState === "hidden" ? r() : (t = e(r), K(r)), t;
|
|
5581
|
-
}, Ce = [200, 500],
|
|
5601
|
+
}, Ce = [200, 500], ir = function(r, e) {
|
|
5582
5602
|
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, z((function() {
|
|
5583
5603
|
var t;
|
|
5584
5604
|
tr();
|
|
5585
|
-
var s,
|
|
5605
|
+
var s, n = y("INP"), i = function(l) {
|
|
5586
5606
|
_t((function() {
|
|
5587
|
-
l.forEach(
|
|
5607
|
+
l.forEach(nr);
|
|
5588
5608
|
var c = sr();
|
|
5589
|
-
c && c.latency !==
|
|
5609
|
+
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, s());
|
|
5590
5610
|
}));
|
|
5591
|
-
}, o =
|
|
5592
|
-
s = w(r,
|
|
5593
|
-
|
|
5611
|
+
}, o = F("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
|
|
5612
|
+
s = w(r, n, Ce, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), K((function() {
|
|
5613
|
+
i(o.takeRecords()), s(!0);
|
|
5594
5614
|
})), V((function() {
|
|
5595
|
-
vt = It(), L.length = 0, te.clear(),
|
|
5615
|
+
vt = It(), L.length = 0, te.clear(), n = y("INP"), s = w(r, n, Ce, e.reportAllChanges);
|
|
5596
5616
|
})));
|
|
5597
5617
|
})));
|
|
5598
5618
|
}, Re = [2500, 4e3], Se = {}, or = function(r, e) {
|
|
5599
5619
|
e = e || {}, z((function() {
|
|
5600
|
-
var t, s = ke(),
|
|
5620
|
+
var t, s = ke(), n = y("LCP"), i = function(c) {
|
|
5601
5621
|
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(d) {
|
|
5602
|
-
d.startTime < s.firstHiddenTime && (
|
|
5622
|
+
d.startTime < s.firstHiddenTime && (n.value = Math.max(d.startTime - de(), 0), n.entries = [d], t());
|
|
5603
5623
|
}));
|
|
5604
|
-
}, o =
|
|
5624
|
+
}, o = F("largest-contentful-paint", i);
|
|
5605
5625
|
if (o) {
|
|
5606
|
-
t = w(r,
|
|
5626
|
+
t = w(r, n, Re, e.reportAllChanges);
|
|
5607
5627
|
var l = ue((function() {
|
|
5608
|
-
Se[
|
|
5628
|
+
Se[n.id] || (i(o.takeRecords()), o.disconnect(), Se[n.id] = !0, t(!0));
|
|
5609
5629
|
}));
|
|
5610
5630
|
["keydown", "click"].forEach((function(c) {
|
|
5611
5631
|
addEventListener(c, (function() {
|
|
5612
5632
|
return _t(l);
|
|
5613
5633
|
}), { once: !0, capture: !0 });
|
|
5614
5634
|
})), K(l), V((function(c) {
|
|
5615
|
-
|
|
5616
|
-
|
|
5635
|
+
n = y("LCP"), t = w(r, n, Re, e.reportAllChanges), De((function() {
|
|
5636
|
+
n.value = performance.now() - c.timeStamp, Se[n.id] = !0, t(!0);
|
|
5617
5637
|
}));
|
|
5618
5638
|
}));
|
|
5619
5639
|
}
|
|
@@ -5628,15 +5648,15 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
|
|
|
5628
5648
|
e = e || {};
|
|
5629
5649
|
var t = y("TTFB"), s = w(r, t, Ne, e.reportAllChanges);
|
|
5630
5650
|
ar((function() {
|
|
5631
|
-
var
|
|
5632
|
-
|
|
5651
|
+
var n = Pe();
|
|
5652
|
+
n && (t.value = Math.max(n.responseStart - de(), 0), t.entries = [n], s(!0), V((function() {
|
|
5633
5653
|
t = y("TTFB", 0), (s = w(r, t, Ne, e.reportAllChanges))(!0);
|
|
5634
5654
|
})));
|
|
5635
5655
|
}));
|
|
5636
5656
|
}, W = { passive: !0, capture: !0 }, cr = /* @__PURE__ */ new Date(), st = function(r, e) {
|
|
5637
|
-
C || (C = e, G = r,
|
|
5657
|
+
C || (C = e, G = r, pt = /* @__PURE__ */ new Date(), wt(removeEventListener), yt());
|
|
5638
5658
|
}, yt = function() {
|
|
5639
|
-
if (G >= 0 && G <
|
|
5659
|
+
if (G >= 0 && G < pt - cr) {
|
|
5640
5660
|
var r = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp + G };
|
|
5641
5661
|
le.forEach((function(e) {
|
|
5642
5662
|
e(r);
|
|
@@ -5646,14 +5666,14 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
|
|
|
5646
5666
|
if (r.cancelable) {
|
|
5647
5667
|
var e = (r.timeStamp > 1e12 ? /* @__PURE__ */ new Date() : performance.now()) - r.timeStamp;
|
|
5648
5668
|
r.type == "pointerdown" ? (function(t, s) {
|
|
5649
|
-
var
|
|
5669
|
+
var n = function() {
|
|
5650
5670
|
st(t, s), o();
|
|
5651
|
-
},
|
|
5671
|
+
}, i = function() {
|
|
5652
5672
|
o();
|
|
5653
5673
|
}, o = function() {
|
|
5654
|
-
removeEventListener("pointerup",
|
|
5674
|
+
removeEventListener("pointerup", n, W), removeEventListener("pointercancel", i, W);
|
|
5655
5675
|
};
|
|
5656
|
-
addEventListener("pointerup",
|
|
5676
|
+
addEventListener("pointerup", n, W), addEventListener("pointercancel", i, W);
|
|
5657
5677
|
})(e, r) : st(e, r);
|
|
5658
5678
|
}
|
|
5659
5679
|
}, wt = function(r) {
|
|
@@ -5662,16 +5682,16 @@ var Le, C, G, Et, le, pt = -1, V = function(r) {
|
|
|
5662
5682
|
}));
|
|
5663
5683
|
}, Oe = [100, 300], ur = function(r, e) {
|
|
5664
5684
|
e = e || {}, z((function() {
|
|
5665
|
-
var t, s = ke(),
|
|
5666
|
-
c.startTime < s.firstHiddenTime && (
|
|
5685
|
+
var t, s = ke(), n = y("FID"), i = function(c) {
|
|
5686
|
+
c.startTime < s.firstHiddenTime && (n.value = c.processingStart - c.startTime, n.entries.push(c), t(!0));
|
|
5667
5687
|
}, o = function(c) {
|
|
5668
|
-
c.forEach(
|
|
5669
|
-
}, l =
|
|
5670
|
-
t = w(r,
|
|
5688
|
+
c.forEach(i);
|
|
5689
|
+
}, l = F("first-input", o);
|
|
5690
|
+
t = w(r, n, Oe, e.reportAllChanges), l && (K(ue((function() {
|
|
5671
5691
|
o(l.takeRecords()), l.disconnect();
|
|
5672
5692
|
}))), V((function() {
|
|
5673
5693
|
var c;
|
|
5674
|
-
|
|
5694
|
+
n = y("FID"), t = w(r, n, Oe, e.reportAllChanges), le = [], G = -1, C = null, wt(addEventListener), c = i, le.push(c), yt();
|
|
5675
5695
|
})));
|
|
5676
5696
|
}));
|
|
5677
5697
|
};
|
|
@@ -5686,7 +5706,7 @@ const hr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
5686
5706
|
onCLS: Zs,
|
|
5687
5707
|
onFCP: St,
|
|
5688
5708
|
onFID: ur,
|
|
5689
|
-
onINP:
|
|
5709
|
+
onINP: ir,
|
|
5690
5710
|
onLCP: or,
|
|
5691
5711
|
onTTFB: lr
|
|
5692
5712
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -5701,14 +5721,14 @@ export {
|
|
|
5701
5721
|
wr as InitializationTimeoutError,
|
|
5702
5722
|
N as IntegrationValidationError,
|
|
5703
5723
|
vr as MAX_ARRAY_LENGTH,
|
|
5704
|
-
|
|
5705
|
-
|
|
5724
|
+
Er as MAX_CUSTOM_EVENT_ARRAY_SIZE,
|
|
5725
|
+
pr as MAX_CUSTOM_EVENT_KEYS,
|
|
5706
5726
|
mr as MAX_CUSTOM_EVENT_NAME_LENGTH,
|
|
5707
5727
|
gr as MAX_CUSTOM_EVENT_STRING_SIZE,
|
|
5708
5728
|
Sr as MAX_NESTED_OBJECT_KEYS,
|
|
5709
5729
|
Tr as MAX_STRING_LENGTH,
|
|
5710
5730
|
Ir as MAX_STRING_LENGTH_IN_ARRAY,
|
|
5711
|
-
|
|
5731
|
+
ie as Mode,
|
|
5712
5732
|
at as PII_PATTERNS,
|
|
5713
5733
|
O as PermanentError,
|
|
5714
5734
|
re as RateLimitError,
|
|
@@ -5716,7 +5736,7 @@ export {
|
|
|
5716
5736
|
Z as ScrollDirection,
|
|
5717
5737
|
Pt as SessionTimeoutValidationError,
|
|
5718
5738
|
$ as SpecialApiUrl,
|
|
5719
|
-
|
|
5739
|
+
ne as TimeoutError,
|
|
5720
5740
|
j as TraceLogValidationError,
|
|
5721
5741
|
br as WEB_VITALS_GOOD_THRESHOLDS,
|
|
5722
5742
|
ze as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
|