@tracelog/lib 2.6.1 → 2.6.2-rc.94.7
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 +809 -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 os = 9e5;
|
|
2
|
+
const as = 120, ls = 8192, cs = 10, us = 10, ds = 20;
|
|
3
|
+
const hs = 1e3, fs = 500, ms = 100;
|
|
4
|
+
const b = "data-tlog", _t = [
|
|
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
|
+
], yt = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"], wt = [
|
|
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
|
+
}, bt = [
|
|
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", At = (s) => s ? `${I}:${s}:queue` : `${I}:queue`, Lt = (s) => s ? `${I}:${s}:session` : `${I}:session`, Mt = (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 gs = (s) => s.type === d.SCROLL && "scroll_data" in s && s.scroll_data.is_primary === !0, Es = (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 Ct 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 Ss 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;", Rt = "background: #d32f2f; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", Nt = (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
|
+
}, Ot = () => {
|
|
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 ? Nt(e, r) : `[TraceLog] ${e}`, u = s === "error" ? "error" : s === "warn" ? "warn" : "log";
|
|
155
|
+
if (!Pt(l, i))
|
|
156
156
|
return;
|
|
157
|
-
const E =
|
|
158
|
-
|
|
159
|
-
},
|
|
157
|
+
const E = Dt(l, o), T = n !== void 0 ? pe(n) : void 0;
|
|
158
|
+
Vt(u, c, E, T);
|
|
159
|
+
}, Pt = (s, e) => s === "critical" ? !0 : s === "qa" || e ? Ot() : !1, Dt = (s, e) => e !== void 0 && e !== "" ? e : s === "critical" ? Rt : "", Vt = (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 kt = () => {
|
|
178
|
+
typeof window < "u" && !Te && (Te = window.matchMedia("(pointer: coarse)"), st = window.matchMedia("(hover: none)"));
|
|
179
|
+
}, ne = "Unknown", Ut = (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
|
+
}, Ht = (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
|
+
}, xt = () => {
|
|
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
|
+
kt();
|
|
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
|
+
}, Ft = () => {
|
|
216
216
|
try {
|
|
217
217
|
const s = navigator;
|
|
218
218
|
return {
|
|
219
|
-
type:
|
|
220
|
-
os:
|
|
221
|
-
browser:
|
|
219
|
+
type: xt(),
|
|
220
|
+
os: Ut(s),
|
|
221
|
+
browser: Ht(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, $t = te * 2, it = 1, Bt = 1e3, Wt = 10, Ge = 5e3, Gt = 6e4, ps = {
|
|
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
|
+
}, Xt = {
|
|
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 Xt;
|
|
290
290
|
default:
|
|
291
|
-
return
|
|
291
|
+
return Xe;
|
|
292
292
|
}
|
|
293
|
-
},
|
|
293
|
+
}, jt = 1e3, Qt = 50, zt = "2.6.2", Kt = zt, ot = () => typeof window < "u" && typeof sessionStorage < "u", Yt = () => {
|
|
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
|
+
}, qt = () => {
|
|
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) && Yt(), r ?? t === "true";
|
|
314
314
|
} catch {
|
|
315
315
|
return !1;
|
|
316
316
|
}
|
|
317
|
-
},
|
|
318
|
-
if (
|
|
317
|
+
}, Jt = (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
|
+
}, Zt = [
|
|
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 Zt.includes(t) ? e.slice(-3).join(".") : e.slice(-2).join(".");
|
|
345
|
+
}, er = (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 er(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 yt.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 tr = () => {
|
|
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
|
+
}, rr = (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
|
+
}, sr = (s) => {
|
|
414
414
|
const e = {};
|
|
415
|
-
s.integrations?.tracelog?.projectId && (e.saas =
|
|
415
|
+
s.integrations?.tracelog?.projectId && (e.saas = rr(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([...wt, ...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 bt) {
|
|
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
|
+
}, nr = (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
|
+
}, ir = (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 Ct(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 && ar(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 && or(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
|
+
}, or = (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
|
+
}, ar = (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
|
+
}, lr = (s) => {
|
|
611
|
+
ir(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,18 @@ 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
|
+
}, cr = (s) => typeof s != "object" || s === null ? !1 : ye(s), ct = (s) => {
|
|
640
|
+
if (typeof s != "object" || s === null || Array.isArray(s)) return;
|
|
641
|
+
const e = {};
|
|
642
|
+
for (const [t, r] of Object.entries(s))
|
|
643
|
+
typeof r == "string" && (e[t] = r);
|
|
644
|
+
return Object.keys(e).length > 0 ? e : void 0;
|
|
645
|
+
}, ur = (s) => typeof s != "string" ? {
|
|
640
646
|
valid: !1,
|
|
641
647
|
error: "Event name must be a string"
|
|
642
648
|
} : s.length === 0 ? {
|
|
@@ -651,9 +657,9 @@ const Jt = () => {
|
|
|
651
657
|
} : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(s.toLowerCase()) ? {
|
|
652
658
|
valid: !1,
|
|
653
659
|
error: "Event name cannot be a reserved word"
|
|
654
|
-
} : { valid: !0 },
|
|
655
|
-
const r =
|
|
656
|
-
if (!
|
|
660
|
+
} : { valid: !0 }, Ke = (s, e, t) => {
|
|
661
|
+
const r = nr(e), n = t && t === "customEvent" ? `${t} "${s}" metadata error` : `${s} metadata error`;
|
|
662
|
+
if (!cr(r))
|
|
657
663
|
return {
|
|
658
664
|
valid: !1,
|
|
659
665
|
error: `${n}: object has invalid types. Valid types are string, number, boolean or string arrays.`
|
|
@@ -677,31 +683,31 @@ const Jt = () => {
|
|
|
677
683
|
valid: !1,
|
|
678
684
|
error: `${n}: object has too many keys (max 10 keys).`
|
|
679
685
|
};
|
|
680
|
-
for (const [
|
|
686
|
+
for (const [l, c] of Object.entries(r)) {
|
|
681
687
|
if (Array.isArray(c)) {
|
|
682
688
|
if (c.length > 10)
|
|
683
689
|
return {
|
|
684
690
|
valid: !1,
|
|
685
|
-
error: `${n}: array property "${
|
|
691
|
+
error: `${n}: array property "${l}" is too large (max 10 items).`
|
|
686
692
|
};
|
|
687
693
|
for (const u of c)
|
|
688
694
|
if (typeof u == "string" && u.length > 500)
|
|
689
695
|
return {
|
|
690
696
|
valid: !1,
|
|
691
|
-
error: `${n}: array property "${
|
|
697
|
+
error: `${n}: array property "${l}" contains strings that are too long (max 500 characters).`
|
|
692
698
|
};
|
|
693
699
|
}
|
|
694
700
|
if (typeof c == "string" && c.length > 1e3)
|
|
695
701
|
return {
|
|
696
702
|
valid: !1,
|
|
697
|
-
error: `${n}: property "${
|
|
703
|
+
error: `${n}: property "${l}" is too long (max 1000 characters).`
|
|
698
704
|
};
|
|
699
705
|
}
|
|
700
706
|
return {
|
|
701
707
|
valid: !0,
|
|
702
708
|
sanitizedMetadata: r
|
|
703
709
|
};
|
|
704
|
-
},
|
|
710
|
+
}, ut = (s, e, t) => {
|
|
705
711
|
if (Array.isArray(e)) {
|
|
706
712
|
const r = [], n = t && t === "customEvent" ? `${t} "${s}" metadata error` : `${s} metadata error`;
|
|
707
713
|
for (let i = 0; i < e.length; i++) {
|
|
@@ -711,37 +717,37 @@ const Jt = () => {
|
|
|
711
717
|
valid: !1,
|
|
712
718
|
error: `${n}: array item at index ${i} must be an object.`
|
|
713
719
|
};
|
|
714
|
-
const
|
|
715
|
-
if (!
|
|
720
|
+
const l = Ke(s, o, t);
|
|
721
|
+
if (!l.valid)
|
|
716
722
|
return {
|
|
717
723
|
valid: !1,
|
|
718
|
-
error: `${n}: array item at index ${i} is invalid: ${
|
|
724
|
+
error: `${n}: array item at index ${i} is invalid: ${l.error}`
|
|
719
725
|
};
|
|
720
|
-
|
|
726
|
+
l.sanitizedMetadata && r.push(l.sanitizedMetadata);
|
|
721
727
|
}
|
|
722
728
|
return {
|
|
723
729
|
valid: !0,
|
|
724
730
|
sanitizedMetadata: r
|
|
725
731
|
};
|
|
726
732
|
}
|
|
727
|
-
return
|
|
728
|
-
},
|
|
729
|
-
const t =
|
|
733
|
+
return Ke(s, e, t);
|
|
734
|
+
}, dr = (s, e) => {
|
|
735
|
+
const t = ur(s);
|
|
730
736
|
if (!t.valid)
|
|
731
|
-
return
|
|
737
|
+
return a("error", "Event name validation failed", {
|
|
732
738
|
data: { eventName: s, error: t.error }
|
|
733
739
|
}), t;
|
|
734
740
|
if (!e)
|
|
735
741
|
return { valid: !0 };
|
|
736
|
-
const r =
|
|
737
|
-
return r.valid ||
|
|
742
|
+
const r = ut(s, e, "customEvent");
|
|
743
|
+
return r.valid || a("error", "Event metadata validation failed", {
|
|
738
744
|
data: {
|
|
739
745
|
eventName: s,
|
|
740
746
|
error: r.error
|
|
741
747
|
}
|
|
742
748
|
}), r;
|
|
743
749
|
};
|
|
744
|
-
class
|
|
750
|
+
class hr {
|
|
745
751
|
listeners = /* @__PURE__ */ new Map();
|
|
746
752
|
/**
|
|
747
753
|
* Subscribes to an event channel
|
|
@@ -858,37 +864,37 @@ class cr {
|
|
|
858
864
|
this.listeners.clear();
|
|
859
865
|
}
|
|
860
866
|
}
|
|
861
|
-
function
|
|
867
|
+
function dt(s, e, t) {
|
|
862
868
|
try {
|
|
863
869
|
const r = e(s);
|
|
864
|
-
return r === null ? null : typeof r == "object" && r !== null && "type" in r ? r : (
|
|
870
|
+
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
871
|
} catch (r) {
|
|
866
|
-
return
|
|
872
|
+
return a("error", `beforeSend transformer threw error, using original event [${t}]`, {
|
|
867
873
|
error: r,
|
|
868
874
|
visibility: "critical"
|
|
869
875
|
}), s;
|
|
870
876
|
}
|
|
871
877
|
}
|
|
872
|
-
function
|
|
873
|
-
return s.map((r) =>
|
|
878
|
+
function fr(s, e, t) {
|
|
879
|
+
return s.map((r) => dt(r, e, t)).filter((r) => r !== null);
|
|
874
880
|
}
|
|
875
|
-
function
|
|
881
|
+
function ht(s, e, t) {
|
|
876
882
|
try {
|
|
877
883
|
const r = e(s);
|
|
878
|
-
return r === null ? (
|
|
884
|
+
return r === null ? (a("debug", `Batch filtered by beforeBatch transformer [${t}]`, {
|
|
879
885
|
data: { eventCount: s.events.length }
|
|
880
|
-
}), null) : typeof r == "object" && r !== null && Array.isArray(r.events) ? r : (
|
|
886
|
+
}), null) : typeof r == "object" && r !== null && Array.isArray(r.events) ? r : (a("warn", `beforeBatch transformer returned invalid data, using original [${t}]`, {
|
|
881
887
|
data: { eventCount: s.events.length }
|
|
882
888
|
}), s);
|
|
883
889
|
} catch (r) {
|
|
884
|
-
return
|
|
890
|
+
return a("error", `beforeBatch transformer threw error, using original batch [${t}]`, {
|
|
885
891
|
error: r,
|
|
886
892
|
data: { eventCount: s.events.length },
|
|
887
893
|
visibility: "critical"
|
|
888
894
|
}), s;
|
|
889
895
|
}
|
|
890
896
|
}
|
|
891
|
-
const
|
|
897
|
+
const fe = {};
|
|
892
898
|
class w {
|
|
893
899
|
/**
|
|
894
900
|
* Retrieves a value from global state.
|
|
@@ -907,7 +913,7 @@ class w {
|
|
|
907
913
|
* ```
|
|
908
914
|
*/
|
|
909
915
|
get(e) {
|
|
910
|
-
return
|
|
916
|
+
return fe[e];
|
|
911
917
|
}
|
|
912
918
|
/**
|
|
913
919
|
* Sets a value in global state.
|
|
@@ -927,7 +933,7 @@ class w {
|
|
|
927
933
|
* ```
|
|
928
934
|
*/
|
|
929
935
|
set(e, t) {
|
|
930
|
-
|
|
936
|
+
fe[e] = t;
|
|
931
937
|
}
|
|
932
938
|
/**
|
|
933
939
|
* Returns an immutable snapshot of the entire global state.
|
|
@@ -944,10 +950,10 @@ class w {
|
|
|
944
950
|
* ```
|
|
945
951
|
*/
|
|
946
952
|
getState() {
|
|
947
|
-
return { ...
|
|
953
|
+
return { ...fe };
|
|
948
954
|
}
|
|
949
955
|
}
|
|
950
|
-
class
|
|
956
|
+
class Ye extends w {
|
|
951
957
|
storeManager;
|
|
952
958
|
integrationId;
|
|
953
959
|
apiUrl;
|
|
@@ -982,10 +988,10 @@ class ze extends w {
|
|
|
982
988
|
* @param customHeadersProvider - Optional callback for dynamic headers
|
|
983
989
|
* @throws Error if integrationId and apiUrl are not both provided or both undefined
|
|
984
990
|
*/
|
|
985
|
-
constructor(e, t, r, n = {}, i = {}, o,
|
|
991
|
+
constructor(e, t, r, n = {}, i = {}, o, l = "include") {
|
|
986
992
|
if (super(), t && !r || !t && r)
|
|
987
993
|
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 =
|
|
994
|
+
this.storeManager = e, this.integrationId = t, this.apiUrl = r, this.transformers = n, this.staticHeaders = i, this.customHeadersProvider = o, this.fetchCredentials = l;
|
|
989
995
|
}
|
|
990
996
|
/**
|
|
991
997
|
* Get the integration ID for this sender
|
|
@@ -1023,16 +1029,16 @@ class ze extends w {
|
|
|
1023
1029
|
if (this.customHeadersProvider)
|
|
1024
1030
|
try {
|
|
1025
1031
|
const t = this.customHeadersProvider();
|
|
1026
|
-
typeof t == "object" && t !== null && !Array.isArray(t) ? e = t :
|
|
1032
|
+
typeof t == "object" && t !== null && !Array.isArray(t) ? e = t : a("warn", "Custom headers provider returned invalid value, expected object", {
|
|
1027
1033
|
data: { received: typeof t }
|
|
1028
1034
|
});
|
|
1029
1035
|
} catch (t) {
|
|
1030
|
-
|
|
1036
|
+
a("warn", "Custom headers provider threw an error, using static headers only", { error: t });
|
|
1031
1037
|
}
|
|
1032
1038
|
return { ...this.staticHeaders, ...e };
|
|
1033
1039
|
}
|
|
1034
1040
|
getQueueStorageKey() {
|
|
1035
|
-
const e = this.get("userId") || "anonymous", t =
|
|
1041
|
+
const e = this.get("userId") || "anonymous", t = At(e);
|
|
1036
1042
|
return this.integrationId ? `${t}:${this.integrationId}` : t;
|
|
1037
1043
|
}
|
|
1038
1044
|
/**
|
|
@@ -1074,13 +1080,13 @@ class ze extends w {
|
|
|
1074
1080
|
* @see src/managers/README.md (lines 82-139) for send details
|
|
1075
1081
|
*/
|
|
1076
1082
|
sendEventsQueueSync(e) {
|
|
1077
|
-
return this.shouldSkipSend() ? !0 : this.apiUrl?.includes(
|
|
1083
|
+
return this.shouldSkipSend() ? !0 : this.apiUrl?.includes(B.Fail) ? (a(
|
|
1078
1084
|
"warn",
|
|
1079
1085
|
`Fail mode: simulating network failure (sync)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1080
1086
|
{
|
|
1081
1087
|
data: { events: e.events.length }
|
|
1082
1088
|
}
|
|
1083
|
-
), !1) : this.apiUrl?.includes(
|
|
1089
|
+
), !1) : this.apiUrl?.includes(B.Localhost) ? (a(
|
|
1084
1090
|
"debug",
|
|
1085
1091
|
`Success mode: simulating successful send (sync)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1086
1092
|
{
|
|
@@ -1123,7 +1129,7 @@ class ze extends w {
|
|
|
1123
1129
|
const r = await this.send(e);
|
|
1124
1130
|
return r ? (this.clearPersistedEvents(), t?.onSuccess?.(e.events.length, e.events, e)) : (this.persistEvents(e), t?.onFailure?.()), r;
|
|
1125
1131
|
} catch (r) {
|
|
1126
|
-
return r instanceof N ? (this.logPermanentError("Permanent error, not retrying", r), this.clearPersistedEvents(), t?.onFailure?.(), !1) : r instanceof O ? (
|
|
1132
|
+
return r instanceof N ? (this.logPermanentError("Permanent error, not retrying", r), this.clearPersistedEvents(), t?.onFailure?.(), !1) : r instanceof O ? (a(
|
|
1127
1133
|
"debug",
|
|
1128
1134
|
`All attempts timed out, skipping persistence (server likely received events)${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1129
1135
|
), this.clearPersistedEvents(), t?.onFailure?.(), !1) : (this.persistEvents(e), t?.onFailure?.(), !1);
|
|
@@ -1180,7 +1186,7 @@ class ze extends w {
|
|
|
1180
1186
|
*/
|
|
1181
1187
|
async recoverPersistedEvents(e) {
|
|
1182
1188
|
if (this.recoveryInProgress) {
|
|
1183
|
-
|
|
1189
|
+
a("debug", "Recovery already in progress, skipping duplicate attempt");
|
|
1184
1190
|
return;
|
|
1185
1191
|
}
|
|
1186
1192
|
this.recoveryInProgress = !0;
|
|
@@ -1192,7 +1198,7 @@ class ze extends w {
|
|
|
1192
1198
|
}
|
|
1193
1199
|
const r = t.recoveryFailures, n = typeof r == "number" && Number.isFinite(r) && r >= 0 ? r : 0;
|
|
1194
1200
|
if (n >= 3) {
|
|
1195
|
-
|
|
1201
|
+
a(
|
|
1196
1202
|
"debug",
|
|
1197
1203
|
`Discarding persisted events after ${n} failed recovery attempts${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1198
1204
|
), this.clearPersistedEvents(), e?.onFailure?.();
|
|
@@ -1206,13 +1212,13 @@ class ze extends w {
|
|
|
1206
1212
|
return;
|
|
1207
1213
|
}
|
|
1208
1214
|
if (t instanceof O) {
|
|
1209
|
-
|
|
1215
|
+
a(
|
|
1210
1216
|
"debug",
|
|
1211
1217
|
`Recovery timed out, clearing persisted events (server likely received them)${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1212
1218
|
), this.clearPersistedEvents(), e?.onFailure?.();
|
|
1213
1219
|
return;
|
|
1214
1220
|
}
|
|
1215
|
-
|
|
1221
|
+
a("error", "Failed to recover persisted events", { error: t });
|
|
1216
1222
|
} finally {
|
|
1217
1223
|
this.recoveryInProgress = !1;
|
|
1218
1224
|
}
|
|
@@ -1262,7 +1268,7 @@ class ze extends w {
|
|
|
1262
1268
|
const t = this.transformers.beforeSend;
|
|
1263
1269
|
if (!t)
|
|
1264
1270
|
return e;
|
|
1265
|
-
const r =
|
|
1271
|
+
const r = fr(
|
|
1266
1272
|
e.events,
|
|
1267
1273
|
t,
|
|
1268
1274
|
this.integrationId || "SenderManager"
|
|
@@ -1307,7 +1313,7 @@ class ze extends w {
|
|
|
1307
1313
|
if (this.integrationId === "saas")
|
|
1308
1314
|
return e;
|
|
1309
1315
|
const t = this.transformers.beforeBatch;
|
|
1310
|
-
return t ?
|
|
1316
|
+
return t ? ht(e, t, this.integrationId || "SenderManager") : e;
|
|
1311
1317
|
}
|
|
1312
1318
|
/**
|
|
1313
1319
|
* Calculates exponential backoff delay with jitter for retry attempts.
|
|
@@ -1376,18 +1382,18 @@ class ze extends w {
|
|
|
1376
1382
|
const r = this.applyBeforeBatchTransformer(t);
|
|
1377
1383
|
if (!r)
|
|
1378
1384
|
return !0;
|
|
1379
|
-
if (this.apiUrl?.includes(
|
|
1380
|
-
return
|
|
1385
|
+
if (this.apiUrl?.includes(B.Fail))
|
|
1386
|
+
return a("debug", `Fail mode: simulating network failure${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1381
1387
|
data: { events: r.events.length }
|
|
1382
1388
|
}), !1;
|
|
1383
|
-
if (this.apiUrl?.includes(
|
|
1384
|
-
return
|
|
1389
|
+
if (this.apiUrl?.includes(B.Localhost))
|
|
1390
|
+
return a("debug", `Success mode: simulating successful send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1385
1391
|
data: { events: r.events.length }
|
|
1386
1392
|
}), !0;
|
|
1387
1393
|
if (this.consecutiveNetworkFailures >= 3) {
|
|
1388
1394
|
const c = Date.now() - this.circuitOpenedAt;
|
|
1389
1395
|
if (c < 12e4)
|
|
1390
|
-
return
|
|
1396
|
+
return a("debug", `Network circuit open, skipping send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1391
1397
|
data: {
|
|
1392
1398
|
consecutiveNetworkFailures: this.consecutiveNetworkFailures,
|
|
1393
1399
|
cooldownRemainingMs: 12e4 - c
|
|
@@ -1395,10 +1401,10 @@ class ze extends w {
|
|
|
1395
1401
|
}), !1;
|
|
1396
1402
|
}
|
|
1397
1403
|
const { url: n, payload: i } = this.prepareRequest(r);
|
|
1398
|
-
let o = !0,
|
|
1404
|
+
let o = !0, l = !1;
|
|
1399
1405
|
for (let c = 1; c <= 3; c++)
|
|
1400
1406
|
try {
|
|
1401
|
-
return (await this.sendWithTimeout(n, i)).ok ? (c > 1 &&
|
|
1407
|
+
return (await this.sendWithTimeout(n, i)).ok ? (c > 1 && a(
|
|
1402
1408
|
"info",
|
|
1403
1409
|
`Send succeeded after ${c - 1} retry attempt(s)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1404
1410
|
{
|
|
@@ -1409,7 +1415,7 @@ class ze extends w {
|
|
|
1409
1415
|
const g = c === 3;
|
|
1410
1416
|
if (u instanceof N)
|
|
1411
1417
|
throw this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, u;
|
|
1412
|
-
if (u instanceof O || (o = !1), u instanceof TypeError || (
|
|
1418
|
+
if (u instanceof O || (o = !1), u instanceof TypeError || (l = !0), a(
|
|
1413
1419
|
g ? "error" : "warn",
|
|
1414
1420
|
`Send attempt ${c} failed${this.integrationId ? ` [${this.integrationId}]` : ""}${g ? " (all retries exhausted)" : ", will retry"}`,
|
|
1415
1421
|
{
|
|
@@ -1427,7 +1433,7 @@ class ze extends w {
|
|
|
1427
1433
|
}
|
|
1428
1434
|
if (o)
|
|
1429
1435
|
throw new O("All retry attempts timed out (server likely received the request)");
|
|
1430
|
-
return
|
|
1436
|
+
return l ? (this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0) : (this.consecutiveNetworkFailures = Math.min(
|
|
1431
1437
|
this.consecutiveNetworkFailures + 1,
|
|
1432
1438
|
3
|
|
1433
1439
|
), this.consecutiveNetworkFailures >= 3 && (this.circuitOpenedAt = Date.now())), !1;
|
|
@@ -1465,7 +1471,7 @@ class ze extends w {
|
|
|
1465
1471
|
n = !0, r.abort();
|
|
1466
1472
|
}, 15e3);
|
|
1467
1473
|
try {
|
|
1468
|
-
const o = this.getCustomHeaders(),
|
|
1474
|
+
const o = this.getCustomHeaders(), l = await fetch(e, {
|
|
1469
1475
|
method: "POST",
|
|
1470
1476
|
body: t,
|
|
1471
1477
|
keepalive: !0,
|
|
@@ -1476,9 +1482,9 @@ class ze extends w {
|
|
|
1476
1482
|
"Content-Type": "application/json"
|
|
1477
1483
|
}
|
|
1478
1484
|
});
|
|
1479
|
-
if (!
|
|
1480
|
-
throw
|
|
1481
|
-
return
|
|
1485
|
+
if (!l.ok)
|
|
1486
|
+
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}`);
|
|
1487
|
+
return l;
|
|
1482
1488
|
} catch (o) {
|
|
1483
1489
|
throw o instanceof N ? o : n ? new O("Request timed out (server likely received the request)") : o;
|
|
1484
1490
|
} finally {
|
|
@@ -1514,7 +1520,7 @@ class ze extends w {
|
|
|
1514
1520
|
return !0;
|
|
1515
1521
|
const { url: n, payload: i } = this.prepareRequest(r);
|
|
1516
1522
|
if (i.length > 65536)
|
|
1517
|
-
return
|
|
1523
|
+
return a(
|
|
1518
1524
|
"warn",
|
|
1519
1525
|
`Payload exceeds sendBeacon limit, persisting for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1520
1526
|
{
|
|
@@ -1527,15 +1533,15 @@ class ze extends w {
|
|
|
1527
1533
|
), this.persistEvents(r), !1;
|
|
1528
1534
|
const o = new Blob([i], { type: "application/json" });
|
|
1529
1535
|
if (!this.isSendBeaconAvailable())
|
|
1530
|
-
return
|
|
1536
|
+
return a(
|
|
1531
1537
|
"warn",
|
|
1532
1538
|
`sendBeacon not available, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1533
1539
|
), this.persistEvents(r), !1;
|
|
1534
|
-
const
|
|
1535
|
-
return
|
|
1540
|
+
const l = navigator.sendBeacon(n, o);
|
|
1541
|
+
return l || (a(
|
|
1536
1542
|
"warn",
|
|
1537
1543
|
`sendBeacon rejected request, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1538
|
-
), this.persistEvents(r)),
|
|
1544
|
+
), this.persistEvents(r)), l;
|
|
1539
1545
|
}
|
|
1540
1546
|
/**
|
|
1541
1547
|
* Prepares request by enriching payload with metadata and serializing to JSON.
|
|
@@ -1563,7 +1569,7 @@ class ze extends w {
|
|
|
1563
1569
|
_metadata: {
|
|
1564
1570
|
referer: typeof window < "u" ? window.location.href : void 0,
|
|
1565
1571
|
timestamp: t,
|
|
1566
|
-
client_version:
|
|
1572
|
+
client_version: Kt
|
|
1567
1573
|
}
|
|
1568
1574
|
};
|
|
1569
1575
|
return {
|
|
@@ -1589,7 +1595,7 @@ class ze extends w {
|
|
|
1589
1595
|
if (t)
|
|
1590
1596
|
return JSON.parse(t);
|
|
1591
1597
|
} catch (e) {
|
|
1592
|
-
|
|
1598
|
+
a("debug", `Failed to parse persisted data${this.integrationId ? ` [${this.integrationId}]` : ""}`, { error: e }), this.clearPersistedEvents();
|
|
1593
1599
|
}
|
|
1594
1600
|
return null;
|
|
1595
1601
|
}
|
|
@@ -1660,13 +1666,13 @@ class ze extends w {
|
|
|
1660
1666
|
try {
|
|
1661
1667
|
const n = this.getPersistedData();
|
|
1662
1668
|
if (!r && n && n.timestamp) {
|
|
1663
|
-
const
|
|
1664
|
-
if (
|
|
1665
|
-
return
|
|
1669
|
+
const l = Date.now() - n.timestamp;
|
|
1670
|
+
if (l < 1e3)
|
|
1671
|
+
return a(
|
|
1666
1672
|
"debug",
|
|
1667
1673
|
`Skipping persistence, another tab recently persisted events${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1668
1674
|
{
|
|
1669
|
-
data: { timeSinceExisting:
|
|
1675
|
+
data: { timeSinceExisting: l }
|
|
1670
1676
|
}
|
|
1671
1677
|
), !0;
|
|
1672
1678
|
}
|
|
@@ -1677,7 +1683,7 @@ class ze extends w {
|
|
|
1677
1683
|
}, o = this.getQueueStorageKey();
|
|
1678
1684
|
return this.storeManager.setItem(o, JSON.stringify(i)), !!this.storeManager.getItem(o);
|
|
1679
1685
|
} catch (n) {
|
|
1680
|
-
return
|
|
1686
|
+
return a("debug", `Failed to persist events${this.integrationId ? ` [${this.integrationId}]` : ""}`, { error: n }), !1;
|
|
1681
1687
|
}
|
|
1682
1688
|
}
|
|
1683
1689
|
clearPersistedEvents() {
|
|
@@ -1685,7 +1691,7 @@ class ze extends w {
|
|
|
1685
1691
|
const e = this.getQueueStorageKey();
|
|
1686
1692
|
this.storeManager.removeItem(e);
|
|
1687
1693
|
} catch (e) {
|
|
1688
|
-
|
|
1694
|
+
a("debug", `Failed to clear persisted events${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1689
1695
|
error: e
|
|
1690
1696
|
});
|
|
1691
1697
|
}
|
|
@@ -1702,12 +1708,12 @@ class ze extends w {
|
|
|
1702
1708
|
}
|
|
1703
1709
|
logPermanentError(e, t) {
|
|
1704
1710
|
const r = Date.now();
|
|
1705
|
-
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || r - this.lastPermanentErrorLog.timestamp >=
|
|
1711
|
+
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || r - this.lastPermanentErrorLog.timestamp >= Gt) && (a("error", `${e}${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1706
1712
|
data: { status: t.statusCode, message: t.message }
|
|
1707
1713
|
}), this.lastPermanentErrorLog = { statusCode: t.statusCode, timestamp: r });
|
|
1708
1714
|
}
|
|
1709
1715
|
}
|
|
1710
|
-
class
|
|
1716
|
+
class mr extends w {
|
|
1711
1717
|
bootTime;
|
|
1712
1718
|
bootTimestamp;
|
|
1713
1719
|
hasPerformanceNow;
|
|
@@ -1732,12 +1738,12 @@ class dr extends w {
|
|
|
1732
1738
|
this.hasPerformanceNow = !1, this.bootTime = 0, this.bootTimestamp = 0;
|
|
1733
1739
|
return;
|
|
1734
1740
|
}
|
|
1735
|
-
this.hasPerformanceNow = typeof performance < "u" && typeof performance.now == "function", this.hasPerformanceNow ? (this.bootTime = performance.now(), this.bootTimestamp = Date.now(),
|
|
1741
|
+
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
1742
|
data: {
|
|
1737
1743
|
bootTime: this.bootTime.toFixed(3),
|
|
1738
1744
|
bootTimestamp: this.bootTimestamp
|
|
1739
1745
|
}
|
|
1740
|
-
})) : (this.bootTime = 0, this.bootTimestamp = Date.now(),
|
|
1746
|
+
})) : (this.bootTime = 0, this.bootTimestamp = Date.now(), a("debug", "performance.now() not available, falling back to Date.now()"));
|
|
1741
1747
|
}
|
|
1742
1748
|
/**
|
|
1743
1749
|
* Returns current timestamp in milliseconds since epoch.
|
|
@@ -1800,7 +1806,7 @@ class dr extends w {
|
|
|
1800
1806
|
return this.detectedSkew;
|
|
1801
1807
|
this.lastClockSkewCheck = e;
|
|
1802
1808
|
const t = this.now(), r = Date.now();
|
|
1803
|
-
return this.detectedSkew = r - t, Math.abs(this.detectedSkew) > 3e4 &&
|
|
1809
|
+
return this.detectedSkew = r - t, Math.abs(this.detectedSkew) > 3e4 && a("warn", "Significant clock skew detected", {
|
|
1804
1810
|
data: {
|
|
1805
1811
|
skewMs: this.detectedSkew,
|
|
1806
1812
|
skewMinutes: (this.detectedSkew / 1e3 / 60).toFixed(2),
|
|
@@ -1856,8 +1862,8 @@ class dr extends w {
|
|
|
1856
1862
|
};
|
|
1857
1863
|
}
|
|
1858
1864
|
}
|
|
1859
|
-
const
|
|
1860
|
-
class
|
|
1865
|
+
const gr = new Set(Object.values(d));
|
|
1866
|
+
class Er extends w {
|
|
1861
1867
|
dataSenders;
|
|
1862
1868
|
emitter;
|
|
1863
1869
|
transformers;
|
|
@@ -1896,13 +1902,13 @@ class fr extends w {
|
|
|
1896
1902
|
* @param fetchCredentials - Fetch credentials mode for custom backend. @default 'include'
|
|
1897
1903
|
*/
|
|
1898
1904
|
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
|
|
1905
|
+
super(), this.emitter = t, this.transformers = r, this.timeManager = new mr(), this.dataSenders = [];
|
|
1906
|
+
const l = this.get("collectApiUrls");
|
|
1907
|
+
l?.saas && this.dataSenders.push(new Ye(e, "saas", l.saas, r)), l?.custom && this.dataSenders.push(
|
|
1908
|
+
new Ye(
|
|
1903
1909
|
e,
|
|
1904
1910
|
"custom",
|
|
1905
|
-
|
|
1911
|
+
l.custom,
|
|
1906
1912
|
r,
|
|
1907
1913
|
n,
|
|
1908
1914
|
i,
|
|
@@ -1941,12 +1947,12 @@ class fr extends w {
|
|
|
1941
1947
|
async (t) => t.recoverPersistedEvents({
|
|
1942
1948
|
onSuccess: (r, n, i) => {
|
|
1943
1949
|
if (n && n.length > 0) {
|
|
1944
|
-
const o = n.map((
|
|
1950
|
+
const o = n.map((l) => l.id);
|
|
1945
1951
|
this.removeProcessedEvents(o), i && this.emitEventsQueue(i);
|
|
1946
1952
|
}
|
|
1947
1953
|
},
|
|
1948
1954
|
onFailure: () => {
|
|
1949
|
-
|
|
1955
|
+
a("debug", "Failed to recover persisted events");
|
|
1950
1956
|
}
|
|
1951
1957
|
})
|
|
1952
1958
|
);
|
|
@@ -2018,24 +2024,24 @@ class fr extends w {
|
|
|
2018
2024
|
scroll_data: n,
|
|
2019
2025
|
click_data: i,
|
|
2020
2026
|
custom_event: o,
|
|
2021
|
-
web_vitals:
|
|
2027
|
+
web_vitals: l,
|
|
2022
2028
|
error_data: c,
|
|
2023
2029
|
viewport_data: u,
|
|
2024
2030
|
page_view: g
|
|
2025
2031
|
}) {
|
|
2026
2032
|
if (!e) {
|
|
2027
|
-
|
|
2033
|
+
a("error", "Event type is required - event will be ignored");
|
|
2028
2034
|
return;
|
|
2029
2035
|
}
|
|
2030
|
-
if (!
|
|
2031
|
-
|
|
2036
|
+
if (!gr.has(e)) {
|
|
2037
|
+
a("error", "Invalid event type - event will be ignored", {
|
|
2032
2038
|
data: { type: e }
|
|
2033
2039
|
});
|
|
2034
2040
|
return;
|
|
2035
2041
|
}
|
|
2036
2042
|
const E = this.get("sessionId");
|
|
2037
2043
|
if (!E) {
|
|
2038
|
-
this.pendingEventsBuffer.length >= 100 && (this.pendingEventsBuffer.shift(),
|
|
2044
|
+
this.pendingEventsBuffer.length >= 100 && (this.pendingEventsBuffer.shift(), a("debug", "Pending events buffer full - dropping oldest event", {
|
|
2039
2045
|
data: { maxBufferSize: 100 }
|
|
2040
2046
|
})), this.pendingEventsBuffer.push({
|
|
2041
2047
|
type: e,
|
|
@@ -2044,7 +2050,7 @@ class fr extends w {
|
|
|
2044
2050
|
scroll_data: n,
|
|
2045
2051
|
click_data: i,
|
|
2046
2052
|
custom_event: o,
|
|
2047
|
-
web_vitals:
|
|
2053
|
+
web_vitals: l,
|
|
2048
2054
|
error_data: c,
|
|
2049
2055
|
viewport_data: u,
|
|
2050
2056
|
page_view: g
|
|
@@ -2052,15 +2058,15 @@ class fr extends w {
|
|
|
2052
2058
|
return;
|
|
2053
2059
|
}
|
|
2054
2060
|
this.lastSessionId !== E && (this.lastSessionId = E, this.sessionEventCounts = this.loadSessionCounts(E));
|
|
2055
|
-
const
|
|
2056
|
-
if (
|
|
2061
|
+
const T = e === d.SESSION_START;
|
|
2062
|
+
if (T && a("debug", "Processing SESSION_START event", {
|
|
2057
2063
|
data: { sessionId: E }
|
|
2058
|
-
}), !
|
|
2064
|
+
}), !T && !this.checkRateLimit())
|
|
2059
2065
|
return;
|
|
2060
2066
|
const S = e;
|
|
2061
|
-
if (!
|
|
2067
|
+
if (!T) {
|
|
2062
2068
|
if (this.sessionEventCounts.total >= 1e3) {
|
|
2063
|
-
|
|
2069
|
+
a("warn", "Session event limit reached", {
|
|
2064
2070
|
data: {
|
|
2065
2071
|
type: S,
|
|
2066
2072
|
total: this.sessionEventCounts.total,
|
|
@@ -2069,15 +2075,15 @@ class fr extends w {
|
|
|
2069
2075
|
});
|
|
2070
2076
|
return;
|
|
2071
2077
|
}
|
|
2072
|
-
const
|
|
2073
|
-
if (
|
|
2074
|
-
const
|
|
2075
|
-
if (
|
|
2076
|
-
|
|
2078
|
+
const v = this.getTypeLimitForEvent(S);
|
|
2079
|
+
if (v) {
|
|
2080
|
+
const ce = this.sessionEventCounts[S];
|
|
2081
|
+
if (ce !== void 0 && ce >= v) {
|
|
2082
|
+
a("warn", "Session event type limit reached", {
|
|
2077
2083
|
data: {
|
|
2078
2084
|
type: S,
|
|
2079
|
-
count:
|
|
2080
|
-
limit:
|
|
2085
|
+
count: ce,
|
|
2086
|
+
limit: v
|
|
2081
2087
|
}
|
|
2082
2088
|
});
|
|
2083
2089
|
return;
|
|
@@ -2085,52 +2091,52 @@ class fr extends w {
|
|
|
2085
2091
|
}
|
|
2086
2092
|
}
|
|
2087
2093
|
if (S === d.CUSTOM && o?.name) {
|
|
2088
|
-
const
|
|
2089
|
-
if (!this.checkPerEventRateLimit(o.name,
|
|
2094
|
+
const v = this.get("config")?.maxSameEventPerMinute ?? 60;
|
|
2095
|
+
if (!this.checkPerEventRateLimit(o.name, v))
|
|
2090
2096
|
return;
|
|
2091
2097
|
}
|
|
2092
|
-
const
|
|
2098
|
+
const De = S === d.SESSION_START, Y = t || this.get("pageUrl"), $ = this.buildEventPayload({
|
|
2093
2099
|
type: S,
|
|
2094
|
-
page_url:
|
|
2100
|
+
page_url: Y,
|
|
2095
2101
|
from_page_url: r,
|
|
2096
2102
|
scroll_data: n,
|
|
2097
2103
|
click_data: i,
|
|
2098
2104
|
custom_event: o,
|
|
2099
|
-
web_vitals:
|
|
2105
|
+
web_vitals: l,
|
|
2100
2106
|
error_data: c,
|
|
2101
2107
|
viewport_data: u,
|
|
2102
2108
|
page_view: g
|
|
2103
2109
|
});
|
|
2104
|
-
if (
|
|
2105
|
-
if (
|
|
2106
|
-
const
|
|
2107
|
-
if (!
|
|
2108
|
-
|
|
2110
|
+
if ($ && !(!T && !this.shouldSample())) {
|
|
2111
|
+
if (De) {
|
|
2112
|
+
const v = this.get("sessionId");
|
|
2113
|
+
if (!v) {
|
|
2114
|
+
a("error", "Session start event requires sessionId - event will be ignored");
|
|
2109
2115
|
return;
|
|
2110
2116
|
}
|
|
2111
2117
|
if (this.get("hasStartSession")) {
|
|
2112
|
-
|
|
2113
|
-
data: { sessionId:
|
|
2118
|
+
a("debug", "Duplicate session_start detected", {
|
|
2119
|
+
data: { sessionId: v }
|
|
2114
2120
|
});
|
|
2115
2121
|
return;
|
|
2116
2122
|
}
|
|
2117
2123
|
this.set("hasStartSession", !0);
|
|
2118
2124
|
}
|
|
2119
|
-
if (!this.isDuplicateEvent(
|
|
2120
|
-
if (this.get("mode") ===
|
|
2125
|
+
if (!this.isDuplicateEvent($)) {
|
|
2126
|
+
if (this.get("mode") === se.QA) {
|
|
2121
2127
|
if (S === d.CUSTOM && o) {
|
|
2122
|
-
|
|
2128
|
+
a("info", `Custom Event: ${o.name}`, {
|
|
2123
2129
|
visibility: "qa",
|
|
2124
2130
|
data: {
|
|
2125
2131
|
name: o.name,
|
|
2126
2132
|
...o.metadata && { metadata: o.metadata }
|
|
2127
2133
|
}
|
|
2128
|
-
}), this.emitEvent(
|
|
2134
|
+
}), this.emitEvent($);
|
|
2129
2135
|
return;
|
|
2130
2136
|
}
|
|
2131
2137
|
if (S === d.VIEWPORT_VISIBLE && u) {
|
|
2132
|
-
const
|
|
2133
|
-
|
|
2138
|
+
const v = u.name || u.id || u.selector;
|
|
2139
|
+
a("info", `Viewport Visible: ${v}`, {
|
|
2134
2140
|
visibility: "qa",
|
|
2135
2141
|
data: {
|
|
2136
2142
|
selector: u.selector,
|
|
@@ -2139,14 +2145,14 @@ class fr extends w {
|
|
|
2139
2145
|
visibilityRatio: u.visibilityRatio,
|
|
2140
2146
|
dwellTime: u.dwellTime
|
|
2141
2147
|
}
|
|
2142
|
-
}), this.emitEvent(
|
|
2148
|
+
}), this.emitEvent($);
|
|
2143
2149
|
return;
|
|
2144
2150
|
}
|
|
2145
2151
|
}
|
|
2146
|
-
if (this.addToQueue(
|
|
2152
|
+
if (this.addToQueue($), !T) {
|
|
2147
2153
|
this.sessionEventCounts.total++, this.sessionEventCounts[S] !== void 0 && this.sessionEventCounts[S]++;
|
|
2148
|
-
const
|
|
2149
|
-
|
|
2154
|
+
const v = this.get("sessionId");
|
|
2155
|
+
v && this.saveSessionCountsDebounced && this.saveSessionCountsDebounced(v);
|
|
2150
2156
|
}
|
|
2151
2157
|
}
|
|
2152
2158
|
}
|
|
@@ -2389,7 +2395,7 @@ class fr extends w {
|
|
|
2389
2395
|
if (this.pendingEventsBuffer.length === 0)
|
|
2390
2396
|
return;
|
|
2391
2397
|
if (!this.get("sessionId")) {
|
|
2392
|
-
|
|
2398
|
+
a("debug", "Cannot flush pending events: session not initialized - keeping in buffer", {
|
|
2393
2399
|
data: { bufferedEventCount: this.pendingEventsBuffer.length }
|
|
2394
2400
|
});
|
|
2395
2401
|
return;
|
|
@@ -2409,13 +2415,13 @@ class fr extends w {
|
|
|
2409
2415
|
if (this.eventsQueue.length === 0)
|
|
2410
2416
|
return e ? !0 : Promise.resolve(!0);
|
|
2411
2417
|
if (!e && this.sendInProgress)
|
|
2412
|
-
return
|
|
2418
|
+
return a("debug", "Async flush skipped: send already in progress"), Promise.resolve(!1);
|
|
2413
2419
|
const t = this.buildEventsPayload(), r = [...this.eventsQueue], n = r.map((i) => i.id);
|
|
2414
2420
|
if (this.dataSenders.length === 0)
|
|
2415
2421
|
return this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t), e ? !0 : Promise.resolve(!0);
|
|
2416
2422
|
if (e) {
|
|
2417
|
-
const o = this.dataSenders.map((
|
|
2418
|
-
return o ? (this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t)) : (this.clearSendTimeout(),
|
|
2423
|
+
const o = this.dataSenders.map((l) => l.sendEventsQueueSync(t)).some((l) => l);
|
|
2424
|
+
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
2425
|
data: { eventCount: n.length }
|
|
2420
2426
|
})), o;
|
|
2421
2427
|
} else {
|
|
@@ -2428,10 +2434,10 @@ class fr extends w {
|
|
|
2428
2434
|
})
|
|
2429
2435
|
);
|
|
2430
2436
|
return Promise.allSettled(i).then((o) => {
|
|
2431
|
-
const
|
|
2432
|
-
return
|
|
2437
|
+
const l = o.some((c) => this.isSuccessfulResult(c));
|
|
2438
|
+
return l ? (this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t)) : a("debug", "Async flush complete failure, events kept in queue for retry", {
|
|
2433
2439
|
data: { eventCount: r.length }
|
|
2434
|
-
}),
|
|
2440
|
+
}), l;
|
|
2435
2441
|
});
|
|
2436
2442
|
}
|
|
2437
2443
|
}
|
|
@@ -2444,22 +2450,22 @@ class fr extends w {
|
|
|
2444
2450
|
this.emitEventsQueue(e);
|
|
2445
2451
|
return;
|
|
2446
2452
|
}
|
|
2447
|
-
const t = [...this.eventsQueue], r = t.map((
|
|
2448
|
-
async (
|
|
2453
|
+
const t = [...this.eventsQueue], r = t.map((l) => l.id), n = this.dataSenders.map(
|
|
2454
|
+
async (l) => l.sendEventsQueue(e, {
|
|
2449
2455
|
onSuccess: () => {
|
|
2450
2456
|
},
|
|
2451
2457
|
onFailure: () => {
|
|
2452
2458
|
}
|
|
2453
2459
|
})
|
|
2454
2460
|
), i = await Promise.allSettled(n);
|
|
2455
|
-
if (i.some((
|
|
2461
|
+
if (i.some((l) => this.isSuccessfulResult(l))) {
|
|
2456
2462
|
this.consecutiveSendFailures = 0, this.removeProcessedEvents(r), this.emitEventsQueue(e);
|
|
2457
|
-
const
|
|
2458
|
-
|
|
2459
|
-
data: { eventCount: t.length, failedCount:
|
|
2463
|
+
const l = i.filter((c) => !this.isSuccessfulResult(c)).length;
|
|
2464
|
+
l > 0 && a("debug", "Periodic send completed with some failures, removed from queue and persisted per-integration", {
|
|
2465
|
+
data: { eventCount: t.length, failedCount: l }
|
|
2460
2466
|
});
|
|
2461
2467
|
} else
|
|
2462
|
-
this.consecutiveSendFailures = Math.min(this.consecutiveSendFailures + 1, 5),
|
|
2468
|
+
this.consecutiveSendFailures = Math.min(this.consecutiveSendFailures + 1, 5), a("debug", "Periodic send complete failure, events kept in queue for retry", {
|
|
2463
2469
|
data: { eventCount: t.length }
|
|
2464
2470
|
});
|
|
2465
2471
|
this.eventsQueue.length === 0 ? this.clearSendTimeout() : this.scheduleSendTimeout();
|
|
@@ -2480,23 +2486,24 @@ class fr extends w {
|
|
|
2480
2486
|
session_id: this.get("sessionId"),
|
|
2481
2487
|
device: this.get("device"),
|
|
2482
2488
|
events: r,
|
|
2483
|
-
...this.get("config")?.globalMetadata && { global_metadata: this.get("config")?.globalMetadata }
|
|
2489
|
+
...this.get("config")?.globalMetadata && { global_metadata: this.get("config")?.globalMetadata },
|
|
2490
|
+
...this.get("identity") && { identify: this.get("identity") }
|
|
2484
2491
|
};
|
|
2485
|
-
const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas),
|
|
2486
|
-
if (!o &&
|
|
2487
|
-
const c =
|
|
2492
|
+
const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas), l = this.transformers.beforeBatch;
|
|
2493
|
+
if (!o && l) {
|
|
2494
|
+
const c = ht(n, l, "EventManager");
|
|
2488
2495
|
c !== null && (n = c);
|
|
2489
2496
|
}
|
|
2490
2497
|
return n;
|
|
2491
2498
|
}
|
|
2492
2499
|
buildEventPayload(e) {
|
|
2493
2500
|
const t = e.page_url ?? this.get("pageUrl"), r = this.timeManager.now(), n = this.timeManager.validateTimestamp(r);
|
|
2494
|
-
n.valid ||
|
|
2501
|
+
n.valid || a("warn", "Event timestamp validation failed", {
|
|
2495
2502
|
data: { type: e.type, error: n.error }
|
|
2496
2503
|
});
|
|
2497
2504
|
const i = this.get("sessionReferrer"), o = this.get("sessionUtm");
|
|
2498
|
-
let
|
|
2499
|
-
id:
|
|
2505
|
+
let l = {
|
|
2506
|
+
id: tr(),
|
|
2500
2507
|
type: e.type,
|
|
2501
2508
|
page_url: t,
|
|
2502
2509
|
timestamp: r,
|
|
@@ -2511,18 +2518,18 @@ class fr extends w {
|
|
|
2511
2518
|
...e.page_view && { page_view: e.page_view },
|
|
2512
2519
|
...o && { utm: o }
|
|
2513
2520
|
};
|
|
2514
|
-
const c = this.get("collectApiUrls"), u = !!c?.custom, g = !!c?.saas, E = u || g,
|
|
2515
|
-
if (S && (!E || u && !
|
|
2516
|
-
const
|
|
2517
|
-
if (
|
|
2521
|
+
const c = this.get("collectApiUrls"), u = !!c?.custom, g = !!c?.saas, E = u || g, T = u && g, S = this.transformers.beforeSend;
|
|
2522
|
+
if (S && (!E || u && !T)) {
|
|
2523
|
+
const Y = dt(l, S, "EventManager");
|
|
2524
|
+
if (Y === null)
|
|
2518
2525
|
return null;
|
|
2519
|
-
|
|
2526
|
+
l = Y;
|
|
2520
2527
|
}
|
|
2521
|
-
return
|
|
2528
|
+
return l;
|
|
2522
2529
|
}
|
|
2523
2530
|
isDuplicateEvent(e) {
|
|
2524
2531
|
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),
|
|
2532
|
+
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
2533
|
data: { hardLimit: 3e3 }
|
|
2527
2534
|
})), !1);
|
|
2528
2535
|
}
|
|
@@ -2530,7 +2537,7 @@ class fr extends w {
|
|
|
2530
2537
|
const e = Date.now(), t = 1e3 * 10;
|
|
2531
2538
|
for (const [r, n] of this.recentEventFingerprints.entries())
|
|
2532
2539
|
e - n > t && this.recentEventFingerprints.delete(r);
|
|
2533
|
-
|
|
2540
|
+
a("debug", "Pruned old event fingerprints", {
|
|
2534
2541
|
data: {
|
|
2535
2542
|
remaining: this.recentEventFingerprints.size,
|
|
2536
2543
|
cutoffMs: t
|
|
@@ -2543,15 +2550,19 @@ class fr extends w {
|
|
|
2543
2550
|
const r = Math.round((e.click_data.x || 0) / 10) * 10, n = Math.round((e.click_data.y || 0) / 10) * 10;
|
|
2544
2551
|
t += `_click_${r}_${n}`;
|
|
2545
2552
|
}
|
|
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;
|
|
2553
|
+
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
2554
|
}
|
|
2548
2555
|
createEventSignature(e) {
|
|
2549
2556
|
return this.createEventFingerprint(e);
|
|
2550
2557
|
}
|
|
2558
|
+
/** Deterministic JSON string with sorted keys to ensure consistent fingerprints regardless of property insertion order */
|
|
2559
|
+
stableStringify(e) {
|
|
2560
|
+
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);
|
|
2561
|
+
}
|
|
2551
2562
|
addToQueue(e) {
|
|
2552
2563
|
if (this.emitEvent(e), this.eventsQueue.push(e), this.eventsQueue.length > 100) {
|
|
2553
2564
|
const t = this.eventsQueue.findIndex((n) => n.type !== d.SESSION_START), r = t >= 0 ? this.eventsQueue.splice(t, 1)[0] : this.eventsQueue.shift();
|
|
2554
|
-
|
|
2565
|
+
a("warn", "Event queue overflow, oldest non-critical event removed", {
|
|
2555
2566
|
data: {
|
|
2556
2567
|
maxLength: 100,
|
|
2557
2568
|
currentLength: this.eventsQueue.length,
|
|
@@ -2585,7 +2596,7 @@ class fr extends w {
|
|
|
2585
2596
|
}
|
|
2586
2597
|
checkPerEventRateLimit(e, t) {
|
|
2587
2598
|
const r = Date.now(), i = (this.perEventRateLimits.get(e) ?? []).filter((o) => r - o < 6e4);
|
|
2588
|
-
return i.length >= t ? (
|
|
2599
|
+
return i.length >= t ? (a("warn", "Per-event rate limit exceeded for custom event", {
|
|
2589
2600
|
data: {
|
|
2590
2601
|
eventName: e,
|
|
2591
2602
|
limit: t,
|
|
@@ -2607,10 +2618,10 @@ class fr extends w {
|
|
|
2607
2618
|
this.eventsQueue = this.eventsQueue.filter((r) => !t.has(r.id));
|
|
2608
2619
|
}
|
|
2609
2620
|
emitEvent(e) {
|
|
2610
|
-
this.emitter && this.emitter.emit(
|
|
2621
|
+
this.emitter && this.emitter.emit(Se.EVENT, e);
|
|
2611
2622
|
}
|
|
2612
2623
|
emitEventsQueue(e) {
|
|
2613
|
-
this.emitter && this.emitter.emit(
|
|
2624
|
+
this.emitter && this.emitter.emit(Se.QUEUE, e);
|
|
2614
2625
|
}
|
|
2615
2626
|
/**
|
|
2616
2627
|
* Creates a debounced version of a function that delays execution until after
|
|
@@ -2686,13 +2697,13 @@ class fr extends w {
|
|
|
2686
2697
|
loadSessionCounts(e) {
|
|
2687
2698
|
if (typeof window > "u" || typeof localStorage > "u")
|
|
2688
2699
|
return this.getInitialCounts();
|
|
2689
|
-
const t = this.get("userId") || "anonymous", r =
|
|
2700
|
+
const t = this.get("userId") || "anonymous", r = Ue(t, e);
|
|
2690
2701
|
try {
|
|
2691
2702
|
const n = localStorage.getItem(r);
|
|
2692
2703
|
if (!n)
|
|
2693
2704
|
return this.getInitialCounts();
|
|
2694
2705
|
const i = JSON.parse(n);
|
|
2695
|
-
return i._timestamp && Date.now() - i._timestamp >
|
|
2706
|
+
return i._timestamp && Date.now() - i._timestamp > He ? (a("debug", "Session counts expired, clearing", {
|
|
2696
2707
|
data: { sessionId: e, age: Date.now() - i._timestamp }
|
|
2697
2708
|
}), 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
2709
|
total: i.total,
|
|
@@ -2701,13 +2712,13 @@ class fr extends w {
|
|
|
2701
2712
|
[d.CUSTOM]: i[d.CUSTOM],
|
|
2702
2713
|
[d.VIEWPORT_VISIBLE]: i[d.VIEWPORT_VISIBLE],
|
|
2703
2714
|
[d.SCROLL]: i[d.SCROLL]
|
|
2704
|
-
} : (
|
|
2715
|
+
} : (a("warn", "Invalid session counts structure in localStorage, resetting", {
|
|
2705
2716
|
data: { sessionId: e, parsed: i }
|
|
2706
|
-
}), localStorage.removeItem(r),
|
|
2717
|
+
}), localStorage.removeItem(r), a("debug", "Session counts removed due to invalid/corrupted data", {
|
|
2707
2718
|
data: { sessionId: e, parsed: i }
|
|
2708
2719
|
}), this.getInitialCounts());
|
|
2709
2720
|
} catch (n) {
|
|
2710
|
-
return
|
|
2721
|
+
return a("warn", "Failed to load session counts from localStorage", {
|
|
2711
2722
|
error: n,
|
|
2712
2723
|
data: { sessionId: e }
|
|
2713
2724
|
}), this.getInitialCounts();
|
|
@@ -2737,34 +2748,34 @@ class fr extends w {
|
|
|
2737
2748
|
cleanupExpiredSessionCounts() {
|
|
2738
2749
|
if (!(typeof window > "u" || typeof localStorage > "u"))
|
|
2739
2750
|
try {
|
|
2740
|
-
const e = localStorage.getItem(
|
|
2751
|
+
const e = localStorage.getItem(xe);
|
|
2741
2752
|
if (e) {
|
|
2742
2753
|
const i = Date.now() - parseInt(e, 10);
|
|
2743
|
-
if (i <
|
|
2744
|
-
|
|
2745
|
-
data: { timeSinceLastCleanup: i, throttleMs:
|
|
2754
|
+
if (i < Fe) {
|
|
2755
|
+
a("debug", "Skipping session counts cleanup (throttled)", {
|
|
2756
|
+
data: { timeSinceLastCleanup: i, throttleMs: Fe }
|
|
2746
2757
|
});
|
|
2747
2758
|
return;
|
|
2748
2759
|
}
|
|
2749
2760
|
}
|
|
2750
|
-
const t = this.get("userId") || "anonymous", r = `${
|
|
2761
|
+
const t = this.get("userId") || "anonymous", r = `${I}:${t}:session_counts:`, n = [];
|
|
2751
2762
|
for (let i = 0; i < localStorage.length; i++) {
|
|
2752
2763
|
const o = localStorage.key(i);
|
|
2753
2764
|
if (o?.startsWith(r))
|
|
2754
2765
|
try {
|
|
2755
|
-
const
|
|
2756
|
-
if (
|
|
2757
|
-
const c = JSON.parse(
|
|
2758
|
-
c._timestamp && Date.now() - c._timestamp >
|
|
2766
|
+
const l = localStorage.getItem(o);
|
|
2767
|
+
if (l) {
|
|
2768
|
+
const c = JSON.parse(l);
|
|
2769
|
+
c._timestamp && Date.now() - c._timestamp > He && n.push(o);
|
|
2759
2770
|
}
|
|
2760
2771
|
} catch {
|
|
2761
2772
|
}
|
|
2762
2773
|
}
|
|
2763
2774
|
n.forEach((i) => {
|
|
2764
|
-
localStorage.removeItem(i),
|
|
2765
|
-
}), n.length > 0 &&
|
|
2775
|
+
localStorage.removeItem(i), a("debug", "Cleaned up expired session counts", { data: { key: i } });
|
|
2776
|
+
}), n.length > 0 && a("info", `Cleaned up ${n.length} expired session counts entries`), localStorage.setItem(xe, Date.now().toString());
|
|
2766
2777
|
} catch (e) {
|
|
2767
|
-
|
|
2778
|
+
a("warn", "Failed to cleanup expired session counts", { error: e });
|
|
2768
2779
|
}
|
|
2769
2780
|
}
|
|
2770
2781
|
/**
|
|
@@ -2796,7 +2807,7 @@ class fr extends w {
|
|
|
2796
2807
|
* @internal
|
|
2797
2808
|
*/
|
|
2798
2809
|
saveSessionCounts(e) {
|
|
2799
|
-
const t = this.get("userId") || "anonymous", r =
|
|
2810
|
+
const t = this.get("userId") || "anonymous", r = Ue(t, e);
|
|
2800
2811
|
try {
|
|
2801
2812
|
const n = {
|
|
2802
2813
|
...this.sessionEventCounts,
|
|
@@ -2805,14 +2816,14 @@ class fr extends w {
|
|
|
2805
2816
|
};
|
|
2806
2817
|
localStorage.setItem(r, JSON.stringify(n));
|
|
2807
2818
|
} catch (n) {
|
|
2808
|
-
|
|
2819
|
+
a("warn", "Failed to persist session counts to localStorage", {
|
|
2809
2820
|
error: n,
|
|
2810
2821
|
data: { sessionId: e }
|
|
2811
2822
|
});
|
|
2812
2823
|
}
|
|
2813
2824
|
}
|
|
2814
2825
|
}
|
|
2815
|
-
class
|
|
2826
|
+
class Sr {
|
|
2816
2827
|
/**
|
|
2817
2828
|
* Gets or creates a unique user ID.
|
|
2818
2829
|
*
|
|
@@ -2830,15 +2841,15 @@ class mr {
|
|
|
2830
2841
|
* @returns Persistent unique user ID (UUID v4 format)
|
|
2831
2842
|
*/
|
|
2832
2843
|
static getId(e) {
|
|
2833
|
-
const t = e.getItem(
|
|
2844
|
+
const t = e.getItem(Ee);
|
|
2834
2845
|
if (t)
|
|
2835
2846
|
return t;
|
|
2836
|
-
const r =
|
|
2837
|
-
return e.setItem(
|
|
2847
|
+
const r = at();
|
|
2848
|
+
return e.setItem(Ee, r), r;
|
|
2838
2849
|
}
|
|
2839
2850
|
}
|
|
2840
|
-
const
|
|
2841
|
-
class
|
|
2851
|
+
const pr = /^\d{13}-[a-z0-9]{9}$/;
|
|
2852
|
+
class Tr extends w {
|
|
2842
2853
|
storageManager;
|
|
2843
2854
|
eventManager;
|
|
2844
2855
|
projectId;
|
|
@@ -2860,13 +2871,13 @@ class Er extends w {
|
|
|
2860
2871
|
}
|
|
2861
2872
|
initCrossTabSync() {
|
|
2862
2873
|
if (typeof BroadcastChannel > "u") {
|
|
2863
|
-
|
|
2874
|
+
a("debug", "BroadcastChannel not supported");
|
|
2864
2875
|
return;
|
|
2865
2876
|
}
|
|
2866
2877
|
const e = this.getProjectId();
|
|
2867
|
-
this.broadcastChannel = new BroadcastChannel(
|
|
2878
|
+
this.broadcastChannel = new BroadcastChannel(Mt(e)), this.broadcastChannel.onmessage = (t) => {
|
|
2868
2879
|
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" &&
|
|
2880
|
+
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
2881
|
};
|
|
2871
2882
|
}
|
|
2872
2883
|
shareSession(e) {
|
|
@@ -2884,8 +2895,8 @@ class Er extends w {
|
|
|
2884
2895
|
const e = this.loadStoredSession();
|
|
2885
2896
|
if (!e)
|
|
2886
2897
|
return null;
|
|
2887
|
-
if (!
|
|
2888
|
-
return
|
|
2898
|
+
if (!pr.test(e.id))
|
|
2899
|
+
return a("warn", "Invalid session ID format recovered from storage, clearing", {
|
|
2889
2900
|
data: { sessionId: e.id }
|
|
2890
2901
|
}), this.clearStoredSession(), null;
|
|
2891
2902
|
const t = this.get("config")?.sessionTimeout ?? 9e5;
|
|
@@ -2929,7 +2940,7 @@ class Er extends w {
|
|
|
2929
2940
|
this.storageManager.setItem(t, r), this.storageManager.setSessionItem(t, r);
|
|
2930
2941
|
}
|
|
2931
2942
|
getSessionStorageKey() {
|
|
2932
|
-
return
|
|
2943
|
+
return Lt(this.getProjectId());
|
|
2933
2944
|
}
|
|
2934
2945
|
getProjectId() {
|
|
2935
2946
|
return this.projectId;
|
|
@@ -2988,17 +2999,17 @@ class Er extends w {
|
|
|
2988
2999
|
*/
|
|
2989
3000
|
startTracking() {
|
|
2990
3001
|
if (this.isTracking) {
|
|
2991
|
-
|
|
3002
|
+
a("debug", "Session tracking already active");
|
|
2992
3003
|
return;
|
|
2993
3004
|
}
|
|
2994
3005
|
const e = this.recoverSession(), t = e ?? this.generateSessionId();
|
|
2995
3006
|
let r, n;
|
|
2996
3007
|
if (e) {
|
|
2997
3008
|
const i = this.loadStoredSession();
|
|
2998
|
-
r = i?.referrer ??
|
|
3009
|
+
r = i?.referrer ?? de(), n = i?.utm ?? he();
|
|
2999
3010
|
} else
|
|
3000
|
-
r =
|
|
3001
|
-
|
|
3011
|
+
r = de(), n = he();
|
|
3012
|
+
a("debug", "Session tracking initialized", {
|
|
3002
3013
|
data: {
|
|
3003
3014
|
sessionId: t,
|
|
3004
3015
|
wasRecovered: !!e,
|
|
@@ -3008,9 +3019,9 @@ class Er extends w {
|
|
|
3008
3019
|
}
|
|
3009
3020
|
}), this.isTracking = !0;
|
|
3010
3021
|
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 ?
|
|
3022
|
+
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
3023
|
data: { sessionId: t }
|
|
3013
|
-
}) : (
|
|
3024
|
+
}) : (a("debug", "Emitting SESSION_START event", {
|
|
3014
3025
|
data: { sessionId: t }
|
|
3015
3026
|
}), this.eventManager.track({
|
|
3016
3027
|
type: d.SESSION_START
|
|
@@ -3048,8 +3059,8 @@ class Er extends w {
|
|
|
3048
3059
|
*/
|
|
3049
3060
|
renewSession() {
|
|
3050
3061
|
this.needsRenewal = !1;
|
|
3051
|
-
const e = this.generateSessionId(), t =
|
|
3052
|
-
|
|
3062
|
+
const e = this.generateSessionId(), t = de(), r = he();
|
|
3063
|
+
a("debug", "Renewing session after timeout", {
|
|
3053
3064
|
data: { newSessionId: e }
|
|
3054
3065
|
}), 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
3066
|
type: d.SESSION_START
|
|
@@ -3064,7 +3075,7 @@ class Er extends w {
|
|
|
3064
3075
|
this.clearSessionTimeout();
|
|
3065
3076
|
else {
|
|
3066
3077
|
if (this.isSessionStale()) {
|
|
3067
|
-
|
|
3078
|
+
a("debug", "Session expired during suspend, entering renewal mode"), this.enterRenewalMode();
|
|
3068
3079
|
return;
|
|
3069
3080
|
}
|
|
3070
3081
|
this.get("sessionId") && this.setupSessionTimeout();
|
|
@@ -3093,7 +3104,7 @@ class Er extends w {
|
|
|
3093
3104
|
* Called by session timeout timer.
|
|
3094
3105
|
*/
|
|
3095
3106
|
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,
|
|
3107
|
+
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
3108
|
}
|
|
3098
3109
|
/**
|
|
3099
3110
|
* Fully resets session state and cleans up all resources.
|
|
@@ -3169,7 +3180,7 @@ class Er extends w {
|
|
|
3169
3180
|
this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupCrossTabSync(), this.cleanupLifecycleListeners(), this.isTracking = !1, this.needsRenewal = !1, this.set("hasStartSession", !1);
|
|
3170
3181
|
}
|
|
3171
3182
|
}
|
|
3172
|
-
class
|
|
3183
|
+
class Ir extends w {
|
|
3173
3184
|
eventManager;
|
|
3174
3185
|
storageManager;
|
|
3175
3186
|
sessionManager = null;
|
|
@@ -3199,12 +3210,12 @@ class Sr extends w {
|
|
|
3199
3210
|
if (this.isActive())
|
|
3200
3211
|
return;
|
|
3201
3212
|
if (this.destroyed) {
|
|
3202
|
-
|
|
3213
|
+
a("debug", "Cannot start tracking on destroyed handler");
|
|
3203
3214
|
return;
|
|
3204
3215
|
}
|
|
3205
3216
|
const t = this.get("config")?.integrations?.tracelog?.projectId ?? "custom";
|
|
3206
3217
|
try {
|
|
3207
|
-
this.sessionManager = new
|
|
3218
|
+
this.sessionManager = new Tr(this.storageManager, this.eventManager, t), this.sessionManager.startTracking(), this.eventManager.flushPendingEvents();
|
|
3208
3219
|
} catch (r) {
|
|
3209
3220
|
if (this.sessionManager) {
|
|
3210
3221
|
try {
|
|
@@ -3213,7 +3224,7 @@ class Sr extends w {
|
|
|
3213
3224
|
}
|
|
3214
3225
|
this.sessionManager = null;
|
|
3215
3226
|
}
|
|
3216
|
-
throw
|
|
3227
|
+
throw a("error", "Failed to start session tracking", { error: r }), r;
|
|
3217
3228
|
}
|
|
3218
3229
|
}
|
|
3219
3230
|
isActive() {
|
|
@@ -3257,7 +3268,7 @@ class Sr extends w {
|
|
|
3257
3268
|
this.destroyed || (this.sessionManager && (this.sessionManager.destroy(), this.sessionManager = null), this.destroyed = !0);
|
|
3258
3269
|
}
|
|
3259
3270
|
}
|
|
3260
|
-
class
|
|
3271
|
+
class vr extends w {
|
|
3261
3272
|
eventManager;
|
|
3262
3273
|
onTrack;
|
|
3263
3274
|
originalPushState;
|
|
@@ -3297,7 +3308,7 @@ class pr extends w {
|
|
|
3297
3308
|
};
|
|
3298
3309
|
}
|
|
3299
3310
|
trackCurrentPage = () => {
|
|
3300
|
-
const e = window.location.href, t =
|
|
3311
|
+
const e = window.location.href, t = ve(e, this.get("config").sensitiveQueryParams);
|
|
3301
3312
|
if (this.get("pageUrl") === t)
|
|
3302
3313
|
return;
|
|
3303
3314
|
const r = Date.now(), n = this.get("config").pageViewThrottleMs ?? 1e3;
|
|
@@ -3315,7 +3326,7 @@ class pr extends w {
|
|
|
3315
3326
|
});
|
|
3316
3327
|
};
|
|
3317
3328
|
trackInitialPageView() {
|
|
3318
|
-
const e =
|
|
3329
|
+
const e = ve(window.location.href, this.get("config").sensitiveQueryParams), t = this.extractPageViewData();
|
|
3319
3330
|
this.lastPageViewTime = Date.now(), this.eventManager.track({
|
|
3320
3331
|
type: d.PAGE_VIEW,
|
|
3321
3332
|
page_url: e,
|
|
@@ -3333,7 +3344,7 @@ class pr extends w {
|
|
|
3333
3344
|
};
|
|
3334
3345
|
}
|
|
3335
3346
|
}
|
|
3336
|
-
class
|
|
3347
|
+
class _r extends w {
|
|
3337
3348
|
eventManager;
|
|
3338
3349
|
lastClickTimes = /* @__PURE__ */ new Map();
|
|
3339
3350
|
clickHandler;
|
|
@@ -3358,7 +3369,7 @@ class Tr extends w {
|
|
|
3358
3369
|
this.clickHandler || (this.clickHandler = (e) => {
|
|
3359
3370
|
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
3371
|
if (!n) {
|
|
3361
|
-
|
|
3372
|
+
a("debug", "Click target not found or not an element");
|
|
3362
3373
|
return;
|
|
3363
3374
|
}
|
|
3364
3375
|
if (this.shouldIgnoreElement(n))
|
|
@@ -3366,7 +3377,7 @@ class Tr extends w {
|
|
|
3366
3377
|
const i = this.get("config")?.clickThrottleMs ?? 300;
|
|
3367
3378
|
if (i > 0 && !this.checkClickThrottle(n, i))
|
|
3368
3379
|
return;
|
|
3369
|
-
const o = this.findTrackingElement(n),
|
|
3380
|
+
const o = this.findTrackingElement(n), l = this.getRelevantClickElement(n), c = this.calculateClickCoordinates(t, n);
|
|
3370
3381
|
if (o) {
|
|
3371
3382
|
const g = this.extractTrackingData(o);
|
|
3372
3383
|
if (g) {
|
|
@@ -3380,7 +3391,7 @@ class Tr extends w {
|
|
|
3380
3391
|
});
|
|
3381
3392
|
}
|
|
3382
3393
|
}
|
|
3383
|
-
const u = this.generateClickData(n,
|
|
3394
|
+
const u = this.generateClickData(n, l, c);
|
|
3384
3395
|
this.eventManager.track({
|
|
3385
3396
|
type: d.CLICK,
|
|
3386
3397
|
click_data: u
|
|
@@ -3407,7 +3418,7 @@ class Tr extends w {
|
|
|
3407
3418
|
const r = this.getElementSignature(e), n = Date.now();
|
|
3408
3419
|
this.pruneThrottleCache(n);
|
|
3409
3420
|
const i = this.lastClickTimes.get(r);
|
|
3410
|
-
return i !== void 0 && n - i < t ? (
|
|
3421
|
+
return i !== void 0 && n - i < t ? (a("debug", "ClickHandler: Click suppressed by throttle", {
|
|
3411
3422
|
data: {
|
|
3412
3423
|
signature: r,
|
|
3413
3424
|
throttleRemaining: t - (n - i)
|
|
@@ -3427,10 +3438,10 @@ class Tr extends w {
|
|
|
3427
3438
|
for (const [r, n] of this.lastClickTimes.entries())
|
|
3428
3439
|
n < t && this.lastClickTimes.delete(r);
|
|
3429
3440
|
if (this.lastClickTimes.size > 1e3) {
|
|
3430
|
-
const r = Array.from(this.lastClickTimes.entries()).sort((o,
|
|
3441
|
+
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
3442
|
for (const [o] of i)
|
|
3432
3443
|
this.lastClickTimes.delete(o);
|
|
3433
|
-
|
|
3444
|
+
a("debug", "ClickHandler: Pruned throttle cache", {
|
|
3434
3445
|
data: {
|
|
3435
3446
|
removed: i.length,
|
|
3436
3447
|
remaining: this.lastClickTimes.size
|
|
@@ -3471,7 +3482,7 @@ class Tr extends w {
|
|
|
3471
3482
|
return e.hasAttribute(`${b}-name`) ? e : e.closest(`[${b}-name]`);
|
|
3472
3483
|
}
|
|
3473
3484
|
getRelevantClickElement(e) {
|
|
3474
|
-
for (const t of
|
|
3485
|
+
for (const t of _t)
|
|
3475
3486
|
try {
|
|
3476
3487
|
if (e.matches(t))
|
|
3477
3488
|
return e;
|
|
@@ -3479,7 +3490,7 @@ class Tr extends w {
|
|
|
3479
3490
|
if (r)
|
|
3480
3491
|
return r;
|
|
3481
3492
|
} catch (r) {
|
|
3482
|
-
|
|
3493
|
+
a("debug", "Invalid selector in element search", { error: r, data: { selector: t } });
|
|
3483
3494
|
continue;
|
|
3484
3495
|
}
|
|
3485
3496
|
return e;
|
|
@@ -3499,8 +3510,8 @@ class Tr extends w {
|
|
|
3499
3510
|
return Math.max(0, Math.min(1, Number(e.toFixed(3))));
|
|
3500
3511
|
}
|
|
3501
3512
|
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:
|
|
3513
|
+
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;
|
|
3514
|
+
return { x: n, y: i, relativeX: o, relativeY: l };
|
|
3504
3515
|
}
|
|
3505
3516
|
extractTrackingData(e) {
|
|
3506
3517
|
const t = e.getAttribute(`${b}-name`), r = e.getAttribute(`${b}-value`);
|
|
@@ -3512,12 +3523,12 @@ class Tr extends w {
|
|
|
3512
3523
|
};
|
|
3513
3524
|
}
|
|
3514
3525
|
generateClickData(e, t, r) {
|
|
3515
|
-
const { x: n, y: i, relativeX: o, relativeY:
|
|
3526
|
+
const { x: n, y: i, relativeX: o, relativeY: l } = r, c = this.getRelevantText(e, t), u = this.extractElementAttributes(t);
|
|
3516
3527
|
return {
|
|
3517
3528
|
x: n,
|
|
3518
3529
|
y: i,
|
|
3519
3530
|
relativeX: o,
|
|
3520
|
-
relativeY:
|
|
3531
|
+
relativeY: l,
|
|
3521
3532
|
tag: t.tagName.toLowerCase(),
|
|
3522
3533
|
...t.id && { id: t.id },
|
|
3523
3534
|
...t.className && { class: t.className },
|
|
@@ -3551,7 +3562,7 @@ class Tr extends w {
|
|
|
3551
3562
|
*/
|
|
3552
3563
|
sanitizeText(e) {
|
|
3553
3564
|
let t = e;
|
|
3554
|
-
for (const r of
|
|
3565
|
+
for (const r of nt) {
|
|
3555
3566
|
const n = new RegExp(r.source, r.flags);
|
|
3556
3567
|
t = t.replace(n, "[REDACTED]");
|
|
3557
3568
|
}
|
|
@@ -3590,7 +3601,7 @@ class Tr extends w {
|
|
|
3590
3601
|
};
|
|
3591
3602
|
}
|
|
3592
3603
|
}
|
|
3593
|
-
class
|
|
3604
|
+
class yr extends w {
|
|
3594
3605
|
eventManager;
|
|
3595
3606
|
containers = [];
|
|
3596
3607
|
limitWarningLogged = !1;
|
|
@@ -3697,29 +3708,29 @@ class vr extends w {
|
|
|
3697
3708
|
n,
|
|
3698
3709
|
this.getScrollHeight(e),
|
|
3699
3710
|
this.getViewportHeight(e)
|
|
3700
|
-
), o = this.determineIfPrimary(e),
|
|
3711
|
+
), o = this.determineIfPrimary(e), l = {
|
|
3701
3712
|
element: e,
|
|
3702
3713
|
selector: t,
|
|
3703
3714
|
isPrimary: o,
|
|
3704
3715
|
lastScrollPos: n,
|
|
3705
3716
|
lastDepth: i,
|
|
3706
|
-
lastDirection:
|
|
3717
|
+
lastDirection: ee.DOWN,
|
|
3707
3718
|
lastEventTime: 0,
|
|
3708
3719
|
firstScrollEventTime: null,
|
|
3709
3720
|
maxDepthReached: i,
|
|
3710
3721
|
debounceTimer: null,
|
|
3711
3722
|
listener: null
|
|
3712
3723
|
}, c = () => {
|
|
3713
|
-
this.get("suppressNextScroll") || (
|
|
3714
|
-
const u = this.calculateScrollData(
|
|
3724
|
+
this.get("suppressNextScroll") || (l.firstScrollEventTime === null && (l.firstScrollEventTime = Date.now()), this.clearContainerTimer(l), l.debounceTimer = window.setTimeout(() => {
|
|
3725
|
+
const u = this.calculateScrollData(l);
|
|
3715
3726
|
if (u) {
|
|
3716
3727
|
const g = Date.now();
|
|
3717
|
-
this.processScrollEvent(
|
|
3728
|
+
this.processScrollEvent(l, u, g);
|
|
3718
3729
|
}
|
|
3719
|
-
|
|
3730
|
+
l.debounceTimer = null;
|
|
3720
3731
|
}, 250));
|
|
3721
3732
|
};
|
|
3722
|
-
|
|
3733
|
+
l.listener = c, this.containers.push(l), e === window ? window.addEventListener("scroll", c, { passive: !0 }) : e.addEventListener("scroll", c, { passive: !0 });
|
|
3723
3734
|
}
|
|
3724
3735
|
processScrollEvent(e, t, r) {
|
|
3725
3736
|
if (!this.shouldEmitScrollEvent(e, t, r))
|
|
@@ -3748,7 +3759,7 @@ class vr extends w {
|
|
|
3748
3759
|
return Math.abs(t - e.lastDepth) >= this.minDepthChange;
|
|
3749
3760
|
}
|
|
3750
3761
|
logLimitOnce() {
|
|
3751
|
-
this.limitWarningLogged || (this.limitWarningLogged = !0,
|
|
3762
|
+
this.limitWarningLogged || (this.limitWarningLogged = !0, a("debug", "Max scroll events per session reached", {
|
|
3752
3763
|
data: { limit: this.maxEventsPerSession }
|
|
3753
3764
|
}));
|
|
3754
3765
|
}
|
|
@@ -3762,7 +3773,7 @@ class vr extends w {
|
|
|
3762
3773
|
e.debounceTimer !== null && (clearTimeout(e.debounceTimer), e.debounceTimer = null);
|
|
3763
3774
|
}
|
|
3764
3775
|
getScrollDirection(e, t) {
|
|
3765
|
-
return e > t ?
|
|
3776
|
+
return e > t ? ee.DOWN : ee.UP;
|
|
3766
3777
|
}
|
|
3767
3778
|
calculateScrollDepth(e, t, r) {
|
|
3768
3779
|
if (t <= r)
|
|
@@ -3771,13 +3782,13 @@ class vr extends w {
|
|
|
3771
3782
|
return Math.min(100, Math.max(0, Math.floor(e / n * 100)));
|
|
3772
3783
|
}
|
|
3773
3784
|
calculateScrollData(e) {
|
|
3774
|
-
const { element: t, lastScrollPos: r, lastEventTime: n } = e, i = this.getScrollTop(t), o = Date.now(),
|
|
3775
|
-
if (
|
|
3785
|
+
const { element: t, lastScrollPos: r, lastEventTime: n } = e, i = this.getScrollTop(t), o = Date.now(), l = Math.abs(i - r);
|
|
3786
|
+
if (l < 10 || t === window && !this.isWindowScrollable())
|
|
3776
3787
|
return null;
|
|
3777
3788
|
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(
|
|
3789
|
+
let T;
|
|
3790
|
+
n > 0 ? T = o - n : e.firstScrollEventTime !== null ? T = o - e.firstScrollEventTime : T = 250;
|
|
3791
|
+
const S = Math.round(l / T * 1e3);
|
|
3781
3792
|
return E > e.maxDepthReached && (e.maxDepthReached = E), e.lastScrollPos = i, {
|
|
3782
3793
|
depth: E,
|
|
3783
3794
|
direction: g,
|
|
@@ -3805,7 +3816,7 @@ class vr extends w {
|
|
|
3805
3816
|
else {
|
|
3806
3817
|
const n = document.querySelector(e);
|
|
3807
3818
|
if (!(n instanceof HTMLElement)) {
|
|
3808
|
-
|
|
3819
|
+
a("debug", `Selector "${e}" did not match an HTMLElement`);
|
|
3809
3820
|
return;
|
|
3810
3821
|
}
|
|
3811
3822
|
t = n;
|
|
@@ -3818,7 +3829,7 @@ class vr extends w {
|
|
|
3818
3829
|
e.isPrimary = t;
|
|
3819
3830
|
}
|
|
3820
3831
|
}
|
|
3821
|
-
class
|
|
3832
|
+
class wr extends w {
|
|
3822
3833
|
eventManager;
|
|
3823
3834
|
trackedElements = /* @__PURE__ */ new Map();
|
|
3824
3835
|
observer = null;
|
|
@@ -3837,15 +3848,15 @@ class _r extends w {
|
|
|
3837
3848
|
return;
|
|
3838
3849
|
const t = this.config.threshold ?? 0.5, r = this.config.minDwellTime ?? 1e3;
|
|
3839
3850
|
if (t < 0 || t > 1) {
|
|
3840
|
-
|
|
3851
|
+
a("debug", "ViewportHandler: Invalid threshold, must be between 0 and 1");
|
|
3841
3852
|
return;
|
|
3842
3853
|
}
|
|
3843
3854
|
if (r < 0) {
|
|
3844
|
-
|
|
3855
|
+
a("debug", "ViewportHandler: Invalid minDwellTime, must be non-negative");
|
|
3845
3856
|
return;
|
|
3846
3857
|
}
|
|
3847
3858
|
if (typeof IntersectionObserver > "u") {
|
|
3848
|
-
|
|
3859
|
+
a("debug", "ViewportHandler: IntersectionObserver not supported in this browser");
|
|
3849
3860
|
return;
|
|
3850
3861
|
}
|
|
3851
3862
|
this.observer = new IntersectionObserver(this.handleIntersection, {
|
|
@@ -3873,7 +3884,7 @@ class _r extends w {
|
|
|
3873
3884
|
const n = document.querySelectorAll(r.selector);
|
|
3874
3885
|
for (const i of Array.from(n)) {
|
|
3875
3886
|
if (t >= e) {
|
|
3876
|
-
|
|
3887
|
+
a("debug", "ViewportHandler: Maximum tracked elements reached", {
|
|
3877
3888
|
data: {
|
|
3878
3889
|
limit: e,
|
|
3879
3890
|
selector: r.selector,
|
|
@@ -3893,9 +3904,9 @@ class _r extends w {
|
|
|
3893
3904
|
}), this.observer?.observe(i), t++);
|
|
3894
3905
|
}
|
|
3895
3906
|
} catch (n) {
|
|
3896
|
-
|
|
3907
|
+
a("debug", `ViewportHandler: Invalid selector "${r.selector}"`, { error: n });
|
|
3897
3908
|
}
|
|
3898
|
-
|
|
3909
|
+
a("debug", "ViewportHandler: Elements tracked", {
|
|
3899
3910
|
data: { count: t, limit: e }
|
|
3900
3911
|
});
|
|
3901
3912
|
}
|
|
@@ -3923,7 +3934,7 @@ class _r extends w {
|
|
|
3923
3934
|
return;
|
|
3924
3935
|
const n = this.config?.cooldownPeriod ?? 6e4, i = Date.now();
|
|
3925
3936
|
if (e.lastFiredTime !== null && i - e.lastFiredTime < n) {
|
|
3926
|
-
|
|
3937
|
+
a("debug", "ViewportHandler: Event suppressed by cooldown period", {
|
|
3927
3938
|
data: {
|
|
3928
3939
|
selector: e.selector,
|
|
3929
3940
|
cooldownRemaining: n - (i - e.lastFiredTime)
|
|
@@ -3949,7 +3960,7 @@ class _r extends w {
|
|
|
3949
3960
|
setupMutationObserver() {
|
|
3950
3961
|
if (!(!this.config || typeof MutationObserver > "u")) {
|
|
3951
3962
|
if (!document.body) {
|
|
3952
|
-
|
|
3963
|
+
a("debug", "ViewportHandler: document.body not available, skipping MutationObserver setup");
|
|
3953
3964
|
return;
|
|
3954
3965
|
}
|
|
3955
3966
|
this.mutationObserver = new MutationObserver((e) => {
|
|
@@ -3973,20 +3984,20 @@ class _r extends w {
|
|
|
3973
3984
|
if (t.nodeType !== 1) return;
|
|
3974
3985
|
const r = t, n = this.trackedElements.get(r);
|
|
3975
3986
|
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
|
-
|
|
3987
|
+
const l = this.trackedElements.get(o);
|
|
3988
|
+
l && l.timeoutId !== null && window.clearTimeout(l.timeoutId), this.observer?.unobserve(o), this.trackedElements.delete(o);
|
|
3978
3989
|
});
|
|
3979
3990
|
});
|
|
3980
3991
|
}
|
|
3981
3992
|
}
|
|
3982
|
-
class
|
|
3993
|
+
class br {
|
|
3983
3994
|
storage;
|
|
3984
3995
|
sessionStorageRef;
|
|
3985
3996
|
fallbackStorage = /* @__PURE__ */ new Map();
|
|
3986
3997
|
fallbackSessionStorage = /* @__PURE__ */ new Map();
|
|
3987
3998
|
hasQuotaExceededError = !1;
|
|
3988
3999
|
constructor() {
|
|
3989
|
-
this.storage = this.initializeStorage("localStorage"), this.sessionStorageRef = this.initializeStorage("sessionStorage"), this.storage ||
|
|
4000
|
+
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
4001
|
}
|
|
3991
4002
|
/**
|
|
3992
4003
|
* Retrieves an item from localStorage.
|
|
@@ -4029,7 +4040,7 @@ class Ir {
|
|
|
4029
4040
|
}
|
|
4030
4041
|
} catch (r) {
|
|
4031
4042
|
if (r instanceof DOMException && r.name === "QuotaExceededError" || r instanceof Error && r.name === "QuotaExceededError")
|
|
4032
|
-
if (this.hasQuotaExceededError = !0,
|
|
4043
|
+
if (this.hasQuotaExceededError = !0, a("warn", "localStorage quota exceeded, attempting cleanup", {
|
|
4033
4044
|
data: { key: e, valueSize: t.length }
|
|
4034
4045
|
}), this.cleanupOldData())
|
|
4035
4046
|
try {
|
|
@@ -4038,13 +4049,13 @@ class Ir {
|
|
|
4038
4049
|
return;
|
|
4039
4050
|
}
|
|
4040
4051
|
} catch (o) {
|
|
4041
|
-
|
|
4052
|
+
a("error", "localStorage quota exceeded even after cleanup - data will not persist", {
|
|
4042
4053
|
error: o,
|
|
4043
4054
|
data: { key: e, valueSize: t.length }
|
|
4044
4055
|
});
|
|
4045
4056
|
}
|
|
4046
4057
|
else
|
|
4047
|
-
|
|
4058
|
+
a("error", "localStorage quota exceeded and no data to cleanup - data will not persist", {
|
|
4048
4059
|
error: r,
|
|
4049
4060
|
data: { key: e, valueSize: t.length }
|
|
4050
4061
|
});
|
|
@@ -4090,7 +4101,7 @@ class Ir {
|
|
|
4090
4101
|
this.storage.removeItem(t);
|
|
4091
4102
|
}), this.fallbackStorage.clear();
|
|
4092
4103
|
} catch (e) {
|
|
4093
|
-
|
|
4104
|
+
a("error", "Failed to clear storage", { error: e }), this.fallbackStorage.clear();
|
|
4094
4105
|
}
|
|
4095
4106
|
}
|
|
4096
4107
|
/**
|
|
@@ -4167,7 +4178,7 @@ class Ir {
|
|
|
4167
4178
|
}
|
|
4168
4179
|
}), !0) : !1;
|
|
4169
4180
|
} catch (e) {
|
|
4170
|
-
return
|
|
4181
|
+
return a("error", "Failed to cleanup old data", { error: e }), !1;
|
|
4171
4182
|
}
|
|
4172
4183
|
}
|
|
4173
4184
|
/**
|
|
@@ -4241,7 +4252,7 @@ class Ir {
|
|
|
4241
4252
|
return;
|
|
4242
4253
|
}
|
|
4243
4254
|
} catch (r) {
|
|
4244
|
-
(r instanceof DOMException && r.name === "QuotaExceededError" || r instanceof Error && r.name === "QuotaExceededError") &&
|
|
4255
|
+
(r instanceof DOMException && r.name === "QuotaExceededError" || r instanceof Error && r.name === "QuotaExceededError") && a("error", "sessionStorage quota exceeded - data will not persist", {
|
|
4245
4256
|
error: r,
|
|
4246
4257
|
data: { key: e, valueSize: t.length }
|
|
4247
4258
|
});
|
|
@@ -4262,7 +4273,7 @@ class Ir {
|
|
|
4262
4273
|
this.fallbackSessionStorage.delete(e);
|
|
4263
4274
|
}
|
|
4264
4275
|
}
|
|
4265
|
-
class
|
|
4276
|
+
class Ar extends w {
|
|
4266
4277
|
eventManager;
|
|
4267
4278
|
reportedByNav = /* @__PURE__ */ new Map();
|
|
4268
4279
|
navigationHistory = [];
|
|
@@ -4273,7 +4284,7 @@ class wr extends w {
|
|
|
4273
4284
|
navigationCounter = 0;
|
|
4274
4285
|
// Counter for handling simultaneous navigations edge case
|
|
4275
4286
|
constructor(e) {
|
|
4276
|
-
super(), this.eventManager = e, this.vitalThresholds =
|
|
4287
|
+
super(), this.eventManager = e, this.vitalThresholds = je(Ie);
|
|
4277
4288
|
}
|
|
4278
4289
|
/**
|
|
4279
4290
|
* Starts tracking Web Vitals and performance metrics.
|
|
@@ -4290,8 +4301,8 @@ class wr extends w {
|
|
|
4290
4301
|
* @returns Promise that resolves when tracking is initialized
|
|
4291
4302
|
*/
|
|
4292
4303
|
async startTracking() {
|
|
4293
|
-
const e = this.get("config"), t = e?.webVitalsMode ??
|
|
4294
|
-
this.vitalThresholds =
|
|
4304
|
+
const e = this.get("config"), t = e?.webVitalsMode ?? Ie;
|
|
4305
|
+
this.vitalThresholds = je(t), e?.webVitalsThresholds && (this.vitalThresholds = { ...this.vitalThresholds, ...e.webVitalsThresholds }), await this.initWebVitals(), this.observeLongTasks();
|
|
4295
4306
|
}
|
|
4296
4307
|
/**
|
|
4297
4308
|
* Stops tracking Web Vitals and cleans up resources.
|
|
@@ -4307,7 +4318,7 @@ class wr extends w {
|
|
|
4307
4318
|
try {
|
|
4308
4319
|
e.disconnect();
|
|
4309
4320
|
} catch (r) {
|
|
4310
|
-
|
|
4321
|
+
a("debug", "Failed to disconnect performance observer", { error: r, data: { observerIndex: t } });
|
|
4311
4322
|
}
|
|
4312
4323
|
}), this.observers.length = 0, this.reportedByNav.clear(), this.navigationHistory.length = 0;
|
|
4313
4324
|
}
|
|
@@ -4331,8 +4342,8 @@ class wr extends w {
|
|
|
4331
4342
|
for (const o of i) {
|
|
4332
4343
|
if (o.hadRecentInput === !0)
|
|
4333
4344
|
continue;
|
|
4334
|
-
const
|
|
4335
|
-
e +=
|
|
4345
|
+
const l = typeof o.value == "number" ? o.value : 0;
|
|
4346
|
+
e += l;
|
|
4336
4347
|
}
|
|
4337
4348
|
this.sendVital({ type: "CLS", value: Number(e.toFixed(2)) });
|
|
4338
4349
|
},
|
|
@@ -4351,8 +4362,8 @@ class wr extends w {
|
|
|
4351
4362
|
let n = 0;
|
|
4352
4363
|
const i = r.getEntries();
|
|
4353
4364
|
for (const o of i) {
|
|
4354
|
-
const
|
|
4355
|
-
n = Math.max(n,
|
|
4365
|
+
const l = (o.processingEnd ?? 0) - (o.startTime ?? 0);
|
|
4366
|
+
n = Math.max(n, l);
|
|
4356
4367
|
}
|
|
4357
4368
|
n > 0 && this.sendVital({ type: "INP", value: Number(n.toFixed(2)) });
|
|
4358
4369
|
},
|
|
@@ -4361,13 +4372,13 @@ class wr extends w {
|
|
|
4361
4372
|
}
|
|
4362
4373
|
async initWebVitals() {
|
|
4363
4374
|
try {
|
|
4364
|
-
const { onLCP: e, onCLS: t, onFCP: r, onTTFB: n, onINP: i } = await Promise.resolve().then(() =>
|
|
4375
|
+
const { onLCP: e, onCLS: t, onFCP: r, onTTFB: n, onINP: i } = await Promise.resolve().then(() => is), o = (l) => (c) => {
|
|
4365
4376
|
const u = Number(c.value.toFixed(2));
|
|
4366
|
-
this.sendVital({ type:
|
|
4377
|
+
this.sendVital({ type: l, value: u });
|
|
4367
4378
|
};
|
|
4368
4379
|
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
4380
|
} catch (e) {
|
|
4370
|
-
|
|
4381
|
+
a("debug", "Failed to load web-vitals library, using fallback", { error: e }), this.observeWebVitalsFallback();
|
|
4371
4382
|
}
|
|
4372
4383
|
}
|
|
4373
4384
|
reportTTFB() {
|
|
@@ -4378,7 +4389,7 @@ class wr extends w {
|
|
|
4378
4389
|
const t = e.responseStart;
|
|
4379
4390
|
typeof t == "number" && Number.isFinite(t) && this.sendVital({ type: "TTFB", value: Number(t.toFixed(2)) });
|
|
4380
4391
|
} catch (e) {
|
|
4381
|
-
|
|
4392
|
+
a("debug", "Failed to report TTFB", { error: e });
|
|
4382
4393
|
}
|
|
4383
4394
|
}
|
|
4384
4395
|
observeLongTasks() {
|
|
@@ -4388,7 +4399,7 @@ class wr extends w {
|
|
|
4388
4399
|
const t = e.getEntries();
|
|
4389
4400
|
for (const r of t) {
|
|
4390
4401
|
const n = Number(r.duration.toFixed(2)), i = Date.now();
|
|
4391
|
-
i - this.lastLongTaskSentAt >=
|
|
4402
|
+
i - this.lastLongTaskSentAt >= jt && (this.shouldSendVital("LONG_TASK", n) && this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = i);
|
|
4392
4403
|
}
|
|
4393
4404
|
},
|
|
4394
4405
|
{ type: "longtask", buffered: !0 }
|
|
@@ -4404,7 +4415,7 @@ class wr extends w {
|
|
|
4404
4415
|
return;
|
|
4405
4416
|
if (r)
|
|
4406
4417
|
r.add(e.type);
|
|
4407
|
-
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length >
|
|
4418
|
+
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length > Qt) {
|
|
4408
4419
|
const i = this.navigationHistory.shift();
|
|
4409
4420
|
i && this.reportedByNav.delete(i);
|
|
4410
4421
|
}
|
|
@@ -4413,7 +4424,7 @@ class wr extends w {
|
|
|
4413
4424
|
}
|
|
4414
4425
|
trackWebVital(e, t) {
|
|
4415
4426
|
if (!Number.isFinite(t)) {
|
|
4416
|
-
|
|
4427
|
+
a("debug", "Invalid web vital value", { data: { type: e, value: t } });
|
|
4417
4428
|
return;
|
|
4418
4429
|
}
|
|
4419
4430
|
this.eventManager.track({
|
|
@@ -4453,7 +4464,7 @@ class wr extends w {
|
|
|
4453
4464
|
const t = e.startTime || performance.now(), r = ++this.navigationCounter, n = `${t.toFixed(2)}_${window.location.pathname}`;
|
|
4454
4465
|
return r > 1 ? `${n}_${r}` : n;
|
|
4455
4466
|
} catch (e) {
|
|
4456
|
-
return
|
|
4467
|
+
return a("debug", "Failed to get navigation ID", { error: e }), null;
|
|
4457
4468
|
}
|
|
4458
4469
|
}
|
|
4459
4470
|
isObserverSupported(e) {
|
|
@@ -4465,24 +4476,24 @@ class wr extends w {
|
|
|
4465
4476
|
try {
|
|
4466
4477
|
if (!this.isObserverSupported(e))
|
|
4467
4478
|
return !1;
|
|
4468
|
-
const i = new PerformanceObserver((o,
|
|
4479
|
+
const i = new PerformanceObserver((o, l) => {
|
|
4469
4480
|
try {
|
|
4470
|
-
t(o,
|
|
4481
|
+
t(o, l);
|
|
4471
4482
|
} catch (c) {
|
|
4472
|
-
|
|
4483
|
+
a("debug", "Observer callback failed", {
|
|
4473
4484
|
error: c,
|
|
4474
4485
|
data: { type: e }
|
|
4475
4486
|
});
|
|
4476
4487
|
}
|
|
4477
4488
|
if (n)
|
|
4478
4489
|
try {
|
|
4479
|
-
|
|
4490
|
+
l.disconnect();
|
|
4480
4491
|
} catch {
|
|
4481
4492
|
}
|
|
4482
4493
|
});
|
|
4483
4494
|
return i.observe(r ?? { type: e, buffered: !0 }), n || this.observers.push(i), !0;
|
|
4484
4495
|
} catch (i) {
|
|
4485
|
-
return
|
|
4496
|
+
return a("debug", "Failed to create performance observer", {
|
|
4486
4497
|
error: i,
|
|
4487
4498
|
data: { type: e }
|
|
4488
4499
|
}), !1;
|
|
@@ -4490,12 +4501,12 @@ class wr extends w {
|
|
|
4490
4501
|
}
|
|
4491
4502
|
shouldSendVital(e, t) {
|
|
4492
4503
|
if (typeof t != "number" || !Number.isFinite(t))
|
|
4493
|
-
return
|
|
4504
|
+
return a("debug", "Invalid web vital value", { data: { type: e, value: t } }), !1;
|
|
4494
4505
|
const r = this.vitalThresholds[e];
|
|
4495
4506
|
return !(typeof r == "number" && t <= r);
|
|
4496
4507
|
}
|
|
4497
4508
|
}
|
|
4498
|
-
class
|
|
4509
|
+
class Lr extends w {
|
|
4499
4510
|
eventManager;
|
|
4500
4511
|
recentErrors = /* @__PURE__ */ new Map();
|
|
4501
4512
|
errorBurstCounter = 0;
|
|
@@ -4531,24 +4542,24 @@ class yr extends w {
|
|
|
4531
4542
|
const e = Date.now();
|
|
4532
4543
|
if (e < this.burstBackoffUntil)
|
|
4533
4544
|
return !1;
|
|
4534
|
-
if (e - this.burstWindowStart >
|
|
4535
|
-
return this.burstBackoffUntil = e +
|
|
4545
|
+
if (e - this.burstWindowStart > Bt && (this.errorBurstCounter = 0, this.burstWindowStart = e), this.errorBurstCounter++, this.errorBurstCounter > Wt)
|
|
4546
|
+
return this.burstBackoffUntil = e + Ge, a("debug", "Error burst detected - entering cooldown", {
|
|
4536
4547
|
data: {
|
|
4537
4548
|
errorsInWindow: this.errorBurstCounter,
|
|
4538
|
-
cooldownMs:
|
|
4549
|
+
cooldownMs: Ge
|
|
4539
4550
|
}
|
|
4540
4551
|
}), !1;
|
|
4541
|
-
const r = this.get("config")?.errorSampling ??
|
|
4552
|
+
const r = this.get("config")?.errorSampling ?? it;
|
|
4542
4553
|
return Math.random() < r;
|
|
4543
4554
|
}
|
|
4544
4555
|
handleError = (e) => {
|
|
4545
4556
|
if (!this.shouldSample())
|
|
4546
4557
|
return;
|
|
4547
4558
|
const t = this.sanitize(e.message || "Unknown error");
|
|
4548
|
-
this.shouldSuppressError(
|
|
4559
|
+
this.shouldSuppressError(W.JS_ERROR, t) || this.eventManager.track({
|
|
4549
4560
|
type: d.ERROR,
|
|
4550
4561
|
error_data: {
|
|
4551
|
-
type:
|
|
4562
|
+
type: W.JS_ERROR,
|
|
4552
4563
|
message: t,
|
|
4553
4564
|
...e.filename && { filename: e.filename },
|
|
4554
4565
|
...e.lineno && { line: e.lineno },
|
|
@@ -4560,10 +4571,10 @@ class yr extends w {
|
|
|
4560
4571
|
if (!this.shouldSample())
|
|
4561
4572
|
return;
|
|
4562
4573
|
const t = this.extractRejectionMessage(e.reason), r = this.sanitize(t);
|
|
4563
|
-
this.shouldSuppressError(
|
|
4574
|
+
this.shouldSuppressError(W.PROMISE_REJECTION, r) || this.eventManager.track({
|
|
4564
4575
|
type: d.ERROR,
|
|
4565
4576
|
error_data: {
|
|
4566
|
-
type:
|
|
4577
|
+
type: W.PROMISE_REJECTION,
|
|
4567
4578
|
message: r
|
|
4568
4579
|
}
|
|
4569
4580
|
});
|
|
@@ -4582,8 +4593,8 @@ class yr extends w {
|
|
|
4582
4593
|
}
|
|
4583
4594
|
}
|
|
4584
4595
|
sanitize(e) {
|
|
4585
|
-
let t = e.length >
|
|
4586
|
-
for (const r of
|
|
4596
|
+
let t = e.length > Be ? e.slice(0, Be) + "..." : e;
|
|
4597
|
+
for (const r of nt) {
|
|
4587
4598
|
const n = new RegExp(r.source, r.flags);
|
|
4588
4599
|
t = t.replace(n, "[REDACTED]");
|
|
4589
4600
|
}
|
|
@@ -4591,26 +4602,26 @@ class yr extends w {
|
|
|
4591
4602
|
}
|
|
4592
4603
|
shouldSuppressError(e, t) {
|
|
4593
4604
|
const r = Date.now(), n = `${e}:${t}`, i = this.recentErrors.get(n);
|
|
4594
|
-
return i && r - i <
|
|
4605
|
+
return i && r - i < We ? (this.recentErrors.set(n, r), !0) : (this.recentErrors.set(n, r), this.recentErrors.size > $t ? (this.recentErrors.clear(), this.recentErrors.set(n, r), !1) : (this.recentErrors.size > te && this.pruneOldErrors(), !1));
|
|
4595
4606
|
}
|
|
4596
4607
|
pruneOldErrors() {
|
|
4597
4608
|
const e = Date.now();
|
|
4598
4609
|
for (const [n, i] of this.recentErrors.entries())
|
|
4599
|
-
e - i >
|
|
4600
|
-
if (this.recentErrors.size <=
|
|
4610
|
+
e - i > We && this.recentErrors.delete(n);
|
|
4611
|
+
if (this.recentErrors.size <= te)
|
|
4601
4612
|
return;
|
|
4602
|
-
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), r = this.recentErrors.size -
|
|
4613
|
+
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), r = this.recentErrors.size - te;
|
|
4603
4614
|
for (let n = 0; n < r; n += 1) {
|
|
4604
4615
|
const i = t[n];
|
|
4605
4616
|
i && this.recentErrors.delete(i[0]);
|
|
4606
4617
|
}
|
|
4607
4618
|
}
|
|
4608
4619
|
}
|
|
4609
|
-
class
|
|
4620
|
+
class Mr extends w {
|
|
4610
4621
|
isInitialized = !1;
|
|
4611
4622
|
suppressNextScrollTimer = null;
|
|
4612
4623
|
pageUnloadHandler = null;
|
|
4613
|
-
emitter = new
|
|
4624
|
+
emitter = new hr();
|
|
4614
4625
|
transformers = {};
|
|
4615
4626
|
customHeadersProvider;
|
|
4616
4627
|
managers = {};
|
|
@@ -4628,19 +4639,19 @@ class br extends w {
|
|
|
4628
4639
|
async init(e = {}) {
|
|
4629
4640
|
if (this.isInitialized)
|
|
4630
4641
|
return { sessionId: this.get("sessionId") ?? "" };
|
|
4631
|
-
this.managers.storage = new
|
|
4642
|
+
this.managers.storage = new br();
|
|
4632
4643
|
try {
|
|
4633
4644
|
this.setupState(e);
|
|
4634
4645
|
const t = e.integrations?.custom?.headers ?? {}, r = e.integrations?.custom?.fetchCredentials ?? "include";
|
|
4635
|
-
return this.managers.event = new
|
|
4646
|
+
return this.managers.event = new Er(
|
|
4636
4647
|
this.managers.storage,
|
|
4637
4648
|
this.emitter,
|
|
4638
4649
|
this.transformers,
|
|
4639
4650
|
t,
|
|
4640
4651
|
this.customHeadersProvider,
|
|
4641
4652
|
r
|
|
4642
|
-
), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((n) => {
|
|
4643
|
-
|
|
4653
|
+
), this.loadPersistedIdentity(), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((n) => {
|
|
4654
|
+
a("warn", "Failed to recover persisted events", { error: n });
|
|
4644
4655
|
}), this.isInitialized = !0, { sessionId: this.get("sessionId") ?? "" };
|
|
4645
4656
|
} catch (t) {
|
|
4646
4657
|
this.destroy(!0);
|
|
@@ -4657,16 +4668,16 @@ class br extends w {
|
|
|
4657
4668
|
*/
|
|
4658
4669
|
sendCustomEvent(e, t) {
|
|
4659
4670
|
if (!this.managers.event) {
|
|
4660
|
-
|
|
4671
|
+
a("warn", "Cannot send custom event: TraceLog not initialized", { data: { name: e } });
|
|
4661
4672
|
return;
|
|
4662
4673
|
}
|
|
4663
4674
|
let r = t;
|
|
4664
4675
|
t && typeof t == "object" && !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && (r = Object.assign({}, t));
|
|
4665
|
-
const { valid: n, error: i, sanitizedMetadata: o } =
|
|
4676
|
+
const { valid: n, error: i, sanitizedMetadata: o } = dr(e, r);
|
|
4666
4677
|
if (!n) {
|
|
4667
|
-
if (this.get("mode") ===
|
|
4678
|
+
if (this.get("mode") === se.QA)
|
|
4668
4679
|
throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${i}`);
|
|
4669
|
-
|
|
4680
|
+
a("warn", `Custom event "${e}" dropped: ${i}`);
|
|
4670
4681
|
return;
|
|
4671
4682
|
}
|
|
4672
4683
|
this.managers.event.track({
|
|
@@ -4726,20 +4737,20 @@ class br extends w {
|
|
|
4726
4737
|
try {
|
|
4727
4738
|
t.stopTracking();
|
|
4728
4739
|
} catch (r) {
|
|
4729
|
-
|
|
4740
|
+
a("warn", "Failed to stop tracking", { error: r });
|
|
4730
4741
|
}
|
|
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 = {});
|
|
4742
|
+
}), 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
4743
|
}
|
|
4733
4744
|
setupState(e = {}) {
|
|
4734
4745
|
this.set("config", e);
|
|
4735
|
-
const t =
|
|
4746
|
+
const t = Sr.getId(this.managers.storage);
|
|
4736
4747
|
this.set("userId", t);
|
|
4737
|
-
const r =
|
|
4748
|
+
const r = sr(e);
|
|
4738
4749
|
this.set("collectApiUrls", r);
|
|
4739
|
-
const n =
|
|
4750
|
+
const n = Ft();
|
|
4740
4751
|
this.set("device", n);
|
|
4741
|
-
const i =
|
|
4742
|
-
this.set("pageUrl", i),
|
|
4752
|
+
const i = ve(window.location.href, e.sensitiveQueryParams);
|
|
4753
|
+
this.set("pageUrl", i), qt() && this.set("mode", se.QA);
|
|
4743
4754
|
}
|
|
4744
4755
|
/**
|
|
4745
4756
|
* Returns the current configuration object.
|
|
@@ -4790,7 +4801,7 @@ class br extends w {
|
|
|
4790
4801
|
valid: !1,
|
|
4791
4802
|
error: "Global metadata must be a plain object"
|
|
4792
4803
|
};
|
|
4793
|
-
const t =
|
|
4804
|
+
const t = ut("Global", e, "globalMetadata");
|
|
4794
4805
|
return t.valid ? { valid: !0 } : {
|
|
4795
4806
|
valid: !1,
|
|
4796
4807
|
error: t.error
|
|
@@ -4811,7 +4822,7 @@ class br extends w {
|
|
|
4811
4822
|
...this.get("config"),
|
|
4812
4823
|
globalMetadata: e
|
|
4813
4824
|
};
|
|
4814
|
-
this.set("config", n),
|
|
4825
|
+
this.set("config", n), a("debug", "Global metadata updated (replaced)", { data: { keys: Object.keys(e) } });
|
|
4815
4826
|
}
|
|
4816
4827
|
/**
|
|
4817
4828
|
* Merges new metadata with existing global metadata.
|
|
@@ -4831,7 +4842,133 @@ class br extends w {
|
|
|
4831
4842
|
...r,
|
|
4832
4843
|
globalMetadata: i
|
|
4833
4844
|
};
|
|
4834
|
-
this.set("config", o),
|
|
4845
|
+
this.set("config", o), a("debug", "Global metadata updated (merged)", { data: { keys: Object.keys(e) } });
|
|
4846
|
+
}
|
|
4847
|
+
/**
|
|
4848
|
+
* Associates the current anonymous visitor with a known user identity.
|
|
4849
|
+
*
|
|
4850
|
+
* Identity is persisted to localStorage (project-scoped) and included in every
|
|
4851
|
+
* subsequent batch payload so the backend always has the latest identity.
|
|
4852
|
+
*
|
|
4853
|
+
* Validation is duplicated here (also in api.ts) as defense-in-depth since
|
|
4854
|
+
* TestBridge and internal callers bypass the API layer.
|
|
4855
|
+
*
|
|
4856
|
+
* @param userId - External user identifier (email, customer_id, etc.)
|
|
4857
|
+
* @param traits - Optional user attributes (name, email, plan, etc.)
|
|
4858
|
+
* @internal Called from api.identify()
|
|
4859
|
+
*/
|
|
4860
|
+
identify(e, t) {
|
|
4861
|
+
if (!e || typeof e != "string" || e.trim().length === 0) {
|
|
4862
|
+
a("warn", "identify() called with invalid userId", {
|
|
4863
|
+
data: { type: typeof e, length: typeof e == "string" ? e.trim().length : 0 }
|
|
4864
|
+
});
|
|
4865
|
+
return;
|
|
4866
|
+
}
|
|
4867
|
+
if (e.trim().length > 256) {
|
|
4868
|
+
a("warn", "identify() userId exceeds 256 characters", { data: { length: e.trim().length } });
|
|
4869
|
+
return;
|
|
4870
|
+
}
|
|
4871
|
+
const r = e.trim(), n = ct(t), i = {
|
|
4872
|
+
userId: r,
|
|
4873
|
+
...n ? { traits: n } : {}
|
|
4874
|
+
};
|
|
4875
|
+
this.set("identity", i), this.persistIdentity(i), a("debug", "Visitor identified", {
|
|
4876
|
+
data: { userIdLength: r.length, traitKeys: n ? Object.keys(n) : [] }
|
|
4877
|
+
});
|
|
4878
|
+
}
|
|
4879
|
+
/**
|
|
4880
|
+
* Clears identity, regenerates UUID, and starts a new session.
|
|
4881
|
+
*
|
|
4882
|
+
* Used for logout flows. The previous visitor profile with its identity
|
|
4883
|
+
* remains in MongoDB — this method ensures the next user in the same browser
|
|
4884
|
+
* gets a fresh anonymous profile.
|
|
4885
|
+
*
|
|
4886
|
+
* @internal Called from api.resetIdentity()
|
|
4887
|
+
*/
|
|
4888
|
+
async resetIdentity() {
|
|
4889
|
+
await this.managers.event?.flushImmediately(), this.set("identity", void 0), this.clearPersistedIdentity();
|
|
4890
|
+
const e = at();
|
|
4891
|
+
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");
|
|
4892
|
+
}
|
|
4893
|
+
/**
|
|
4894
|
+
* Returns the project ID used for identity storage scoping.
|
|
4895
|
+
* Matches the same logic used by SessionHandler.
|
|
4896
|
+
*/
|
|
4897
|
+
getProjectId() {
|
|
4898
|
+
return this.get("config")?.integrations?.tracelog?.projectId ?? "custom";
|
|
4899
|
+
}
|
|
4900
|
+
/**
|
|
4901
|
+
* Persists identity to localStorage under the project-scoped key.
|
|
4902
|
+
*/
|
|
4903
|
+
persistIdentity(e) {
|
|
4904
|
+
try {
|
|
4905
|
+
const t = this.getProjectId(), r = ue(t);
|
|
4906
|
+
this.managers.storage.setItem(r, JSON.stringify(e));
|
|
4907
|
+
} catch {
|
|
4908
|
+
a("debug", "Failed to persist identity to localStorage");
|
|
4909
|
+
}
|
|
4910
|
+
}
|
|
4911
|
+
/**
|
|
4912
|
+
* Loads identity from localStorage on init.
|
|
4913
|
+
* Also migrates pending identity (set before init) to the project-scoped key.
|
|
4914
|
+
*/
|
|
4915
|
+
loadPersistedIdentity() {
|
|
4916
|
+
const e = this.managers.storage, t = this.getProjectId(), r = ue(t);
|
|
4917
|
+
try {
|
|
4918
|
+
const n = e.getItem(H);
|
|
4919
|
+
if (n) {
|
|
4920
|
+
const i = JSON.parse(n);
|
|
4921
|
+
if (e.removeItem(H), !this.isValidIdentityData(i)) {
|
|
4922
|
+
a("debug", "Invalid pending identity in localStorage, discarded");
|
|
4923
|
+
return;
|
|
4924
|
+
}
|
|
4925
|
+
const o = { ...i, userId: i.userId.trim() };
|
|
4926
|
+
e.setItem(r, JSON.stringify(o)), this.set("identity", o), a("debug", "Migrated pending identity to project-scoped key");
|
|
4927
|
+
return;
|
|
4928
|
+
}
|
|
4929
|
+
} catch {
|
|
4930
|
+
e.removeItem(H);
|
|
4931
|
+
}
|
|
4932
|
+
try {
|
|
4933
|
+
const n = e.getItem(r);
|
|
4934
|
+
if (n) {
|
|
4935
|
+
const i = JSON.parse(n);
|
|
4936
|
+
if (!this.isValidIdentityData(i)) {
|
|
4937
|
+
e.removeItem(r), a("debug", "Invalid persisted identity in localStorage, discarded");
|
|
4938
|
+
return;
|
|
4939
|
+
}
|
|
4940
|
+
const o = { ...i, userId: i.userId.trim() };
|
|
4941
|
+
this.set("identity", o), a("debug", "Loaded persisted identity");
|
|
4942
|
+
}
|
|
4943
|
+
} catch {
|
|
4944
|
+
a("debug", "Failed to load persisted identity");
|
|
4945
|
+
}
|
|
4946
|
+
}
|
|
4947
|
+
/**
|
|
4948
|
+
* Validates identity data loaded from localStorage.
|
|
4949
|
+
* Guards against tampered or corrupted localStorage values.
|
|
4950
|
+
*/
|
|
4951
|
+
isValidIdentityData(e) {
|
|
4952
|
+
if (!e || typeof e != "object") return !1;
|
|
4953
|
+
const { userId: t, traits: r } = e;
|
|
4954
|
+
if (typeof t != "string" || t.trim().length === 0 || t.trim().length > 256) return !1;
|
|
4955
|
+
if (r !== void 0) {
|
|
4956
|
+
if (typeof r != "object" || r === null || Array.isArray(r)) return !1;
|
|
4957
|
+
for (const n of Object.values(r))
|
|
4958
|
+
if (typeof n != "string") return !1;
|
|
4959
|
+
}
|
|
4960
|
+
return !0;
|
|
4961
|
+
}
|
|
4962
|
+
/**
|
|
4963
|
+
* Clears persisted identity from localStorage.
|
|
4964
|
+
*/
|
|
4965
|
+
clearPersistedIdentity() {
|
|
4966
|
+
try {
|
|
4967
|
+
const e = this.managers.storage, t = this.getProjectId();
|
|
4968
|
+
e.removeItem(ue(t)), e.removeItem(H);
|
|
4969
|
+
} catch {
|
|
4970
|
+
a("debug", "Failed to clear persisted identity");
|
|
4971
|
+
}
|
|
4835
4972
|
}
|
|
4836
4973
|
setupPageLifecycleListeners() {
|
|
4837
4974
|
this.pageUnloadHandler = () => {
|
|
@@ -4840,7 +4977,7 @@ class br extends w {
|
|
|
4840
4977
|
}
|
|
4841
4978
|
initializeHandlers() {
|
|
4842
4979
|
const e = this.get("config");
|
|
4843
|
-
this.handlers.session = new
|
|
4980
|
+
this.handlers.session = new Ir(
|
|
4844
4981
|
this.managers.storage,
|
|
4845
4982
|
this.managers.event
|
|
4846
4983
|
), this.handlers.session.startTracking();
|
|
@@ -4849,25 +4986,25 @@ class br extends w {
|
|
|
4849
4986
|
this.set("suppressNextScroll", !1);
|
|
4850
4987
|
}, 500);
|
|
4851
4988
|
};
|
|
4852
|
-
this.handlers.pageView = new
|
|
4853
|
-
|
|
4854
|
-
}), this.handlers.error = new
|
|
4989
|
+
this.handlers.pageView = new vr(this.managers.event, t), this.handlers.pageView.startTracking(), this.handlers.click = new _r(this.managers.event), this.handlers.click.startTracking(), this.handlers.scroll = new yr(this.managers.event), this.handlers.scroll.startTracking(), this.handlers.performance = new Ar(this.managers.event), this.handlers.performance.startTracking().catch((r) => {
|
|
4990
|
+
a("warn", "Failed to start performance tracking", { error: r });
|
|
4991
|
+
}), this.handlers.error = new Lr(this.managers.event), this.handlers.error.startTracking(), e.viewport && (this.handlers.viewport = new wr(this.managers.event), this.handlers.viewport.startTracking());
|
|
4855
4992
|
}
|
|
4856
4993
|
}
|
|
4857
4994
|
const V = [], M = [];
|
|
4858
|
-
let D = null, h = null, R = !1,
|
|
4859
|
-
const
|
|
4995
|
+
let D = null, h = null, R = !1, p = !1, P = null;
|
|
4996
|
+
const Cr = 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
4997
|
try {
|
|
4861
|
-
const e =
|
|
4998
|
+
const e = lr(s ?? {}), t = new Mr();
|
|
4862
4999
|
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",
|
|
5000
|
+
V.forEach(({ event: o, callback: l }) => {
|
|
5001
|
+
t.on(o, l);
|
|
5002
|
+
}), V.length = 0, M.forEach(({ hook: o, fn: l }) => {
|
|
5003
|
+
o === "beforeSend" ? t.setTransformer("beforeSend", l) : t.setTransformer("beforeBatch", l);
|
|
4867
5004
|
}), M.length = 0, D && (t.setCustomHeaders(D), D = null);
|
|
4868
|
-
const r = t.init(e), n = new Promise((o,
|
|
5005
|
+
const r = t.init(e), n = new Promise((o, l) => {
|
|
4869
5006
|
setTimeout(() => {
|
|
4870
|
-
|
|
5007
|
+
l(new Error("[TraceLog] Initialization timeout after 10000ms"));
|
|
4871
5008
|
}, 1e4);
|
|
4872
5009
|
}), i = await Promise.race([r, n]);
|
|
4873
5010
|
return h = t, i;
|
|
@@ -4875,7 +5012,7 @@ const Ar = async (s) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
4875
5012
|
try {
|
|
4876
5013
|
t.destroy(!0);
|
|
4877
5014
|
} catch (n) {
|
|
4878
|
-
|
|
5015
|
+
a("error", "Failed to cleanup partially initialized app", { error: n });
|
|
4879
5016
|
}
|
|
4880
5017
|
throw r;
|
|
4881
5018
|
}
|
|
@@ -4884,15 +5021,15 @@ const Ar = async (s) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
4884
5021
|
} finally {
|
|
4885
5022
|
R = !1, P = null;
|
|
4886
5023
|
}
|
|
4887
|
-
})()), P)),
|
|
5024
|
+
})()), P)), Rr = (s, e) => {
|
|
4888
5025
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4889
5026
|
if (!h)
|
|
4890
5027
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4891
|
-
if (
|
|
5028
|
+
if (p)
|
|
4892
5029
|
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
4893
5030
|
h.sendCustomEvent(s, e);
|
|
4894
5031
|
}
|
|
4895
|
-
},
|
|
5032
|
+
}, Nr = (s, e) => {
|
|
4896
5033
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4897
5034
|
if (!h || R) {
|
|
4898
5035
|
V.push({ event: s, callback: e });
|
|
@@ -4900,7 +5037,7 @@ const Ar = async (s) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
4900
5037
|
}
|
|
4901
5038
|
h.on(s, e);
|
|
4902
5039
|
}
|
|
4903
|
-
},
|
|
5040
|
+
}, Or = (s, e) => {
|
|
4904
5041
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4905
5042
|
if (!h) {
|
|
4906
5043
|
const t = V.findIndex((r) => r.event === s && r.callback === e);
|
|
@@ -4910,7 +5047,7 @@ const Ar = async (s) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
4910
5047
|
h.off(s, e);
|
|
4911
5048
|
}
|
|
4912
5049
|
};
|
|
4913
|
-
function
|
|
5050
|
+
function Pr(s, e) {
|
|
4914
5051
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4915
5052
|
if (typeof e != "function")
|
|
4916
5053
|
throw new Error(`[TraceLog] Transformer must be a function, received: ${typeof e}`);
|
|
@@ -4919,23 +5056,23 @@ function Rr(s, e) {
|
|
|
4919
5056
|
t !== -1 && M.splice(t, 1), M.push({ hook: s, fn: e });
|
|
4920
5057
|
return;
|
|
4921
5058
|
}
|
|
4922
|
-
if (
|
|
5059
|
+
if (p)
|
|
4923
5060
|
throw new Error("[TraceLog] Cannot set transformers while TraceLog is being destroyed");
|
|
4924
5061
|
s === "beforeSend" ? h.setTransformer("beforeSend", e) : h.setTransformer("beforeBatch", e);
|
|
4925
5062
|
}
|
|
4926
5063
|
}
|
|
4927
|
-
const
|
|
5064
|
+
const Dr = (s) => {
|
|
4928
5065
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4929
5066
|
if (!h) {
|
|
4930
5067
|
const e = M.findIndex((t) => t.hook === s);
|
|
4931
5068
|
e !== -1 && M.splice(e, 1);
|
|
4932
5069
|
return;
|
|
4933
5070
|
}
|
|
4934
|
-
if (
|
|
5071
|
+
if (p)
|
|
4935
5072
|
throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
|
|
4936
5073
|
h.removeTransformer(s);
|
|
4937
5074
|
}
|
|
4938
|
-
},
|
|
5075
|
+
}, Vr = (s) => {
|
|
4939
5076
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4940
5077
|
if (typeof s != "function")
|
|
4941
5078
|
throw new Error(`[TraceLog] Custom headers provider must be a function, received: ${typeof s}`);
|
|
@@ -4943,83 +5080,126 @@ const Nr = (s) => {
|
|
|
4943
5080
|
D = s;
|
|
4944
5081
|
return;
|
|
4945
5082
|
}
|
|
4946
|
-
if (
|
|
5083
|
+
if (p)
|
|
4947
5084
|
throw new Error("[TraceLog] Cannot set custom headers while TraceLog is being destroyed");
|
|
4948
5085
|
h.setCustomHeaders(s);
|
|
4949
5086
|
}
|
|
4950
|
-
},
|
|
5087
|
+
}, kr = () => {
|
|
4951
5088
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4952
5089
|
if (!h) {
|
|
4953
5090
|
D = null;
|
|
4954
5091
|
return;
|
|
4955
5092
|
}
|
|
4956
|
-
if (
|
|
5093
|
+
if (p)
|
|
4957
5094
|
throw new Error("[TraceLog] Cannot remove custom headers while TraceLog is being destroyed");
|
|
4958
5095
|
h.removeCustomHeaders();
|
|
4959
5096
|
}
|
|
4960
|
-
},
|
|
5097
|
+
}, Ur = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, Hr = () => typeof window > "u" || typeof document > "u" || !h ? null : h.getSessionId(), xr = () => {
|
|
4961
5098
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4962
|
-
if (
|
|
5099
|
+
if (p)
|
|
4963
5100
|
throw new Error("[TraceLog] Destroy operation already in progress");
|
|
4964
5101
|
if (!h) {
|
|
4965
|
-
|
|
5102
|
+
p = !1;
|
|
4966
5103
|
return;
|
|
4967
5104
|
}
|
|
4968
|
-
|
|
5105
|
+
p = !0;
|
|
4969
5106
|
try {
|
|
4970
|
-
h.destroy(), h = null, R = !1, P = null, V.length = 0, M.length = 0, D = null,
|
|
5107
|
+
h.destroy(), h = null, R = !1, P = null, V.length = 0, M.length = 0, D = null, p = !1;
|
|
4971
5108
|
} catch (s) {
|
|
4972
|
-
h = null, R = !1, P = null, V.length = 0, M.length = 0, D = null,
|
|
5109
|
+
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
5110
|
}
|
|
4974
5111
|
}
|
|
4975
|
-
},
|
|
4976
|
-
typeof window > "u" || typeof document > "u" ||
|
|
4977
|
-
},
|
|
5112
|
+
}, Fr = (s) => {
|
|
5113
|
+
typeof window > "u" || typeof document > "u" || Jt(s);
|
|
5114
|
+
}, $r = (s) => {
|
|
4978
5115
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4979
5116
|
if (!h)
|
|
4980
5117
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4981
|
-
if (
|
|
5118
|
+
if (p)
|
|
4982
5119
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
4983
5120
|
h.updateGlobalMetadata(s);
|
|
4984
5121
|
}
|
|
4985
|
-
},
|
|
5122
|
+
}, Br = (s) => {
|
|
4986
5123
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4987
5124
|
if (!h)
|
|
4988
5125
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4989
|
-
if (
|
|
5126
|
+
if (p)
|
|
4990
5127
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
4991
5128
|
h.mergeGlobalMetadata(s);
|
|
4992
5129
|
}
|
|
4993
|
-
},
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5130
|
+
}, Wr = (s, e) => {
|
|
5131
|
+
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5132
|
+
if (!s || typeof s != "string" || s.trim().length === 0) {
|
|
5133
|
+
a("warn", "identify() called with invalid userId");
|
|
5134
|
+
return;
|
|
5135
|
+
}
|
|
5136
|
+
if (s.trim().length > 256) {
|
|
5137
|
+
a("warn", "identify() userId exceeds 256 characters");
|
|
5138
|
+
return;
|
|
5139
|
+
}
|
|
5140
|
+
if (p) {
|
|
5141
|
+
a("warn", "Cannot identify while TraceLog is being destroyed");
|
|
5142
|
+
return;
|
|
5143
|
+
}
|
|
5144
|
+
if (h) {
|
|
5145
|
+
h.identify(s, e);
|
|
5146
|
+
return;
|
|
5147
|
+
}
|
|
5148
|
+
try {
|
|
5149
|
+
const t = ct(e), r = {
|
|
5150
|
+
userId: s.trim(),
|
|
5151
|
+
...t ? { traits: t } : {}
|
|
5152
|
+
};
|
|
5153
|
+
localStorage.setItem(H, JSON.stringify(r)), a("debug", "Identity persisted pre-init (will be applied on init)");
|
|
5154
|
+
} catch {
|
|
5155
|
+
a("debug", "Failed to persist pre-init identity");
|
|
5156
|
+
}
|
|
5157
|
+
}
|
|
5158
|
+
}, Gr = async () => {
|
|
5159
|
+
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5160
|
+
if (!h) {
|
|
5161
|
+
try {
|
|
5162
|
+
localStorage.removeItem(H);
|
|
5163
|
+
} catch {
|
|
5164
|
+
}
|
|
5165
|
+
return;
|
|
5166
|
+
}
|
|
5167
|
+
if (p)
|
|
5168
|
+
throw new Error("[TraceLog] Cannot reset identity while TraceLog is being destroyed");
|
|
5169
|
+
await h.resetIdentity();
|
|
5170
|
+
}
|
|
5171
|
+
}, Ts = {
|
|
5172
|
+
init: Cr,
|
|
5173
|
+
event: Rr,
|
|
5174
|
+
on: Nr,
|
|
5175
|
+
off: Or,
|
|
5176
|
+
setTransformer: Pr,
|
|
5177
|
+
removeTransformer: Dr,
|
|
5178
|
+
setCustomHeaders: Vr,
|
|
5179
|
+
removeCustomHeaders: kr,
|
|
5180
|
+
isInitialized: Ur,
|
|
5181
|
+
getSessionId: Hr,
|
|
5182
|
+
destroy: xr,
|
|
5183
|
+
setQaMode: Fr,
|
|
5184
|
+
updateGlobalMetadata: $r,
|
|
5185
|
+
mergeGlobalMetadata: Br,
|
|
5186
|
+
identify: Wr,
|
|
5187
|
+
resetIdentity: Gr
|
|
5008
5188
|
};
|
|
5009
|
-
var
|
|
5189
|
+
var we, C, j, ft, ie, mt = -1, k = function(s) {
|
|
5010
5190
|
addEventListener("pageshow", (function(e) {
|
|
5011
|
-
e.persisted && (
|
|
5191
|
+
e.persisted && (mt = e.timeStamp, s(e));
|
|
5012
5192
|
}), !0);
|
|
5013
|
-
},
|
|
5193
|
+
}, Ne = function() {
|
|
5014
5194
|
var s = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
|
|
5015
5195
|
if (s && s.responseStart > 0 && s.responseStart < performance.now()) return s;
|
|
5016
|
-
},
|
|
5017
|
-
var s =
|
|
5196
|
+
}, ae = function() {
|
|
5197
|
+
var s = Ne();
|
|
5018
5198
|
return s && s.activationStart || 0;
|
|
5019
5199
|
}, _ = function(s, e) {
|
|
5020
|
-
var t =
|
|
5021
|
-
return
|
|
5022
|
-
},
|
|
5200
|
+
var t = Ne(), r = "navigate";
|
|
5201
|
+
return mt >= 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 };
|
|
5202
|
+
}, F = function(s, e, t) {
|
|
5023
5203
|
try {
|
|
5024
5204
|
if (PerformanceObserver.supportedEntryTypes.includes(s)) {
|
|
5025
5205
|
var r = new PerformanceObserver((function(n) {
|
|
@@ -5031,63 +5211,63 @@ var _e, C, X, ct, ne, ut = -1, k = function(s) {
|
|
|
5031
5211
|
}
|
|
5032
5212
|
} catch {
|
|
5033
5213
|
}
|
|
5034
|
-
},
|
|
5214
|
+
}, y = function(s, e, t, r) {
|
|
5035
5215
|
var n, i;
|
|
5036
5216
|
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
|
|
5217
|
+
e.value >= 0 && (o || r) && ((i = e.value - (n || 0)) || n === void 0) && (n = e.value, e.delta = i, e.rating = (function(l, c) {
|
|
5218
|
+
return l > c[1] ? "poor" : l > c[0] ? "needs-improvement" : "good";
|
|
5039
5219
|
})(e.value, t), s(e));
|
|
5040
5220
|
};
|
|
5041
|
-
},
|
|
5221
|
+
}, Oe = function(s) {
|
|
5042
5222
|
requestAnimationFrame((function() {
|
|
5043
5223
|
return requestAnimationFrame((function() {
|
|
5044
5224
|
return s();
|
|
5045
5225
|
}));
|
|
5046
5226
|
}));
|
|
5047
|
-
},
|
|
5227
|
+
}, z = function(s) {
|
|
5048
5228
|
document.addEventListener("visibilitychange", (function() {
|
|
5049
5229
|
document.visibilityState === "hidden" && s();
|
|
5050
5230
|
}));
|
|
5051
|
-
},
|
|
5231
|
+
}, le = function(s) {
|
|
5052
5232
|
var e = !1;
|
|
5053
5233
|
return function() {
|
|
5054
5234
|
e || (s(), e = !0);
|
|
5055
5235
|
};
|
|
5056
|
-
},
|
|
5236
|
+
}, x = -1, qe = function() {
|
|
5057
5237
|
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
|
|
5238
|
+
}, oe = function(s) {
|
|
5239
|
+
document.visibilityState === "hidden" && x > -1 && (x = s.type === "visibilitychange" ? s.timeStamp : 0, Xr());
|
|
5240
|
+
}, Je = function() {
|
|
5241
|
+
addEventListener("visibilitychange", oe, !0), addEventListener("prerenderingchange", oe, !0);
|
|
5242
|
+
}, Xr = function() {
|
|
5243
|
+
removeEventListener("visibilitychange", oe, !0), removeEventListener("prerenderingchange", oe, !0);
|
|
5244
|
+
}, Pe = function() {
|
|
5245
|
+
return x < 0 && (x = qe(), Je(), k((function() {
|
|
5066
5246
|
setTimeout((function() {
|
|
5067
|
-
|
|
5247
|
+
x = qe(), Je();
|
|
5068
5248
|
}), 0);
|
|
5069
5249
|
}))), { get firstHiddenTime() {
|
|
5070
|
-
return
|
|
5250
|
+
return x;
|
|
5071
5251
|
} };
|
|
5072
|
-
},
|
|
5252
|
+
}, K = function(s) {
|
|
5073
5253
|
document.prerendering ? addEventListener("prerenderingchange", (function() {
|
|
5074
5254
|
return s();
|
|
5075
5255
|
}), !0) : s();
|
|
5076
|
-
},
|
|
5077
|
-
e = e || {},
|
|
5078
|
-
var t, r =
|
|
5079
|
-
o.forEach((function(
|
|
5080
|
-
|
|
5256
|
+
}, be = [1800, 3e3], gt = function(s, e) {
|
|
5257
|
+
e = e || {}, K((function() {
|
|
5258
|
+
var t, r = Pe(), n = _("FCP"), i = F("paint", (function(o) {
|
|
5259
|
+
o.forEach((function(l) {
|
|
5260
|
+
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
5261
|
}));
|
|
5082
5262
|
}));
|
|
5083
|
-
i && (t =
|
|
5084
|
-
n = _("FCP"), t =
|
|
5263
|
+
i && (t = y(s, n, be, e.reportAllChanges), k((function(o) {
|
|
5264
|
+
n = _("FCP"), t = y(s, n, be, e.reportAllChanges), Oe((function() {
|
|
5085
5265
|
n.value = performance.now() - o.timeStamp, t(!0);
|
|
5086
5266
|
}));
|
|
5087
5267
|
})));
|
|
5088
5268
|
}));
|
|
5089
|
-
},
|
|
5090
|
-
e = e || {},
|
|
5269
|
+
}, Ae = [0.1, 0.25], jr = function(s, e) {
|
|
5270
|
+
e = e || {}, gt(le((function() {
|
|
5091
5271
|
var t, r = _("CLS", 0), n = 0, i = [], o = function(c) {
|
|
5092
5272
|
c.forEach((function(u) {
|
|
5093
5273
|
if (!u.hadRecentInput) {
|
|
@@ -5095,191 +5275,191 @@ var _e, C, X, ct, ne, ut = -1, k = function(s) {
|
|
|
5095
5275
|
n && u.startTime - E.startTime < 1e3 && u.startTime - g.startTime < 5e3 ? (n += u.value, i.push(u)) : (n = u.value, i = [u]);
|
|
5096
5276
|
}
|
|
5097
5277
|
})), n > r.value && (r.value = n, r.entries = i, t());
|
|
5098
|
-
},
|
|
5099
|
-
|
|
5100
|
-
o(
|
|
5278
|
+
}, l = F("layout-shift", o);
|
|
5279
|
+
l && (t = y(s, r, Ae, e.reportAllChanges), z((function() {
|
|
5280
|
+
o(l.takeRecords()), t(!0);
|
|
5101
5281
|
})), k((function() {
|
|
5102
|
-
n = 0, r = _("CLS", 0), t =
|
|
5282
|
+
n = 0, r = _("CLS", 0), t = y(s, r, Ae, e.reportAllChanges), Oe((function() {
|
|
5103
5283
|
return t();
|
|
5104
5284
|
}));
|
|
5105
5285
|
})), setTimeout(t, 0));
|
|
5106
5286
|
})));
|
|
5107
|
-
},
|
|
5287
|
+
}, Et = 0, me = 1 / 0, Z = 0, Qr = function(s) {
|
|
5108
5288
|
s.forEach((function(e) {
|
|
5109
|
-
e.interactionId && (
|
|
5289
|
+
e.interactionId && (me = Math.min(me, e.interactionId), Z = Math.max(Z, e.interactionId), Et = Z ? (Z - me) / 7 + 1 : 0);
|
|
5110
5290
|
}));
|
|
5111
|
-
},
|
|
5112
|
-
return
|
|
5113
|
-
},
|
|
5114
|
-
"interactionCount" in performance ||
|
|
5115
|
-
}, A = [],
|
|
5116
|
-
var s = Math.min(A.length - 1, Math.floor((
|
|
5291
|
+
}, St = function() {
|
|
5292
|
+
return we ? Et : performance.interactionCount || 0;
|
|
5293
|
+
}, zr = function() {
|
|
5294
|
+
"interactionCount" in performance || we || (we = F("event", Qr, { type: "event", buffered: !0, durationThreshold: 0 }));
|
|
5295
|
+
}, A = [], re = /* @__PURE__ */ new Map(), pt = 0, Kr = function() {
|
|
5296
|
+
var s = Math.min(A.length - 1, Math.floor((St() - pt) / 50));
|
|
5117
5297
|
return A[s];
|
|
5118
|
-
},
|
|
5119
|
-
if (
|
|
5298
|
+
}, Yr = [], qr = function(s) {
|
|
5299
|
+
if (Yr.forEach((function(n) {
|
|
5120
5300
|
return n(s);
|
|
5121
5301
|
})), s.interactionId || s.entryType === "first-input") {
|
|
5122
|
-
var e = A[A.length - 1], t =
|
|
5302
|
+
var e = A[A.length - 1], t = re.get(s.interactionId);
|
|
5123
5303
|
if (t || A.length < 10 || s.duration > e.latency) {
|
|
5124
5304
|
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
5305
|
else {
|
|
5126
5306
|
var r = { id: s.interactionId, latency: s.duration, entries: [s] };
|
|
5127
|
-
|
|
5307
|
+
re.set(r.id, r), A.push(r);
|
|
5128
5308
|
}
|
|
5129
5309
|
A.sort((function(n, i) {
|
|
5130
5310
|
return i.latency - n.latency;
|
|
5131
5311
|
})), A.length > 10 && A.splice(10).forEach((function(n) {
|
|
5132
|
-
return
|
|
5312
|
+
return re.delete(n.id);
|
|
5133
5313
|
}));
|
|
5134
5314
|
}
|
|
5135
5315
|
}
|
|
5136
|
-
},
|
|
5316
|
+
}, Tt = function(s) {
|
|
5137
5317
|
var e = self.requestIdleCallback || self.setTimeout, t = -1;
|
|
5138
|
-
return s =
|
|
5139
|
-
},
|
|
5140
|
-
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {},
|
|
5318
|
+
return s = le(s), document.visibilityState === "hidden" ? s() : (t = e(s), z(s)), t;
|
|
5319
|
+
}, Le = [200, 500], Jr = function(s, e) {
|
|
5320
|
+
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, K((function() {
|
|
5141
5321
|
var t;
|
|
5142
|
-
|
|
5143
|
-
var r, n = _("INP"), i = function(
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
var c =
|
|
5322
|
+
zr();
|
|
5323
|
+
var r, n = _("INP"), i = function(l) {
|
|
5324
|
+
Tt((function() {
|
|
5325
|
+
l.forEach(qr);
|
|
5326
|
+
var c = Kr();
|
|
5147
5327
|
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, r());
|
|
5148
5328
|
}));
|
|
5149
|
-
}, o =
|
|
5150
|
-
r =
|
|
5329
|
+
}, o = F("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
|
|
5330
|
+
r = y(s, n, Le, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), z((function() {
|
|
5151
5331
|
i(o.takeRecords()), r(!0);
|
|
5152
5332
|
})), k((function() {
|
|
5153
|
-
|
|
5333
|
+
pt = St(), A.length = 0, re.clear(), n = _("INP"), r = y(s, n, Le, e.reportAllChanges);
|
|
5154
5334
|
})));
|
|
5155
5335
|
})));
|
|
5156
|
-
},
|
|
5157
|
-
e = e || {},
|
|
5158
|
-
var t, r =
|
|
5336
|
+
}, Me = [2500, 4e3], ge = {}, Zr = function(s, e) {
|
|
5337
|
+
e = e || {}, K((function() {
|
|
5338
|
+
var t, r = Pe(), n = _("LCP"), i = function(c) {
|
|
5159
5339
|
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(u) {
|
|
5160
|
-
u.startTime < r.firstHiddenTime && (n.value = Math.max(u.startTime -
|
|
5340
|
+
u.startTime < r.firstHiddenTime && (n.value = Math.max(u.startTime - ae(), 0), n.entries = [u], t());
|
|
5161
5341
|
}));
|
|
5162
|
-
}, o =
|
|
5342
|
+
}, o = F("largest-contentful-paint", i);
|
|
5163
5343
|
if (o) {
|
|
5164
|
-
t =
|
|
5165
|
-
var
|
|
5166
|
-
|
|
5344
|
+
t = y(s, n, Me, e.reportAllChanges);
|
|
5345
|
+
var l = le((function() {
|
|
5346
|
+
ge[n.id] || (i(o.takeRecords()), o.disconnect(), ge[n.id] = !0, t(!0));
|
|
5167
5347
|
}));
|
|
5168
5348
|
["keydown", "click"].forEach((function(c) {
|
|
5169
5349
|
addEventListener(c, (function() {
|
|
5170
|
-
return
|
|
5350
|
+
return Tt(l);
|
|
5171
5351
|
}), { once: !0, capture: !0 });
|
|
5172
|
-
})),
|
|
5173
|
-
n = _("LCP"), t =
|
|
5174
|
-
n.value = performance.now() - c.timeStamp,
|
|
5352
|
+
})), z(l), k((function(c) {
|
|
5353
|
+
n = _("LCP"), t = y(s, n, Me, e.reportAllChanges), Oe((function() {
|
|
5354
|
+
n.value = performance.now() - c.timeStamp, ge[n.id] = !0, t(!0);
|
|
5175
5355
|
}));
|
|
5176
5356
|
}));
|
|
5177
5357
|
}
|
|
5178
5358
|
}));
|
|
5179
|
-
},
|
|
5180
|
-
document.prerendering ?
|
|
5359
|
+
}, Ce = [800, 1800], es = function s(e) {
|
|
5360
|
+
document.prerendering ? K((function() {
|
|
5181
5361
|
return s(e);
|
|
5182
5362
|
})) : document.readyState !== "complete" ? addEventListener("load", (function() {
|
|
5183
5363
|
return s(e);
|
|
5184
5364
|
}), !0) : setTimeout(e, 0);
|
|
5185
|
-
},
|
|
5365
|
+
}, ts = function(s, e) {
|
|
5186
5366
|
e = e || {};
|
|
5187
|
-
var t = _("TTFB"), r =
|
|
5188
|
-
|
|
5189
|
-
var n =
|
|
5190
|
-
n && (t.value = Math.max(n.responseStart -
|
|
5191
|
-
t = _("TTFB", 0), (r =
|
|
5367
|
+
var t = _("TTFB"), r = y(s, t, Ce, e.reportAllChanges);
|
|
5368
|
+
es((function() {
|
|
5369
|
+
var n = Ne();
|
|
5370
|
+
n && (t.value = Math.max(n.responseStart - ae(), 0), t.entries = [n], r(!0), k((function() {
|
|
5371
|
+
t = _("TTFB", 0), (r = y(s, t, Ce, e.reportAllChanges))(!0);
|
|
5192
5372
|
})));
|
|
5193
5373
|
}));
|
|
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
|
-
|
|
5374
|
+
}, G = { passive: !0, capture: !0 }, rs = /* @__PURE__ */ new Date(), Ze = function(s, e) {
|
|
5375
|
+
C || (C = e, j = s, ft = /* @__PURE__ */ new Date(), vt(removeEventListener), It());
|
|
5376
|
+
}, It = function() {
|
|
5377
|
+
if (j >= 0 && j < ft - rs) {
|
|
5378
|
+
var s = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp + j };
|
|
5379
|
+
ie.forEach((function(e) {
|
|
5200
5380
|
e(s);
|
|
5201
|
-
})),
|
|
5381
|
+
})), ie = [];
|
|
5202
5382
|
}
|
|
5203
|
-
},
|
|
5383
|
+
}, ss = function(s) {
|
|
5204
5384
|
if (s.cancelable) {
|
|
5205
5385
|
var e = (s.timeStamp > 1e12 ? /* @__PURE__ */ new Date() : performance.now()) - s.timeStamp;
|
|
5206
5386
|
s.type == "pointerdown" ? (function(t, r) {
|
|
5207
5387
|
var n = function() {
|
|
5208
|
-
|
|
5388
|
+
Ze(t, r), o();
|
|
5209
5389
|
}, i = function() {
|
|
5210
5390
|
o();
|
|
5211
5391
|
}, o = function() {
|
|
5212
|
-
removeEventListener("pointerup", n,
|
|
5392
|
+
removeEventListener("pointerup", n, G), removeEventListener("pointercancel", i, G);
|
|
5213
5393
|
};
|
|
5214
|
-
addEventListener("pointerup", n,
|
|
5215
|
-
})(e, s) :
|
|
5394
|
+
addEventListener("pointerup", n, G), addEventListener("pointercancel", i, G);
|
|
5395
|
+
})(e, s) : Ze(e, s);
|
|
5216
5396
|
}
|
|
5217
|
-
},
|
|
5397
|
+
}, vt = function(s) {
|
|
5218
5398
|
["mousedown", "keydown", "touchstart", "pointerdown"].forEach((function(e) {
|
|
5219
|
-
return s(e,
|
|
5399
|
+
return s(e, ss, G);
|
|
5220
5400
|
}));
|
|
5221
|
-
},
|
|
5222
|
-
e = e || {},
|
|
5223
|
-
var t, r =
|
|
5401
|
+
}, Re = [100, 300], ns = function(s, e) {
|
|
5402
|
+
e = e || {}, K((function() {
|
|
5403
|
+
var t, r = Pe(), n = _("FID"), i = function(c) {
|
|
5224
5404
|
c.startTime < r.firstHiddenTime && (n.value = c.processingStart - c.startTime, n.entries.push(c), t(!0));
|
|
5225
5405
|
}, o = function(c) {
|
|
5226
5406
|
c.forEach(i);
|
|
5227
|
-
},
|
|
5228
|
-
t =
|
|
5229
|
-
o(
|
|
5407
|
+
}, l = F("first-input", o);
|
|
5408
|
+
t = y(s, n, Re, e.reportAllChanges), l && (z(le((function() {
|
|
5409
|
+
o(l.takeRecords()), l.disconnect();
|
|
5230
5410
|
}))), k((function() {
|
|
5231
5411
|
var c;
|
|
5232
|
-
n = _("FID"), t =
|
|
5412
|
+
n = _("FID"), t = y(s, n, Re, e.reportAllChanges), ie = [], j = -1, C = null, vt(addEventListener), c = i, ie.push(c), It();
|
|
5233
5413
|
})));
|
|
5234
5414
|
}));
|
|
5235
5415
|
};
|
|
5236
|
-
const
|
|
5416
|
+
const is = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5237
5417
|
__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:
|
|
5418
|
+
CLSThresholds: Ae,
|
|
5419
|
+
FCPThresholds: be,
|
|
5420
|
+
FIDThresholds: Re,
|
|
5421
|
+
INPThresholds: Le,
|
|
5422
|
+
LCPThresholds: Me,
|
|
5423
|
+
TTFBThresholds: Ce,
|
|
5424
|
+
onCLS: jr,
|
|
5425
|
+
onFCP: gt,
|
|
5426
|
+
onFID: ns,
|
|
5427
|
+
onINP: Jr,
|
|
5428
|
+
onLCP: Zr,
|
|
5429
|
+
onTTFB: ts
|
|
5250
5430
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
5251
5431
|
export {
|
|
5252
5432
|
f as AppConfigValidationError,
|
|
5253
|
-
|
|
5254
|
-
|
|
5433
|
+
os as DEFAULT_SESSION_TIMEOUT,
|
|
5434
|
+
Ie as DEFAULT_WEB_VITALS_MODE,
|
|
5255
5435
|
L as DeviceType,
|
|
5256
|
-
|
|
5257
|
-
|
|
5436
|
+
Se as EmitterEvent,
|
|
5437
|
+
W as ErrorType,
|
|
5258
5438
|
d as EventType,
|
|
5259
|
-
|
|
5439
|
+
Ss as InitializationTimeoutError,
|
|
5260
5440
|
U as IntegrationValidationError,
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5441
|
+
ms as MAX_ARRAY_LENGTH,
|
|
5442
|
+
us as MAX_CUSTOM_EVENT_ARRAY_SIZE,
|
|
5443
|
+
cs as MAX_CUSTOM_EVENT_KEYS,
|
|
5444
|
+
as as MAX_CUSTOM_EVENT_NAME_LENGTH,
|
|
5445
|
+
ls as MAX_CUSTOM_EVENT_STRING_SIZE,
|
|
5446
|
+
ds as MAX_NESTED_OBJECT_KEYS,
|
|
5447
|
+
hs as MAX_STRING_LENGTH,
|
|
5448
|
+
fs as MAX_STRING_LENGTH_IN_ARRAY,
|
|
5449
|
+
se as Mode,
|
|
5450
|
+
nt as PII_PATTERNS,
|
|
5271
5451
|
N as PermanentError,
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5452
|
+
$e as SamplingRateValidationError,
|
|
5453
|
+
ee as ScrollDirection,
|
|
5454
|
+
Ct as SessionTimeoutValidationError,
|
|
5455
|
+
B as SpecialApiUrl,
|
|
5276
5456
|
O as TimeoutError,
|
|
5277
5457
|
Q as TraceLogValidationError,
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5458
|
+
ps as WEB_VITALS_GOOD_THRESHOLDS,
|
|
5459
|
+
Xe as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
|
|
5460
|
+
Xt as WEB_VITALS_POOR_THRESHOLDS,
|
|
5461
|
+
je as getWebVitalsThresholds,
|
|
5462
|
+
gs as isPrimaryScrollEvent,
|
|
5463
|
+
Es as isSecondaryScrollEvent,
|
|
5464
|
+
Ts as tracelog
|
|
5285
5465
|
};
|