@tracelog/lib 2.6.1 → 2.6.2-rc.94.6
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/README.md +10 -2
- package/dist/browser/tracelog.esm.js +801 -629
- 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.d.mts +23 -1
- package/dist/public-api.d.ts +23 -1
- package/dist/public-api.js +2 -2
- package/dist/public-api.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const b = "data-tlog",
|
|
1
|
+
const is = 9e5;
|
|
2
|
+
const os = 120, as = 8192, ls = 10, cs = 10, us = 20;
|
|
3
|
+
const ds = 1e3, hs = 500, fs = 100;
|
|
4
|
+
const b = "data-tlog", vt = [
|
|
5
5
|
"button",
|
|
6
6
|
"a",
|
|
7
7
|
'input[type="button"]',
|
|
@@ -33,7 +33,7 @@ const b = "data-tlog", pt = [
|
|
|
33
33
|
".menu-item",
|
|
34
34
|
"[data-testid]",
|
|
35
35
|
'[tabindex="0"]'
|
|
36
|
-
],
|
|
36
|
+
], _t = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"], yt = [
|
|
37
37
|
"token",
|
|
38
38
|
"auth",
|
|
39
39
|
"key",
|
|
@@ -72,15 +72,15 @@ const m = {
|
|
|
72
72
|
INVALID_VIEWPORT_COOLDOWN_PERIOD: "Viewport cooldownPeriod must be a non-negative number",
|
|
73
73
|
INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS: "Viewport maxTrackedElements must be a positive number",
|
|
74
74
|
INVALID_SEND_INTERVAL: "Send interval must be between 1000ms (1 second) and 60000ms (60 seconds)"
|
|
75
|
-
},
|
|
75
|
+
}, wt = [
|
|
76
76
|
/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
|
77
77
|
/javascript:/gi,
|
|
78
78
|
/on\w+\s*=/gi,
|
|
79
79
|
/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
|
|
80
80
|
/<embed\b[^>]*>/gi,
|
|
81
81
|
/<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi
|
|
82
|
-
],
|
|
83
|
-
var
|
|
82
|
+
], I = "tlog", X = `${I}:qa_mode`, Ee = `${I}:uid`, et = "tlog_mode", Ve = "qa", ke = "qa_off", bt = (s) => s ? `${I}:${s}:queue` : `${I}:queue`, At = (s) => s ? `${I}:${s}:session` : `${I}:session`, Lt = (s) => s ? `${I}:${s}:broadcast` : `${I}:broadcast`, Ue = (s, e) => `${I}:${s}:session_counts:${e}`, He = 10080 * 60 * 1e3, xe = `${I}:session_counts_last_cleanup`, Fe = 3600 * 1e3, ue = (s) => s ? `${I}:${s}:identity` : `${I}:identity`, H = `${I}:pending_identity`;
|
|
83
|
+
var B = /* @__PURE__ */ ((s) => (s.Localhost = "localhost:8080", s.Fail = "localhost:9999", s))(B || {}), L = /* @__PURE__ */ ((s) => (s.Mobile = "mobile", s.Tablet = "tablet", s.Desktop = "desktop", s.Unknown = "unknown", s))(L || {}), Se = /* @__PURE__ */ ((s) => (s.EVENT = "event", s.QUEUE = "queue", s))(Se || {});
|
|
84
84
|
class N extends Error {
|
|
85
85
|
constructor(e, t) {
|
|
86
86
|
super(e), this.statusCode = t, this.name = "PermanentError", Error.captureStackTrace && Error.captureStackTrace(this, N);
|
|
@@ -91,8 +91,8 @@ class O extends Error {
|
|
|
91
91
|
super(e), this.name = "TimeoutError", Error.captureStackTrace && Error.captureStackTrace(this, O);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
var d = /* @__PURE__ */ ((s) => (s.PAGE_VIEW = "page_view", s.CLICK = "click", s.SCROLL = "scroll", s.SESSION_START = "session_start", s.CUSTOM = "custom", s.WEB_VITALS = "web_vitals", s.ERROR = "error", s.VIEWPORT_VISIBLE = "viewport_visible", s))(d || {}),
|
|
95
|
-
const
|
|
94
|
+
var d = /* @__PURE__ */ ((s) => (s.PAGE_VIEW = "page_view", s.CLICK = "click", s.SCROLL = "scroll", s.SESSION_START = "session_start", s.CUSTOM = "custom", s.WEB_VITALS = "web_vitals", s.ERROR = "error", s.VIEWPORT_VISIBLE = "viewport_visible", s))(d || {}), ee = /* @__PURE__ */ ((s) => (s.UP = "up", s.DOWN = "down", s))(ee || {}), W = /* @__PURE__ */ ((s) => (s.JS_ERROR = "js_error", s.PROMISE_REJECTION = "promise_rejection", s))(W || {}), se = /* @__PURE__ */ ((s) => (s.QA = "qa", s))(se || {});
|
|
95
|
+
const ms = (s) => s.type === d.SCROLL && "scroll_data" in s && s.scroll_data.is_primary === !0, gs = (s) => s.type === d.SCROLL && "scroll_data" in s && s.scroll_data.is_primary === !1;
|
|
96
96
|
class Q extends Error {
|
|
97
97
|
constructor(e, t, r) {
|
|
98
98
|
super(e), this.errorCode = t, this.layer = r, this.name = this.constructor.name, Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
|
|
@@ -103,12 +103,12 @@ class f extends Q {
|
|
|
103
103
|
super(e, "APP_CONFIG_INVALID", t);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
class
|
|
106
|
+
class Mt extends Q {
|
|
107
107
|
constructor(e, t = "config") {
|
|
108
108
|
super(e, "SESSION_TIMEOUT_INVALID", t);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
class
|
|
111
|
+
class $e extends Q {
|
|
112
112
|
constructor(e, t = "config") {
|
|
113
113
|
super(e, "SAMPLING_RATE_INVALID", t);
|
|
114
114
|
}
|
|
@@ -118,12 +118,12 @@ class U extends Q {
|
|
|
118
118
|
super(e, "INTEGRATION_INVALID", t);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
class
|
|
121
|
+
class Es extends Q {
|
|
122
122
|
constructor(e, t, r = "runtime") {
|
|
123
123
|
super(e, "INITIALIZATION_TIMEOUT", r), this.timeoutMs = t;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
const
|
|
126
|
+
const tt = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", rt = "background: #9e9e9e; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", Ct = "background: #d32f2f; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", Rt = (s, e) => {
|
|
127
127
|
if (e) {
|
|
128
128
|
if (e instanceof Error) {
|
|
129
129
|
const t = e.message.replace(/\s+at\s+.*$/gm, "").replace(/\s*\([^()]+:\d+:\d+\)/g, "");
|
|
@@ -142,24 +142,24 @@ const Ze = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8
|
|
|
142
142
|
return `[TraceLog] ${s}: ${String(e)}`;
|
|
143
143
|
}
|
|
144
144
|
return `[TraceLog] ${s}`;
|
|
145
|
-
},
|
|
145
|
+
}, Nt = () => {
|
|
146
146
|
if (typeof window > "u" || typeof sessionStorage > "u")
|
|
147
147
|
return !1;
|
|
148
148
|
try {
|
|
149
|
-
return sessionStorage.getItem(
|
|
149
|
+
return sessionStorage.getItem(X) === "true";
|
|
150
150
|
} catch {
|
|
151
151
|
return !1;
|
|
152
152
|
}
|
|
153
|
-
},
|
|
154
|
-
const { error: r, data: n, showToClient: i = !1, style: o, visibility:
|
|
155
|
-
if (!
|
|
153
|
+
}, a = (s, e, t) => {
|
|
154
|
+
const { error: r, data: n, showToClient: i = !1, style: o, visibility: l } = t ?? {}, c = r ? Rt(e, r) : `[TraceLog] ${e}`, u = s === "error" ? "error" : s === "warn" ? "warn" : "log";
|
|
155
|
+
if (!Ot(l, i))
|
|
156
156
|
return;
|
|
157
|
-
const E =
|
|
158
|
-
|
|
159
|
-
},
|
|
157
|
+
const E = Pt(l, o), T = n !== void 0 ? pe(n) : void 0;
|
|
158
|
+
Dt(u, c, E, T);
|
|
159
|
+
}, Ot = (s, e) => s === "critical" ? !0 : s === "qa" || e ? Nt() : !1, Pt = (s, e) => e !== void 0 && e !== "" ? e : s === "critical" ? Ct : "", Dt = (s, e, t, r) => {
|
|
160
160
|
const n = t !== void 0 && t !== "", i = n ? `%c${e}` : e;
|
|
161
161
|
r !== void 0 ? n ? console[s](i, t, r) : console[s](i, r) : n ? console[s](i, t) : console[s](i);
|
|
162
|
-
},
|
|
162
|
+
}, pe = (s) => {
|
|
163
163
|
const e = {}, t = ["token", "password", "secret", "key", "apikey", "api_key", "sessionid", "session_id"];
|
|
164
164
|
for (const [r, n] of Object.entries(s)) {
|
|
165
165
|
const i = r.toLowerCase();
|
|
@@ -167,16 +167,16 @@ const Ze = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8
|
|
|
167
167
|
e[r] = "[REDACTED]";
|
|
168
168
|
continue;
|
|
169
169
|
}
|
|
170
|
-
n !== null && typeof n == "object" && !Array.isArray(n) ? e[r] =
|
|
171
|
-
(o) => o !== null && typeof o == "object" && !Array.isArray(o) ?
|
|
170
|
+
n !== null && typeof n == "object" && !Array.isArray(n) ? e[r] = pe(n) : Array.isArray(n) ? e[r] = n.map(
|
|
171
|
+
(o) => o !== null && typeof o == "object" && !Array.isArray(o) ? pe(o) : o
|
|
172
172
|
) : e[r] = n;
|
|
173
173
|
}
|
|
174
174
|
return e;
|
|
175
175
|
};
|
|
176
|
-
let
|
|
177
|
-
const
|
|
178
|
-
typeof window < "u" && !
|
|
179
|
-
},
|
|
176
|
+
let Te, st;
|
|
177
|
+
const Vt = () => {
|
|
178
|
+
typeof window < "u" && !Te && (Te = window.matchMedia("(pointer: coarse)"), st = window.matchMedia("(hover: none)"));
|
|
179
|
+
}, ne = "Unknown", kt = (s) => {
|
|
180
180
|
const e = s.userAgentData?.platform;
|
|
181
181
|
if (e != null && e !== "") {
|
|
182
182
|
if (/windows/i.test(e)) return "Windows";
|
|
@@ -187,8 +187,8 @@ const Ot = () => {
|
|
|
187
187
|
if (/ios/i.test(e)) return "iOS";
|
|
188
188
|
}
|
|
189
189
|
const t = navigator.userAgent;
|
|
190
|
-
return /Windows/i.test(t) ? "Windows" : /iPhone|iPad|iPod/i.test(t) ? "iOS" : /Mac OS X|Macintosh/i.test(t) ? "macOS" : /Android/i.test(t) ? "Android" : /CrOS/i.test(t) ? "ChromeOS" : /Linux/i.test(t) ? "Linux" :
|
|
191
|
-
},
|
|
190
|
+
return /Windows/i.test(t) ? "Windows" : /iPhone|iPad|iPod/i.test(t) ? "iOS" : /Mac OS X|Macintosh/i.test(t) ? "macOS" : /Android/i.test(t) ? "Android" : /CrOS/i.test(t) ? "ChromeOS" : /Linux/i.test(t) ? "Linux" : ne;
|
|
191
|
+
}, Ut = (s) => {
|
|
192
192
|
const e = s.userAgentData?.brands;
|
|
193
193
|
if (e != null && e.length > 0) {
|
|
194
194
|
const n = e.filter((i) => !/not.?a.?brand|chromium/i.test(i.brand))[0];
|
|
@@ -198,36 +198,36 @@ const Ot = () => {
|
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
const t = navigator.userAgent;
|
|
201
|
-
return /Edg\//i.test(t) ? "Edge" : /OPR\//i.test(t) ? "Opera" : /Chrome/i.test(t) ? "Chrome" : /Firefox/i.test(t) ? "Firefox" : /Safari/i.test(t) && !/Chrome/i.test(t) ? "Safari" :
|
|
202
|
-
},
|
|
201
|
+
return /Edg\//i.test(t) ? "Edge" : /OPR\//i.test(t) ? "Opera" : /Chrome/i.test(t) ? "Chrome" : /Firefox/i.test(t) ? "Firefox" : /Safari/i.test(t) && !/Chrome/i.test(t) ? "Safari" : ne;
|
|
202
|
+
}, Ht = () => {
|
|
203
203
|
try {
|
|
204
204
|
const s = navigator;
|
|
205
205
|
if (s.userAgentData != null && typeof s.userAgentData.mobile == "boolean") {
|
|
206
206
|
const c = s.userAgentData.platform;
|
|
207
207
|
return c != null && c !== "" && /ipad|tablet/i.test(c) ? L.Tablet : s.userAgentData.mobile ? L.Mobile : L.Desktop;
|
|
208
208
|
}
|
|
209
|
-
|
|
210
|
-
const e = window.innerWidth, t =
|
|
211
|
-
return e <= 767 || o && n ? L.Mobile : e >= 768 && e <= 1024 ||
|
|
209
|
+
Vt();
|
|
210
|
+
const e = window.innerWidth, t = Te?.matches ?? !1, r = st?.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);
|
|
211
|
+
return e <= 767 || o && n ? L.Mobile : e >= 768 && e <= 1024 || l || t && r && n ? L.Tablet : L.Desktop;
|
|
212
212
|
} catch (s) {
|
|
213
|
-
return
|
|
213
|
+
return a("debug", "Device detection failed, defaulting to desktop", { error: s }), L.Desktop;
|
|
214
214
|
}
|
|
215
|
-
},
|
|
215
|
+
}, xt = () => {
|
|
216
216
|
try {
|
|
217
217
|
const s = navigator;
|
|
218
218
|
return {
|
|
219
|
-
type:
|
|
220
|
-
os:
|
|
221
|
-
browser:
|
|
219
|
+
type: Ht(),
|
|
220
|
+
os: kt(s),
|
|
221
|
+
browser: Ut(s)
|
|
222
222
|
};
|
|
223
223
|
} catch (s) {
|
|
224
|
-
return
|
|
224
|
+
return a("debug", "Device info detection failed, using defaults", { error: s }), {
|
|
225
225
|
type: L.Desktop,
|
|
226
|
-
os:
|
|
227
|
-
browser:
|
|
226
|
+
os: ne,
|
|
227
|
+
browser: ne
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
|
-
},
|
|
230
|
+
}, nt = [
|
|
231
231
|
// Email addresses
|
|
232
232
|
/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/gi,
|
|
233
233
|
// US Phone numbers (various formats)
|
|
@@ -242,7 +242,7 @@ const Ot = () => {
|
|
|
242
242
|
/Bearer\s+[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)?(?:\.[A-Za-z0-9_-]+)?/gi,
|
|
243
243
|
// Passwords in connection strings (protocol://user:password@host)
|
|
244
244
|
/:\/\/[^:/]+:([^@]+)@/gi
|
|
245
|
-
],
|
|
245
|
+
], Be = 500, We = 5e3, te = 50, Ft = te * 2, it = 1, $t = 1e3, Bt = 10, Ge = 5e3, Wt = 6e4, Ss = {
|
|
246
246
|
LCP: 2500,
|
|
247
247
|
// Good: ≤ 2.5s
|
|
248
248
|
FCP: 1800,
|
|
@@ -254,7 +254,7 @@ const Ot = () => {
|
|
|
254
254
|
TTFB: 800,
|
|
255
255
|
// Good: ≤ 800ms
|
|
256
256
|
LONG_TASK: 50
|
|
257
|
-
},
|
|
257
|
+
}, Xe = {
|
|
258
258
|
LCP: 2500,
|
|
259
259
|
// Needs improvement: > 2.5s (same as good boundary)
|
|
260
260
|
FCP: 1800,
|
|
@@ -266,7 +266,7 @@ const Ot = () => {
|
|
|
266
266
|
TTFB: 800,
|
|
267
267
|
// Needs improvement: > 800ms
|
|
268
268
|
LONG_TASK: 50
|
|
269
|
-
},
|
|
269
|
+
}, Gt = {
|
|
270
270
|
LCP: 4e3,
|
|
271
271
|
// Poor: > 4s
|
|
272
272
|
FCP: 3e3,
|
|
@@ -278,53 +278,53 @@ const Ot = () => {
|
|
|
278
278
|
TTFB: 1800,
|
|
279
279
|
// Poor: > 1800ms
|
|
280
280
|
LONG_TASK: 50
|
|
281
|
-
},
|
|
281
|
+
}, Ie = "needs-improvement", je = (s = Ie) => {
|
|
282
282
|
switch (s) {
|
|
283
283
|
case "all":
|
|
284
284
|
return { LCP: 0, FCP: 0, CLS: 0, INP: 0, TTFB: 0, LONG_TASK: 0 };
|
|
285
285
|
// Track everything
|
|
286
286
|
case "needs-improvement":
|
|
287
|
-
return
|
|
287
|
+
return Xe;
|
|
288
288
|
case "poor":
|
|
289
|
-
return
|
|
289
|
+
return Gt;
|
|
290
290
|
default:
|
|
291
|
-
return
|
|
291
|
+
return Xe;
|
|
292
292
|
}
|
|
293
|
-
},
|
|
293
|
+
}, Xt = 1e3, jt = 50, Qt = "2.6.2", zt = Qt, ot = () => typeof window < "u" && typeof sessionStorage < "u", Kt = () => {
|
|
294
294
|
try {
|
|
295
295
|
const s = new URLSearchParams(window.location.search);
|
|
296
|
-
s.delete(
|
|
296
|
+
s.delete(et);
|
|
297
297
|
const e = s.toString(), t = window.location.pathname + (e ? "?" + e : "") + window.location.hash;
|
|
298
298
|
window.history.replaceState({}, "", t);
|
|
299
299
|
} catch {
|
|
300
300
|
}
|
|
301
|
-
},
|
|
302
|
-
if (!
|
|
301
|
+
}, Yt = () => {
|
|
302
|
+
if (!ot())
|
|
303
303
|
return !1;
|
|
304
304
|
try {
|
|
305
|
-
const e = new URLSearchParams(window.location.search).get(
|
|
305
|
+
const e = new URLSearchParams(window.location.search).get(et), t = sessionStorage.getItem(X);
|
|
306
306
|
let r = null;
|
|
307
|
-
return e ===
|
|
307
|
+
return e === Ve ? (r = !0, sessionStorage.setItem(X, "true"), a("info", "QA Mode ACTIVE", {
|
|
308
308
|
visibility: "qa",
|
|
309
|
-
style:
|
|
310
|
-
})) : e ===
|
|
309
|
+
style: tt
|
|
310
|
+
})) : e === ke && (r = !1, sessionStorage.setItem(X, "false"), a("info", "QA Mode DISABLED", {
|
|
311
311
|
visibility: "qa",
|
|
312
|
-
style:
|
|
313
|
-
})), (e ===
|
|
312
|
+
style: rt
|
|
313
|
+
})), (e === Ve || e === ke) && Kt(), r ?? t === "true";
|
|
314
314
|
} catch {
|
|
315
315
|
return !1;
|
|
316
316
|
}
|
|
317
|
-
},
|
|
318
|
-
if (
|
|
317
|
+
}, qt = (s) => {
|
|
318
|
+
if (ot())
|
|
319
319
|
try {
|
|
320
|
-
sessionStorage.setItem(
|
|
320
|
+
sessionStorage.setItem(X, s ? "true" : "false"), a("info", s ? "QA Mode ACTIVE" : "QA Mode DISABLED", {
|
|
321
321
|
visibility: "qa",
|
|
322
|
-
style: s ?
|
|
322
|
+
style: s ? tt : rt
|
|
323
323
|
});
|
|
324
324
|
} catch {
|
|
325
|
-
|
|
325
|
+
a("debug", "Cannot set QA mode: sessionStorage unavailable");
|
|
326
326
|
}
|
|
327
|
-
},
|
|
327
|
+
}, Jt = [
|
|
328
328
|
"co.uk",
|
|
329
329
|
"org.uk",
|
|
330
330
|
"com.au",
|
|
@@ -336,40 +336,40 @@ const Ot = () => {
|
|
|
336
336
|
"co.in",
|
|
337
337
|
"com.cn",
|
|
338
338
|
"co.za"
|
|
339
|
-
],
|
|
339
|
+
], Qe = (s) => {
|
|
340
340
|
const e = s.toLowerCase().split(".");
|
|
341
341
|
if (e.length <= 2)
|
|
342
342
|
return s.toLowerCase();
|
|
343
343
|
const t = e.slice(-2).join(".");
|
|
344
|
-
return
|
|
345
|
-
},
|
|
344
|
+
return Jt.includes(t) ? e.slice(-3).join(".") : e.slice(-2).join(".");
|
|
345
|
+
}, Zt = (s, e) => s === e ? !0 : Qe(s) === Qe(e), de = () => {
|
|
346
346
|
const s = document.referrer;
|
|
347
347
|
if (!s)
|
|
348
348
|
return "Direct";
|
|
349
349
|
try {
|
|
350
350
|
const e = new URL(s).hostname.toLowerCase(), t = window.location.hostname.toLowerCase();
|
|
351
|
-
return
|
|
351
|
+
return Zt(e, t) ? "Direct" : s;
|
|
352
352
|
} catch (e) {
|
|
353
|
-
return
|
|
353
|
+
return a("debug", "Failed to parse referrer URL, using raw value", { error: e, data: { referrer: s } }), s;
|
|
354
354
|
}
|
|
355
|
-
},
|
|
355
|
+
}, he = () => {
|
|
356
356
|
const s = new URLSearchParams(window.location.search), e = {};
|
|
357
|
-
return
|
|
357
|
+
return _t.forEach((r) => {
|
|
358
358
|
const n = s.get(r);
|
|
359
359
|
if (n) {
|
|
360
360
|
const i = r.split("utm_")[1];
|
|
361
361
|
e[i] = n;
|
|
362
362
|
}
|
|
363
363
|
}), Object.keys(e).length ? e : void 0;
|
|
364
|
-
},
|
|
364
|
+
}, at = () => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (s) => {
|
|
365
365
|
const e = Math.random() * 16 | 0;
|
|
366
366
|
return (s === "x" ? e : e & 3 | 8).toString(16);
|
|
367
367
|
});
|
|
368
|
-
let
|
|
369
|
-
const
|
|
368
|
+
let q = 0, J = 0;
|
|
369
|
+
const er = () => {
|
|
370
370
|
let s = Date.now();
|
|
371
|
-
s <
|
|
372
|
-
const e =
|
|
371
|
+
s < J && (s = J), s === J ? q = (q + 1) % 1e3 : q = 0, J = s;
|
|
372
|
+
const e = q.toString().padStart(3, "0");
|
|
373
373
|
let t = "";
|
|
374
374
|
try {
|
|
375
375
|
if (typeof crypto < "u" && crypto.getRandomValues) {
|
|
@@ -379,14 +379,14 @@ const Jt = () => {
|
|
|
379
379
|
} catch {
|
|
380
380
|
}
|
|
381
381
|
return t || (t = Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")), `${s}-${e}-${t}`;
|
|
382
|
-
},
|
|
382
|
+
}, lt = (s, e = !1) => {
|
|
383
383
|
try {
|
|
384
384
|
const t = new URL(s), r = t.protocol === "https:", n = t.protocol === "http:";
|
|
385
385
|
return r || e && n;
|
|
386
386
|
} catch {
|
|
387
387
|
return !1;
|
|
388
388
|
}
|
|
389
|
-
},
|
|
389
|
+
}, tr = (s) => {
|
|
390
390
|
try {
|
|
391
391
|
const t = new URL(window.location.href).hostname;
|
|
392
392
|
if (!t || typeof t != "string")
|
|
@@ -404,57 +404,57 @@ const Jt = () => {
|
|
|
404
404
|
if (r.length === 2 ? n = r.join(".") : n = r.slice(-2).join("."), !n || n.split(".").length < 2)
|
|
405
405
|
throw new Error("Invalid domain structure for SaaS");
|
|
406
406
|
const i = `https://${s}.${n}/collect`;
|
|
407
|
-
if (!
|
|
407
|
+
if (!lt(i))
|
|
408
408
|
throw new Error("Generated URL failed validation");
|
|
409
409
|
return i;
|
|
410
410
|
} catch (e) {
|
|
411
411
|
throw new Error(`Invalid SaaS URL configuration: ${e instanceof Error ? e.message : String(e)}`);
|
|
412
412
|
}
|
|
413
|
-
},
|
|
413
|
+
}, rr = (s) => {
|
|
414
414
|
const e = {};
|
|
415
|
-
s.integrations?.tracelog?.projectId && (e.saas =
|
|
415
|
+
s.integrations?.tracelog?.projectId && (e.saas = tr(s.integrations.tracelog.projectId));
|
|
416
416
|
const t = s.integrations?.custom?.collectApiUrl;
|
|
417
417
|
if (t) {
|
|
418
418
|
const r = s.integrations?.custom?.allowHttp ?? !1;
|
|
419
|
-
if (!
|
|
419
|
+
if (!lt(t, r))
|
|
420
420
|
throw new Error("Invalid custom API URL");
|
|
421
421
|
e.custom = t;
|
|
422
422
|
}
|
|
423
423
|
return e;
|
|
424
|
-
},
|
|
424
|
+
}, ve = (s, e = []) => {
|
|
425
425
|
if (!s || typeof s != "string")
|
|
426
|
-
return
|
|
426
|
+
return a("warn", "Invalid URL provided to normalizeUrl", { data: { type: typeof s } }), s || "";
|
|
427
427
|
try {
|
|
428
|
-
const t = new URL(s), r = t.searchParams, n = [.../* @__PURE__ */ new Set([...
|
|
428
|
+
const t = new URL(s), r = t.searchParams, n = [.../* @__PURE__ */ new Set([...yt, ...e])];
|
|
429
429
|
let i = !1;
|
|
430
430
|
const o = [];
|
|
431
431
|
return n.forEach((c) => {
|
|
432
432
|
r.has(c) && (r.delete(c), i = !0, o.push(c));
|
|
433
433
|
}), !i && s.includes("?") ? s : (t.search = r.toString(), t.toString());
|
|
434
434
|
} catch (t) {
|
|
435
|
-
return
|
|
435
|
+
return a("warn", "URL normalization failed, returning original", { error: t, data: { urlLength: s?.length } }), s;
|
|
436
436
|
}
|
|
437
|
-
},
|
|
437
|
+
}, ze = (s) => {
|
|
438
438
|
if (!s || typeof s != "string" || s.trim().length === 0)
|
|
439
439
|
return "";
|
|
440
440
|
let e = s;
|
|
441
441
|
s.length > 1e3 && (e = s.slice(0, Math.max(0, 1e3)));
|
|
442
442
|
let t = 0;
|
|
443
|
-
for (const n of
|
|
443
|
+
for (const n of wt) {
|
|
444
444
|
const i = e;
|
|
445
445
|
e = e.replace(n, ""), i !== e && t++;
|
|
446
446
|
}
|
|
447
|
-
return t > 0 &&
|
|
447
|
+
return t > 0 && a("warn", "XSS patterns detected and removed", {
|
|
448
448
|
data: {
|
|
449
449
|
patternMatches: t,
|
|
450
450
|
valueLength: s.length
|
|
451
451
|
}
|
|
452
452
|
}), e.trim();
|
|
453
|
-
},
|
|
453
|
+
}, _e = (s, e = 0) => {
|
|
454
454
|
if (s == null)
|
|
455
455
|
return null;
|
|
456
456
|
if (typeof s == "string")
|
|
457
|
-
return
|
|
457
|
+
return ze(s);
|
|
458
458
|
if (typeof s == "number")
|
|
459
459
|
return !Number.isFinite(s) || s < -Number.MAX_SAFE_INTEGER || s > Number.MAX_SAFE_INTEGER ? 0 : s;
|
|
460
460
|
if (typeof s == "boolean")
|
|
@@ -462,38 +462,38 @@ const Jt = () => {
|
|
|
462
462
|
if (e > 10)
|
|
463
463
|
return null;
|
|
464
464
|
if (Array.isArray(s))
|
|
465
|
-
return s.slice(0, 100).map((n) =>
|
|
465
|
+
return s.slice(0, 100).map((n) => _e(n, e + 1)).filter((n) => n !== null);
|
|
466
466
|
if (typeof s == "object") {
|
|
467
467
|
const t = {}, n = Object.entries(s).slice(0, 20);
|
|
468
468
|
for (const [i, o] of n) {
|
|
469
|
-
const
|
|
470
|
-
if (
|
|
471
|
-
const c =
|
|
472
|
-
c !== null && (t[
|
|
469
|
+
const l = ze(i);
|
|
470
|
+
if (l) {
|
|
471
|
+
const c = _e(o, e + 1);
|
|
472
|
+
c !== null && (t[l] = c);
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
475
|
return t;
|
|
476
476
|
}
|
|
477
477
|
return null;
|
|
478
|
-
},
|
|
478
|
+
}, sr = (s) => {
|
|
479
479
|
if (typeof s != "object" || s === null)
|
|
480
480
|
return {};
|
|
481
481
|
try {
|
|
482
|
-
const e =
|
|
482
|
+
const e = _e(s);
|
|
483
483
|
return typeof e == "object" && e !== null ? e : {};
|
|
484
484
|
} catch (e) {
|
|
485
485
|
const t = e instanceof Error ? e.message : String(e);
|
|
486
486
|
throw new Error(`[TraceLog] Metadata sanitization failed: ${t}`);
|
|
487
487
|
}
|
|
488
|
-
},
|
|
488
|
+
}, nr = (s) => {
|
|
489
489
|
if (s !== void 0 && (s === null || typeof s != "object"))
|
|
490
490
|
throw new f("Configuration must be an object", "config");
|
|
491
491
|
if (s) {
|
|
492
492
|
if (s.sessionTimeout !== void 0 && (typeof s.sessionTimeout != "number" || s.sessionTimeout < 3e4 || s.sessionTimeout > 864e5))
|
|
493
|
-
throw new
|
|
493
|
+
throw new Mt(m.INVALID_SESSION_TIMEOUT, "config");
|
|
494
494
|
if (s.globalMetadata !== void 0 && (typeof s.globalMetadata != "object" || s.globalMetadata === null))
|
|
495
495
|
throw new f(m.INVALID_GLOBAL_METADATA, "config");
|
|
496
|
-
if (s.integrations &&
|
|
496
|
+
if (s.integrations && or(s.integrations), s.sensitiveQueryParams !== void 0) {
|
|
497
497
|
if (!Array.isArray(s.sensitiveQueryParams))
|
|
498
498
|
throw new f(m.INVALID_SENSITIVE_QUERY_PARAMS, "config");
|
|
499
499
|
for (const e of s.sensitiveQueryParams)
|
|
@@ -501,9 +501,9 @@ const Jt = () => {
|
|
|
501
501
|
throw new f("All sensitive query params must be strings", "config");
|
|
502
502
|
}
|
|
503
503
|
if (s.errorSampling !== void 0 && (typeof s.errorSampling != "number" || s.errorSampling < 0 || s.errorSampling > 1))
|
|
504
|
-
throw new
|
|
504
|
+
throw new $e(m.INVALID_ERROR_SAMPLING_RATE, "config");
|
|
505
505
|
if (s.samplingRate !== void 0 && (typeof s.samplingRate != "number" || s.samplingRate < 0 || s.samplingRate > 1))
|
|
506
|
-
throw new
|
|
506
|
+
throw new $e(m.INVALID_SAMPLING_RATE, "config");
|
|
507
507
|
if (s.primaryScrollSelector !== void 0) {
|
|
508
508
|
if (typeof s.primaryScrollSelector != "string" || !s.primaryScrollSelector.trim())
|
|
509
509
|
throw new f(m.INVALID_PRIMARY_SCROLL_SELECTOR, "config");
|
|
@@ -525,7 +525,7 @@ const Jt = () => {
|
|
|
525
525
|
throw new f(m.INVALID_MAX_SAME_EVENT_PER_MINUTE, "config");
|
|
526
526
|
if (s.sendIntervalMs !== void 0 && (!Number.isFinite(s.sendIntervalMs) || s.sendIntervalMs < 1e3 || s.sendIntervalMs > 6e4))
|
|
527
527
|
throw new f(m.INVALID_SEND_INTERVAL, "config");
|
|
528
|
-
if (s.viewport !== void 0 &&
|
|
528
|
+
if (s.viewport !== void 0 && ir(s.viewport), s.webVitalsMode !== void 0) {
|
|
529
529
|
if (typeof s.webVitalsMode != "string")
|
|
530
530
|
throw new f(
|
|
531
531
|
`Invalid webVitalsMode type: ${typeof s.webVitalsMode}. Must be a string`,
|
|
@@ -556,7 +556,7 @@ const Jt = () => {
|
|
|
556
556
|
}
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
|
-
},
|
|
559
|
+
}, ir = (s) => {
|
|
560
560
|
if (typeof s != "object" || s === null)
|
|
561
561
|
throw new f(m.INVALID_VIEWPORT_CONFIG, "config");
|
|
562
562
|
if (!s.elements || !Array.isArray(s.elements))
|
|
@@ -586,7 +586,7 @@ const Jt = () => {
|
|
|
586
586
|
throw new f(m.INVALID_VIEWPORT_COOLDOWN_PERIOD, "config");
|
|
587
587
|
if (s.maxTrackedElements !== void 0 && (typeof s.maxTrackedElements != "number" || s.maxTrackedElements <= 0))
|
|
588
588
|
throw new f(m.INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS, "config");
|
|
589
|
-
},
|
|
589
|
+
}, or = (s) => {
|
|
590
590
|
if (s) {
|
|
591
591
|
if (s.tracelog && (!s.tracelog.projectId || typeof s.tracelog.projectId != "string" || s.tracelog.projectId.trim() === ""))
|
|
592
592
|
throw new U(m.INVALID_TRACELOG_PROJECT_ID, "config");
|
|
@@ -607,14 +607,14 @@ const Jt = () => {
|
|
|
607
607
|
throw new U('fetchCredentials must be "include", "same-origin", or "omit"', "config");
|
|
608
608
|
}
|
|
609
609
|
}
|
|
610
|
-
},
|
|
611
|
-
|
|
610
|
+
}, ar = (s) => {
|
|
611
|
+
nr(s);
|
|
612
612
|
const e = {
|
|
613
613
|
...s ?? {},
|
|
614
614
|
sessionTimeout: s?.sessionTimeout ?? 9e5,
|
|
615
615
|
globalMetadata: s?.globalMetadata ?? {},
|
|
616
616
|
sensitiveQueryParams: s?.sensitiveQueryParams ?? [],
|
|
617
|
-
errorSampling: s?.errorSampling ??
|
|
617
|
+
errorSampling: s?.errorSampling ?? it,
|
|
618
618
|
samplingRate: s?.samplingRate ?? 1,
|
|
619
619
|
pageViewThrottleMs: s?.pageViewThrottleMs ?? 1e3,
|
|
620
620
|
clickThrottleMs: s?.clickThrottleMs ?? 300,
|
|
@@ -631,12 +631,12 @@ const Jt = () => {
|
|
|
631
631
|
cooldownPeriod: e.viewport.cooldownPeriod ?? 6e4,
|
|
632
632
|
maxTrackedElements: e.viewport.maxTrackedElements ?? 100
|
|
633
633
|
}), e;
|
|
634
|
-
},
|
|
634
|
+
}, ye = (s, e = /* @__PURE__ */ new Set()) => {
|
|
635
635
|
if (s == null)
|
|
636
636
|
return !0;
|
|
637
637
|
const t = typeof s;
|
|
638
|
-
return t === "string" || t === "number" || t === "boolean" ? !0 : t === "function" || t === "symbol" || t === "bigint" || e.has(s) ? !1 : (e.add(s), Array.isArray(s) ? s.every((r) =>
|
|
639
|
-
},
|
|
638
|
+
return t === "string" || t === "number" || t === "boolean" ? !0 : t === "function" || t === "symbol" || t === "bigint" || e.has(s) ? !1 : (e.add(s), Array.isArray(s) ? s.every((r) => ye(r, e)) : t === "object" ? Object.values(s).every((r) => ye(r, e)) : !1);
|
|
639
|
+
}, lr = (s) => typeof s != "object" || s === null ? !1 : ye(s), cr = (s) => typeof s != "string" ? {
|
|
640
640
|
valid: !1,
|
|
641
641
|
error: "Event name must be a string"
|
|
642
642
|
} : s.length === 0 ? {
|
|
@@ -651,9 +651,9 @@ const Jt = () => {
|
|
|
651
651
|
} : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(s.toLowerCase()) ? {
|
|
652
652
|
valid: !1,
|
|
653
653
|
error: "Event name cannot be a reserved word"
|
|
654
|
-
} : { valid: !0 },
|
|
655
|
-
const r =
|
|
656
|
-
if (!
|
|
654
|
+
} : { valid: !0 }, Ke = (s, e, t) => {
|
|
655
|
+
const r = sr(e), n = t && t === "customEvent" ? `${t} "${s}" metadata error` : `${s} metadata error`;
|
|
656
|
+
if (!lr(r))
|
|
657
657
|
return {
|
|
658
658
|
valid: !1,
|
|
659
659
|
error: `${n}: object has invalid types. Valid types are string, number, boolean or string arrays.`
|
|
@@ -677,31 +677,31 @@ const Jt = () => {
|
|
|
677
677
|
valid: !1,
|
|
678
678
|
error: `${n}: object has too many keys (max 10 keys).`
|
|
679
679
|
};
|
|
680
|
-
for (const [
|
|
680
|
+
for (const [l, c] of Object.entries(r)) {
|
|
681
681
|
if (Array.isArray(c)) {
|
|
682
682
|
if (c.length > 10)
|
|
683
683
|
return {
|
|
684
684
|
valid: !1,
|
|
685
|
-
error: `${n}: array property "${
|
|
685
|
+
error: `${n}: array property "${l}" is too large (max 10 items).`
|
|
686
686
|
};
|
|
687
687
|
for (const u of c)
|
|
688
688
|
if (typeof u == "string" && u.length > 500)
|
|
689
689
|
return {
|
|
690
690
|
valid: !1,
|
|
691
|
-
error: `${n}: array property "${
|
|
691
|
+
error: `${n}: array property "${l}" contains strings that are too long (max 500 characters).`
|
|
692
692
|
};
|
|
693
693
|
}
|
|
694
694
|
if (typeof c == "string" && c.length > 1e3)
|
|
695
695
|
return {
|
|
696
696
|
valid: !1,
|
|
697
|
-
error: `${n}: property "${
|
|
697
|
+
error: `${n}: property "${l}" is too long (max 1000 characters).`
|
|
698
698
|
};
|
|
699
699
|
}
|
|
700
700
|
return {
|
|
701
701
|
valid: !0,
|
|
702
702
|
sanitizedMetadata: r
|
|
703
703
|
};
|
|
704
|
-
},
|
|
704
|
+
}, ct = (s, e, t) => {
|
|
705
705
|
if (Array.isArray(e)) {
|
|
706
706
|
const r = [], n = t && t === "customEvent" ? `${t} "${s}" metadata error` : `${s} metadata error`;
|
|
707
707
|
for (let i = 0; i < e.length; i++) {
|
|
@@ -711,37 +711,37 @@ const Jt = () => {
|
|
|
711
711
|
valid: !1,
|
|
712
712
|
error: `${n}: array item at index ${i} must be an object.`
|
|
713
713
|
};
|
|
714
|
-
const
|
|
715
|
-
if (!
|
|
714
|
+
const l = Ke(s, o, t);
|
|
715
|
+
if (!l.valid)
|
|
716
716
|
return {
|
|
717
717
|
valid: !1,
|
|
718
|
-
error: `${n}: array item at index ${i} is invalid: ${
|
|
718
|
+
error: `${n}: array item at index ${i} is invalid: ${l.error}`
|
|
719
719
|
};
|
|
720
|
-
|
|
720
|
+
l.sanitizedMetadata && r.push(l.sanitizedMetadata);
|
|
721
721
|
}
|
|
722
722
|
return {
|
|
723
723
|
valid: !0,
|
|
724
724
|
sanitizedMetadata: r
|
|
725
725
|
};
|
|
726
726
|
}
|
|
727
|
-
return
|
|
728
|
-
},
|
|
729
|
-
const t =
|
|
727
|
+
return Ke(s, e, t);
|
|
728
|
+
}, ur = (s, e) => {
|
|
729
|
+
const t = cr(s);
|
|
730
730
|
if (!t.valid)
|
|
731
|
-
return
|
|
731
|
+
return a("error", "Event name validation failed", {
|
|
732
732
|
data: { eventName: s, error: t.error }
|
|
733
733
|
}), t;
|
|
734
734
|
if (!e)
|
|
735
735
|
return { valid: !0 };
|
|
736
|
-
const r =
|
|
737
|
-
return r.valid ||
|
|
736
|
+
const r = ct(s, e, "customEvent");
|
|
737
|
+
return r.valid || a("error", "Event metadata validation failed", {
|
|
738
738
|
data: {
|
|
739
739
|
eventName: s,
|
|
740
740
|
error: r.error
|
|
741
741
|
}
|
|
742
742
|
}), r;
|
|
743
743
|
};
|
|
744
|
-
class
|
|
744
|
+
class dr {
|
|
745
745
|
listeners = /* @__PURE__ */ new Map();
|
|
746
746
|
/**
|
|
747
747
|
* Subscribes to an event channel
|
|
@@ -858,37 +858,37 @@ class cr {
|
|
|
858
858
|
this.listeners.clear();
|
|
859
859
|
}
|
|
860
860
|
}
|
|
861
|
-
function
|
|
861
|
+
function ut(s, e, t) {
|
|
862
862
|
try {
|
|
863
863
|
const r = e(s);
|
|
864
|
-
return r === null ? null : typeof r == "object" && r !== null && "type" in r ? r : (
|
|
864
|
+
return r === null ? null : typeof r == "object" && r !== null && "type" in r ? r : (a("warn", `beforeSend transformer returned invalid data, using original [${t}]`), s);
|
|
865
865
|
} catch (r) {
|
|
866
|
-
return
|
|
866
|
+
return a("error", `beforeSend transformer threw error, using original event [${t}]`, {
|
|
867
867
|
error: r,
|
|
868
868
|
visibility: "critical"
|
|
869
869
|
}), s;
|
|
870
870
|
}
|
|
871
871
|
}
|
|
872
|
-
function
|
|
873
|
-
return s.map((r) =>
|
|
872
|
+
function hr(s, e, t) {
|
|
873
|
+
return s.map((r) => ut(r, e, t)).filter((r) => r !== null);
|
|
874
874
|
}
|
|
875
|
-
function
|
|
875
|
+
function dt(s, e, t) {
|
|
876
876
|
try {
|
|
877
877
|
const r = e(s);
|
|
878
|
-
return r === null ? (
|
|
878
|
+
return r === null ? (a("debug", `Batch filtered by beforeBatch transformer [${t}]`, {
|
|
879
879
|
data: { eventCount: s.events.length }
|
|
880
|
-
}), null) : typeof r == "object" && r !== null && Array.isArray(r.events) ? r : (
|
|
880
|
+
}), null) : typeof r == "object" && r !== null && Array.isArray(r.events) ? r : (a("warn", `beforeBatch transformer returned invalid data, using original [${t}]`, {
|
|
881
881
|
data: { eventCount: s.events.length }
|
|
882
882
|
}), s);
|
|
883
883
|
} catch (r) {
|
|
884
|
-
return
|
|
884
|
+
return a("error", `beforeBatch transformer threw error, using original batch [${t}]`, {
|
|
885
885
|
error: r,
|
|
886
886
|
data: { eventCount: s.events.length },
|
|
887
887
|
visibility: "critical"
|
|
888
888
|
}), s;
|
|
889
889
|
}
|
|
890
890
|
}
|
|
891
|
-
const
|
|
891
|
+
const fe = {};
|
|
892
892
|
class w {
|
|
893
893
|
/**
|
|
894
894
|
* Retrieves a value from global state.
|
|
@@ -907,7 +907,7 @@ class w {
|
|
|
907
907
|
* ```
|
|
908
908
|
*/
|
|
909
909
|
get(e) {
|
|
910
|
-
return
|
|
910
|
+
return fe[e];
|
|
911
911
|
}
|
|
912
912
|
/**
|
|
913
913
|
* Sets a value in global state.
|
|
@@ -927,7 +927,7 @@ class w {
|
|
|
927
927
|
* ```
|
|
928
928
|
*/
|
|
929
929
|
set(e, t) {
|
|
930
|
-
|
|
930
|
+
fe[e] = t;
|
|
931
931
|
}
|
|
932
932
|
/**
|
|
933
933
|
* Returns an immutable snapshot of the entire global state.
|
|
@@ -944,10 +944,10 @@ class w {
|
|
|
944
944
|
* ```
|
|
945
945
|
*/
|
|
946
946
|
getState() {
|
|
947
|
-
return { ...
|
|
947
|
+
return { ...fe };
|
|
948
948
|
}
|
|
949
949
|
}
|
|
950
|
-
class
|
|
950
|
+
class Ye extends w {
|
|
951
951
|
storeManager;
|
|
952
952
|
integrationId;
|
|
953
953
|
apiUrl;
|
|
@@ -982,10 +982,10 @@ class ze extends w {
|
|
|
982
982
|
* @param customHeadersProvider - Optional callback for dynamic headers
|
|
983
983
|
* @throws Error if integrationId and apiUrl are not both provided or both undefined
|
|
984
984
|
*/
|
|
985
|
-
constructor(e, t, r, n = {}, i = {}, o,
|
|
985
|
+
constructor(e, t, r, n = {}, i = {}, o, l = "include") {
|
|
986
986
|
if (super(), t && !r || !t && r)
|
|
987
987
|
throw new Error("SenderManager: integrationId and apiUrl must either both be provided or both be undefined");
|
|
988
|
-
this.storeManager = e, this.integrationId = t, this.apiUrl = r, this.transformers = n, this.staticHeaders = i, this.customHeadersProvider = o, this.fetchCredentials =
|
|
988
|
+
this.storeManager = e, this.integrationId = t, this.apiUrl = r, this.transformers = n, this.staticHeaders = i, this.customHeadersProvider = o, this.fetchCredentials = l;
|
|
989
989
|
}
|
|
990
990
|
/**
|
|
991
991
|
* Get the integration ID for this sender
|
|
@@ -1023,16 +1023,16 @@ class ze extends w {
|
|
|
1023
1023
|
if (this.customHeadersProvider)
|
|
1024
1024
|
try {
|
|
1025
1025
|
const t = this.customHeadersProvider();
|
|
1026
|
-
typeof t == "object" && t !== null && !Array.isArray(t) ? e = t :
|
|
1026
|
+
typeof t == "object" && t !== null && !Array.isArray(t) ? e = t : a("warn", "Custom headers provider returned invalid value, expected object", {
|
|
1027
1027
|
data: { received: typeof t }
|
|
1028
1028
|
});
|
|
1029
1029
|
} catch (t) {
|
|
1030
|
-
|
|
1030
|
+
a("warn", "Custom headers provider threw an error, using static headers only", { error: t });
|
|
1031
1031
|
}
|
|
1032
1032
|
return { ...this.staticHeaders, ...e };
|
|
1033
1033
|
}
|
|
1034
1034
|
getQueueStorageKey() {
|
|
1035
|
-
const e = this.get("userId") || "anonymous", t =
|
|
1035
|
+
const e = this.get("userId") || "anonymous", t = bt(e);
|
|
1036
1036
|
return this.integrationId ? `${t}:${this.integrationId}` : t;
|
|
1037
1037
|
}
|
|
1038
1038
|
/**
|
|
@@ -1074,13 +1074,13 @@ class ze extends w {
|
|
|
1074
1074
|
* @see src/managers/README.md (lines 82-139) for send details
|
|
1075
1075
|
*/
|
|
1076
1076
|
sendEventsQueueSync(e) {
|
|
1077
|
-
return this.shouldSkipSend() ? !0 : this.apiUrl?.includes(
|
|
1077
|
+
return this.shouldSkipSend() ? !0 : this.apiUrl?.includes(B.Fail) ? (a(
|
|
1078
1078
|
"warn",
|
|
1079
1079
|
`Fail mode: simulating network failure (sync)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1080
1080
|
{
|
|
1081
1081
|
data: { events: e.events.length }
|
|
1082
1082
|
}
|
|
1083
|
-
), !1) : this.apiUrl?.includes(
|
|
1083
|
+
), !1) : this.apiUrl?.includes(B.Localhost) ? (a(
|
|
1084
1084
|
"debug",
|
|
1085
1085
|
`Success mode: simulating successful send (sync)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1086
1086
|
{
|
|
@@ -1123,7 +1123,7 @@ class ze extends w {
|
|
|
1123
1123
|
const r = await this.send(e);
|
|
1124
1124
|
return r ? (this.clearPersistedEvents(), t?.onSuccess?.(e.events.length, e.events, e)) : (this.persistEvents(e), t?.onFailure?.()), r;
|
|
1125
1125
|
} catch (r) {
|
|
1126
|
-
return r instanceof N ? (this.logPermanentError("Permanent error, not retrying", r), this.clearPersistedEvents(), t?.onFailure?.(), !1) : r instanceof O ? (
|
|
1126
|
+
return r instanceof N ? (this.logPermanentError("Permanent error, not retrying", r), this.clearPersistedEvents(), t?.onFailure?.(), !1) : r instanceof O ? (a(
|
|
1127
1127
|
"debug",
|
|
1128
1128
|
`All attempts timed out, skipping persistence (server likely received events)${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1129
1129
|
), this.clearPersistedEvents(), t?.onFailure?.(), !1) : (this.persistEvents(e), t?.onFailure?.(), !1);
|
|
@@ -1180,7 +1180,7 @@ class ze extends w {
|
|
|
1180
1180
|
*/
|
|
1181
1181
|
async recoverPersistedEvents(e) {
|
|
1182
1182
|
if (this.recoveryInProgress) {
|
|
1183
|
-
|
|
1183
|
+
a("debug", "Recovery already in progress, skipping duplicate attempt");
|
|
1184
1184
|
return;
|
|
1185
1185
|
}
|
|
1186
1186
|
this.recoveryInProgress = !0;
|
|
@@ -1192,7 +1192,7 @@ class ze extends w {
|
|
|
1192
1192
|
}
|
|
1193
1193
|
const r = t.recoveryFailures, n = typeof r == "number" && Number.isFinite(r) && r >= 0 ? r : 0;
|
|
1194
1194
|
if (n >= 3) {
|
|
1195
|
-
|
|
1195
|
+
a(
|
|
1196
1196
|
"debug",
|
|
1197
1197
|
`Discarding persisted events after ${n} failed recovery attempts${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1198
1198
|
), this.clearPersistedEvents(), e?.onFailure?.();
|
|
@@ -1206,13 +1206,13 @@ class ze extends w {
|
|
|
1206
1206
|
return;
|
|
1207
1207
|
}
|
|
1208
1208
|
if (t instanceof O) {
|
|
1209
|
-
|
|
1209
|
+
a(
|
|
1210
1210
|
"debug",
|
|
1211
1211
|
`Recovery timed out, clearing persisted events (server likely received them)${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1212
1212
|
), this.clearPersistedEvents(), e?.onFailure?.();
|
|
1213
1213
|
return;
|
|
1214
1214
|
}
|
|
1215
|
-
|
|
1215
|
+
a("error", "Failed to recover persisted events", { error: t });
|
|
1216
1216
|
} finally {
|
|
1217
1217
|
this.recoveryInProgress = !1;
|
|
1218
1218
|
}
|
|
@@ -1262,7 +1262,7 @@ class ze extends w {
|
|
|
1262
1262
|
const t = this.transformers.beforeSend;
|
|
1263
1263
|
if (!t)
|
|
1264
1264
|
return e;
|
|
1265
|
-
const r =
|
|
1265
|
+
const r = hr(
|
|
1266
1266
|
e.events,
|
|
1267
1267
|
t,
|
|
1268
1268
|
this.integrationId || "SenderManager"
|
|
@@ -1307,7 +1307,7 @@ class ze extends w {
|
|
|
1307
1307
|
if (this.integrationId === "saas")
|
|
1308
1308
|
return e;
|
|
1309
1309
|
const t = this.transformers.beforeBatch;
|
|
1310
|
-
return t ?
|
|
1310
|
+
return t ? dt(e, t, this.integrationId || "SenderManager") : e;
|
|
1311
1311
|
}
|
|
1312
1312
|
/**
|
|
1313
1313
|
* Calculates exponential backoff delay with jitter for retry attempts.
|
|
@@ -1376,18 +1376,18 @@ class ze extends w {
|
|
|
1376
1376
|
const r = this.applyBeforeBatchTransformer(t);
|
|
1377
1377
|
if (!r)
|
|
1378
1378
|
return !0;
|
|
1379
|
-
if (this.apiUrl?.includes(
|
|
1380
|
-
return
|
|
1379
|
+
if (this.apiUrl?.includes(B.Fail))
|
|
1380
|
+
return a("debug", `Fail mode: simulating network failure${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1381
1381
|
data: { events: r.events.length }
|
|
1382
1382
|
}), !1;
|
|
1383
|
-
if (this.apiUrl?.includes(
|
|
1384
|
-
return
|
|
1383
|
+
if (this.apiUrl?.includes(B.Localhost))
|
|
1384
|
+
return a("debug", `Success mode: simulating successful send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1385
1385
|
data: { events: r.events.length }
|
|
1386
1386
|
}), !0;
|
|
1387
1387
|
if (this.consecutiveNetworkFailures >= 3) {
|
|
1388
1388
|
const c = Date.now() - this.circuitOpenedAt;
|
|
1389
1389
|
if (c < 12e4)
|
|
1390
|
-
return
|
|
1390
|
+
return a("debug", `Network circuit open, skipping send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1391
1391
|
data: {
|
|
1392
1392
|
consecutiveNetworkFailures: this.consecutiveNetworkFailures,
|
|
1393
1393
|
cooldownRemainingMs: 12e4 - c
|
|
@@ -1395,10 +1395,10 @@ class ze extends w {
|
|
|
1395
1395
|
}), !1;
|
|
1396
1396
|
}
|
|
1397
1397
|
const { url: n, payload: i } = this.prepareRequest(r);
|
|
1398
|
-
let o = !0,
|
|
1398
|
+
let o = !0, l = !1;
|
|
1399
1399
|
for (let c = 1; c <= 3; c++)
|
|
1400
1400
|
try {
|
|
1401
|
-
return (await this.sendWithTimeout(n, i)).ok ? (c > 1 &&
|
|
1401
|
+
return (await this.sendWithTimeout(n, i)).ok ? (c > 1 && a(
|
|
1402
1402
|
"info",
|
|
1403
1403
|
`Send succeeded after ${c - 1} retry attempt(s)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1404
1404
|
{
|
|
@@ -1409,7 +1409,7 @@ class ze extends w {
|
|
|
1409
1409
|
const g = c === 3;
|
|
1410
1410
|
if (u instanceof N)
|
|
1411
1411
|
throw this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, u;
|
|
1412
|
-
if (u instanceof O || (o = !1), u instanceof TypeError || (
|
|
1412
|
+
if (u instanceof O || (o = !1), u instanceof TypeError || (l = !0), a(
|
|
1413
1413
|
g ? "error" : "warn",
|
|
1414
1414
|
`Send attempt ${c} failed${this.integrationId ? ` [${this.integrationId}]` : ""}${g ? " (all retries exhausted)" : ", will retry"}`,
|
|
1415
1415
|
{
|
|
@@ -1427,7 +1427,7 @@ class ze extends w {
|
|
|
1427
1427
|
}
|
|
1428
1428
|
if (o)
|
|
1429
1429
|
throw new O("All retry attempts timed out (server likely received the request)");
|
|
1430
|
-
return
|
|
1430
|
+
return l ? (this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0) : (this.consecutiveNetworkFailures = Math.min(
|
|
1431
1431
|
this.consecutiveNetworkFailures + 1,
|
|
1432
1432
|
3
|
|
1433
1433
|
), this.consecutiveNetworkFailures >= 3 && (this.circuitOpenedAt = Date.now())), !1;
|
|
@@ -1465,7 +1465,7 @@ class ze extends w {
|
|
|
1465
1465
|
n = !0, r.abort();
|
|
1466
1466
|
}, 15e3);
|
|
1467
1467
|
try {
|
|
1468
|
-
const o = this.getCustomHeaders(),
|
|
1468
|
+
const o = this.getCustomHeaders(), l = await fetch(e, {
|
|
1469
1469
|
method: "POST",
|
|
1470
1470
|
body: t,
|
|
1471
1471
|
keepalive: !0,
|
|
@@ -1476,9 +1476,9 @@ class ze extends w {
|
|
|
1476
1476
|
"Content-Type": "application/json"
|
|
1477
1477
|
}
|
|
1478
1478
|
});
|
|
1479
|
-
if (!
|
|
1480
|
-
throw
|
|
1481
|
-
return
|
|
1479
|
+
if (!l.ok)
|
|
1480
|
+
throw l.status >= 400 && l.status < 500 && l.status !== 408 && l.status !== 429 ? new N(`HTTP ${l.status}: ${l.statusText}`, l.status) : new Error(`HTTP ${l.status}: ${l.statusText}`);
|
|
1481
|
+
return l;
|
|
1482
1482
|
} catch (o) {
|
|
1483
1483
|
throw o instanceof N ? o : n ? new O("Request timed out (server likely received the request)") : o;
|
|
1484
1484
|
} finally {
|
|
@@ -1514,7 +1514,7 @@ class ze extends w {
|
|
|
1514
1514
|
return !0;
|
|
1515
1515
|
const { url: n, payload: i } = this.prepareRequest(r);
|
|
1516
1516
|
if (i.length > 65536)
|
|
1517
|
-
return
|
|
1517
|
+
return a(
|
|
1518
1518
|
"warn",
|
|
1519
1519
|
`Payload exceeds sendBeacon limit, persisting for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1520
1520
|
{
|
|
@@ -1527,15 +1527,15 @@ class ze extends w {
|
|
|
1527
1527
|
), this.persistEvents(r), !1;
|
|
1528
1528
|
const o = new Blob([i], { type: "application/json" });
|
|
1529
1529
|
if (!this.isSendBeaconAvailable())
|
|
1530
|
-
return
|
|
1530
|
+
return a(
|
|
1531
1531
|
"warn",
|
|
1532
1532
|
`sendBeacon not available, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1533
1533
|
), this.persistEvents(r), !1;
|
|
1534
|
-
const
|
|
1535
|
-
return
|
|
1534
|
+
const l = navigator.sendBeacon(n, o);
|
|
1535
|
+
return l || (a(
|
|
1536
1536
|
"warn",
|
|
1537
1537
|
`sendBeacon rejected request, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1538
|
-
), this.persistEvents(r)),
|
|
1538
|
+
), this.persistEvents(r)), l;
|
|
1539
1539
|
}
|
|
1540
1540
|
/**
|
|
1541
1541
|
* Prepares request by enriching payload with metadata and serializing to JSON.
|
|
@@ -1563,7 +1563,7 @@ class ze extends w {
|
|
|
1563
1563
|
_metadata: {
|
|
1564
1564
|
referer: typeof window < "u" ? window.location.href : void 0,
|
|
1565
1565
|
timestamp: t,
|
|
1566
|
-
client_version:
|
|
1566
|
+
client_version: zt
|
|
1567
1567
|
}
|
|
1568
1568
|
};
|
|
1569
1569
|
return {
|
|
@@ -1589,7 +1589,7 @@ class ze extends w {
|
|
|
1589
1589
|
if (t)
|
|
1590
1590
|
return JSON.parse(t);
|
|
1591
1591
|
} catch (e) {
|
|
1592
|
-
|
|
1592
|
+
a("debug", `Failed to parse persisted data${this.integrationId ? ` [${this.integrationId}]` : ""}`, { error: e }), this.clearPersistedEvents();
|
|
1593
1593
|
}
|
|
1594
1594
|
return null;
|
|
1595
1595
|
}
|
|
@@ -1660,13 +1660,13 @@ class ze extends w {
|
|
|
1660
1660
|
try {
|
|
1661
1661
|
const n = this.getPersistedData();
|
|
1662
1662
|
if (!r && n && n.timestamp) {
|
|
1663
|
-
const
|
|
1664
|
-
if (
|
|
1665
|
-
return
|
|
1663
|
+
const l = Date.now() - n.timestamp;
|
|
1664
|
+
if (l < 1e3)
|
|
1665
|
+
return a(
|
|
1666
1666
|
"debug",
|
|
1667
1667
|
`Skipping persistence, another tab recently persisted events${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1668
1668
|
{
|
|
1669
|
-
data: { timeSinceExisting:
|
|
1669
|
+
data: { timeSinceExisting: l }
|
|
1670
1670
|
}
|
|
1671
1671
|
), !0;
|
|
1672
1672
|
}
|
|
@@ -1677,7 +1677,7 @@ class ze extends w {
|
|
|
1677
1677
|
}, o = this.getQueueStorageKey();
|
|
1678
1678
|
return this.storeManager.setItem(o, JSON.stringify(i)), !!this.storeManager.getItem(o);
|
|
1679
1679
|
} catch (n) {
|
|
1680
|
-
return
|
|
1680
|
+
return a("debug", `Failed to persist events${this.integrationId ? ` [${this.integrationId}]` : ""}`, { error: n }), !1;
|
|
1681
1681
|
}
|
|
1682
1682
|
}
|
|
1683
1683
|
clearPersistedEvents() {
|
|
@@ -1685,7 +1685,7 @@ class ze extends w {
|
|
|
1685
1685
|
const e = this.getQueueStorageKey();
|
|
1686
1686
|
this.storeManager.removeItem(e);
|
|
1687
1687
|
} catch (e) {
|
|
1688
|
-
|
|
1688
|
+
a("debug", `Failed to clear persisted events${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1689
1689
|
error: e
|
|
1690
1690
|
});
|
|
1691
1691
|
}
|
|
@@ -1702,12 +1702,12 @@ class ze extends w {
|
|
|
1702
1702
|
}
|
|
1703
1703
|
logPermanentError(e, t) {
|
|
1704
1704
|
const r = Date.now();
|
|
1705
|
-
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || r - this.lastPermanentErrorLog.timestamp >=
|
|
1705
|
+
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || r - this.lastPermanentErrorLog.timestamp >= Wt) && (a("error", `${e}${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1706
1706
|
data: { status: t.statusCode, message: t.message }
|
|
1707
1707
|
}), this.lastPermanentErrorLog = { statusCode: t.statusCode, timestamp: r });
|
|
1708
1708
|
}
|
|
1709
1709
|
}
|
|
1710
|
-
class
|
|
1710
|
+
class fr extends w {
|
|
1711
1711
|
bootTime;
|
|
1712
1712
|
bootTimestamp;
|
|
1713
1713
|
hasPerformanceNow;
|
|
@@ -1732,12 +1732,12 @@ class dr extends w {
|
|
|
1732
1732
|
this.hasPerformanceNow = !1, this.bootTime = 0, this.bootTimestamp = 0;
|
|
1733
1733
|
return;
|
|
1734
1734
|
}
|
|
1735
|
-
this.hasPerformanceNow = typeof performance < "u" && typeof performance.now == "function", this.hasPerformanceNow ? (this.bootTime = performance.now(), this.bootTimestamp = Date.now(),
|
|
1735
|
+
this.hasPerformanceNow = typeof performance < "u" && typeof performance.now == "function", this.hasPerformanceNow ? (this.bootTime = performance.now(), this.bootTimestamp = Date.now(), a("debug", "TimeManager initialized with monotonic clock", {
|
|
1736
1736
|
data: {
|
|
1737
1737
|
bootTime: this.bootTime.toFixed(3),
|
|
1738
1738
|
bootTimestamp: this.bootTimestamp
|
|
1739
1739
|
}
|
|
1740
|
-
})) : (this.bootTime = 0, this.bootTimestamp = Date.now(),
|
|
1740
|
+
})) : (this.bootTime = 0, this.bootTimestamp = Date.now(), a("debug", "performance.now() not available, falling back to Date.now()"));
|
|
1741
1741
|
}
|
|
1742
1742
|
/**
|
|
1743
1743
|
* Returns current timestamp in milliseconds since epoch.
|
|
@@ -1800,7 +1800,7 @@ class dr extends w {
|
|
|
1800
1800
|
return this.detectedSkew;
|
|
1801
1801
|
this.lastClockSkewCheck = e;
|
|
1802
1802
|
const t = this.now(), r = Date.now();
|
|
1803
|
-
return this.detectedSkew = r - t, Math.abs(this.detectedSkew) > 3e4 &&
|
|
1803
|
+
return this.detectedSkew = r - t, Math.abs(this.detectedSkew) > 3e4 && a("warn", "Significant clock skew detected", {
|
|
1804
1804
|
data: {
|
|
1805
1805
|
skewMs: this.detectedSkew,
|
|
1806
1806
|
skewMinutes: (this.detectedSkew / 1e3 / 60).toFixed(2),
|
|
@@ -1856,8 +1856,8 @@ class dr extends w {
|
|
|
1856
1856
|
};
|
|
1857
1857
|
}
|
|
1858
1858
|
}
|
|
1859
|
-
const
|
|
1860
|
-
class
|
|
1859
|
+
const mr = new Set(Object.values(d));
|
|
1860
|
+
class gr extends w {
|
|
1861
1861
|
dataSenders;
|
|
1862
1862
|
emitter;
|
|
1863
1863
|
transformers;
|
|
@@ -1896,13 +1896,13 @@ class fr extends w {
|
|
|
1896
1896
|
* @param fetchCredentials - Fetch credentials mode for custom backend. @default 'include'
|
|
1897
1897
|
*/
|
|
1898
1898
|
constructor(e, t = null, r = {}, n = {}, i, o = "include") {
|
|
1899
|
-
super(), this.emitter = t, this.transformers = r, this.timeManager = new
|
|
1900
|
-
const
|
|
1901
|
-
|
|
1902
|
-
new
|
|
1899
|
+
super(), this.emitter = t, this.transformers = r, this.timeManager = new fr(), this.dataSenders = [];
|
|
1900
|
+
const l = this.get("collectApiUrls");
|
|
1901
|
+
l?.saas && this.dataSenders.push(new Ye(e, "saas", l.saas, r)), l?.custom && this.dataSenders.push(
|
|
1902
|
+
new Ye(
|
|
1903
1903
|
e,
|
|
1904
1904
|
"custom",
|
|
1905
|
-
|
|
1905
|
+
l.custom,
|
|
1906
1906
|
r,
|
|
1907
1907
|
n,
|
|
1908
1908
|
i,
|
|
@@ -1941,12 +1941,12 @@ class fr extends w {
|
|
|
1941
1941
|
async (t) => t.recoverPersistedEvents({
|
|
1942
1942
|
onSuccess: (r, n, i) => {
|
|
1943
1943
|
if (n && n.length > 0) {
|
|
1944
|
-
const o = n.map((
|
|
1944
|
+
const o = n.map((l) => l.id);
|
|
1945
1945
|
this.removeProcessedEvents(o), i && this.emitEventsQueue(i);
|
|
1946
1946
|
}
|
|
1947
1947
|
},
|
|
1948
1948
|
onFailure: () => {
|
|
1949
|
-
|
|
1949
|
+
a("debug", "Failed to recover persisted events");
|
|
1950
1950
|
}
|
|
1951
1951
|
})
|
|
1952
1952
|
);
|
|
@@ -2018,24 +2018,24 @@ class fr extends w {
|
|
|
2018
2018
|
scroll_data: n,
|
|
2019
2019
|
click_data: i,
|
|
2020
2020
|
custom_event: o,
|
|
2021
|
-
web_vitals:
|
|
2021
|
+
web_vitals: l,
|
|
2022
2022
|
error_data: c,
|
|
2023
2023
|
viewport_data: u,
|
|
2024
2024
|
page_view: g
|
|
2025
2025
|
}) {
|
|
2026
2026
|
if (!e) {
|
|
2027
|
-
|
|
2027
|
+
a("error", "Event type is required - event will be ignored");
|
|
2028
2028
|
return;
|
|
2029
2029
|
}
|
|
2030
|
-
if (!
|
|
2031
|
-
|
|
2030
|
+
if (!mr.has(e)) {
|
|
2031
|
+
a("error", "Invalid event type - event will be ignored", {
|
|
2032
2032
|
data: { type: e }
|
|
2033
2033
|
});
|
|
2034
2034
|
return;
|
|
2035
2035
|
}
|
|
2036
2036
|
const E = this.get("sessionId");
|
|
2037
2037
|
if (!E) {
|
|
2038
|
-
this.pendingEventsBuffer.length >= 100 && (this.pendingEventsBuffer.shift(),
|
|
2038
|
+
this.pendingEventsBuffer.length >= 100 && (this.pendingEventsBuffer.shift(), a("debug", "Pending events buffer full - dropping oldest event", {
|
|
2039
2039
|
data: { maxBufferSize: 100 }
|
|
2040
2040
|
})), this.pendingEventsBuffer.push({
|
|
2041
2041
|
type: e,
|
|
@@ -2044,7 +2044,7 @@ class fr extends w {
|
|
|
2044
2044
|
scroll_data: n,
|
|
2045
2045
|
click_data: i,
|
|
2046
2046
|
custom_event: o,
|
|
2047
|
-
web_vitals:
|
|
2047
|
+
web_vitals: l,
|
|
2048
2048
|
error_data: c,
|
|
2049
2049
|
viewport_data: u,
|
|
2050
2050
|
page_view: g
|
|
@@ -2052,15 +2052,15 @@ class fr extends w {
|
|
|
2052
2052
|
return;
|
|
2053
2053
|
}
|
|
2054
2054
|
this.lastSessionId !== E && (this.lastSessionId = E, this.sessionEventCounts = this.loadSessionCounts(E));
|
|
2055
|
-
const
|
|
2056
|
-
if (
|
|
2055
|
+
const T = e === d.SESSION_START;
|
|
2056
|
+
if (T && a("debug", "Processing SESSION_START event", {
|
|
2057
2057
|
data: { sessionId: E }
|
|
2058
|
-
}), !
|
|
2058
|
+
}), !T && !this.checkRateLimit())
|
|
2059
2059
|
return;
|
|
2060
2060
|
const S = e;
|
|
2061
|
-
if (!
|
|
2061
|
+
if (!T) {
|
|
2062
2062
|
if (this.sessionEventCounts.total >= 1e3) {
|
|
2063
|
-
|
|
2063
|
+
a("warn", "Session event limit reached", {
|
|
2064
2064
|
data: {
|
|
2065
2065
|
type: S,
|
|
2066
2066
|
total: this.sessionEventCounts.total,
|
|
@@ -2069,15 +2069,15 @@ class fr extends w {
|
|
|
2069
2069
|
});
|
|
2070
2070
|
return;
|
|
2071
2071
|
}
|
|
2072
|
-
const
|
|
2073
|
-
if (
|
|
2074
|
-
const
|
|
2075
|
-
if (
|
|
2076
|
-
|
|
2072
|
+
const v = this.getTypeLimitForEvent(S);
|
|
2073
|
+
if (v) {
|
|
2074
|
+
const ce = this.sessionEventCounts[S];
|
|
2075
|
+
if (ce !== void 0 && ce >= v) {
|
|
2076
|
+
a("warn", "Session event type limit reached", {
|
|
2077
2077
|
data: {
|
|
2078
2078
|
type: S,
|
|
2079
|
-
count:
|
|
2080
|
-
limit:
|
|
2079
|
+
count: ce,
|
|
2080
|
+
limit: v
|
|
2081
2081
|
}
|
|
2082
2082
|
});
|
|
2083
2083
|
return;
|
|
@@ -2085,52 +2085,52 @@ class fr extends w {
|
|
|
2085
2085
|
}
|
|
2086
2086
|
}
|
|
2087
2087
|
if (S === d.CUSTOM && o?.name) {
|
|
2088
|
-
const
|
|
2089
|
-
if (!this.checkPerEventRateLimit(o.name,
|
|
2088
|
+
const v = this.get("config")?.maxSameEventPerMinute ?? 60;
|
|
2089
|
+
if (!this.checkPerEventRateLimit(o.name, v))
|
|
2090
2090
|
return;
|
|
2091
2091
|
}
|
|
2092
|
-
const
|
|
2092
|
+
const De = S === d.SESSION_START, Y = t || this.get("pageUrl"), $ = this.buildEventPayload({
|
|
2093
2093
|
type: S,
|
|
2094
|
-
page_url:
|
|
2094
|
+
page_url: Y,
|
|
2095
2095
|
from_page_url: r,
|
|
2096
2096
|
scroll_data: n,
|
|
2097
2097
|
click_data: i,
|
|
2098
2098
|
custom_event: o,
|
|
2099
|
-
web_vitals:
|
|
2099
|
+
web_vitals: l,
|
|
2100
2100
|
error_data: c,
|
|
2101
2101
|
viewport_data: u,
|
|
2102
2102
|
page_view: g
|
|
2103
2103
|
});
|
|
2104
|
-
if (
|
|
2105
|
-
if (
|
|
2106
|
-
const
|
|
2107
|
-
if (!
|
|
2108
|
-
|
|
2104
|
+
if ($ && !(!T && !this.shouldSample())) {
|
|
2105
|
+
if (De) {
|
|
2106
|
+
const v = this.get("sessionId");
|
|
2107
|
+
if (!v) {
|
|
2108
|
+
a("error", "Session start event requires sessionId - event will be ignored");
|
|
2109
2109
|
return;
|
|
2110
2110
|
}
|
|
2111
2111
|
if (this.get("hasStartSession")) {
|
|
2112
|
-
|
|
2113
|
-
data: { sessionId:
|
|
2112
|
+
a("debug", "Duplicate session_start detected", {
|
|
2113
|
+
data: { sessionId: v }
|
|
2114
2114
|
});
|
|
2115
2115
|
return;
|
|
2116
2116
|
}
|
|
2117
2117
|
this.set("hasStartSession", !0);
|
|
2118
2118
|
}
|
|
2119
|
-
if (!this.isDuplicateEvent(
|
|
2120
|
-
if (this.get("mode") ===
|
|
2119
|
+
if (!this.isDuplicateEvent($)) {
|
|
2120
|
+
if (this.get("mode") === se.QA) {
|
|
2121
2121
|
if (S === d.CUSTOM && o) {
|
|
2122
|
-
|
|
2122
|
+
a("info", `Custom Event: ${o.name}`, {
|
|
2123
2123
|
visibility: "qa",
|
|
2124
2124
|
data: {
|
|
2125
2125
|
name: o.name,
|
|
2126
2126
|
...o.metadata && { metadata: o.metadata }
|
|
2127
2127
|
}
|
|
2128
|
-
}), this.emitEvent(
|
|
2128
|
+
}), this.emitEvent($);
|
|
2129
2129
|
return;
|
|
2130
2130
|
}
|
|
2131
2131
|
if (S === d.VIEWPORT_VISIBLE && u) {
|
|
2132
|
-
const
|
|
2133
|
-
|
|
2132
|
+
const v = u.name || u.id || u.selector;
|
|
2133
|
+
a("info", `Viewport Visible: ${v}`, {
|
|
2134
2134
|
visibility: "qa",
|
|
2135
2135
|
data: {
|
|
2136
2136
|
selector: u.selector,
|
|
@@ -2139,14 +2139,14 @@ class fr extends w {
|
|
|
2139
2139
|
visibilityRatio: u.visibilityRatio,
|
|
2140
2140
|
dwellTime: u.dwellTime
|
|
2141
2141
|
}
|
|
2142
|
-
}), this.emitEvent(
|
|
2142
|
+
}), this.emitEvent($);
|
|
2143
2143
|
return;
|
|
2144
2144
|
}
|
|
2145
2145
|
}
|
|
2146
|
-
if (this.addToQueue(
|
|
2146
|
+
if (this.addToQueue($), !T) {
|
|
2147
2147
|
this.sessionEventCounts.total++, this.sessionEventCounts[S] !== void 0 && this.sessionEventCounts[S]++;
|
|
2148
|
-
const
|
|
2149
|
-
|
|
2148
|
+
const v = this.get("sessionId");
|
|
2149
|
+
v && this.saveSessionCountsDebounced && this.saveSessionCountsDebounced(v);
|
|
2150
2150
|
}
|
|
2151
2151
|
}
|
|
2152
2152
|
}
|
|
@@ -2389,7 +2389,7 @@ class fr extends w {
|
|
|
2389
2389
|
if (this.pendingEventsBuffer.length === 0)
|
|
2390
2390
|
return;
|
|
2391
2391
|
if (!this.get("sessionId")) {
|
|
2392
|
-
|
|
2392
|
+
a("debug", "Cannot flush pending events: session not initialized - keeping in buffer", {
|
|
2393
2393
|
data: { bufferedEventCount: this.pendingEventsBuffer.length }
|
|
2394
2394
|
});
|
|
2395
2395
|
return;
|
|
@@ -2409,13 +2409,13 @@ class fr extends w {
|
|
|
2409
2409
|
if (this.eventsQueue.length === 0)
|
|
2410
2410
|
return e ? !0 : Promise.resolve(!0);
|
|
2411
2411
|
if (!e && this.sendInProgress)
|
|
2412
|
-
return
|
|
2412
|
+
return a("debug", "Async flush skipped: send already in progress"), Promise.resolve(!1);
|
|
2413
2413
|
const t = this.buildEventsPayload(), r = [...this.eventsQueue], n = r.map((i) => i.id);
|
|
2414
2414
|
if (this.dataSenders.length === 0)
|
|
2415
2415
|
return this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t), e ? !0 : Promise.resolve(!0);
|
|
2416
2416
|
if (e) {
|
|
2417
|
-
const o = this.dataSenders.map((
|
|
2418
|
-
return o ? (this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t)) : (this.clearSendTimeout(),
|
|
2417
|
+
const o = this.dataSenders.map((l) => l.sendEventsQueueSync(t)).some((l) => l);
|
|
2418
|
+
return o ? (this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t)) : (this.clearSendTimeout(), a("debug", "Sync flush complete failure, events kept in queue for retry", {
|
|
2419
2419
|
data: { eventCount: n.length }
|
|
2420
2420
|
})), o;
|
|
2421
2421
|
} else {
|
|
@@ -2428,10 +2428,10 @@ class fr extends w {
|
|
|
2428
2428
|
})
|
|
2429
2429
|
);
|
|
2430
2430
|
return Promise.allSettled(i).then((o) => {
|
|
2431
|
-
const
|
|
2432
|
-
return
|
|
2431
|
+
const l = o.some((c) => this.isSuccessfulResult(c));
|
|
2432
|
+
return l ? (this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t)) : a("debug", "Async flush complete failure, events kept in queue for retry", {
|
|
2433
2433
|
data: { eventCount: r.length }
|
|
2434
|
-
}),
|
|
2434
|
+
}), l;
|
|
2435
2435
|
});
|
|
2436
2436
|
}
|
|
2437
2437
|
}
|
|
@@ -2444,22 +2444,22 @@ class fr extends w {
|
|
|
2444
2444
|
this.emitEventsQueue(e);
|
|
2445
2445
|
return;
|
|
2446
2446
|
}
|
|
2447
|
-
const t = [...this.eventsQueue], r = t.map((
|
|
2448
|
-
async (
|
|
2447
|
+
const t = [...this.eventsQueue], r = t.map((l) => l.id), n = this.dataSenders.map(
|
|
2448
|
+
async (l) => l.sendEventsQueue(e, {
|
|
2449
2449
|
onSuccess: () => {
|
|
2450
2450
|
},
|
|
2451
2451
|
onFailure: () => {
|
|
2452
2452
|
}
|
|
2453
2453
|
})
|
|
2454
2454
|
), i = await Promise.allSettled(n);
|
|
2455
|
-
if (i.some((
|
|
2455
|
+
if (i.some((l) => this.isSuccessfulResult(l))) {
|
|
2456
2456
|
this.consecutiveSendFailures = 0, this.removeProcessedEvents(r), this.emitEventsQueue(e);
|
|
2457
|
-
const
|
|
2458
|
-
|
|
2459
|
-
data: { eventCount: t.length, failedCount:
|
|
2457
|
+
const l = i.filter((c) => !this.isSuccessfulResult(c)).length;
|
|
2458
|
+
l > 0 && a("debug", "Periodic send completed with some failures, removed from queue and persisted per-integration", {
|
|
2459
|
+
data: { eventCount: t.length, failedCount: l }
|
|
2460
2460
|
});
|
|
2461
2461
|
} else
|
|
2462
|
-
this.consecutiveSendFailures = Math.min(this.consecutiveSendFailures + 1, 5),
|
|
2462
|
+
this.consecutiveSendFailures = Math.min(this.consecutiveSendFailures + 1, 5), a("debug", "Periodic send complete failure, events kept in queue for retry", {
|
|
2463
2463
|
data: { eventCount: t.length }
|
|
2464
2464
|
});
|
|
2465
2465
|
this.eventsQueue.length === 0 ? this.clearSendTimeout() : this.scheduleSendTimeout();
|
|
@@ -2480,23 +2480,24 @@ class fr extends w {
|
|
|
2480
2480
|
session_id: this.get("sessionId"),
|
|
2481
2481
|
device: this.get("device"),
|
|
2482
2482
|
events: r,
|
|
2483
|
-
...this.get("config")?.globalMetadata && { global_metadata: this.get("config")?.globalMetadata }
|
|
2483
|
+
...this.get("config")?.globalMetadata && { global_metadata: this.get("config")?.globalMetadata },
|
|
2484
|
+
...this.get("identity") && { identify: this.get("identity") }
|
|
2484
2485
|
};
|
|
2485
|
-
const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas),
|
|
2486
|
-
if (!o &&
|
|
2487
|
-
const c =
|
|
2486
|
+
const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas), l = this.transformers.beforeBatch;
|
|
2487
|
+
if (!o && l) {
|
|
2488
|
+
const c = dt(n, l, "EventManager");
|
|
2488
2489
|
c !== null && (n = c);
|
|
2489
2490
|
}
|
|
2490
2491
|
return n;
|
|
2491
2492
|
}
|
|
2492
2493
|
buildEventPayload(e) {
|
|
2493
2494
|
const t = e.page_url ?? this.get("pageUrl"), r = this.timeManager.now(), n = this.timeManager.validateTimestamp(r);
|
|
2494
|
-
n.valid ||
|
|
2495
|
+
n.valid || a("warn", "Event timestamp validation failed", {
|
|
2495
2496
|
data: { type: e.type, error: n.error }
|
|
2496
2497
|
});
|
|
2497
2498
|
const i = this.get("sessionReferrer"), o = this.get("sessionUtm");
|
|
2498
|
-
let
|
|
2499
|
-
id:
|
|
2499
|
+
let l = {
|
|
2500
|
+
id: er(),
|
|
2500
2501
|
type: e.type,
|
|
2501
2502
|
page_url: t,
|
|
2502
2503
|
timestamp: r,
|
|
@@ -2511,18 +2512,18 @@ class fr extends w {
|
|
|
2511
2512
|
...e.page_view && { page_view: e.page_view },
|
|
2512
2513
|
...o && { utm: o }
|
|
2513
2514
|
};
|
|
2514
|
-
const c = this.get("collectApiUrls"), u = !!c?.custom, g = !!c?.saas, E = u || g,
|
|
2515
|
-
if (S && (!E || u && !
|
|
2516
|
-
const
|
|
2517
|
-
if (
|
|
2515
|
+
const c = this.get("collectApiUrls"), u = !!c?.custom, g = !!c?.saas, E = u || g, T = u && g, S = this.transformers.beforeSend;
|
|
2516
|
+
if (S && (!E || u && !T)) {
|
|
2517
|
+
const Y = ut(l, S, "EventManager");
|
|
2518
|
+
if (Y === null)
|
|
2518
2519
|
return null;
|
|
2519
|
-
|
|
2520
|
+
l = Y;
|
|
2520
2521
|
}
|
|
2521
|
-
return
|
|
2522
|
+
return l;
|
|
2522
2523
|
}
|
|
2523
2524
|
isDuplicateEvent(e) {
|
|
2524
2525
|
const t = Date.now(), r = this.createEventFingerprint(e), n = this.recentEventFingerprints.get(r);
|
|
2525
|
-
return n && t - n < 1e3 ? (this.recentEventFingerprints.set(r, t), !0) : (this.recentEventFingerprints.set(r, t), this.recentEventFingerprints.size > 1500 && this.pruneOldFingerprints(), this.recentEventFingerprints.size > 3e3 && (this.recentEventFingerprints.clear(), this.recentEventFingerprints.set(r, t),
|
|
2526
|
+
return n && t - n < 1e3 ? (this.recentEventFingerprints.set(r, t), !0) : (this.recentEventFingerprints.set(r, t), this.recentEventFingerprints.size > 1500 && this.pruneOldFingerprints(), this.recentEventFingerprints.size > 3e3 && (this.recentEventFingerprints.clear(), this.recentEventFingerprints.set(r, t), a("debug", "Event fingerprint cache exceeded hard limit, cleared", {
|
|
2526
2527
|
data: { hardLimit: 3e3 }
|
|
2527
2528
|
})), !1);
|
|
2528
2529
|
}
|
|
@@ -2530,7 +2531,7 @@ class fr extends w {
|
|
|
2530
2531
|
const e = Date.now(), t = 1e3 * 10;
|
|
2531
2532
|
for (const [r, n] of this.recentEventFingerprints.entries())
|
|
2532
2533
|
e - n > t && this.recentEventFingerprints.delete(r);
|
|
2533
|
-
|
|
2534
|
+
a("debug", "Pruned old event fingerprints", {
|
|
2534
2535
|
data: {
|
|
2535
2536
|
remaining: this.recentEventFingerprints.size,
|
|
2536
2537
|
cutoffMs: t
|
|
@@ -2543,15 +2544,19 @@ class fr extends w {
|
|
|
2543
2544
|
const r = Math.round((e.click_data.x || 0) / 10) * 10, n = Math.round((e.click_data.y || 0) / 10) * 10;
|
|
2544
2545
|
t += `_click_${r}_${n}`;
|
|
2545
2546
|
}
|
|
2546
|
-
return e.scroll_data && (t += `_scroll_${e.scroll_data.depth}_${e.scroll_data.direction}`), e.custom_event && (t += `_custom_${e.custom_event.name}`), e.web_vitals && (t += `_vitals_${e.web_vitals.type}`), e.error_data && (t += `_error_${e.error_data.type}_${e.error_data.message}`), t;
|
|
2547
|
+
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;
|
|
2547
2548
|
}
|
|
2548
2549
|
createEventSignature(e) {
|
|
2549
2550
|
return this.createEventFingerprint(e);
|
|
2550
2551
|
}
|
|
2552
|
+
/** Deterministic JSON string with sorted keys to ensure consistent fingerprints regardless of property insertion order */
|
|
2553
|
+
stableStringify(e) {
|
|
2554
|
+
return JSON.stringify(e, (t, r) => r && typeof r == "object" && !Array.isArray(r) ? Object.keys(r).sort().reduce((n, i) => (n[i] = r[i], n), {}) : r);
|
|
2555
|
+
}
|
|
2551
2556
|
addToQueue(e) {
|
|
2552
2557
|
if (this.emitEvent(e), this.eventsQueue.push(e), this.eventsQueue.length > 100) {
|
|
2553
2558
|
const t = this.eventsQueue.findIndex((n) => n.type !== d.SESSION_START), r = t >= 0 ? this.eventsQueue.splice(t, 1)[0] : this.eventsQueue.shift();
|
|
2554
|
-
|
|
2559
|
+
a("warn", "Event queue overflow, oldest non-critical event removed", {
|
|
2555
2560
|
data: {
|
|
2556
2561
|
maxLength: 100,
|
|
2557
2562
|
currentLength: this.eventsQueue.length,
|
|
@@ -2585,7 +2590,7 @@ class fr extends w {
|
|
|
2585
2590
|
}
|
|
2586
2591
|
checkPerEventRateLimit(e, t) {
|
|
2587
2592
|
const r = Date.now(), i = (this.perEventRateLimits.get(e) ?? []).filter((o) => r - o < 6e4);
|
|
2588
|
-
return i.length >= t ? (
|
|
2593
|
+
return i.length >= t ? (a("warn", "Per-event rate limit exceeded for custom event", {
|
|
2589
2594
|
data: {
|
|
2590
2595
|
eventName: e,
|
|
2591
2596
|
limit: t,
|
|
@@ -2607,10 +2612,10 @@ class fr extends w {
|
|
|
2607
2612
|
this.eventsQueue = this.eventsQueue.filter((r) => !t.has(r.id));
|
|
2608
2613
|
}
|
|
2609
2614
|
emitEvent(e) {
|
|
2610
|
-
this.emitter && this.emitter.emit(
|
|
2615
|
+
this.emitter && this.emitter.emit(Se.EVENT, e);
|
|
2611
2616
|
}
|
|
2612
2617
|
emitEventsQueue(e) {
|
|
2613
|
-
this.emitter && this.emitter.emit(
|
|
2618
|
+
this.emitter && this.emitter.emit(Se.QUEUE, e);
|
|
2614
2619
|
}
|
|
2615
2620
|
/**
|
|
2616
2621
|
* Creates a debounced version of a function that delays execution until after
|
|
@@ -2686,13 +2691,13 @@ class fr extends w {
|
|
|
2686
2691
|
loadSessionCounts(e) {
|
|
2687
2692
|
if (typeof window > "u" || typeof localStorage > "u")
|
|
2688
2693
|
return this.getInitialCounts();
|
|
2689
|
-
const t = this.get("userId") || "anonymous", r =
|
|
2694
|
+
const t = this.get("userId") || "anonymous", r = Ue(t, e);
|
|
2690
2695
|
try {
|
|
2691
2696
|
const n = localStorage.getItem(r);
|
|
2692
2697
|
if (!n)
|
|
2693
2698
|
return this.getInitialCounts();
|
|
2694
2699
|
const i = JSON.parse(n);
|
|
2695
|
-
return i._timestamp && Date.now() - i._timestamp >
|
|
2700
|
+
return i._timestamp && Date.now() - i._timestamp > He ? (a("debug", "Session counts expired, clearing", {
|
|
2696
2701
|
data: { sessionId: e, age: Date.now() - i._timestamp }
|
|
2697
2702
|
}), localStorage.removeItem(r), this.getInitialCounts()) : typeof i.total == "number" && typeof i[d.CLICK] == "number" && typeof i[d.PAGE_VIEW] == "number" && typeof i[d.CUSTOM] == "number" && typeof i[d.VIEWPORT_VISIBLE] == "number" && typeof i[d.SCROLL] == "number" ? {
|
|
2698
2703
|
total: i.total,
|
|
@@ -2701,13 +2706,13 @@ class fr extends w {
|
|
|
2701
2706
|
[d.CUSTOM]: i[d.CUSTOM],
|
|
2702
2707
|
[d.VIEWPORT_VISIBLE]: i[d.VIEWPORT_VISIBLE],
|
|
2703
2708
|
[d.SCROLL]: i[d.SCROLL]
|
|
2704
|
-
} : (
|
|
2709
|
+
} : (a("warn", "Invalid session counts structure in localStorage, resetting", {
|
|
2705
2710
|
data: { sessionId: e, parsed: i }
|
|
2706
|
-
}), localStorage.removeItem(r),
|
|
2711
|
+
}), localStorage.removeItem(r), a("debug", "Session counts removed due to invalid/corrupted data", {
|
|
2707
2712
|
data: { sessionId: e, parsed: i }
|
|
2708
2713
|
}), this.getInitialCounts());
|
|
2709
2714
|
} catch (n) {
|
|
2710
|
-
return
|
|
2715
|
+
return a("warn", "Failed to load session counts from localStorage", {
|
|
2711
2716
|
error: n,
|
|
2712
2717
|
data: { sessionId: e }
|
|
2713
2718
|
}), this.getInitialCounts();
|
|
@@ -2737,34 +2742,34 @@ class fr extends w {
|
|
|
2737
2742
|
cleanupExpiredSessionCounts() {
|
|
2738
2743
|
if (!(typeof window > "u" || typeof localStorage > "u"))
|
|
2739
2744
|
try {
|
|
2740
|
-
const e = localStorage.getItem(
|
|
2745
|
+
const e = localStorage.getItem(xe);
|
|
2741
2746
|
if (e) {
|
|
2742
2747
|
const i = Date.now() - parseInt(e, 10);
|
|
2743
|
-
if (i <
|
|
2744
|
-
|
|
2745
|
-
data: { timeSinceLastCleanup: i, throttleMs:
|
|
2748
|
+
if (i < Fe) {
|
|
2749
|
+
a("debug", "Skipping session counts cleanup (throttled)", {
|
|
2750
|
+
data: { timeSinceLastCleanup: i, throttleMs: Fe }
|
|
2746
2751
|
});
|
|
2747
2752
|
return;
|
|
2748
2753
|
}
|
|
2749
2754
|
}
|
|
2750
|
-
const t = this.get("userId") || "anonymous", r = `${
|
|
2755
|
+
const t = this.get("userId") || "anonymous", r = `${I}:${t}:session_counts:`, n = [];
|
|
2751
2756
|
for (let i = 0; i < localStorage.length; i++) {
|
|
2752
2757
|
const o = localStorage.key(i);
|
|
2753
2758
|
if (o?.startsWith(r))
|
|
2754
2759
|
try {
|
|
2755
|
-
const
|
|
2756
|
-
if (
|
|
2757
|
-
const c = JSON.parse(
|
|
2758
|
-
c._timestamp && Date.now() - c._timestamp >
|
|
2760
|
+
const l = localStorage.getItem(o);
|
|
2761
|
+
if (l) {
|
|
2762
|
+
const c = JSON.parse(l);
|
|
2763
|
+
c._timestamp && Date.now() - c._timestamp > He && n.push(o);
|
|
2759
2764
|
}
|
|
2760
2765
|
} catch {
|
|
2761
2766
|
}
|
|
2762
2767
|
}
|
|
2763
2768
|
n.forEach((i) => {
|
|
2764
|
-
localStorage.removeItem(i),
|
|
2765
|
-
}), n.length > 0 &&
|
|
2769
|
+
localStorage.removeItem(i), a("debug", "Cleaned up expired session counts", { data: { key: i } });
|
|
2770
|
+
}), n.length > 0 && a("info", `Cleaned up ${n.length} expired session counts entries`), localStorage.setItem(xe, Date.now().toString());
|
|
2766
2771
|
} catch (e) {
|
|
2767
|
-
|
|
2772
|
+
a("warn", "Failed to cleanup expired session counts", { error: e });
|
|
2768
2773
|
}
|
|
2769
2774
|
}
|
|
2770
2775
|
/**
|
|
@@ -2796,7 +2801,7 @@ class fr extends w {
|
|
|
2796
2801
|
* @internal
|
|
2797
2802
|
*/
|
|
2798
2803
|
saveSessionCounts(e) {
|
|
2799
|
-
const t = this.get("userId") || "anonymous", r =
|
|
2804
|
+
const t = this.get("userId") || "anonymous", r = Ue(t, e);
|
|
2800
2805
|
try {
|
|
2801
2806
|
const n = {
|
|
2802
2807
|
...this.sessionEventCounts,
|
|
@@ -2805,14 +2810,14 @@ class fr extends w {
|
|
|
2805
2810
|
};
|
|
2806
2811
|
localStorage.setItem(r, JSON.stringify(n));
|
|
2807
2812
|
} catch (n) {
|
|
2808
|
-
|
|
2813
|
+
a("warn", "Failed to persist session counts to localStorage", {
|
|
2809
2814
|
error: n,
|
|
2810
2815
|
data: { sessionId: e }
|
|
2811
2816
|
});
|
|
2812
2817
|
}
|
|
2813
2818
|
}
|
|
2814
2819
|
}
|
|
2815
|
-
class
|
|
2820
|
+
class Er {
|
|
2816
2821
|
/**
|
|
2817
2822
|
* Gets or creates a unique user ID.
|
|
2818
2823
|
*
|
|
@@ -2830,15 +2835,15 @@ class mr {
|
|
|
2830
2835
|
* @returns Persistent unique user ID (UUID v4 format)
|
|
2831
2836
|
*/
|
|
2832
2837
|
static getId(e) {
|
|
2833
|
-
const t = e.getItem(
|
|
2838
|
+
const t = e.getItem(Ee);
|
|
2834
2839
|
if (t)
|
|
2835
2840
|
return t;
|
|
2836
|
-
const r =
|
|
2837
|
-
return e.setItem(
|
|
2841
|
+
const r = at();
|
|
2842
|
+
return e.setItem(Ee, r), r;
|
|
2838
2843
|
}
|
|
2839
2844
|
}
|
|
2840
|
-
const
|
|
2841
|
-
class
|
|
2845
|
+
const Sr = /^\d{13}-[a-z0-9]{9}$/;
|
|
2846
|
+
class pr extends w {
|
|
2842
2847
|
storageManager;
|
|
2843
2848
|
eventManager;
|
|
2844
2849
|
projectId;
|
|
@@ -2860,13 +2865,13 @@ class Er extends w {
|
|
|
2860
2865
|
}
|
|
2861
2866
|
initCrossTabSync() {
|
|
2862
2867
|
if (typeof BroadcastChannel > "u") {
|
|
2863
|
-
|
|
2868
|
+
a("debug", "BroadcastChannel not supported");
|
|
2864
2869
|
return;
|
|
2865
2870
|
}
|
|
2866
2871
|
const e = this.getProjectId();
|
|
2867
|
-
this.broadcastChannel = new BroadcastChannel(
|
|
2872
|
+
this.broadcastChannel = new BroadcastChannel(Lt(e)), this.broadcastChannel.onmessage = (t) => {
|
|
2868
2873
|
const { action: r, sessionId: n, timestamp: i, projectId: o } = t.data ?? {};
|
|
2869
|
-
o === e && (r === "session_start" && n && typeof i == "number" && i > Date.now() - 5e3 ? (this.set("sessionId", n), this.persistSession(n, i), this.isTracking && this.setupSessionTimeout()) : r && r !== "session_start" &&
|
|
2874
|
+
o === e && (r === "session_start" && n && typeof i == "number" && i > Date.now() - 5e3 ? (this.set("sessionId", n), this.persistSession(n, i), this.isTracking && this.setupSessionTimeout()) : r && r !== "session_start" && a("debug", "Ignored BroadcastChannel message with unknown action", { data: { action: r } }));
|
|
2870
2875
|
};
|
|
2871
2876
|
}
|
|
2872
2877
|
shareSession(e) {
|
|
@@ -2884,8 +2889,8 @@ class Er extends w {
|
|
|
2884
2889
|
const e = this.loadStoredSession();
|
|
2885
2890
|
if (!e)
|
|
2886
2891
|
return null;
|
|
2887
|
-
if (!
|
|
2888
|
-
return
|
|
2892
|
+
if (!Sr.test(e.id))
|
|
2893
|
+
return a("warn", "Invalid session ID format recovered from storage, clearing", {
|
|
2889
2894
|
data: { sessionId: e.id }
|
|
2890
2895
|
}), this.clearStoredSession(), null;
|
|
2891
2896
|
const t = this.get("config")?.sessionTimeout ?? 9e5;
|
|
@@ -2929,7 +2934,7 @@ class Er extends w {
|
|
|
2929
2934
|
this.storageManager.setItem(t, r), this.storageManager.setSessionItem(t, r);
|
|
2930
2935
|
}
|
|
2931
2936
|
getSessionStorageKey() {
|
|
2932
|
-
return
|
|
2937
|
+
return At(this.getProjectId());
|
|
2933
2938
|
}
|
|
2934
2939
|
getProjectId() {
|
|
2935
2940
|
return this.projectId;
|
|
@@ -2988,17 +2993,17 @@ class Er extends w {
|
|
|
2988
2993
|
*/
|
|
2989
2994
|
startTracking() {
|
|
2990
2995
|
if (this.isTracking) {
|
|
2991
|
-
|
|
2996
|
+
a("debug", "Session tracking already active");
|
|
2992
2997
|
return;
|
|
2993
2998
|
}
|
|
2994
2999
|
const e = this.recoverSession(), t = e ?? this.generateSessionId();
|
|
2995
3000
|
let r, n;
|
|
2996
3001
|
if (e) {
|
|
2997
3002
|
const i = this.loadStoredSession();
|
|
2998
|
-
r = i?.referrer ??
|
|
3003
|
+
r = i?.referrer ?? de(), n = i?.utm ?? he();
|
|
2999
3004
|
} else
|
|
3000
|
-
r =
|
|
3001
|
-
|
|
3005
|
+
r = de(), n = he();
|
|
3006
|
+
a("debug", "Session tracking initialized", {
|
|
3002
3007
|
data: {
|
|
3003
3008
|
sessionId: t,
|
|
3004
3009
|
wasRecovered: !!e,
|
|
@@ -3008,9 +3013,9 @@ class Er extends w {
|
|
|
3008
3013
|
}
|
|
3009
3014
|
}), this.isTracking = !0;
|
|
3010
3015
|
try {
|
|
3011
|
-
this.set("sessionId", t), this.set("sessionReferrer", r), this.set("sessionUtm", n), this.persistSession(t, Date.now(), r, n), this.initCrossTabSync(), this.shareSession(t), e ?
|
|
3016
|
+
this.set("sessionId", t), this.set("sessionReferrer", r), this.set("sessionUtm", n), this.persistSession(t, Date.now(), r, n), this.initCrossTabSync(), this.shareSession(t), e ? a("debug", "Session recovered, skipping SESSION_START", {
|
|
3012
3017
|
data: { sessionId: t }
|
|
3013
|
-
}) : (
|
|
3018
|
+
}) : (a("debug", "Emitting SESSION_START event", {
|
|
3014
3019
|
data: { sessionId: t }
|
|
3015
3020
|
}), this.eventManager.track({
|
|
3016
3021
|
type: d.SESSION_START
|
|
@@ -3048,8 +3053,8 @@ class Er extends w {
|
|
|
3048
3053
|
*/
|
|
3049
3054
|
renewSession() {
|
|
3050
3055
|
this.needsRenewal = !1;
|
|
3051
|
-
const e = this.generateSessionId(), t =
|
|
3052
|
-
|
|
3056
|
+
const e = this.generateSessionId(), t = de(), r = he();
|
|
3057
|
+
a("debug", "Renewing session after timeout", {
|
|
3053
3058
|
data: { newSessionId: e }
|
|
3054
3059
|
}), this.set("sessionId", e), this.set("sessionReferrer", t), this.set("sessionUtm", r), this.persistSession(e, Date.now(), t, r), this.cleanupCrossTabSync(), this.initCrossTabSync(), this.shareSession(e), this.eventManager.track({
|
|
3055
3060
|
type: d.SESSION_START
|
|
@@ -3064,7 +3069,7 @@ class Er extends w {
|
|
|
3064
3069
|
this.clearSessionTimeout();
|
|
3065
3070
|
else {
|
|
3066
3071
|
if (this.isSessionStale()) {
|
|
3067
|
-
|
|
3072
|
+
a("debug", "Session expired during suspend, entering renewal mode"), this.enterRenewalMode();
|
|
3068
3073
|
return;
|
|
3069
3074
|
}
|
|
3070
3075
|
this.get("sessionId") && this.setupSessionTimeout();
|
|
@@ -3093,7 +3098,7 @@ class Er extends w {
|
|
|
3093
3098
|
* Called by session timeout timer.
|
|
3094
3099
|
*/
|
|
3095
3100
|
enterRenewalMode() {
|
|
3096
|
-
this.clearSessionTimeout(), this.cleanupCrossTabSync(), this.clearStoredSession(), this.set("sessionId", null), this.set("hasStartSession", !1), this.set("sessionReferrer", void 0), this.set("sessionUtm", void 0), this.needsRenewal = !0,
|
|
3101
|
+
this.clearSessionTimeout(), this.cleanupCrossTabSync(), this.clearStoredSession(), this.set("sessionId", null), this.set("hasStartSession", !1), this.set("sessionReferrer", void 0), this.set("sessionUtm", void 0), this.needsRenewal = !0, a("debug", "Session timed out, entering renewal mode");
|
|
3097
3102
|
}
|
|
3098
3103
|
/**
|
|
3099
3104
|
* Fully resets session state and cleans up all resources.
|
|
@@ -3169,7 +3174,7 @@ class Er extends w {
|
|
|
3169
3174
|
this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupCrossTabSync(), this.cleanupLifecycleListeners(), this.isTracking = !1, this.needsRenewal = !1, this.set("hasStartSession", !1);
|
|
3170
3175
|
}
|
|
3171
3176
|
}
|
|
3172
|
-
class
|
|
3177
|
+
class Tr extends w {
|
|
3173
3178
|
eventManager;
|
|
3174
3179
|
storageManager;
|
|
3175
3180
|
sessionManager = null;
|
|
@@ -3199,12 +3204,12 @@ class Sr extends w {
|
|
|
3199
3204
|
if (this.isActive())
|
|
3200
3205
|
return;
|
|
3201
3206
|
if (this.destroyed) {
|
|
3202
|
-
|
|
3207
|
+
a("debug", "Cannot start tracking on destroyed handler");
|
|
3203
3208
|
return;
|
|
3204
3209
|
}
|
|
3205
3210
|
const t = this.get("config")?.integrations?.tracelog?.projectId ?? "custom";
|
|
3206
3211
|
try {
|
|
3207
|
-
this.sessionManager = new
|
|
3212
|
+
this.sessionManager = new pr(this.storageManager, this.eventManager, t), this.sessionManager.startTracking(), this.eventManager.flushPendingEvents();
|
|
3208
3213
|
} catch (r) {
|
|
3209
3214
|
if (this.sessionManager) {
|
|
3210
3215
|
try {
|
|
@@ -3213,7 +3218,7 @@ class Sr extends w {
|
|
|
3213
3218
|
}
|
|
3214
3219
|
this.sessionManager = null;
|
|
3215
3220
|
}
|
|
3216
|
-
throw
|
|
3221
|
+
throw a("error", "Failed to start session tracking", { error: r }), r;
|
|
3217
3222
|
}
|
|
3218
3223
|
}
|
|
3219
3224
|
isActive() {
|
|
@@ -3257,7 +3262,7 @@ class Sr extends w {
|
|
|
3257
3262
|
this.destroyed || (this.sessionManager && (this.sessionManager.destroy(), this.sessionManager = null), this.destroyed = !0);
|
|
3258
3263
|
}
|
|
3259
3264
|
}
|
|
3260
|
-
class
|
|
3265
|
+
class Ir extends w {
|
|
3261
3266
|
eventManager;
|
|
3262
3267
|
onTrack;
|
|
3263
3268
|
originalPushState;
|
|
@@ -3297,7 +3302,7 @@ class pr extends w {
|
|
|
3297
3302
|
};
|
|
3298
3303
|
}
|
|
3299
3304
|
trackCurrentPage = () => {
|
|
3300
|
-
const e = window.location.href, t =
|
|
3305
|
+
const e = window.location.href, t = ve(e, this.get("config").sensitiveQueryParams);
|
|
3301
3306
|
if (this.get("pageUrl") === t)
|
|
3302
3307
|
return;
|
|
3303
3308
|
const r = Date.now(), n = this.get("config").pageViewThrottleMs ?? 1e3;
|
|
@@ -3315,7 +3320,7 @@ class pr extends w {
|
|
|
3315
3320
|
});
|
|
3316
3321
|
};
|
|
3317
3322
|
trackInitialPageView() {
|
|
3318
|
-
const e =
|
|
3323
|
+
const e = ve(window.location.href, this.get("config").sensitiveQueryParams), t = this.extractPageViewData();
|
|
3319
3324
|
this.lastPageViewTime = Date.now(), this.eventManager.track({
|
|
3320
3325
|
type: d.PAGE_VIEW,
|
|
3321
3326
|
page_url: e,
|
|
@@ -3333,7 +3338,7 @@ class pr extends w {
|
|
|
3333
3338
|
};
|
|
3334
3339
|
}
|
|
3335
3340
|
}
|
|
3336
|
-
class
|
|
3341
|
+
class vr extends w {
|
|
3337
3342
|
eventManager;
|
|
3338
3343
|
lastClickTimes = /* @__PURE__ */ new Map();
|
|
3339
3344
|
clickHandler;
|
|
@@ -3358,7 +3363,7 @@ class Tr extends w {
|
|
|
3358
3363
|
this.clickHandler || (this.clickHandler = (e) => {
|
|
3359
3364
|
const t = e, r = t.target, n = typeof HTMLElement < "u" && r instanceof HTMLElement ? r : typeof HTMLElement < "u" && r instanceof Node && r.parentElement instanceof HTMLElement ? r.parentElement : null;
|
|
3360
3365
|
if (!n) {
|
|
3361
|
-
|
|
3366
|
+
a("debug", "Click target not found or not an element");
|
|
3362
3367
|
return;
|
|
3363
3368
|
}
|
|
3364
3369
|
if (this.shouldIgnoreElement(n))
|
|
@@ -3366,7 +3371,7 @@ class Tr extends w {
|
|
|
3366
3371
|
const i = this.get("config")?.clickThrottleMs ?? 300;
|
|
3367
3372
|
if (i > 0 && !this.checkClickThrottle(n, i))
|
|
3368
3373
|
return;
|
|
3369
|
-
const o = this.findTrackingElement(n),
|
|
3374
|
+
const o = this.findTrackingElement(n), l = this.getRelevantClickElement(n), c = this.calculateClickCoordinates(t, n);
|
|
3370
3375
|
if (o) {
|
|
3371
3376
|
const g = this.extractTrackingData(o);
|
|
3372
3377
|
if (g) {
|
|
@@ -3380,7 +3385,7 @@ class Tr extends w {
|
|
|
3380
3385
|
});
|
|
3381
3386
|
}
|
|
3382
3387
|
}
|
|
3383
|
-
const u = this.generateClickData(n,
|
|
3388
|
+
const u = this.generateClickData(n, l, c);
|
|
3384
3389
|
this.eventManager.track({
|
|
3385
3390
|
type: d.CLICK,
|
|
3386
3391
|
click_data: u
|
|
@@ -3407,7 +3412,7 @@ class Tr extends w {
|
|
|
3407
3412
|
const r = this.getElementSignature(e), n = Date.now();
|
|
3408
3413
|
this.pruneThrottleCache(n);
|
|
3409
3414
|
const i = this.lastClickTimes.get(r);
|
|
3410
|
-
return i !== void 0 && n - i < t ? (
|
|
3415
|
+
return i !== void 0 && n - i < t ? (a("debug", "ClickHandler: Click suppressed by throttle", {
|
|
3411
3416
|
data: {
|
|
3412
3417
|
signature: r,
|
|
3413
3418
|
throttleRemaining: t - (n - i)
|
|
@@ -3427,10 +3432,10 @@ class Tr extends w {
|
|
|
3427
3432
|
for (const [r, n] of this.lastClickTimes.entries())
|
|
3428
3433
|
n < t && this.lastClickTimes.delete(r);
|
|
3429
3434
|
if (this.lastClickTimes.size > 1e3) {
|
|
3430
|
-
const r = Array.from(this.lastClickTimes.entries()).sort((o,
|
|
3435
|
+
const r = Array.from(this.lastClickTimes.entries()).sort((o, l) => o[1] - l[1]), n = this.lastClickTimes.size - 1e3, i = r.slice(0, n);
|
|
3431
3436
|
for (const [o] of i)
|
|
3432
3437
|
this.lastClickTimes.delete(o);
|
|
3433
|
-
|
|
3438
|
+
a("debug", "ClickHandler: Pruned throttle cache", {
|
|
3434
3439
|
data: {
|
|
3435
3440
|
removed: i.length,
|
|
3436
3441
|
remaining: this.lastClickTimes.size
|
|
@@ -3471,7 +3476,7 @@ class Tr extends w {
|
|
|
3471
3476
|
return e.hasAttribute(`${b}-name`) ? e : e.closest(`[${b}-name]`);
|
|
3472
3477
|
}
|
|
3473
3478
|
getRelevantClickElement(e) {
|
|
3474
|
-
for (const t of
|
|
3479
|
+
for (const t of vt)
|
|
3475
3480
|
try {
|
|
3476
3481
|
if (e.matches(t))
|
|
3477
3482
|
return e;
|
|
@@ -3479,7 +3484,7 @@ class Tr extends w {
|
|
|
3479
3484
|
if (r)
|
|
3480
3485
|
return r;
|
|
3481
3486
|
} catch (r) {
|
|
3482
|
-
|
|
3487
|
+
a("debug", "Invalid selector in element search", { error: r, data: { selector: t } });
|
|
3483
3488
|
continue;
|
|
3484
3489
|
}
|
|
3485
3490
|
return e;
|
|
@@ -3499,8 +3504,8 @@ class Tr extends w {
|
|
|
3499
3504
|
return Math.max(0, Math.min(1, Number(e.toFixed(3))));
|
|
3500
3505
|
}
|
|
3501
3506
|
calculateClickCoordinates(e, t) {
|
|
3502
|
-
const r = t.getBoundingClientRect(), n = e.clientX, i = e.clientY, o = r.width > 0 ? this.clamp((n - r.left) / r.width) : 0,
|
|
3503
|
-
return { x: n, y: i, relativeX: o, relativeY:
|
|
3507
|
+
const r = t.getBoundingClientRect(), n = e.clientX, i = e.clientY, o = r.width > 0 ? this.clamp((n - r.left) / r.width) : 0, l = r.height > 0 ? this.clamp((i - r.top) / r.height) : 0;
|
|
3508
|
+
return { x: n, y: i, relativeX: o, relativeY: l };
|
|
3504
3509
|
}
|
|
3505
3510
|
extractTrackingData(e) {
|
|
3506
3511
|
const t = e.getAttribute(`${b}-name`), r = e.getAttribute(`${b}-value`);
|
|
@@ -3512,12 +3517,12 @@ class Tr extends w {
|
|
|
3512
3517
|
};
|
|
3513
3518
|
}
|
|
3514
3519
|
generateClickData(e, t, r) {
|
|
3515
|
-
const { x: n, y: i, relativeX: o, relativeY:
|
|
3520
|
+
const { x: n, y: i, relativeX: o, relativeY: l } = r, c = this.getRelevantText(e, t), u = this.extractElementAttributes(t);
|
|
3516
3521
|
return {
|
|
3517
3522
|
x: n,
|
|
3518
3523
|
y: i,
|
|
3519
3524
|
relativeX: o,
|
|
3520
|
-
relativeY:
|
|
3525
|
+
relativeY: l,
|
|
3521
3526
|
tag: t.tagName.toLowerCase(),
|
|
3522
3527
|
...t.id && { id: t.id },
|
|
3523
3528
|
...t.className && { class: t.className },
|
|
@@ -3551,7 +3556,7 @@ class Tr extends w {
|
|
|
3551
3556
|
*/
|
|
3552
3557
|
sanitizeText(e) {
|
|
3553
3558
|
let t = e;
|
|
3554
|
-
for (const r of
|
|
3559
|
+
for (const r of nt) {
|
|
3555
3560
|
const n = new RegExp(r.source, r.flags);
|
|
3556
3561
|
t = t.replace(n, "[REDACTED]");
|
|
3557
3562
|
}
|
|
@@ -3590,7 +3595,7 @@ class Tr extends w {
|
|
|
3590
3595
|
};
|
|
3591
3596
|
}
|
|
3592
3597
|
}
|
|
3593
|
-
class
|
|
3598
|
+
class _r extends w {
|
|
3594
3599
|
eventManager;
|
|
3595
3600
|
containers = [];
|
|
3596
3601
|
limitWarningLogged = !1;
|
|
@@ -3697,29 +3702,29 @@ class vr extends w {
|
|
|
3697
3702
|
n,
|
|
3698
3703
|
this.getScrollHeight(e),
|
|
3699
3704
|
this.getViewportHeight(e)
|
|
3700
|
-
), o = this.determineIfPrimary(e),
|
|
3705
|
+
), o = this.determineIfPrimary(e), l = {
|
|
3701
3706
|
element: e,
|
|
3702
3707
|
selector: t,
|
|
3703
3708
|
isPrimary: o,
|
|
3704
3709
|
lastScrollPos: n,
|
|
3705
3710
|
lastDepth: i,
|
|
3706
|
-
lastDirection:
|
|
3711
|
+
lastDirection: ee.DOWN,
|
|
3707
3712
|
lastEventTime: 0,
|
|
3708
3713
|
firstScrollEventTime: null,
|
|
3709
3714
|
maxDepthReached: i,
|
|
3710
3715
|
debounceTimer: null,
|
|
3711
3716
|
listener: null
|
|
3712
3717
|
}, c = () => {
|
|
3713
|
-
this.get("suppressNextScroll") || (
|
|
3714
|
-
const u = this.calculateScrollData(
|
|
3718
|
+
this.get("suppressNextScroll") || (l.firstScrollEventTime === null && (l.firstScrollEventTime = Date.now()), this.clearContainerTimer(l), l.debounceTimer = window.setTimeout(() => {
|
|
3719
|
+
const u = this.calculateScrollData(l);
|
|
3715
3720
|
if (u) {
|
|
3716
3721
|
const g = Date.now();
|
|
3717
|
-
this.processScrollEvent(
|
|
3722
|
+
this.processScrollEvent(l, u, g);
|
|
3718
3723
|
}
|
|
3719
|
-
|
|
3724
|
+
l.debounceTimer = null;
|
|
3720
3725
|
}, 250));
|
|
3721
3726
|
};
|
|
3722
|
-
|
|
3727
|
+
l.listener = c, this.containers.push(l), e === window ? window.addEventListener("scroll", c, { passive: !0 }) : e.addEventListener("scroll", c, { passive: !0 });
|
|
3723
3728
|
}
|
|
3724
3729
|
processScrollEvent(e, t, r) {
|
|
3725
3730
|
if (!this.shouldEmitScrollEvent(e, t, r))
|
|
@@ -3748,7 +3753,7 @@ class vr extends w {
|
|
|
3748
3753
|
return Math.abs(t - e.lastDepth) >= this.minDepthChange;
|
|
3749
3754
|
}
|
|
3750
3755
|
logLimitOnce() {
|
|
3751
|
-
this.limitWarningLogged || (this.limitWarningLogged = !0,
|
|
3756
|
+
this.limitWarningLogged || (this.limitWarningLogged = !0, a("debug", "Max scroll events per session reached", {
|
|
3752
3757
|
data: { limit: this.maxEventsPerSession }
|
|
3753
3758
|
}));
|
|
3754
3759
|
}
|
|
@@ -3762,7 +3767,7 @@ class vr extends w {
|
|
|
3762
3767
|
e.debounceTimer !== null && (clearTimeout(e.debounceTimer), e.debounceTimer = null);
|
|
3763
3768
|
}
|
|
3764
3769
|
getScrollDirection(e, t) {
|
|
3765
|
-
return e > t ?
|
|
3770
|
+
return e > t ? ee.DOWN : ee.UP;
|
|
3766
3771
|
}
|
|
3767
3772
|
calculateScrollDepth(e, t, r) {
|
|
3768
3773
|
if (t <= r)
|
|
@@ -3771,13 +3776,13 @@ class vr extends w {
|
|
|
3771
3776
|
return Math.min(100, Math.max(0, Math.floor(e / n * 100)));
|
|
3772
3777
|
}
|
|
3773
3778
|
calculateScrollData(e) {
|
|
3774
|
-
const { element: t, lastScrollPos: r, lastEventTime: n } = e, i = this.getScrollTop(t), o = Date.now(),
|
|
3775
|
-
if (
|
|
3779
|
+
const { element: t, lastScrollPos: r, lastEventTime: n } = e, i = this.getScrollTop(t), o = Date.now(), l = Math.abs(i - r);
|
|
3780
|
+
if (l < 10 || t === window && !this.isWindowScrollable())
|
|
3776
3781
|
return null;
|
|
3777
3782
|
const c = this.getViewportHeight(t), u = this.getScrollHeight(t), g = this.getScrollDirection(i, r), E = this.calculateScrollDepth(i, u, c);
|
|
3778
|
-
let
|
|
3779
|
-
n > 0 ?
|
|
3780
|
-
const S = Math.round(
|
|
3783
|
+
let T;
|
|
3784
|
+
n > 0 ? T = o - n : e.firstScrollEventTime !== null ? T = o - e.firstScrollEventTime : T = 250;
|
|
3785
|
+
const S = Math.round(l / T * 1e3);
|
|
3781
3786
|
return E > e.maxDepthReached && (e.maxDepthReached = E), e.lastScrollPos = i, {
|
|
3782
3787
|
depth: E,
|
|
3783
3788
|
direction: g,
|
|
@@ -3805,7 +3810,7 @@ class vr extends w {
|
|
|
3805
3810
|
else {
|
|
3806
3811
|
const n = document.querySelector(e);
|
|
3807
3812
|
if (!(n instanceof HTMLElement)) {
|
|
3808
|
-
|
|
3813
|
+
a("debug", `Selector "${e}" did not match an HTMLElement`);
|
|
3809
3814
|
return;
|
|
3810
3815
|
}
|
|
3811
3816
|
t = n;
|
|
@@ -3818,7 +3823,7 @@ class vr extends w {
|
|
|
3818
3823
|
e.isPrimary = t;
|
|
3819
3824
|
}
|
|
3820
3825
|
}
|
|
3821
|
-
class
|
|
3826
|
+
class yr extends w {
|
|
3822
3827
|
eventManager;
|
|
3823
3828
|
trackedElements = /* @__PURE__ */ new Map();
|
|
3824
3829
|
observer = null;
|
|
@@ -3837,15 +3842,15 @@ class _r extends w {
|
|
|
3837
3842
|
return;
|
|
3838
3843
|
const t = this.config.threshold ?? 0.5, r = this.config.minDwellTime ?? 1e3;
|
|
3839
3844
|
if (t < 0 || t > 1) {
|
|
3840
|
-
|
|
3845
|
+
a("debug", "ViewportHandler: Invalid threshold, must be between 0 and 1");
|
|
3841
3846
|
return;
|
|
3842
3847
|
}
|
|
3843
3848
|
if (r < 0) {
|
|
3844
|
-
|
|
3849
|
+
a("debug", "ViewportHandler: Invalid minDwellTime, must be non-negative");
|
|
3845
3850
|
return;
|
|
3846
3851
|
}
|
|
3847
3852
|
if (typeof IntersectionObserver > "u") {
|
|
3848
|
-
|
|
3853
|
+
a("debug", "ViewportHandler: IntersectionObserver not supported in this browser");
|
|
3849
3854
|
return;
|
|
3850
3855
|
}
|
|
3851
3856
|
this.observer = new IntersectionObserver(this.handleIntersection, {
|
|
@@ -3873,7 +3878,7 @@ class _r extends w {
|
|
|
3873
3878
|
const n = document.querySelectorAll(r.selector);
|
|
3874
3879
|
for (const i of Array.from(n)) {
|
|
3875
3880
|
if (t >= e) {
|
|
3876
|
-
|
|
3881
|
+
a("debug", "ViewportHandler: Maximum tracked elements reached", {
|
|
3877
3882
|
data: {
|
|
3878
3883
|
limit: e,
|
|
3879
3884
|
selector: r.selector,
|
|
@@ -3893,9 +3898,9 @@ class _r extends w {
|
|
|
3893
3898
|
}), this.observer?.observe(i), t++);
|
|
3894
3899
|
}
|
|
3895
3900
|
} catch (n) {
|
|
3896
|
-
|
|
3901
|
+
a("debug", `ViewportHandler: Invalid selector "${r.selector}"`, { error: n });
|
|
3897
3902
|
}
|
|
3898
|
-
|
|
3903
|
+
a("debug", "ViewportHandler: Elements tracked", {
|
|
3899
3904
|
data: { count: t, limit: e }
|
|
3900
3905
|
});
|
|
3901
3906
|
}
|
|
@@ -3923,7 +3928,7 @@ class _r extends w {
|
|
|
3923
3928
|
return;
|
|
3924
3929
|
const n = this.config?.cooldownPeriod ?? 6e4, i = Date.now();
|
|
3925
3930
|
if (e.lastFiredTime !== null && i - e.lastFiredTime < n) {
|
|
3926
|
-
|
|
3931
|
+
a("debug", "ViewportHandler: Event suppressed by cooldown period", {
|
|
3927
3932
|
data: {
|
|
3928
3933
|
selector: e.selector,
|
|
3929
3934
|
cooldownRemaining: n - (i - e.lastFiredTime)
|
|
@@ -3949,7 +3954,7 @@ class _r extends w {
|
|
|
3949
3954
|
setupMutationObserver() {
|
|
3950
3955
|
if (!(!this.config || typeof MutationObserver > "u")) {
|
|
3951
3956
|
if (!document.body) {
|
|
3952
|
-
|
|
3957
|
+
a("debug", "ViewportHandler: document.body not available, skipping MutationObserver setup");
|
|
3953
3958
|
return;
|
|
3954
3959
|
}
|
|
3955
3960
|
this.mutationObserver = new MutationObserver((e) => {
|
|
@@ -3973,20 +3978,20 @@ class _r extends w {
|
|
|
3973
3978
|
if (t.nodeType !== 1) return;
|
|
3974
3979
|
const r = t, n = this.trackedElements.get(r);
|
|
3975
3980
|
n && (n.timeoutId !== null && window.clearTimeout(n.timeoutId), this.observer?.unobserve(r), this.trackedElements.delete(r)), Array.from(this.trackedElements.keys()).filter((o) => r.contains(o)).forEach((o) => {
|
|
3976
|
-
const
|
|
3977
|
-
|
|
3981
|
+
const l = this.trackedElements.get(o);
|
|
3982
|
+
l && l.timeoutId !== null && window.clearTimeout(l.timeoutId), this.observer?.unobserve(o), this.trackedElements.delete(o);
|
|
3978
3983
|
});
|
|
3979
3984
|
});
|
|
3980
3985
|
}
|
|
3981
3986
|
}
|
|
3982
|
-
class
|
|
3987
|
+
class wr {
|
|
3983
3988
|
storage;
|
|
3984
3989
|
sessionStorageRef;
|
|
3985
3990
|
fallbackStorage = /* @__PURE__ */ new Map();
|
|
3986
3991
|
fallbackSessionStorage = /* @__PURE__ */ new Map();
|
|
3987
3992
|
hasQuotaExceededError = !1;
|
|
3988
3993
|
constructor() {
|
|
3989
|
-
this.storage = this.initializeStorage("localStorage"), this.sessionStorageRef = this.initializeStorage("sessionStorage"), this.storage ||
|
|
3994
|
+
this.storage = this.initializeStorage("localStorage"), this.sessionStorageRef = this.initializeStorage("sessionStorage"), this.storage || a("debug", "localStorage not available, using memory fallback"), this.sessionStorageRef || a("debug", "sessionStorage not available, using memory fallback");
|
|
3990
3995
|
}
|
|
3991
3996
|
/**
|
|
3992
3997
|
* Retrieves an item from localStorage.
|
|
@@ -4029,7 +4034,7 @@ class Ir {
|
|
|
4029
4034
|
}
|
|
4030
4035
|
} catch (r) {
|
|
4031
4036
|
if (r instanceof DOMException && r.name === "QuotaExceededError" || r instanceof Error && r.name === "QuotaExceededError")
|
|
4032
|
-
if (this.hasQuotaExceededError = !0,
|
|
4037
|
+
if (this.hasQuotaExceededError = !0, a("warn", "localStorage quota exceeded, attempting cleanup", {
|
|
4033
4038
|
data: { key: e, valueSize: t.length }
|
|
4034
4039
|
}), this.cleanupOldData())
|
|
4035
4040
|
try {
|
|
@@ -4038,13 +4043,13 @@ class Ir {
|
|
|
4038
4043
|
return;
|
|
4039
4044
|
}
|
|
4040
4045
|
} catch (o) {
|
|
4041
|
-
|
|
4046
|
+
a("error", "localStorage quota exceeded even after cleanup - data will not persist", {
|
|
4042
4047
|
error: o,
|
|
4043
4048
|
data: { key: e, valueSize: t.length }
|
|
4044
4049
|
});
|
|
4045
4050
|
}
|
|
4046
4051
|
else
|
|
4047
|
-
|
|
4052
|
+
a("error", "localStorage quota exceeded and no data to cleanup - data will not persist", {
|
|
4048
4053
|
error: r,
|
|
4049
4054
|
data: { key: e, valueSize: t.length }
|
|
4050
4055
|
});
|
|
@@ -4090,7 +4095,7 @@ class Ir {
|
|
|
4090
4095
|
this.storage.removeItem(t);
|
|
4091
4096
|
}), this.fallbackStorage.clear();
|
|
4092
4097
|
} catch (e) {
|
|
4093
|
-
|
|
4098
|
+
a("error", "Failed to clear storage", { error: e }), this.fallbackStorage.clear();
|
|
4094
4099
|
}
|
|
4095
4100
|
}
|
|
4096
4101
|
/**
|
|
@@ -4167,7 +4172,7 @@ class Ir {
|
|
|
4167
4172
|
}
|
|
4168
4173
|
}), !0) : !1;
|
|
4169
4174
|
} catch (e) {
|
|
4170
|
-
return
|
|
4175
|
+
return a("error", "Failed to cleanup old data", { error: e }), !1;
|
|
4171
4176
|
}
|
|
4172
4177
|
}
|
|
4173
4178
|
/**
|
|
@@ -4241,7 +4246,7 @@ class Ir {
|
|
|
4241
4246
|
return;
|
|
4242
4247
|
}
|
|
4243
4248
|
} catch (r) {
|
|
4244
|
-
(r instanceof DOMException && r.name === "QuotaExceededError" || r instanceof Error && r.name === "QuotaExceededError") &&
|
|
4249
|
+
(r instanceof DOMException && r.name === "QuotaExceededError" || r instanceof Error && r.name === "QuotaExceededError") && a("error", "sessionStorage quota exceeded - data will not persist", {
|
|
4245
4250
|
error: r,
|
|
4246
4251
|
data: { key: e, valueSize: t.length }
|
|
4247
4252
|
});
|
|
@@ -4262,7 +4267,7 @@ class Ir {
|
|
|
4262
4267
|
this.fallbackSessionStorage.delete(e);
|
|
4263
4268
|
}
|
|
4264
4269
|
}
|
|
4265
|
-
class
|
|
4270
|
+
class br extends w {
|
|
4266
4271
|
eventManager;
|
|
4267
4272
|
reportedByNav = /* @__PURE__ */ new Map();
|
|
4268
4273
|
navigationHistory = [];
|
|
@@ -4273,7 +4278,7 @@ class wr extends w {
|
|
|
4273
4278
|
navigationCounter = 0;
|
|
4274
4279
|
// Counter for handling simultaneous navigations edge case
|
|
4275
4280
|
constructor(e) {
|
|
4276
|
-
super(), this.eventManager = e, this.vitalThresholds =
|
|
4281
|
+
super(), this.eventManager = e, this.vitalThresholds = je(Ie);
|
|
4277
4282
|
}
|
|
4278
4283
|
/**
|
|
4279
4284
|
* Starts tracking Web Vitals and performance metrics.
|
|
@@ -4290,8 +4295,8 @@ class wr extends w {
|
|
|
4290
4295
|
* @returns Promise that resolves when tracking is initialized
|
|
4291
4296
|
*/
|
|
4292
4297
|
async startTracking() {
|
|
4293
|
-
const e = this.get("config"), t = e?.webVitalsMode ??
|
|
4294
|
-
this.vitalThresholds =
|
|
4298
|
+
const e = this.get("config"), t = e?.webVitalsMode ?? Ie;
|
|
4299
|
+
this.vitalThresholds = je(t), e?.webVitalsThresholds && (this.vitalThresholds = { ...this.vitalThresholds, ...e.webVitalsThresholds }), await this.initWebVitals(), this.observeLongTasks();
|
|
4295
4300
|
}
|
|
4296
4301
|
/**
|
|
4297
4302
|
* Stops tracking Web Vitals and cleans up resources.
|
|
@@ -4307,7 +4312,7 @@ class wr extends w {
|
|
|
4307
4312
|
try {
|
|
4308
4313
|
e.disconnect();
|
|
4309
4314
|
} catch (r) {
|
|
4310
|
-
|
|
4315
|
+
a("debug", "Failed to disconnect performance observer", { error: r, data: { observerIndex: t } });
|
|
4311
4316
|
}
|
|
4312
4317
|
}), this.observers.length = 0, this.reportedByNav.clear(), this.navigationHistory.length = 0;
|
|
4313
4318
|
}
|
|
@@ -4331,8 +4336,8 @@ class wr extends w {
|
|
|
4331
4336
|
for (const o of i) {
|
|
4332
4337
|
if (o.hadRecentInput === !0)
|
|
4333
4338
|
continue;
|
|
4334
|
-
const
|
|
4335
|
-
e +=
|
|
4339
|
+
const l = typeof o.value == "number" ? o.value : 0;
|
|
4340
|
+
e += l;
|
|
4336
4341
|
}
|
|
4337
4342
|
this.sendVital({ type: "CLS", value: Number(e.toFixed(2)) });
|
|
4338
4343
|
},
|
|
@@ -4351,8 +4356,8 @@ class wr extends w {
|
|
|
4351
4356
|
let n = 0;
|
|
4352
4357
|
const i = r.getEntries();
|
|
4353
4358
|
for (const o of i) {
|
|
4354
|
-
const
|
|
4355
|
-
n = Math.max(n,
|
|
4359
|
+
const l = (o.processingEnd ?? 0) - (o.startTime ?? 0);
|
|
4360
|
+
n = Math.max(n, l);
|
|
4356
4361
|
}
|
|
4357
4362
|
n > 0 && this.sendVital({ type: "INP", value: Number(n.toFixed(2)) });
|
|
4358
4363
|
},
|
|
@@ -4361,13 +4366,13 @@ class wr extends w {
|
|
|
4361
4366
|
}
|
|
4362
4367
|
async initWebVitals() {
|
|
4363
4368
|
try {
|
|
4364
|
-
const { onLCP: e, onCLS: t, onFCP: r, onTTFB: n, onINP: i } = await Promise.resolve().then(() =>
|
|
4369
|
+
const { onLCP: e, onCLS: t, onFCP: r, onTTFB: n, onINP: i } = await Promise.resolve().then(() => ns), o = (l) => (c) => {
|
|
4365
4370
|
const u = Number(c.value.toFixed(2));
|
|
4366
|
-
this.sendVital({ type:
|
|
4371
|
+
this.sendVital({ type: l, value: u });
|
|
4367
4372
|
};
|
|
4368
4373
|
e(o("LCP"), { reportAllChanges: !1 }), t(o("CLS"), { reportAllChanges: !1 }), r(o("FCP"), { reportAllChanges: !1 }), n(o("TTFB"), { reportAllChanges: !1 }), i(o("INP"), { reportAllChanges: !1 });
|
|
4369
4374
|
} catch (e) {
|
|
4370
|
-
|
|
4375
|
+
a("debug", "Failed to load web-vitals library, using fallback", { error: e }), this.observeWebVitalsFallback();
|
|
4371
4376
|
}
|
|
4372
4377
|
}
|
|
4373
4378
|
reportTTFB() {
|
|
@@ -4378,7 +4383,7 @@ class wr extends w {
|
|
|
4378
4383
|
const t = e.responseStart;
|
|
4379
4384
|
typeof t == "number" && Number.isFinite(t) && this.sendVital({ type: "TTFB", value: Number(t.toFixed(2)) });
|
|
4380
4385
|
} catch (e) {
|
|
4381
|
-
|
|
4386
|
+
a("debug", "Failed to report TTFB", { error: e });
|
|
4382
4387
|
}
|
|
4383
4388
|
}
|
|
4384
4389
|
observeLongTasks() {
|
|
@@ -4388,7 +4393,7 @@ class wr extends w {
|
|
|
4388
4393
|
const t = e.getEntries();
|
|
4389
4394
|
for (const r of t) {
|
|
4390
4395
|
const n = Number(r.duration.toFixed(2)), i = Date.now();
|
|
4391
|
-
i - this.lastLongTaskSentAt >=
|
|
4396
|
+
i - this.lastLongTaskSentAt >= Xt && (this.shouldSendVital("LONG_TASK", n) && this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = i);
|
|
4392
4397
|
}
|
|
4393
4398
|
},
|
|
4394
4399
|
{ type: "longtask", buffered: !0 }
|
|
@@ -4404,7 +4409,7 @@ class wr extends w {
|
|
|
4404
4409
|
return;
|
|
4405
4410
|
if (r)
|
|
4406
4411
|
r.add(e.type);
|
|
4407
|
-
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length >
|
|
4412
|
+
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length > jt) {
|
|
4408
4413
|
const i = this.navigationHistory.shift();
|
|
4409
4414
|
i && this.reportedByNav.delete(i);
|
|
4410
4415
|
}
|
|
@@ -4413,7 +4418,7 @@ class wr extends w {
|
|
|
4413
4418
|
}
|
|
4414
4419
|
trackWebVital(e, t) {
|
|
4415
4420
|
if (!Number.isFinite(t)) {
|
|
4416
|
-
|
|
4421
|
+
a("debug", "Invalid web vital value", { data: { type: e, value: t } });
|
|
4417
4422
|
return;
|
|
4418
4423
|
}
|
|
4419
4424
|
this.eventManager.track({
|
|
@@ -4453,7 +4458,7 @@ class wr extends w {
|
|
|
4453
4458
|
const t = e.startTime || performance.now(), r = ++this.navigationCounter, n = `${t.toFixed(2)}_${window.location.pathname}`;
|
|
4454
4459
|
return r > 1 ? `${n}_${r}` : n;
|
|
4455
4460
|
} catch (e) {
|
|
4456
|
-
return
|
|
4461
|
+
return a("debug", "Failed to get navigation ID", { error: e }), null;
|
|
4457
4462
|
}
|
|
4458
4463
|
}
|
|
4459
4464
|
isObserverSupported(e) {
|
|
@@ -4465,24 +4470,24 @@ class wr extends w {
|
|
|
4465
4470
|
try {
|
|
4466
4471
|
if (!this.isObserverSupported(e))
|
|
4467
4472
|
return !1;
|
|
4468
|
-
const i = new PerformanceObserver((o,
|
|
4473
|
+
const i = new PerformanceObserver((o, l) => {
|
|
4469
4474
|
try {
|
|
4470
|
-
t(o,
|
|
4475
|
+
t(o, l);
|
|
4471
4476
|
} catch (c) {
|
|
4472
|
-
|
|
4477
|
+
a("debug", "Observer callback failed", {
|
|
4473
4478
|
error: c,
|
|
4474
4479
|
data: { type: e }
|
|
4475
4480
|
});
|
|
4476
4481
|
}
|
|
4477
4482
|
if (n)
|
|
4478
4483
|
try {
|
|
4479
|
-
|
|
4484
|
+
l.disconnect();
|
|
4480
4485
|
} catch {
|
|
4481
4486
|
}
|
|
4482
4487
|
});
|
|
4483
4488
|
return i.observe(r ?? { type: e, buffered: !0 }), n || this.observers.push(i), !0;
|
|
4484
4489
|
} catch (i) {
|
|
4485
|
-
return
|
|
4490
|
+
return a("debug", "Failed to create performance observer", {
|
|
4486
4491
|
error: i,
|
|
4487
4492
|
data: { type: e }
|
|
4488
4493
|
}), !1;
|
|
@@ -4490,12 +4495,12 @@ class wr extends w {
|
|
|
4490
4495
|
}
|
|
4491
4496
|
shouldSendVital(e, t) {
|
|
4492
4497
|
if (typeof t != "number" || !Number.isFinite(t))
|
|
4493
|
-
return
|
|
4498
|
+
return a("debug", "Invalid web vital value", { data: { type: e, value: t } }), !1;
|
|
4494
4499
|
const r = this.vitalThresholds[e];
|
|
4495
4500
|
return !(typeof r == "number" && t <= r);
|
|
4496
4501
|
}
|
|
4497
4502
|
}
|
|
4498
|
-
class
|
|
4503
|
+
class Ar extends w {
|
|
4499
4504
|
eventManager;
|
|
4500
4505
|
recentErrors = /* @__PURE__ */ new Map();
|
|
4501
4506
|
errorBurstCounter = 0;
|
|
@@ -4531,24 +4536,24 @@ class yr extends w {
|
|
|
4531
4536
|
const e = Date.now();
|
|
4532
4537
|
if (e < this.burstBackoffUntil)
|
|
4533
4538
|
return !1;
|
|
4534
|
-
if (e - this.burstWindowStart >
|
|
4535
|
-
return this.burstBackoffUntil = e +
|
|
4539
|
+
if (e - this.burstWindowStart > $t && (this.errorBurstCounter = 0, this.burstWindowStart = e), this.errorBurstCounter++, this.errorBurstCounter > Bt)
|
|
4540
|
+
return this.burstBackoffUntil = e + Ge, a("debug", "Error burst detected - entering cooldown", {
|
|
4536
4541
|
data: {
|
|
4537
4542
|
errorsInWindow: this.errorBurstCounter,
|
|
4538
|
-
cooldownMs:
|
|
4543
|
+
cooldownMs: Ge
|
|
4539
4544
|
}
|
|
4540
4545
|
}), !1;
|
|
4541
|
-
const r = this.get("config")?.errorSampling ??
|
|
4546
|
+
const r = this.get("config")?.errorSampling ?? it;
|
|
4542
4547
|
return Math.random() < r;
|
|
4543
4548
|
}
|
|
4544
4549
|
handleError = (e) => {
|
|
4545
4550
|
if (!this.shouldSample())
|
|
4546
4551
|
return;
|
|
4547
4552
|
const t = this.sanitize(e.message || "Unknown error");
|
|
4548
|
-
this.shouldSuppressError(
|
|
4553
|
+
this.shouldSuppressError(W.JS_ERROR, t) || this.eventManager.track({
|
|
4549
4554
|
type: d.ERROR,
|
|
4550
4555
|
error_data: {
|
|
4551
|
-
type:
|
|
4556
|
+
type: W.JS_ERROR,
|
|
4552
4557
|
message: t,
|
|
4553
4558
|
...e.filename && { filename: e.filename },
|
|
4554
4559
|
...e.lineno && { line: e.lineno },
|
|
@@ -4560,10 +4565,10 @@ class yr extends w {
|
|
|
4560
4565
|
if (!this.shouldSample())
|
|
4561
4566
|
return;
|
|
4562
4567
|
const t = this.extractRejectionMessage(e.reason), r = this.sanitize(t);
|
|
4563
|
-
this.shouldSuppressError(
|
|
4568
|
+
this.shouldSuppressError(W.PROMISE_REJECTION, r) || this.eventManager.track({
|
|
4564
4569
|
type: d.ERROR,
|
|
4565
4570
|
error_data: {
|
|
4566
|
-
type:
|
|
4571
|
+
type: W.PROMISE_REJECTION,
|
|
4567
4572
|
message: r
|
|
4568
4573
|
}
|
|
4569
4574
|
});
|
|
@@ -4582,8 +4587,8 @@ class yr extends w {
|
|
|
4582
4587
|
}
|
|
4583
4588
|
}
|
|
4584
4589
|
sanitize(e) {
|
|
4585
|
-
let t = e.length >
|
|
4586
|
-
for (const r of
|
|
4590
|
+
let t = e.length > Be ? e.slice(0, Be) + "..." : e;
|
|
4591
|
+
for (const r of nt) {
|
|
4587
4592
|
const n = new RegExp(r.source, r.flags);
|
|
4588
4593
|
t = t.replace(n, "[REDACTED]");
|
|
4589
4594
|
}
|
|
@@ -4591,26 +4596,26 @@ class yr extends w {
|
|
|
4591
4596
|
}
|
|
4592
4597
|
shouldSuppressError(e, t) {
|
|
4593
4598
|
const r = Date.now(), n = `${e}:${t}`, i = this.recentErrors.get(n);
|
|
4594
|
-
return i && r - i <
|
|
4599
|
+
return i && r - i < We ? (this.recentErrors.set(n, r), !0) : (this.recentErrors.set(n, r), this.recentErrors.size > Ft ? (this.recentErrors.clear(), this.recentErrors.set(n, r), !1) : (this.recentErrors.size > te && this.pruneOldErrors(), !1));
|
|
4595
4600
|
}
|
|
4596
4601
|
pruneOldErrors() {
|
|
4597
4602
|
const e = Date.now();
|
|
4598
4603
|
for (const [n, i] of this.recentErrors.entries())
|
|
4599
|
-
e - i >
|
|
4600
|
-
if (this.recentErrors.size <=
|
|
4604
|
+
e - i > We && this.recentErrors.delete(n);
|
|
4605
|
+
if (this.recentErrors.size <= te)
|
|
4601
4606
|
return;
|
|
4602
|
-
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), r = this.recentErrors.size -
|
|
4607
|
+
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), r = this.recentErrors.size - te;
|
|
4603
4608
|
for (let n = 0; n < r; n += 1) {
|
|
4604
4609
|
const i = t[n];
|
|
4605
4610
|
i && this.recentErrors.delete(i[0]);
|
|
4606
4611
|
}
|
|
4607
4612
|
}
|
|
4608
4613
|
}
|
|
4609
|
-
class
|
|
4614
|
+
class Lr extends w {
|
|
4610
4615
|
isInitialized = !1;
|
|
4611
4616
|
suppressNextScrollTimer = null;
|
|
4612
4617
|
pageUnloadHandler = null;
|
|
4613
|
-
emitter = new
|
|
4618
|
+
emitter = new dr();
|
|
4614
4619
|
transformers = {};
|
|
4615
4620
|
customHeadersProvider;
|
|
4616
4621
|
managers = {};
|
|
@@ -4628,19 +4633,19 @@ class br extends w {
|
|
|
4628
4633
|
async init(e = {}) {
|
|
4629
4634
|
if (this.isInitialized)
|
|
4630
4635
|
return { sessionId: this.get("sessionId") ?? "" };
|
|
4631
|
-
this.managers.storage = new
|
|
4636
|
+
this.managers.storage = new wr();
|
|
4632
4637
|
try {
|
|
4633
4638
|
this.setupState(e);
|
|
4634
4639
|
const t = e.integrations?.custom?.headers ?? {}, r = e.integrations?.custom?.fetchCredentials ?? "include";
|
|
4635
|
-
return this.managers.event = new
|
|
4640
|
+
return this.managers.event = new gr(
|
|
4636
4641
|
this.managers.storage,
|
|
4637
4642
|
this.emitter,
|
|
4638
4643
|
this.transformers,
|
|
4639
4644
|
t,
|
|
4640
4645
|
this.customHeadersProvider,
|
|
4641
4646
|
r
|
|
4642
|
-
), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((n) => {
|
|
4643
|
-
|
|
4647
|
+
), this.loadPersistedIdentity(), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((n) => {
|
|
4648
|
+
a("warn", "Failed to recover persisted events", { error: n });
|
|
4644
4649
|
}), this.isInitialized = !0, { sessionId: this.get("sessionId") ?? "" };
|
|
4645
4650
|
} catch (t) {
|
|
4646
4651
|
this.destroy(!0);
|
|
@@ -4657,16 +4662,16 @@ class br extends w {
|
|
|
4657
4662
|
*/
|
|
4658
4663
|
sendCustomEvent(e, t) {
|
|
4659
4664
|
if (!this.managers.event) {
|
|
4660
|
-
|
|
4665
|
+
a("warn", "Cannot send custom event: TraceLog not initialized", { data: { name: e } });
|
|
4661
4666
|
return;
|
|
4662
4667
|
}
|
|
4663
4668
|
let r = t;
|
|
4664
4669
|
t && typeof t == "object" && !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && (r = Object.assign({}, t));
|
|
4665
|
-
const { valid: n, error: i, sanitizedMetadata: o } =
|
|
4670
|
+
const { valid: n, error: i, sanitizedMetadata: o } = ur(e, r);
|
|
4666
4671
|
if (!n) {
|
|
4667
|
-
if (this.get("mode") ===
|
|
4672
|
+
if (this.get("mode") === se.QA)
|
|
4668
4673
|
throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${i}`);
|
|
4669
|
-
|
|
4674
|
+
a("warn", `Custom event "${e}" dropped: ${i}`);
|
|
4670
4675
|
return;
|
|
4671
4676
|
}
|
|
4672
4677
|
this.managers.event.track({
|
|
@@ -4726,20 +4731,20 @@ class br extends w {
|
|
|
4726
4731
|
try {
|
|
4727
4732
|
t.stopTracking();
|
|
4728
4733
|
} catch (r) {
|
|
4729
|
-
|
|
4734
|
+
a("warn", "Failed to stop tracking", { error: r });
|
|
4730
4735
|
}
|
|
4731
|
-
}), this.suppressNextScrollTimer && (clearTimeout(this.suppressNextScrollTimer), this.suppressNextScrollTimer = null), this.pageUnloadHandler && (window.removeEventListener("pagehide", this.pageUnloadHandler), window.removeEventListener("beforeunload", this.pageUnloadHandler), this.pageUnloadHandler = null), this.managers.event?.flushImmediatelySync(), this.managers.event?.stop(), this.emitter.removeAllListeners(), this.transformers.beforeSend = void 0, this.transformers.beforeBatch = void 0, this.customHeadersProvider = void 0, this.set("suppressNextScroll", !1), this.set("sessionId", null), this.isInitialized = !1, this.handlers = {}, this.managers = {});
|
|
4736
|
+
}), this.suppressNextScrollTimer && (clearTimeout(this.suppressNextScrollTimer), this.suppressNextScrollTimer = null), this.pageUnloadHandler && (window.removeEventListener("pagehide", this.pageUnloadHandler), window.removeEventListener("beforeunload", this.pageUnloadHandler), this.pageUnloadHandler = null), this.managers.event?.flushImmediatelySync(), this.managers.event?.stop(), this.emitter.removeAllListeners(), this.transformers.beforeSend = void 0, this.transformers.beforeBatch = void 0, this.customHeadersProvider = void 0, this.set("suppressNextScroll", !1), this.set("sessionId", null), this.set("identity", void 0), this.clearPersistedIdentity(), this.isInitialized = !1, this.handlers = {}, this.managers = {});
|
|
4732
4737
|
}
|
|
4733
4738
|
setupState(e = {}) {
|
|
4734
4739
|
this.set("config", e);
|
|
4735
|
-
const t =
|
|
4740
|
+
const t = Er.getId(this.managers.storage);
|
|
4736
4741
|
this.set("userId", t);
|
|
4737
|
-
const r =
|
|
4742
|
+
const r = rr(e);
|
|
4738
4743
|
this.set("collectApiUrls", r);
|
|
4739
|
-
const n =
|
|
4744
|
+
const n = xt();
|
|
4740
4745
|
this.set("device", n);
|
|
4741
|
-
const i =
|
|
4742
|
-
this.set("pageUrl", i),
|
|
4746
|
+
const i = ve(window.location.href, e.sensitiveQueryParams);
|
|
4747
|
+
this.set("pageUrl", i), Yt() && this.set("mode", se.QA);
|
|
4743
4748
|
}
|
|
4744
4749
|
/**
|
|
4745
4750
|
* Returns the current configuration object.
|
|
@@ -4790,7 +4795,7 @@ class br extends w {
|
|
|
4790
4795
|
valid: !1,
|
|
4791
4796
|
error: "Global metadata must be a plain object"
|
|
4792
4797
|
};
|
|
4793
|
-
const t =
|
|
4798
|
+
const t = ct("Global", e, "globalMetadata");
|
|
4794
4799
|
return t.valid ? { valid: !0 } : {
|
|
4795
4800
|
valid: !1,
|
|
4796
4801
|
error: t.error
|
|
@@ -4811,7 +4816,7 @@ class br extends w {
|
|
|
4811
4816
|
...this.get("config"),
|
|
4812
4817
|
globalMetadata: e
|
|
4813
4818
|
};
|
|
4814
|
-
this.set("config", n),
|
|
4819
|
+
this.set("config", n), a("debug", "Global metadata updated (replaced)", { data: { keys: Object.keys(e) } });
|
|
4815
4820
|
}
|
|
4816
4821
|
/**
|
|
4817
4822
|
* Merges new metadata with existing global metadata.
|
|
@@ -4831,7 +4836,131 @@ class br extends w {
|
|
|
4831
4836
|
...r,
|
|
4832
4837
|
globalMetadata: i
|
|
4833
4838
|
};
|
|
4834
|
-
this.set("config", o),
|
|
4839
|
+
this.set("config", o), a("debug", "Global metadata updated (merged)", { data: { keys: Object.keys(e) } });
|
|
4840
|
+
}
|
|
4841
|
+
/**
|
|
4842
|
+
* Associates the current anonymous visitor with a known user identity.
|
|
4843
|
+
*
|
|
4844
|
+
* Identity is persisted to localStorage (project-scoped) and included in every
|
|
4845
|
+
* subsequent batch payload so the backend always has the latest identity.
|
|
4846
|
+
*
|
|
4847
|
+
* Validation is duplicated here (also in api.ts) as defense-in-depth since
|
|
4848
|
+
* TestBridge and internal callers bypass the API layer.
|
|
4849
|
+
*
|
|
4850
|
+
* @param userId - External user identifier (email, customer_id, etc.)
|
|
4851
|
+
* @param traits - Optional user attributes (name, email, plan, etc.)
|
|
4852
|
+
* @internal Called from api.identify()
|
|
4853
|
+
*/
|
|
4854
|
+
identify(e, t) {
|
|
4855
|
+
if (!e || typeof e != "string" || e.trim().length === 0) {
|
|
4856
|
+
a("warn", "identify() called with invalid userId", {
|
|
4857
|
+
data: { type: typeof e, length: typeof e == "string" ? e.trim().length : 0 }
|
|
4858
|
+
});
|
|
4859
|
+
return;
|
|
4860
|
+
}
|
|
4861
|
+
if (e.trim().length > 256) {
|
|
4862
|
+
a("warn", "identify() userId exceeds 256 characters", { data: { length: e.trim().length } });
|
|
4863
|
+
return;
|
|
4864
|
+
}
|
|
4865
|
+
const r = e.trim(), n = t && typeof t == "object" && Object.keys(t).length > 0, i = {
|
|
4866
|
+
userId: r,
|
|
4867
|
+
...n ? { traits: t } : {}
|
|
4868
|
+
};
|
|
4869
|
+
this.set("identity", i), this.persistIdentity(i), a("debug", "Visitor identified", {
|
|
4870
|
+
data: { userIdLength: r.length, traitKeys: n ? Object.keys(t) : [] }
|
|
4871
|
+
});
|
|
4872
|
+
}
|
|
4873
|
+
/**
|
|
4874
|
+
* Clears identity, regenerates UUID, and starts a new session.
|
|
4875
|
+
*
|
|
4876
|
+
* Used for logout flows. The previous visitor profile with its identity
|
|
4877
|
+
* remains in MongoDB — this method ensures the next user in the same browser
|
|
4878
|
+
* gets a fresh anonymous profile.
|
|
4879
|
+
*
|
|
4880
|
+
* @internal Called from api.resetIdentity()
|
|
4881
|
+
*/
|
|
4882
|
+
async resetIdentity() {
|
|
4883
|
+
await this.managers.event?.flushImmediately(), this.set("identity", void 0), this.clearPersistedIdentity();
|
|
4884
|
+
const e = at();
|
|
4885
|
+
this.managers.storage.setItem(Ee, e), this.set("userId", e), this.set("hasStartSession", !1), this.set("sessionId", null), this.handlers.session?.stopTracking(), this.handlers.session?.startTracking(), a("debug", "Identity reset, new UUID generated");
|
|
4886
|
+
}
|
|
4887
|
+
/**
|
|
4888
|
+
* Returns the project ID used for identity storage scoping.
|
|
4889
|
+
* Matches the same logic used by SessionHandler.
|
|
4890
|
+
*/
|
|
4891
|
+
getProjectId() {
|
|
4892
|
+
return this.get("config")?.integrations?.tracelog?.projectId ?? "custom";
|
|
4893
|
+
}
|
|
4894
|
+
/**
|
|
4895
|
+
* Persists identity to localStorage under the project-scoped key.
|
|
4896
|
+
*/
|
|
4897
|
+
persistIdentity(e) {
|
|
4898
|
+
try {
|
|
4899
|
+
const t = this.getProjectId(), r = ue(t);
|
|
4900
|
+
this.managers.storage.setItem(r, JSON.stringify(e));
|
|
4901
|
+
} catch {
|
|
4902
|
+
a("debug", "Failed to persist identity to localStorage");
|
|
4903
|
+
}
|
|
4904
|
+
}
|
|
4905
|
+
/**
|
|
4906
|
+
* Loads identity from localStorage on init.
|
|
4907
|
+
* Also migrates pending identity (set before init) to the project-scoped key.
|
|
4908
|
+
*/
|
|
4909
|
+
loadPersistedIdentity() {
|
|
4910
|
+
const e = this.managers.storage, t = this.getProjectId(), r = ue(t);
|
|
4911
|
+
try {
|
|
4912
|
+
const n = e.getItem(H);
|
|
4913
|
+
if (n) {
|
|
4914
|
+
const i = JSON.parse(n);
|
|
4915
|
+
if (e.removeItem(H), !this.isValidIdentityData(i)) {
|
|
4916
|
+
a("debug", "Invalid pending identity in localStorage, discarded");
|
|
4917
|
+
return;
|
|
4918
|
+
}
|
|
4919
|
+
e.setItem(r, JSON.stringify(i)), this.set("identity", i), a("debug", "Migrated pending identity to project-scoped key");
|
|
4920
|
+
return;
|
|
4921
|
+
}
|
|
4922
|
+
} catch {
|
|
4923
|
+
e.removeItem(H);
|
|
4924
|
+
}
|
|
4925
|
+
try {
|
|
4926
|
+
const n = e.getItem(r);
|
|
4927
|
+
if (n) {
|
|
4928
|
+
const i = JSON.parse(n);
|
|
4929
|
+
if (!this.isValidIdentityData(i)) {
|
|
4930
|
+
e.removeItem(r), a("debug", "Invalid persisted identity in localStorage, discarded");
|
|
4931
|
+
return;
|
|
4932
|
+
}
|
|
4933
|
+
this.set("identity", i), a("debug", "Loaded persisted identity");
|
|
4934
|
+
}
|
|
4935
|
+
} catch {
|
|
4936
|
+
a("debug", "Failed to load persisted identity");
|
|
4937
|
+
}
|
|
4938
|
+
}
|
|
4939
|
+
/**
|
|
4940
|
+
* Validates identity data loaded from localStorage.
|
|
4941
|
+
* Guards against tampered or corrupted localStorage values.
|
|
4942
|
+
*/
|
|
4943
|
+
isValidIdentityData(e) {
|
|
4944
|
+
if (!e || typeof e != "object") return !1;
|
|
4945
|
+
const { userId: t, traits: r } = e;
|
|
4946
|
+
if (typeof t != "string" || t.trim().length === 0 || t.trim().length > 256) return !1;
|
|
4947
|
+
if (r !== void 0) {
|
|
4948
|
+
if (typeof r != "object" || r === null || Array.isArray(r)) return !1;
|
|
4949
|
+
for (const n of Object.values(r))
|
|
4950
|
+
if (typeof n != "string") return !1;
|
|
4951
|
+
}
|
|
4952
|
+
return !0;
|
|
4953
|
+
}
|
|
4954
|
+
/**
|
|
4955
|
+
* Clears persisted identity from localStorage.
|
|
4956
|
+
*/
|
|
4957
|
+
clearPersistedIdentity() {
|
|
4958
|
+
try {
|
|
4959
|
+
const e = this.managers.storage, t = this.getProjectId();
|
|
4960
|
+
e.removeItem(ue(t)), e.removeItem(H);
|
|
4961
|
+
} catch {
|
|
4962
|
+
a("debug", "Failed to clear persisted identity");
|
|
4963
|
+
}
|
|
4835
4964
|
}
|
|
4836
4965
|
setupPageLifecycleListeners() {
|
|
4837
4966
|
this.pageUnloadHandler = () => {
|
|
@@ -4840,7 +4969,7 @@ class br extends w {
|
|
|
4840
4969
|
}
|
|
4841
4970
|
initializeHandlers() {
|
|
4842
4971
|
const e = this.get("config");
|
|
4843
|
-
this.handlers.session = new
|
|
4972
|
+
this.handlers.session = new Tr(
|
|
4844
4973
|
this.managers.storage,
|
|
4845
4974
|
this.managers.event
|
|
4846
4975
|
), this.handlers.session.startTracking();
|
|
@@ -4849,25 +4978,25 @@ class br extends w {
|
|
|
4849
4978
|
this.set("suppressNextScroll", !1);
|
|
4850
4979
|
}, 500);
|
|
4851
4980
|
};
|
|
4852
|
-
this.handlers.pageView = new
|
|
4853
|
-
|
|
4854
|
-
}), this.handlers.error = new
|
|
4981
|
+
this.handlers.pageView = new Ir(this.managers.event, t), this.handlers.pageView.startTracking(), this.handlers.click = new vr(this.managers.event), this.handlers.click.startTracking(), this.handlers.scroll = new _r(this.managers.event), this.handlers.scroll.startTracking(), this.handlers.performance = new br(this.managers.event), this.handlers.performance.startTracking().catch((r) => {
|
|
4982
|
+
a("warn", "Failed to start performance tracking", { error: r });
|
|
4983
|
+
}), this.handlers.error = new Ar(this.managers.event), this.handlers.error.startTracking(), e.viewport && (this.handlers.viewport = new yr(this.managers.event), this.handlers.viewport.startTracking());
|
|
4855
4984
|
}
|
|
4856
4985
|
}
|
|
4857
4986
|
const V = [], M = [];
|
|
4858
|
-
let D = null, h = null, R = !1,
|
|
4859
|
-
const
|
|
4987
|
+
let D = null, h = null, R = !1, p = !1, P = null;
|
|
4988
|
+
const Mr = async (s) => typeof window > "u" || typeof document > "u" ? { sessionId: "" } : (p = !1, window.__traceLogDisabled === !0 ? { sessionId: "" } : h ? { sessionId: h.getSessionId() ?? "" } : (R && P || (R = !0, P = (async () => {
|
|
4860
4989
|
try {
|
|
4861
|
-
const e =
|
|
4990
|
+
const e = ar(s ?? {}), t = new Lr();
|
|
4862
4991
|
try {
|
|
4863
|
-
V.forEach(({ event: o, callback:
|
|
4864
|
-
t.on(o,
|
|
4865
|
-
}), V.length = 0, M.forEach(({ hook: o, fn:
|
|
4866
|
-
o === "beforeSend" ? t.setTransformer("beforeSend",
|
|
4992
|
+
V.forEach(({ event: o, callback: l }) => {
|
|
4993
|
+
t.on(o, l);
|
|
4994
|
+
}), V.length = 0, M.forEach(({ hook: o, fn: l }) => {
|
|
4995
|
+
o === "beforeSend" ? t.setTransformer("beforeSend", l) : t.setTransformer("beforeBatch", l);
|
|
4867
4996
|
}), M.length = 0, D && (t.setCustomHeaders(D), D = null);
|
|
4868
|
-
const r = t.init(e), n = new Promise((o,
|
|
4997
|
+
const r = t.init(e), n = new Promise((o, l) => {
|
|
4869
4998
|
setTimeout(() => {
|
|
4870
|
-
|
|
4999
|
+
l(new Error("[TraceLog] Initialization timeout after 10000ms"));
|
|
4871
5000
|
}, 1e4);
|
|
4872
5001
|
}), i = await Promise.race([r, n]);
|
|
4873
5002
|
return h = t, i;
|
|
@@ -4875,7 +5004,7 @@ const Ar = async (s) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
4875
5004
|
try {
|
|
4876
5005
|
t.destroy(!0);
|
|
4877
5006
|
} catch (n) {
|
|
4878
|
-
|
|
5007
|
+
a("error", "Failed to cleanup partially initialized app", { error: n });
|
|
4879
5008
|
}
|
|
4880
5009
|
throw r;
|
|
4881
5010
|
}
|
|
@@ -4884,15 +5013,15 @@ const Ar = async (s) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
4884
5013
|
} finally {
|
|
4885
5014
|
R = !1, P = null;
|
|
4886
5015
|
}
|
|
4887
|
-
})()), P)),
|
|
5016
|
+
})()), P)), Cr = (s, e) => {
|
|
4888
5017
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4889
5018
|
if (!h)
|
|
4890
5019
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4891
|
-
if (
|
|
5020
|
+
if (p)
|
|
4892
5021
|
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
4893
5022
|
h.sendCustomEvent(s, e);
|
|
4894
5023
|
}
|
|
4895
|
-
},
|
|
5024
|
+
}, Rr = (s, e) => {
|
|
4896
5025
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4897
5026
|
if (!h || R) {
|
|
4898
5027
|
V.push({ event: s, callback: e });
|
|
@@ -4900,7 +5029,7 @@ const Ar = async (s) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
4900
5029
|
}
|
|
4901
5030
|
h.on(s, e);
|
|
4902
5031
|
}
|
|
4903
|
-
},
|
|
5032
|
+
}, Nr = (s, e) => {
|
|
4904
5033
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4905
5034
|
if (!h) {
|
|
4906
5035
|
const t = V.findIndex((r) => r.event === s && r.callback === e);
|
|
@@ -4910,7 +5039,7 @@ const Ar = async (s) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
4910
5039
|
h.off(s, e);
|
|
4911
5040
|
}
|
|
4912
5041
|
};
|
|
4913
|
-
function
|
|
5042
|
+
function Or(s, e) {
|
|
4914
5043
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4915
5044
|
if (typeof e != "function")
|
|
4916
5045
|
throw new Error(`[TraceLog] Transformer must be a function, received: ${typeof e}`);
|
|
@@ -4919,23 +5048,23 @@ function Rr(s, e) {
|
|
|
4919
5048
|
t !== -1 && M.splice(t, 1), M.push({ hook: s, fn: e });
|
|
4920
5049
|
return;
|
|
4921
5050
|
}
|
|
4922
|
-
if (
|
|
5051
|
+
if (p)
|
|
4923
5052
|
throw new Error("[TraceLog] Cannot set transformers while TraceLog is being destroyed");
|
|
4924
5053
|
s === "beforeSend" ? h.setTransformer("beforeSend", e) : h.setTransformer("beforeBatch", e);
|
|
4925
5054
|
}
|
|
4926
5055
|
}
|
|
4927
|
-
const
|
|
5056
|
+
const Pr = (s) => {
|
|
4928
5057
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4929
5058
|
if (!h) {
|
|
4930
5059
|
const e = M.findIndex((t) => t.hook === s);
|
|
4931
5060
|
e !== -1 && M.splice(e, 1);
|
|
4932
5061
|
return;
|
|
4933
5062
|
}
|
|
4934
|
-
if (
|
|
5063
|
+
if (p)
|
|
4935
5064
|
throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
|
|
4936
5065
|
h.removeTransformer(s);
|
|
4937
5066
|
}
|
|
4938
|
-
},
|
|
5067
|
+
}, Dr = (s) => {
|
|
4939
5068
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4940
5069
|
if (typeof s != "function")
|
|
4941
5070
|
throw new Error(`[TraceLog] Custom headers provider must be a function, received: ${typeof s}`);
|
|
@@ -4943,83 +5072,126 @@ const Nr = (s) => {
|
|
|
4943
5072
|
D = s;
|
|
4944
5073
|
return;
|
|
4945
5074
|
}
|
|
4946
|
-
if (
|
|
5075
|
+
if (p)
|
|
4947
5076
|
throw new Error("[TraceLog] Cannot set custom headers while TraceLog is being destroyed");
|
|
4948
5077
|
h.setCustomHeaders(s);
|
|
4949
5078
|
}
|
|
4950
|
-
},
|
|
5079
|
+
}, Vr = () => {
|
|
4951
5080
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4952
5081
|
if (!h) {
|
|
4953
5082
|
D = null;
|
|
4954
5083
|
return;
|
|
4955
5084
|
}
|
|
4956
|
-
if (
|
|
5085
|
+
if (p)
|
|
4957
5086
|
throw new Error("[TraceLog] Cannot remove custom headers while TraceLog is being destroyed");
|
|
4958
5087
|
h.removeCustomHeaders();
|
|
4959
5088
|
}
|
|
4960
|
-
},
|
|
5089
|
+
}, kr = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, Ur = () => typeof window > "u" || typeof document > "u" || !h ? null : h.getSessionId(), Hr = () => {
|
|
4961
5090
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4962
|
-
if (
|
|
5091
|
+
if (p)
|
|
4963
5092
|
throw new Error("[TraceLog] Destroy operation already in progress");
|
|
4964
5093
|
if (!h) {
|
|
4965
|
-
|
|
5094
|
+
p = !1;
|
|
4966
5095
|
return;
|
|
4967
5096
|
}
|
|
4968
|
-
|
|
5097
|
+
p = !0;
|
|
4969
5098
|
try {
|
|
4970
|
-
h.destroy(), h = null, R = !1, P = null, V.length = 0, M.length = 0, D = null,
|
|
5099
|
+
h.destroy(), h = null, R = !1, P = null, V.length = 0, M.length = 0, D = null, p = !1;
|
|
4971
5100
|
} catch (s) {
|
|
4972
|
-
h = null, R = !1, P = null, V.length = 0, M.length = 0, D = null,
|
|
5101
|
+
h = null, R = !1, P = null, V.length = 0, M.length = 0, D = null, p = !1, a("warn", "Error during destroy, forced cleanup completed", { error: s });
|
|
4973
5102
|
}
|
|
4974
5103
|
}
|
|
4975
|
-
},
|
|
4976
|
-
typeof window > "u" || typeof document > "u" ||
|
|
4977
|
-
},
|
|
5104
|
+
}, xr = (s) => {
|
|
5105
|
+
typeof window > "u" || typeof document > "u" || qt(s);
|
|
5106
|
+
}, Fr = (s) => {
|
|
4978
5107
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4979
5108
|
if (!h)
|
|
4980
5109
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4981
|
-
if (
|
|
5110
|
+
if (p)
|
|
4982
5111
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
4983
5112
|
h.updateGlobalMetadata(s);
|
|
4984
5113
|
}
|
|
4985
|
-
},
|
|
5114
|
+
}, $r = (s) => {
|
|
4986
5115
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4987
5116
|
if (!h)
|
|
4988
5117
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4989
|
-
if (
|
|
5118
|
+
if (p)
|
|
4990
5119
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
4991
5120
|
h.mergeGlobalMetadata(s);
|
|
4992
5121
|
}
|
|
4993
|
-
},
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5122
|
+
}, Br = (s, e) => {
|
|
5123
|
+
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5124
|
+
if (!s || typeof s != "string" || s.trim().length === 0) {
|
|
5125
|
+
a("warn", "identify() called with invalid userId");
|
|
5126
|
+
return;
|
|
5127
|
+
}
|
|
5128
|
+
if (s.trim().length > 256) {
|
|
5129
|
+
a("warn", "identify() userId exceeds 256 characters");
|
|
5130
|
+
return;
|
|
5131
|
+
}
|
|
5132
|
+
if (p) {
|
|
5133
|
+
a("warn", "Cannot identify while TraceLog is being destroyed");
|
|
5134
|
+
return;
|
|
5135
|
+
}
|
|
5136
|
+
if (h) {
|
|
5137
|
+
h.identify(s, e);
|
|
5138
|
+
return;
|
|
5139
|
+
}
|
|
5140
|
+
try {
|
|
5141
|
+
const t = e && typeof e == "object" && Object.keys(e).length > 0, r = {
|
|
5142
|
+
userId: s.trim(),
|
|
5143
|
+
...t ? { traits: e } : {}
|
|
5144
|
+
};
|
|
5145
|
+
localStorage.setItem(H, JSON.stringify(r)), a("debug", "Identity persisted pre-init (will be applied on init)");
|
|
5146
|
+
} catch {
|
|
5147
|
+
a("debug", "Failed to persist pre-init identity");
|
|
5148
|
+
}
|
|
5149
|
+
}
|
|
5150
|
+
}, Wr = async () => {
|
|
5151
|
+
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5152
|
+
if (!h) {
|
|
5153
|
+
try {
|
|
5154
|
+
localStorage.removeItem(H);
|
|
5155
|
+
} catch {
|
|
5156
|
+
}
|
|
5157
|
+
return;
|
|
5158
|
+
}
|
|
5159
|
+
if (p)
|
|
5160
|
+
throw new Error("[TraceLog] Cannot reset identity while TraceLog is being destroyed");
|
|
5161
|
+
await h.resetIdentity();
|
|
5162
|
+
}
|
|
5163
|
+
}, ps = {
|
|
5164
|
+
init: Mr,
|
|
5165
|
+
event: Cr,
|
|
5166
|
+
on: Rr,
|
|
5167
|
+
off: Nr,
|
|
5168
|
+
setTransformer: Or,
|
|
5169
|
+
removeTransformer: Pr,
|
|
5170
|
+
setCustomHeaders: Dr,
|
|
5171
|
+
removeCustomHeaders: Vr,
|
|
5172
|
+
isInitialized: kr,
|
|
5173
|
+
getSessionId: Ur,
|
|
5174
|
+
destroy: Hr,
|
|
5175
|
+
setQaMode: xr,
|
|
5176
|
+
updateGlobalMetadata: Fr,
|
|
5177
|
+
mergeGlobalMetadata: $r,
|
|
5178
|
+
identify: Br,
|
|
5179
|
+
resetIdentity: Wr
|
|
5008
5180
|
};
|
|
5009
|
-
var
|
|
5181
|
+
var we, C, j, ht, ie, ft = -1, k = function(s) {
|
|
5010
5182
|
addEventListener("pageshow", (function(e) {
|
|
5011
|
-
e.persisted && (
|
|
5183
|
+
e.persisted && (ft = e.timeStamp, s(e));
|
|
5012
5184
|
}), !0);
|
|
5013
|
-
},
|
|
5185
|
+
}, Ne = function() {
|
|
5014
5186
|
var s = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
|
|
5015
5187
|
if (s && s.responseStart > 0 && s.responseStart < performance.now()) return s;
|
|
5016
|
-
},
|
|
5017
|
-
var s =
|
|
5188
|
+
}, ae = function() {
|
|
5189
|
+
var s = Ne();
|
|
5018
5190
|
return s && s.activationStart || 0;
|
|
5019
5191
|
}, _ = function(s, e) {
|
|
5020
|
-
var t =
|
|
5021
|
-
return
|
|
5022
|
-
},
|
|
5192
|
+
var t = Ne(), r = "navigate";
|
|
5193
|
+
return ft >= 0 ? r = "back-forward-cache" : t && (document.prerendering || ae() > 0 ? r = "prerender" : document.wasDiscarded ? r = "restore" : t.type && (r = t.type.replace(/_/g, "-"))), { name: s, value: e === void 0 ? -1 : e, rating: "good", delta: 0, entries: [], id: "v4-".concat(Date.now(), "-").concat(Math.floor(8999999999999 * Math.random()) + 1e12), navigationType: r };
|
|
5194
|
+
}, F = function(s, e, t) {
|
|
5023
5195
|
try {
|
|
5024
5196
|
if (PerformanceObserver.supportedEntryTypes.includes(s)) {
|
|
5025
5197
|
var r = new PerformanceObserver((function(n) {
|
|
@@ -5031,63 +5203,63 @@ var _e, C, X, ct, ne, ut = -1, k = function(s) {
|
|
|
5031
5203
|
}
|
|
5032
5204
|
} catch {
|
|
5033
5205
|
}
|
|
5034
|
-
},
|
|
5206
|
+
}, y = function(s, e, t, r) {
|
|
5035
5207
|
var n, i;
|
|
5036
5208
|
return function(o) {
|
|
5037
|
-
e.value >= 0 && (o || r) && ((i = e.value - (n || 0)) || n === void 0) && (n = e.value, e.delta = i, e.rating = (function(
|
|
5038
|
-
return
|
|
5209
|
+
e.value >= 0 && (o || r) && ((i = e.value - (n || 0)) || n === void 0) && (n = e.value, e.delta = i, e.rating = (function(l, c) {
|
|
5210
|
+
return l > c[1] ? "poor" : l > c[0] ? "needs-improvement" : "good";
|
|
5039
5211
|
})(e.value, t), s(e));
|
|
5040
5212
|
};
|
|
5041
|
-
},
|
|
5213
|
+
}, Oe = function(s) {
|
|
5042
5214
|
requestAnimationFrame((function() {
|
|
5043
5215
|
return requestAnimationFrame((function() {
|
|
5044
5216
|
return s();
|
|
5045
5217
|
}));
|
|
5046
5218
|
}));
|
|
5047
|
-
},
|
|
5219
|
+
}, z = function(s) {
|
|
5048
5220
|
document.addEventListener("visibilitychange", (function() {
|
|
5049
5221
|
document.visibilityState === "hidden" && s();
|
|
5050
5222
|
}));
|
|
5051
|
-
},
|
|
5223
|
+
}, le = function(s) {
|
|
5052
5224
|
var e = !1;
|
|
5053
5225
|
return function() {
|
|
5054
5226
|
e || (s(), e = !0);
|
|
5055
5227
|
};
|
|
5056
|
-
},
|
|
5228
|
+
}, x = -1, qe = function() {
|
|
5057
5229
|
return document.visibilityState !== "hidden" || document.prerendering ? 1 / 0 : 0;
|
|
5058
|
-
},
|
|
5059
|
-
document.visibilityState === "hidden" &&
|
|
5060
|
-
},
|
|
5061
|
-
addEventListener("visibilitychange",
|
|
5062
|
-
},
|
|
5063
|
-
removeEventListener("visibilitychange",
|
|
5064
|
-
},
|
|
5065
|
-
return
|
|
5230
|
+
}, oe = function(s) {
|
|
5231
|
+
document.visibilityState === "hidden" && x > -1 && (x = s.type === "visibilitychange" ? s.timeStamp : 0, Gr());
|
|
5232
|
+
}, Je = function() {
|
|
5233
|
+
addEventListener("visibilitychange", oe, !0), addEventListener("prerenderingchange", oe, !0);
|
|
5234
|
+
}, Gr = function() {
|
|
5235
|
+
removeEventListener("visibilitychange", oe, !0), removeEventListener("prerenderingchange", oe, !0);
|
|
5236
|
+
}, Pe = function() {
|
|
5237
|
+
return x < 0 && (x = qe(), Je(), k((function() {
|
|
5066
5238
|
setTimeout((function() {
|
|
5067
|
-
|
|
5239
|
+
x = qe(), Je();
|
|
5068
5240
|
}), 0);
|
|
5069
5241
|
}))), { get firstHiddenTime() {
|
|
5070
|
-
return
|
|
5242
|
+
return x;
|
|
5071
5243
|
} };
|
|
5072
|
-
},
|
|
5244
|
+
}, K = function(s) {
|
|
5073
5245
|
document.prerendering ? addEventListener("prerenderingchange", (function() {
|
|
5074
5246
|
return s();
|
|
5075
5247
|
}), !0) : s();
|
|
5076
|
-
},
|
|
5077
|
-
e = e || {},
|
|
5078
|
-
var t, r =
|
|
5079
|
-
o.forEach((function(
|
|
5080
|
-
|
|
5248
|
+
}, be = [1800, 3e3], mt = function(s, e) {
|
|
5249
|
+
e = e || {}, K((function() {
|
|
5250
|
+
var t, r = Pe(), n = _("FCP"), i = F("paint", (function(o) {
|
|
5251
|
+
o.forEach((function(l) {
|
|
5252
|
+
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime < r.firstHiddenTime && (n.value = Math.max(l.startTime - ae(), 0), n.entries.push(l), t(!0)));
|
|
5081
5253
|
}));
|
|
5082
5254
|
}));
|
|
5083
|
-
i && (t =
|
|
5084
|
-
n = _("FCP"), t =
|
|
5255
|
+
i && (t = y(s, n, be, e.reportAllChanges), k((function(o) {
|
|
5256
|
+
n = _("FCP"), t = y(s, n, be, e.reportAllChanges), Oe((function() {
|
|
5085
5257
|
n.value = performance.now() - o.timeStamp, t(!0);
|
|
5086
5258
|
}));
|
|
5087
5259
|
})));
|
|
5088
5260
|
}));
|
|
5089
|
-
},
|
|
5090
|
-
e = e || {},
|
|
5261
|
+
}, Ae = [0.1, 0.25], Xr = function(s, e) {
|
|
5262
|
+
e = e || {}, mt(le((function() {
|
|
5091
5263
|
var t, r = _("CLS", 0), n = 0, i = [], o = function(c) {
|
|
5092
5264
|
c.forEach((function(u) {
|
|
5093
5265
|
if (!u.hadRecentInput) {
|
|
@@ -5095,191 +5267,191 @@ var _e, C, X, ct, ne, ut = -1, k = function(s) {
|
|
|
5095
5267
|
n && u.startTime - E.startTime < 1e3 && u.startTime - g.startTime < 5e3 ? (n += u.value, i.push(u)) : (n = u.value, i = [u]);
|
|
5096
5268
|
}
|
|
5097
5269
|
})), n > r.value && (r.value = n, r.entries = i, t());
|
|
5098
|
-
},
|
|
5099
|
-
|
|
5100
|
-
o(
|
|
5270
|
+
}, l = F("layout-shift", o);
|
|
5271
|
+
l && (t = y(s, r, Ae, e.reportAllChanges), z((function() {
|
|
5272
|
+
o(l.takeRecords()), t(!0);
|
|
5101
5273
|
})), k((function() {
|
|
5102
|
-
n = 0, r = _("CLS", 0), t =
|
|
5274
|
+
n = 0, r = _("CLS", 0), t = y(s, r, Ae, e.reportAllChanges), Oe((function() {
|
|
5103
5275
|
return t();
|
|
5104
5276
|
}));
|
|
5105
5277
|
})), setTimeout(t, 0));
|
|
5106
5278
|
})));
|
|
5107
|
-
},
|
|
5279
|
+
}, gt = 0, me = 1 / 0, Z = 0, jr = function(s) {
|
|
5108
5280
|
s.forEach((function(e) {
|
|
5109
|
-
e.interactionId && (
|
|
5281
|
+
e.interactionId && (me = Math.min(me, e.interactionId), Z = Math.max(Z, e.interactionId), gt = Z ? (Z - me) / 7 + 1 : 0);
|
|
5110
5282
|
}));
|
|
5111
|
-
},
|
|
5112
|
-
return
|
|
5113
|
-
},
|
|
5114
|
-
"interactionCount" in performance ||
|
|
5115
|
-
}, A = [],
|
|
5116
|
-
var s = Math.min(A.length - 1, Math.floor((
|
|
5283
|
+
}, Et = function() {
|
|
5284
|
+
return we ? gt : performance.interactionCount || 0;
|
|
5285
|
+
}, Qr = function() {
|
|
5286
|
+
"interactionCount" in performance || we || (we = F("event", jr, { type: "event", buffered: !0, durationThreshold: 0 }));
|
|
5287
|
+
}, A = [], re = /* @__PURE__ */ new Map(), St = 0, zr = function() {
|
|
5288
|
+
var s = Math.min(A.length - 1, Math.floor((Et() - St) / 50));
|
|
5117
5289
|
return A[s];
|
|
5118
|
-
},
|
|
5119
|
-
if (
|
|
5290
|
+
}, Kr = [], Yr = function(s) {
|
|
5291
|
+
if (Kr.forEach((function(n) {
|
|
5120
5292
|
return n(s);
|
|
5121
5293
|
})), s.interactionId || s.entryType === "first-input") {
|
|
5122
|
-
var e = A[A.length - 1], t =
|
|
5294
|
+
var e = A[A.length - 1], t = re.get(s.interactionId);
|
|
5123
5295
|
if (t || A.length < 10 || s.duration > e.latency) {
|
|
5124
5296
|
if (t) s.duration > t.latency ? (t.entries = [s], t.latency = s.duration) : s.duration === t.latency && s.startTime === t.entries[0].startTime && t.entries.push(s);
|
|
5125
5297
|
else {
|
|
5126
5298
|
var r = { id: s.interactionId, latency: s.duration, entries: [s] };
|
|
5127
|
-
|
|
5299
|
+
re.set(r.id, r), A.push(r);
|
|
5128
5300
|
}
|
|
5129
5301
|
A.sort((function(n, i) {
|
|
5130
5302
|
return i.latency - n.latency;
|
|
5131
5303
|
})), A.length > 10 && A.splice(10).forEach((function(n) {
|
|
5132
|
-
return
|
|
5304
|
+
return re.delete(n.id);
|
|
5133
5305
|
}));
|
|
5134
5306
|
}
|
|
5135
5307
|
}
|
|
5136
|
-
},
|
|
5308
|
+
}, pt = function(s) {
|
|
5137
5309
|
var e = self.requestIdleCallback || self.setTimeout, t = -1;
|
|
5138
|
-
return s =
|
|
5139
|
-
},
|
|
5140
|
-
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {},
|
|
5310
|
+
return s = le(s), document.visibilityState === "hidden" ? s() : (t = e(s), z(s)), t;
|
|
5311
|
+
}, Le = [200, 500], qr = function(s, e) {
|
|
5312
|
+
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, K((function() {
|
|
5141
5313
|
var t;
|
|
5142
|
-
|
|
5143
|
-
var r, n = _("INP"), i = function(
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
var c =
|
|
5314
|
+
Qr();
|
|
5315
|
+
var r, n = _("INP"), i = function(l) {
|
|
5316
|
+
pt((function() {
|
|
5317
|
+
l.forEach(Yr);
|
|
5318
|
+
var c = zr();
|
|
5147
5319
|
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, r());
|
|
5148
5320
|
}));
|
|
5149
|
-
}, o =
|
|
5150
|
-
r =
|
|
5321
|
+
}, o = F("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
|
|
5322
|
+
r = y(s, n, Le, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), z((function() {
|
|
5151
5323
|
i(o.takeRecords()), r(!0);
|
|
5152
5324
|
})), k((function() {
|
|
5153
|
-
|
|
5325
|
+
St = Et(), A.length = 0, re.clear(), n = _("INP"), r = y(s, n, Le, e.reportAllChanges);
|
|
5154
5326
|
})));
|
|
5155
5327
|
})));
|
|
5156
|
-
},
|
|
5157
|
-
e = e || {},
|
|
5158
|
-
var t, r =
|
|
5328
|
+
}, Me = [2500, 4e3], ge = {}, Jr = function(s, e) {
|
|
5329
|
+
e = e || {}, K((function() {
|
|
5330
|
+
var t, r = Pe(), n = _("LCP"), i = function(c) {
|
|
5159
5331
|
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(u) {
|
|
5160
|
-
u.startTime < r.firstHiddenTime && (n.value = Math.max(u.startTime -
|
|
5332
|
+
u.startTime < r.firstHiddenTime && (n.value = Math.max(u.startTime - ae(), 0), n.entries = [u], t());
|
|
5161
5333
|
}));
|
|
5162
|
-
}, o =
|
|
5334
|
+
}, o = F("largest-contentful-paint", i);
|
|
5163
5335
|
if (o) {
|
|
5164
|
-
t =
|
|
5165
|
-
var
|
|
5166
|
-
|
|
5336
|
+
t = y(s, n, Me, e.reportAllChanges);
|
|
5337
|
+
var l = le((function() {
|
|
5338
|
+
ge[n.id] || (i(o.takeRecords()), o.disconnect(), ge[n.id] = !0, t(!0));
|
|
5167
5339
|
}));
|
|
5168
5340
|
["keydown", "click"].forEach((function(c) {
|
|
5169
5341
|
addEventListener(c, (function() {
|
|
5170
|
-
return
|
|
5342
|
+
return pt(l);
|
|
5171
5343
|
}), { once: !0, capture: !0 });
|
|
5172
|
-
})),
|
|
5173
|
-
n = _("LCP"), t =
|
|
5174
|
-
n.value = performance.now() - c.timeStamp,
|
|
5344
|
+
})), z(l), k((function(c) {
|
|
5345
|
+
n = _("LCP"), t = y(s, n, Me, e.reportAllChanges), Oe((function() {
|
|
5346
|
+
n.value = performance.now() - c.timeStamp, ge[n.id] = !0, t(!0);
|
|
5175
5347
|
}));
|
|
5176
5348
|
}));
|
|
5177
5349
|
}
|
|
5178
5350
|
}));
|
|
5179
|
-
},
|
|
5180
|
-
document.prerendering ?
|
|
5351
|
+
}, Ce = [800, 1800], Zr = function s(e) {
|
|
5352
|
+
document.prerendering ? K((function() {
|
|
5181
5353
|
return s(e);
|
|
5182
5354
|
})) : document.readyState !== "complete" ? addEventListener("load", (function() {
|
|
5183
5355
|
return s(e);
|
|
5184
5356
|
}), !0) : setTimeout(e, 0);
|
|
5185
|
-
},
|
|
5357
|
+
}, es = function(s, e) {
|
|
5186
5358
|
e = e || {};
|
|
5187
|
-
var t = _("TTFB"), r =
|
|
5188
|
-
|
|
5189
|
-
var n =
|
|
5190
|
-
n && (t.value = Math.max(n.responseStart -
|
|
5191
|
-
t = _("TTFB", 0), (r =
|
|
5359
|
+
var t = _("TTFB"), r = y(s, t, Ce, e.reportAllChanges);
|
|
5360
|
+
Zr((function() {
|
|
5361
|
+
var n = Ne();
|
|
5362
|
+
n && (t.value = Math.max(n.responseStart - ae(), 0), t.entries = [n], r(!0), k((function() {
|
|
5363
|
+
t = _("TTFB", 0), (r = y(s, t, Ce, e.reportAllChanges))(!0);
|
|
5192
5364
|
})));
|
|
5193
5365
|
}));
|
|
5194
|
-
},
|
|
5195
|
-
C || (C = e,
|
|
5196
|
-
},
|
|
5197
|
-
if (
|
|
5198
|
-
var s = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp +
|
|
5199
|
-
|
|
5366
|
+
}, G = { passive: !0, capture: !0 }, ts = /* @__PURE__ */ new Date(), Ze = function(s, e) {
|
|
5367
|
+
C || (C = e, j = s, ht = /* @__PURE__ */ new Date(), It(removeEventListener), Tt());
|
|
5368
|
+
}, Tt = function() {
|
|
5369
|
+
if (j >= 0 && j < ht - ts) {
|
|
5370
|
+
var s = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp + j };
|
|
5371
|
+
ie.forEach((function(e) {
|
|
5200
5372
|
e(s);
|
|
5201
|
-
})),
|
|
5373
|
+
})), ie = [];
|
|
5202
5374
|
}
|
|
5203
|
-
},
|
|
5375
|
+
}, rs = function(s) {
|
|
5204
5376
|
if (s.cancelable) {
|
|
5205
5377
|
var e = (s.timeStamp > 1e12 ? /* @__PURE__ */ new Date() : performance.now()) - s.timeStamp;
|
|
5206
5378
|
s.type == "pointerdown" ? (function(t, r) {
|
|
5207
5379
|
var n = function() {
|
|
5208
|
-
|
|
5380
|
+
Ze(t, r), o();
|
|
5209
5381
|
}, i = function() {
|
|
5210
5382
|
o();
|
|
5211
5383
|
}, o = function() {
|
|
5212
|
-
removeEventListener("pointerup", n,
|
|
5384
|
+
removeEventListener("pointerup", n, G), removeEventListener("pointercancel", i, G);
|
|
5213
5385
|
};
|
|
5214
|
-
addEventListener("pointerup", n,
|
|
5215
|
-
})(e, s) :
|
|
5386
|
+
addEventListener("pointerup", n, G), addEventListener("pointercancel", i, G);
|
|
5387
|
+
})(e, s) : Ze(e, s);
|
|
5216
5388
|
}
|
|
5217
|
-
},
|
|
5389
|
+
}, It = function(s) {
|
|
5218
5390
|
["mousedown", "keydown", "touchstart", "pointerdown"].forEach((function(e) {
|
|
5219
|
-
return s(e,
|
|
5391
|
+
return s(e, rs, G);
|
|
5220
5392
|
}));
|
|
5221
|
-
},
|
|
5222
|
-
e = e || {},
|
|
5223
|
-
var t, r =
|
|
5393
|
+
}, Re = [100, 300], ss = function(s, e) {
|
|
5394
|
+
e = e || {}, K((function() {
|
|
5395
|
+
var t, r = Pe(), n = _("FID"), i = function(c) {
|
|
5224
5396
|
c.startTime < r.firstHiddenTime && (n.value = c.processingStart - c.startTime, n.entries.push(c), t(!0));
|
|
5225
5397
|
}, o = function(c) {
|
|
5226
5398
|
c.forEach(i);
|
|
5227
|
-
},
|
|
5228
|
-
t =
|
|
5229
|
-
o(
|
|
5399
|
+
}, l = F("first-input", o);
|
|
5400
|
+
t = y(s, n, Re, e.reportAllChanges), l && (z(le((function() {
|
|
5401
|
+
o(l.takeRecords()), l.disconnect();
|
|
5230
5402
|
}))), k((function() {
|
|
5231
5403
|
var c;
|
|
5232
|
-
n = _("FID"), t =
|
|
5404
|
+
n = _("FID"), t = y(s, n, Re, e.reportAllChanges), ie = [], j = -1, C = null, It(addEventListener), c = i, ie.push(c), Tt();
|
|
5233
5405
|
})));
|
|
5234
5406
|
}));
|
|
5235
5407
|
};
|
|
5236
|
-
const
|
|
5408
|
+
const ns = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5237
5409
|
__proto__: null,
|
|
5238
|
-
CLSThresholds:
|
|
5239
|
-
FCPThresholds:
|
|
5240
|
-
FIDThresholds:
|
|
5241
|
-
INPThresholds:
|
|
5242
|
-
LCPThresholds:
|
|
5243
|
-
TTFBThresholds:
|
|
5244
|
-
onCLS:
|
|
5245
|
-
onFCP:
|
|
5246
|
-
onFID:
|
|
5247
|
-
onINP:
|
|
5248
|
-
onLCP:
|
|
5249
|
-
onTTFB:
|
|
5410
|
+
CLSThresholds: Ae,
|
|
5411
|
+
FCPThresholds: be,
|
|
5412
|
+
FIDThresholds: Re,
|
|
5413
|
+
INPThresholds: Le,
|
|
5414
|
+
LCPThresholds: Me,
|
|
5415
|
+
TTFBThresholds: Ce,
|
|
5416
|
+
onCLS: Xr,
|
|
5417
|
+
onFCP: mt,
|
|
5418
|
+
onFID: ss,
|
|
5419
|
+
onINP: qr,
|
|
5420
|
+
onLCP: Jr,
|
|
5421
|
+
onTTFB: es
|
|
5250
5422
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
5251
5423
|
export {
|
|
5252
5424
|
f as AppConfigValidationError,
|
|
5253
|
-
|
|
5254
|
-
|
|
5425
|
+
is as DEFAULT_SESSION_TIMEOUT,
|
|
5426
|
+
Ie as DEFAULT_WEB_VITALS_MODE,
|
|
5255
5427
|
L as DeviceType,
|
|
5256
|
-
|
|
5257
|
-
|
|
5428
|
+
Se as EmitterEvent,
|
|
5429
|
+
W as ErrorType,
|
|
5258
5430
|
d as EventType,
|
|
5259
|
-
|
|
5431
|
+
Es as InitializationTimeoutError,
|
|
5260
5432
|
U as IntegrationValidationError,
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5433
|
+
fs as MAX_ARRAY_LENGTH,
|
|
5434
|
+
cs as MAX_CUSTOM_EVENT_ARRAY_SIZE,
|
|
5435
|
+
ls as MAX_CUSTOM_EVENT_KEYS,
|
|
5436
|
+
os as MAX_CUSTOM_EVENT_NAME_LENGTH,
|
|
5437
|
+
as as MAX_CUSTOM_EVENT_STRING_SIZE,
|
|
5438
|
+
us as MAX_NESTED_OBJECT_KEYS,
|
|
5439
|
+
ds as MAX_STRING_LENGTH,
|
|
5440
|
+
hs as MAX_STRING_LENGTH_IN_ARRAY,
|
|
5441
|
+
se as Mode,
|
|
5442
|
+
nt as PII_PATTERNS,
|
|
5271
5443
|
N as PermanentError,
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5444
|
+
$e as SamplingRateValidationError,
|
|
5445
|
+
ee as ScrollDirection,
|
|
5446
|
+
Mt as SessionTimeoutValidationError,
|
|
5447
|
+
B as SpecialApiUrl,
|
|
5276
5448
|
O as TimeoutError,
|
|
5277
5449
|
Q as TraceLogValidationError,
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5450
|
+
Ss as WEB_VITALS_GOOD_THRESHOLDS,
|
|
5451
|
+
Xe as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
|
|
5452
|
+
Gt as WEB_VITALS_POOR_THRESHOLDS,
|
|
5453
|
+
je as getWebVitalsThresholds,
|
|
5454
|
+
ms as isPrimaryScrollEvent,
|
|
5455
|
+
gs as isSecondaryScrollEvent,
|
|
5456
|
+
ps as tracelog
|
|
5285
5457
|
};
|