@tracelog/lib 2.6.2 → 2.7.0-rc.95.2
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 +11 -3
- package/dist/browser/tracelog.esm.js +810 -634
- 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 +25 -5
- package/dist/public-api.d.ts +25 -5
- 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 = 65536, cs = 100, us = 500, ds = 200;
|
|
3
|
+
const hs = 1e3, fs = 500, ms = 1e3;
|
|
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.7.0", 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,
|
|
465
|
+
return s.slice(0, 1e3).map((n) => _e(n, e + 1)).filter((n) => n !== null);
|
|
466
466
|
if (typeof s == "object") {
|
|
467
|
-
const t = {}, n = Object.entries(s).slice(0,
|
|
467
|
+
const t = {}, n = Object.entries(s).slice(0, 200);
|
|
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.`
|
|
@@ -667,41 +673,41 @@ const Jt = () => {
|
|
|
667
673
|
error: `${n}: object contains circular references or cannot be serialized.`
|
|
668
674
|
};
|
|
669
675
|
}
|
|
670
|
-
if (i.length >
|
|
676
|
+
if (i.length > 65536)
|
|
671
677
|
return {
|
|
672
678
|
valid: !1,
|
|
673
|
-
error: `${n}: object is too large (max ${
|
|
679
|
+
error: `${n}: object is too large (max ${65536 / 1024} KB).`
|
|
674
680
|
};
|
|
675
|
-
if (Object.keys(r).length >
|
|
681
|
+
if (Object.keys(r).length > 100)
|
|
676
682
|
return {
|
|
677
683
|
valid: !1,
|
|
678
|
-
error: `${n}: object has too many keys (max
|
|
684
|
+
error: `${n}: object has too many keys (max 100 keys).`
|
|
679
685
|
};
|
|
680
|
-
for (const [
|
|
686
|
+
for (const [l, c] of Object.entries(r)) {
|
|
681
687
|
if (Array.isArray(c)) {
|
|
682
|
-
if (c.length >
|
|
688
|
+
if (c.length > 500)
|
|
683
689
|
return {
|
|
684
690
|
valid: !1,
|
|
685
|
-
error: `${n}: array property "${
|
|
691
|
+
error: `${n}: array property "${l}" is too large (max 500 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
|
|
@@ -2555,7 +2562,7 @@ class fr extends w {
|
|
|
2555
2562
|
addToQueue(e) {
|
|
2556
2563
|
if (this.emitEvent(e), this.eventsQueue.push(e), this.eventsQueue.length > 100) {
|
|
2557
2564
|
const t = this.eventsQueue.findIndex((n) => n.type !== d.SESSION_START), r = t >= 0 ? this.eventsQueue.splice(t, 1)[0] : this.eventsQueue.shift();
|
|
2558
|
-
|
|
2565
|
+
a("warn", "Event queue overflow, oldest non-critical event removed", {
|
|
2559
2566
|
data: {
|
|
2560
2567
|
maxLength: 100,
|
|
2561
2568
|
currentLength: this.eventsQueue.length,
|
|
@@ -2589,7 +2596,7 @@ class fr extends w {
|
|
|
2589
2596
|
}
|
|
2590
2597
|
checkPerEventRateLimit(e, t) {
|
|
2591
2598
|
const r = Date.now(), i = (this.perEventRateLimits.get(e) ?? []).filter((o) => r - o < 6e4);
|
|
2592
|
-
return i.length >= t ? (
|
|
2599
|
+
return i.length >= t ? (a("warn", "Per-event rate limit exceeded for custom event", {
|
|
2593
2600
|
data: {
|
|
2594
2601
|
eventName: e,
|
|
2595
2602
|
limit: t,
|
|
@@ -2611,10 +2618,10 @@ class fr extends w {
|
|
|
2611
2618
|
this.eventsQueue = this.eventsQueue.filter((r) => !t.has(r.id));
|
|
2612
2619
|
}
|
|
2613
2620
|
emitEvent(e) {
|
|
2614
|
-
this.emitter && this.emitter.emit(
|
|
2621
|
+
this.emitter && this.emitter.emit(Se.EVENT, e);
|
|
2615
2622
|
}
|
|
2616
2623
|
emitEventsQueue(e) {
|
|
2617
|
-
this.emitter && this.emitter.emit(
|
|
2624
|
+
this.emitter && this.emitter.emit(Se.QUEUE, e);
|
|
2618
2625
|
}
|
|
2619
2626
|
/**
|
|
2620
2627
|
* Creates a debounced version of a function that delays execution until after
|
|
@@ -2690,13 +2697,13 @@ class fr extends w {
|
|
|
2690
2697
|
loadSessionCounts(e) {
|
|
2691
2698
|
if (typeof window > "u" || typeof localStorage > "u")
|
|
2692
2699
|
return this.getInitialCounts();
|
|
2693
|
-
const t = this.get("userId") || "anonymous", r =
|
|
2700
|
+
const t = this.get("userId") || "anonymous", r = Ue(t, e);
|
|
2694
2701
|
try {
|
|
2695
2702
|
const n = localStorage.getItem(r);
|
|
2696
2703
|
if (!n)
|
|
2697
2704
|
return this.getInitialCounts();
|
|
2698
2705
|
const i = JSON.parse(n);
|
|
2699
|
-
return i._timestamp && Date.now() - i._timestamp >
|
|
2706
|
+
return i._timestamp && Date.now() - i._timestamp > He ? (a("debug", "Session counts expired, clearing", {
|
|
2700
2707
|
data: { sessionId: e, age: Date.now() - i._timestamp }
|
|
2701
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" ? {
|
|
2702
2709
|
total: i.total,
|
|
@@ -2705,13 +2712,13 @@ class fr extends w {
|
|
|
2705
2712
|
[d.CUSTOM]: i[d.CUSTOM],
|
|
2706
2713
|
[d.VIEWPORT_VISIBLE]: i[d.VIEWPORT_VISIBLE],
|
|
2707
2714
|
[d.SCROLL]: i[d.SCROLL]
|
|
2708
|
-
} : (
|
|
2715
|
+
} : (a("warn", "Invalid session counts structure in localStorage, resetting", {
|
|
2709
2716
|
data: { sessionId: e, parsed: i }
|
|
2710
|
-
}), localStorage.removeItem(r),
|
|
2717
|
+
}), localStorage.removeItem(r), a("debug", "Session counts removed due to invalid/corrupted data", {
|
|
2711
2718
|
data: { sessionId: e, parsed: i }
|
|
2712
2719
|
}), this.getInitialCounts());
|
|
2713
2720
|
} catch (n) {
|
|
2714
|
-
return
|
|
2721
|
+
return a("warn", "Failed to load session counts from localStorage", {
|
|
2715
2722
|
error: n,
|
|
2716
2723
|
data: { sessionId: e }
|
|
2717
2724
|
}), this.getInitialCounts();
|
|
@@ -2741,34 +2748,34 @@ class fr extends w {
|
|
|
2741
2748
|
cleanupExpiredSessionCounts() {
|
|
2742
2749
|
if (!(typeof window > "u" || typeof localStorage > "u"))
|
|
2743
2750
|
try {
|
|
2744
|
-
const e = localStorage.getItem(
|
|
2751
|
+
const e = localStorage.getItem(xe);
|
|
2745
2752
|
if (e) {
|
|
2746
2753
|
const i = Date.now() - parseInt(e, 10);
|
|
2747
|
-
if (i <
|
|
2748
|
-
|
|
2749
|
-
data: { timeSinceLastCleanup: i, throttleMs:
|
|
2754
|
+
if (i < Fe) {
|
|
2755
|
+
a("debug", "Skipping session counts cleanup (throttled)", {
|
|
2756
|
+
data: { timeSinceLastCleanup: i, throttleMs: Fe }
|
|
2750
2757
|
});
|
|
2751
2758
|
return;
|
|
2752
2759
|
}
|
|
2753
2760
|
}
|
|
2754
|
-
const t = this.get("userId") || "anonymous", r = `${
|
|
2761
|
+
const t = this.get("userId") || "anonymous", r = `${I}:${t}:session_counts:`, n = [];
|
|
2755
2762
|
for (let i = 0; i < localStorage.length; i++) {
|
|
2756
2763
|
const o = localStorage.key(i);
|
|
2757
2764
|
if (o?.startsWith(r))
|
|
2758
2765
|
try {
|
|
2759
|
-
const
|
|
2760
|
-
if (
|
|
2761
|
-
const c = JSON.parse(
|
|
2762
|
-
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);
|
|
2763
2770
|
}
|
|
2764
2771
|
} catch {
|
|
2765
2772
|
}
|
|
2766
2773
|
}
|
|
2767
2774
|
n.forEach((i) => {
|
|
2768
|
-
localStorage.removeItem(i),
|
|
2769
|
-
}), 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());
|
|
2770
2777
|
} catch (e) {
|
|
2771
|
-
|
|
2778
|
+
a("warn", "Failed to cleanup expired session counts", { error: e });
|
|
2772
2779
|
}
|
|
2773
2780
|
}
|
|
2774
2781
|
/**
|
|
@@ -2800,7 +2807,7 @@ class fr extends w {
|
|
|
2800
2807
|
* @internal
|
|
2801
2808
|
*/
|
|
2802
2809
|
saveSessionCounts(e) {
|
|
2803
|
-
const t = this.get("userId") || "anonymous", r =
|
|
2810
|
+
const t = this.get("userId") || "anonymous", r = Ue(t, e);
|
|
2804
2811
|
try {
|
|
2805
2812
|
const n = {
|
|
2806
2813
|
...this.sessionEventCounts,
|
|
@@ -2809,14 +2816,14 @@ class fr extends w {
|
|
|
2809
2816
|
};
|
|
2810
2817
|
localStorage.setItem(r, JSON.stringify(n));
|
|
2811
2818
|
} catch (n) {
|
|
2812
|
-
|
|
2819
|
+
a("warn", "Failed to persist session counts to localStorage", {
|
|
2813
2820
|
error: n,
|
|
2814
2821
|
data: { sessionId: e }
|
|
2815
2822
|
});
|
|
2816
2823
|
}
|
|
2817
2824
|
}
|
|
2818
2825
|
}
|
|
2819
|
-
class
|
|
2826
|
+
class Sr {
|
|
2820
2827
|
/**
|
|
2821
2828
|
* Gets or creates a unique user ID.
|
|
2822
2829
|
*
|
|
@@ -2834,15 +2841,15 @@ class mr {
|
|
|
2834
2841
|
* @returns Persistent unique user ID (UUID v4 format)
|
|
2835
2842
|
*/
|
|
2836
2843
|
static getId(e) {
|
|
2837
|
-
const t = e.getItem(
|
|
2844
|
+
const t = e.getItem(Ee);
|
|
2838
2845
|
if (t)
|
|
2839
2846
|
return t;
|
|
2840
|
-
const r =
|
|
2841
|
-
return e.setItem(
|
|
2847
|
+
const r = at();
|
|
2848
|
+
return e.setItem(Ee, r), r;
|
|
2842
2849
|
}
|
|
2843
2850
|
}
|
|
2844
|
-
const
|
|
2845
|
-
class
|
|
2851
|
+
const pr = /^\d{13}-[a-z0-9]{9}$/;
|
|
2852
|
+
class Tr extends w {
|
|
2846
2853
|
storageManager;
|
|
2847
2854
|
eventManager;
|
|
2848
2855
|
projectId;
|
|
@@ -2864,13 +2871,13 @@ class Er extends w {
|
|
|
2864
2871
|
}
|
|
2865
2872
|
initCrossTabSync() {
|
|
2866
2873
|
if (typeof BroadcastChannel > "u") {
|
|
2867
|
-
|
|
2874
|
+
a("debug", "BroadcastChannel not supported");
|
|
2868
2875
|
return;
|
|
2869
2876
|
}
|
|
2870
2877
|
const e = this.getProjectId();
|
|
2871
|
-
this.broadcastChannel = new BroadcastChannel(
|
|
2878
|
+
this.broadcastChannel = new BroadcastChannel(Mt(e)), this.broadcastChannel.onmessage = (t) => {
|
|
2872
2879
|
const { action: r, sessionId: n, timestamp: i, projectId: o } = t.data ?? {};
|
|
2873
|
-
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 } }));
|
|
2874
2881
|
};
|
|
2875
2882
|
}
|
|
2876
2883
|
shareSession(e) {
|
|
@@ -2888,8 +2895,8 @@ class Er extends w {
|
|
|
2888
2895
|
const e = this.loadStoredSession();
|
|
2889
2896
|
if (!e)
|
|
2890
2897
|
return null;
|
|
2891
|
-
if (!
|
|
2892
|
-
return
|
|
2898
|
+
if (!pr.test(e.id))
|
|
2899
|
+
return a("warn", "Invalid session ID format recovered from storage, clearing", {
|
|
2893
2900
|
data: { sessionId: e.id }
|
|
2894
2901
|
}), this.clearStoredSession(), null;
|
|
2895
2902
|
const t = this.get("config")?.sessionTimeout ?? 9e5;
|
|
@@ -2933,7 +2940,7 @@ class Er extends w {
|
|
|
2933
2940
|
this.storageManager.setItem(t, r), this.storageManager.setSessionItem(t, r);
|
|
2934
2941
|
}
|
|
2935
2942
|
getSessionStorageKey() {
|
|
2936
|
-
return
|
|
2943
|
+
return Lt(this.getProjectId());
|
|
2937
2944
|
}
|
|
2938
2945
|
getProjectId() {
|
|
2939
2946
|
return this.projectId;
|
|
@@ -2992,17 +2999,17 @@ class Er extends w {
|
|
|
2992
2999
|
*/
|
|
2993
3000
|
startTracking() {
|
|
2994
3001
|
if (this.isTracking) {
|
|
2995
|
-
|
|
3002
|
+
a("debug", "Session tracking already active");
|
|
2996
3003
|
return;
|
|
2997
3004
|
}
|
|
2998
3005
|
const e = this.recoverSession(), t = e ?? this.generateSessionId();
|
|
2999
3006
|
let r, n;
|
|
3000
3007
|
if (e) {
|
|
3001
3008
|
const i = this.loadStoredSession();
|
|
3002
|
-
r = i?.referrer ??
|
|
3009
|
+
r = i?.referrer ?? de(), n = i?.utm ?? he();
|
|
3003
3010
|
} else
|
|
3004
|
-
r =
|
|
3005
|
-
|
|
3011
|
+
r = de(), n = he();
|
|
3012
|
+
a("debug", "Session tracking initialized", {
|
|
3006
3013
|
data: {
|
|
3007
3014
|
sessionId: t,
|
|
3008
3015
|
wasRecovered: !!e,
|
|
@@ -3012,9 +3019,9 @@ class Er extends w {
|
|
|
3012
3019
|
}
|
|
3013
3020
|
}), this.isTracking = !0;
|
|
3014
3021
|
try {
|
|
3015
|
-
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", {
|
|
3016
3023
|
data: { sessionId: t }
|
|
3017
|
-
}) : (
|
|
3024
|
+
}) : (a("debug", "Emitting SESSION_START event", {
|
|
3018
3025
|
data: { sessionId: t }
|
|
3019
3026
|
}), this.eventManager.track({
|
|
3020
3027
|
type: d.SESSION_START
|
|
@@ -3052,8 +3059,8 @@ class Er extends w {
|
|
|
3052
3059
|
*/
|
|
3053
3060
|
renewSession() {
|
|
3054
3061
|
this.needsRenewal = !1;
|
|
3055
|
-
const e = this.generateSessionId(), t =
|
|
3056
|
-
|
|
3062
|
+
const e = this.generateSessionId(), t = de(), r = he();
|
|
3063
|
+
a("debug", "Renewing session after timeout", {
|
|
3057
3064
|
data: { newSessionId: e }
|
|
3058
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({
|
|
3059
3066
|
type: d.SESSION_START
|
|
@@ -3068,7 +3075,7 @@ class Er extends w {
|
|
|
3068
3075
|
this.clearSessionTimeout();
|
|
3069
3076
|
else {
|
|
3070
3077
|
if (this.isSessionStale()) {
|
|
3071
|
-
|
|
3078
|
+
a("debug", "Session expired during suspend, entering renewal mode"), this.enterRenewalMode();
|
|
3072
3079
|
return;
|
|
3073
3080
|
}
|
|
3074
3081
|
this.get("sessionId") && this.setupSessionTimeout();
|
|
@@ -3097,7 +3104,7 @@ class Er extends w {
|
|
|
3097
3104
|
* Called by session timeout timer.
|
|
3098
3105
|
*/
|
|
3099
3106
|
enterRenewalMode() {
|
|
3100
|
-
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");
|
|
3101
3108
|
}
|
|
3102
3109
|
/**
|
|
3103
3110
|
* Fully resets session state and cleans up all resources.
|
|
@@ -3173,7 +3180,7 @@ class Er extends w {
|
|
|
3173
3180
|
this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupCrossTabSync(), this.cleanupLifecycleListeners(), this.isTracking = !1, this.needsRenewal = !1, this.set("hasStartSession", !1);
|
|
3174
3181
|
}
|
|
3175
3182
|
}
|
|
3176
|
-
class
|
|
3183
|
+
class Ir extends w {
|
|
3177
3184
|
eventManager;
|
|
3178
3185
|
storageManager;
|
|
3179
3186
|
sessionManager = null;
|
|
@@ -3203,12 +3210,12 @@ class Sr extends w {
|
|
|
3203
3210
|
if (this.isActive())
|
|
3204
3211
|
return;
|
|
3205
3212
|
if (this.destroyed) {
|
|
3206
|
-
|
|
3213
|
+
a("debug", "Cannot start tracking on destroyed handler");
|
|
3207
3214
|
return;
|
|
3208
3215
|
}
|
|
3209
3216
|
const t = this.get("config")?.integrations?.tracelog?.projectId ?? "custom";
|
|
3210
3217
|
try {
|
|
3211
|
-
this.sessionManager = new
|
|
3218
|
+
this.sessionManager = new Tr(this.storageManager, this.eventManager, t), this.sessionManager.startTracking(), this.eventManager.flushPendingEvents();
|
|
3212
3219
|
} catch (r) {
|
|
3213
3220
|
if (this.sessionManager) {
|
|
3214
3221
|
try {
|
|
@@ -3217,7 +3224,7 @@ class Sr extends w {
|
|
|
3217
3224
|
}
|
|
3218
3225
|
this.sessionManager = null;
|
|
3219
3226
|
}
|
|
3220
|
-
throw
|
|
3227
|
+
throw a("error", "Failed to start session tracking", { error: r }), r;
|
|
3221
3228
|
}
|
|
3222
3229
|
}
|
|
3223
3230
|
isActive() {
|
|
@@ -3261,7 +3268,7 @@ class Sr extends w {
|
|
|
3261
3268
|
this.destroyed || (this.sessionManager && (this.sessionManager.destroy(), this.sessionManager = null), this.destroyed = !0);
|
|
3262
3269
|
}
|
|
3263
3270
|
}
|
|
3264
|
-
class
|
|
3271
|
+
class vr extends w {
|
|
3265
3272
|
eventManager;
|
|
3266
3273
|
onTrack;
|
|
3267
3274
|
originalPushState;
|
|
@@ -3301,7 +3308,7 @@ class pr extends w {
|
|
|
3301
3308
|
};
|
|
3302
3309
|
}
|
|
3303
3310
|
trackCurrentPage = () => {
|
|
3304
|
-
const e = window.location.href, t =
|
|
3311
|
+
const e = window.location.href, t = ve(e, this.get("config").sensitiveQueryParams);
|
|
3305
3312
|
if (this.get("pageUrl") === t)
|
|
3306
3313
|
return;
|
|
3307
3314
|
const r = Date.now(), n = this.get("config").pageViewThrottleMs ?? 1e3;
|
|
@@ -3319,7 +3326,7 @@ class pr extends w {
|
|
|
3319
3326
|
});
|
|
3320
3327
|
};
|
|
3321
3328
|
trackInitialPageView() {
|
|
3322
|
-
const e =
|
|
3329
|
+
const e = ve(window.location.href, this.get("config").sensitiveQueryParams), t = this.extractPageViewData();
|
|
3323
3330
|
this.lastPageViewTime = Date.now(), this.eventManager.track({
|
|
3324
3331
|
type: d.PAGE_VIEW,
|
|
3325
3332
|
page_url: e,
|
|
@@ -3337,7 +3344,7 @@ class pr extends w {
|
|
|
3337
3344
|
};
|
|
3338
3345
|
}
|
|
3339
3346
|
}
|
|
3340
|
-
class
|
|
3347
|
+
class _r extends w {
|
|
3341
3348
|
eventManager;
|
|
3342
3349
|
lastClickTimes = /* @__PURE__ */ new Map();
|
|
3343
3350
|
clickHandler;
|
|
@@ -3362,7 +3369,7 @@ class Tr extends w {
|
|
|
3362
3369
|
this.clickHandler || (this.clickHandler = (e) => {
|
|
3363
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;
|
|
3364
3371
|
if (!n) {
|
|
3365
|
-
|
|
3372
|
+
a("debug", "Click target not found or not an element");
|
|
3366
3373
|
return;
|
|
3367
3374
|
}
|
|
3368
3375
|
if (this.shouldIgnoreElement(n))
|
|
@@ -3370,7 +3377,7 @@ class Tr extends w {
|
|
|
3370
3377
|
const i = this.get("config")?.clickThrottleMs ?? 300;
|
|
3371
3378
|
if (i > 0 && !this.checkClickThrottle(n, i))
|
|
3372
3379
|
return;
|
|
3373
|
-
const o = this.findTrackingElement(n),
|
|
3380
|
+
const o = this.findTrackingElement(n), l = this.getRelevantClickElement(n), c = this.calculateClickCoordinates(t, n);
|
|
3374
3381
|
if (o) {
|
|
3375
3382
|
const g = this.extractTrackingData(o);
|
|
3376
3383
|
if (g) {
|
|
@@ -3384,7 +3391,7 @@ class Tr extends w {
|
|
|
3384
3391
|
});
|
|
3385
3392
|
}
|
|
3386
3393
|
}
|
|
3387
|
-
const u = this.generateClickData(n,
|
|
3394
|
+
const u = this.generateClickData(n, l, c);
|
|
3388
3395
|
this.eventManager.track({
|
|
3389
3396
|
type: d.CLICK,
|
|
3390
3397
|
click_data: u
|
|
@@ -3411,7 +3418,7 @@ class Tr extends w {
|
|
|
3411
3418
|
const r = this.getElementSignature(e), n = Date.now();
|
|
3412
3419
|
this.pruneThrottleCache(n);
|
|
3413
3420
|
const i = this.lastClickTimes.get(r);
|
|
3414
|
-
return i !== void 0 && n - i < t ? (
|
|
3421
|
+
return i !== void 0 && n - i < t ? (a("debug", "ClickHandler: Click suppressed by throttle", {
|
|
3415
3422
|
data: {
|
|
3416
3423
|
signature: r,
|
|
3417
3424
|
throttleRemaining: t - (n - i)
|
|
@@ -3431,10 +3438,10 @@ class Tr extends w {
|
|
|
3431
3438
|
for (const [r, n] of this.lastClickTimes.entries())
|
|
3432
3439
|
n < t && this.lastClickTimes.delete(r);
|
|
3433
3440
|
if (this.lastClickTimes.size > 1e3) {
|
|
3434
|
-
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);
|
|
3435
3442
|
for (const [o] of i)
|
|
3436
3443
|
this.lastClickTimes.delete(o);
|
|
3437
|
-
|
|
3444
|
+
a("debug", "ClickHandler: Pruned throttle cache", {
|
|
3438
3445
|
data: {
|
|
3439
3446
|
removed: i.length,
|
|
3440
3447
|
remaining: this.lastClickTimes.size
|
|
@@ -3475,7 +3482,7 @@ class Tr extends w {
|
|
|
3475
3482
|
return e.hasAttribute(`${b}-name`) ? e : e.closest(`[${b}-name]`);
|
|
3476
3483
|
}
|
|
3477
3484
|
getRelevantClickElement(e) {
|
|
3478
|
-
for (const t of
|
|
3485
|
+
for (const t of _t)
|
|
3479
3486
|
try {
|
|
3480
3487
|
if (e.matches(t))
|
|
3481
3488
|
return e;
|
|
@@ -3483,7 +3490,7 @@ class Tr extends w {
|
|
|
3483
3490
|
if (r)
|
|
3484
3491
|
return r;
|
|
3485
3492
|
} catch (r) {
|
|
3486
|
-
|
|
3493
|
+
a("debug", "Invalid selector in element search", { error: r, data: { selector: t } });
|
|
3487
3494
|
continue;
|
|
3488
3495
|
}
|
|
3489
3496
|
return e;
|
|
@@ -3503,8 +3510,8 @@ class Tr extends w {
|
|
|
3503
3510
|
return Math.max(0, Math.min(1, Number(e.toFixed(3))));
|
|
3504
3511
|
}
|
|
3505
3512
|
calculateClickCoordinates(e, t) {
|
|
3506
|
-
const r = t.getBoundingClientRect(), n = e.clientX, i = e.clientY, o = r.width > 0 ? this.clamp((n - r.left) / r.width) : 0,
|
|
3507
|
-
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 };
|
|
3508
3515
|
}
|
|
3509
3516
|
extractTrackingData(e) {
|
|
3510
3517
|
const t = e.getAttribute(`${b}-name`), r = e.getAttribute(`${b}-value`);
|
|
@@ -3516,12 +3523,12 @@ class Tr extends w {
|
|
|
3516
3523
|
};
|
|
3517
3524
|
}
|
|
3518
3525
|
generateClickData(e, t, r) {
|
|
3519
|
-
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);
|
|
3520
3527
|
return {
|
|
3521
3528
|
x: n,
|
|
3522
3529
|
y: i,
|
|
3523
3530
|
relativeX: o,
|
|
3524
|
-
relativeY:
|
|
3531
|
+
relativeY: l,
|
|
3525
3532
|
tag: t.tagName.toLowerCase(),
|
|
3526
3533
|
...t.id && { id: t.id },
|
|
3527
3534
|
...t.className && { class: t.className },
|
|
@@ -3555,7 +3562,7 @@ class Tr extends w {
|
|
|
3555
3562
|
*/
|
|
3556
3563
|
sanitizeText(e) {
|
|
3557
3564
|
let t = e;
|
|
3558
|
-
for (const r of
|
|
3565
|
+
for (const r of nt) {
|
|
3559
3566
|
const n = new RegExp(r.source, r.flags);
|
|
3560
3567
|
t = t.replace(n, "[REDACTED]");
|
|
3561
3568
|
}
|
|
@@ -3594,7 +3601,7 @@ class Tr extends w {
|
|
|
3594
3601
|
};
|
|
3595
3602
|
}
|
|
3596
3603
|
}
|
|
3597
|
-
class
|
|
3604
|
+
class yr extends w {
|
|
3598
3605
|
eventManager;
|
|
3599
3606
|
containers = [];
|
|
3600
3607
|
limitWarningLogged = !1;
|
|
@@ -3701,29 +3708,29 @@ class vr extends w {
|
|
|
3701
3708
|
n,
|
|
3702
3709
|
this.getScrollHeight(e),
|
|
3703
3710
|
this.getViewportHeight(e)
|
|
3704
|
-
), o = this.determineIfPrimary(e),
|
|
3711
|
+
), o = this.determineIfPrimary(e), l = {
|
|
3705
3712
|
element: e,
|
|
3706
3713
|
selector: t,
|
|
3707
3714
|
isPrimary: o,
|
|
3708
3715
|
lastScrollPos: n,
|
|
3709
3716
|
lastDepth: i,
|
|
3710
|
-
lastDirection:
|
|
3717
|
+
lastDirection: ee.DOWN,
|
|
3711
3718
|
lastEventTime: 0,
|
|
3712
3719
|
firstScrollEventTime: null,
|
|
3713
3720
|
maxDepthReached: i,
|
|
3714
3721
|
debounceTimer: null,
|
|
3715
3722
|
listener: null
|
|
3716
3723
|
}, c = () => {
|
|
3717
|
-
this.get("suppressNextScroll") || (
|
|
3718
|
-
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);
|
|
3719
3726
|
if (u) {
|
|
3720
3727
|
const g = Date.now();
|
|
3721
|
-
this.processScrollEvent(
|
|
3728
|
+
this.processScrollEvent(l, u, g);
|
|
3722
3729
|
}
|
|
3723
|
-
|
|
3730
|
+
l.debounceTimer = null;
|
|
3724
3731
|
}, 250));
|
|
3725
3732
|
};
|
|
3726
|
-
|
|
3733
|
+
l.listener = c, this.containers.push(l), e === window ? window.addEventListener("scroll", c, { passive: !0 }) : e.addEventListener("scroll", c, { passive: !0 });
|
|
3727
3734
|
}
|
|
3728
3735
|
processScrollEvent(e, t, r) {
|
|
3729
3736
|
if (!this.shouldEmitScrollEvent(e, t, r))
|
|
@@ -3752,7 +3759,7 @@ class vr extends w {
|
|
|
3752
3759
|
return Math.abs(t - e.lastDepth) >= this.minDepthChange;
|
|
3753
3760
|
}
|
|
3754
3761
|
logLimitOnce() {
|
|
3755
|
-
this.limitWarningLogged || (this.limitWarningLogged = !0,
|
|
3762
|
+
this.limitWarningLogged || (this.limitWarningLogged = !0, a("debug", "Max scroll events per session reached", {
|
|
3756
3763
|
data: { limit: this.maxEventsPerSession }
|
|
3757
3764
|
}));
|
|
3758
3765
|
}
|
|
@@ -3766,7 +3773,7 @@ class vr extends w {
|
|
|
3766
3773
|
e.debounceTimer !== null && (clearTimeout(e.debounceTimer), e.debounceTimer = null);
|
|
3767
3774
|
}
|
|
3768
3775
|
getScrollDirection(e, t) {
|
|
3769
|
-
return e > t ?
|
|
3776
|
+
return e > t ? ee.DOWN : ee.UP;
|
|
3770
3777
|
}
|
|
3771
3778
|
calculateScrollDepth(e, t, r) {
|
|
3772
3779
|
if (t <= r)
|
|
@@ -3775,13 +3782,13 @@ class vr extends w {
|
|
|
3775
3782
|
return Math.min(100, Math.max(0, Math.floor(e / n * 100)));
|
|
3776
3783
|
}
|
|
3777
3784
|
calculateScrollData(e) {
|
|
3778
|
-
const { element: t, lastScrollPos: r, lastEventTime: n } = e, i = this.getScrollTop(t), o = Date.now(),
|
|
3779
|
-
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())
|
|
3780
3787
|
return null;
|
|
3781
3788
|
const c = this.getViewportHeight(t), u = this.getScrollHeight(t), g = this.getScrollDirection(i, r), E = this.calculateScrollDepth(i, u, c);
|
|
3782
|
-
let
|
|
3783
|
-
n > 0 ?
|
|
3784
|
-
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);
|
|
3785
3792
|
return E > e.maxDepthReached && (e.maxDepthReached = E), e.lastScrollPos = i, {
|
|
3786
3793
|
depth: E,
|
|
3787
3794
|
direction: g,
|
|
@@ -3809,7 +3816,7 @@ class vr extends w {
|
|
|
3809
3816
|
else {
|
|
3810
3817
|
const n = document.querySelector(e);
|
|
3811
3818
|
if (!(n instanceof HTMLElement)) {
|
|
3812
|
-
|
|
3819
|
+
a("debug", `Selector "${e}" did not match an HTMLElement`);
|
|
3813
3820
|
return;
|
|
3814
3821
|
}
|
|
3815
3822
|
t = n;
|
|
@@ -3822,7 +3829,7 @@ class vr extends w {
|
|
|
3822
3829
|
e.isPrimary = t;
|
|
3823
3830
|
}
|
|
3824
3831
|
}
|
|
3825
|
-
class
|
|
3832
|
+
class wr extends w {
|
|
3826
3833
|
eventManager;
|
|
3827
3834
|
trackedElements = /* @__PURE__ */ new Map();
|
|
3828
3835
|
observer = null;
|
|
@@ -3841,15 +3848,15 @@ class _r extends w {
|
|
|
3841
3848
|
return;
|
|
3842
3849
|
const t = this.config.threshold ?? 0.5, r = this.config.minDwellTime ?? 1e3;
|
|
3843
3850
|
if (t < 0 || t > 1) {
|
|
3844
|
-
|
|
3851
|
+
a("debug", "ViewportHandler: Invalid threshold, must be between 0 and 1");
|
|
3845
3852
|
return;
|
|
3846
3853
|
}
|
|
3847
3854
|
if (r < 0) {
|
|
3848
|
-
|
|
3855
|
+
a("debug", "ViewportHandler: Invalid minDwellTime, must be non-negative");
|
|
3849
3856
|
return;
|
|
3850
3857
|
}
|
|
3851
3858
|
if (typeof IntersectionObserver > "u") {
|
|
3852
|
-
|
|
3859
|
+
a("debug", "ViewportHandler: IntersectionObserver not supported in this browser");
|
|
3853
3860
|
return;
|
|
3854
3861
|
}
|
|
3855
3862
|
this.observer = new IntersectionObserver(this.handleIntersection, {
|
|
@@ -3877,7 +3884,7 @@ class _r extends w {
|
|
|
3877
3884
|
const n = document.querySelectorAll(r.selector);
|
|
3878
3885
|
for (const i of Array.from(n)) {
|
|
3879
3886
|
if (t >= e) {
|
|
3880
|
-
|
|
3887
|
+
a("debug", "ViewportHandler: Maximum tracked elements reached", {
|
|
3881
3888
|
data: {
|
|
3882
3889
|
limit: e,
|
|
3883
3890
|
selector: r.selector,
|
|
@@ -3897,9 +3904,9 @@ class _r extends w {
|
|
|
3897
3904
|
}), this.observer?.observe(i), t++);
|
|
3898
3905
|
}
|
|
3899
3906
|
} catch (n) {
|
|
3900
|
-
|
|
3907
|
+
a("debug", `ViewportHandler: Invalid selector "${r.selector}"`, { error: n });
|
|
3901
3908
|
}
|
|
3902
|
-
|
|
3909
|
+
a("debug", "ViewportHandler: Elements tracked", {
|
|
3903
3910
|
data: { count: t, limit: e }
|
|
3904
3911
|
});
|
|
3905
3912
|
}
|
|
@@ -3927,7 +3934,7 @@ class _r extends w {
|
|
|
3927
3934
|
return;
|
|
3928
3935
|
const n = this.config?.cooldownPeriod ?? 6e4, i = Date.now();
|
|
3929
3936
|
if (e.lastFiredTime !== null && i - e.lastFiredTime < n) {
|
|
3930
|
-
|
|
3937
|
+
a("debug", "ViewportHandler: Event suppressed by cooldown period", {
|
|
3931
3938
|
data: {
|
|
3932
3939
|
selector: e.selector,
|
|
3933
3940
|
cooldownRemaining: n - (i - e.lastFiredTime)
|
|
@@ -3953,7 +3960,7 @@ class _r extends w {
|
|
|
3953
3960
|
setupMutationObserver() {
|
|
3954
3961
|
if (!(!this.config || typeof MutationObserver > "u")) {
|
|
3955
3962
|
if (!document.body) {
|
|
3956
|
-
|
|
3963
|
+
a("debug", "ViewportHandler: document.body not available, skipping MutationObserver setup");
|
|
3957
3964
|
return;
|
|
3958
3965
|
}
|
|
3959
3966
|
this.mutationObserver = new MutationObserver((e) => {
|
|
@@ -3977,20 +3984,20 @@ class _r extends w {
|
|
|
3977
3984
|
if (t.nodeType !== 1) return;
|
|
3978
3985
|
const r = t, n = this.trackedElements.get(r);
|
|
3979
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) => {
|
|
3980
|
-
const
|
|
3981
|
-
|
|
3987
|
+
const l = this.trackedElements.get(o);
|
|
3988
|
+
l && l.timeoutId !== null && window.clearTimeout(l.timeoutId), this.observer?.unobserve(o), this.trackedElements.delete(o);
|
|
3982
3989
|
});
|
|
3983
3990
|
});
|
|
3984
3991
|
}
|
|
3985
3992
|
}
|
|
3986
|
-
class
|
|
3993
|
+
class br {
|
|
3987
3994
|
storage;
|
|
3988
3995
|
sessionStorageRef;
|
|
3989
3996
|
fallbackStorage = /* @__PURE__ */ new Map();
|
|
3990
3997
|
fallbackSessionStorage = /* @__PURE__ */ new Map();
|
|
3991
3998
|
hasQuotaExceededError = !1;
|
|
3992
3999
|
constructor() {
|
|
3993
|
-
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");
|
|
3994
4001
|
}
|
|
3995
4002
|
/**
|
|
3996
4003
|
* Retrieves an item from localStorage.
|
|
@@ -4033,7 +4040,7 @@ class Ir {
|
|
|
4033
4040
|
}
|
|
4034
4041
|
} catch (r) {
|
|
4035
4042
|
if (r instanceof DOMException && r.name === "QuotaExceededError" || r instanceof Error && r.name === "QuotaExceededError")
|
|
4036
|
-
if (this.hasQuotaExceededError = !0,
|
|
4043
|
+
if (this.hasQuotaExceededError = !0, a("warn", "localStorage quota exceeded, attempting cleanup", {
|
|
4037
4044
|
data: { key: e, valueSize: t.length }
|
|
4038
4045
|
}), this.cleanupOldData())
|
|
4039
4046
|
try {
|
|
@@ -4042,13 +4049,13 @@ class Ir {
|
|
|
4042
4049
|
return;
|
|
4043
4050
|
}
|
|
4044
4051
|
} catch (o) {
|
|
4045
|
-
|
|
4052
|
+
a("error", "localStorage quota exceeded even after cleanup - data will not persist", {
|
|
4046
4053
|
error: o,
|
|
4047
4054
|
data: { key: e, valueSize: t.length }
|
|
4048
4055
|
});
|
|
4049
4056
|
}
|
|
4050
4057
|
else
|
|
4051
|
-
|
|
4058
|
+
a("error", "localStorage quota exceeded and no data to cleanup - data will not persist", {
|
|
4052
4059
|
error: r,
|
|
4053
4060
|
data: { key: e, valueSize: t.length }
|
|
4054
4061
|
});
|
|
@@ -4094,7 +4101,7 @@ class Ir {
|
|
|
4094
4101
|
this.storage.removeItem(t);
|
|
4095
4102
|
}), this.fallbackStorage.clear();
|
|
4096
4103
|
} catch (e) {
|
|
4097
|
-
|
|
4104
|
+
a("error", "Failed to clear storage", { error: e }), this.fallbackStorage.clear();
|
|
4098
4105
|
}
|
|
4099
4106
|
}
|
|
4100
4107
|
/**
|
|
@@ -4171,7 +4178,7 @@ class Ir {
|
|
|
4171
4178
|
}
|
|
4172
4179
|
}), !0) : !1;
|
|
4173
4180
|
} catch (e) {
|
|
4174
|
-
return
|
|
4181
|
+
return a("error", "Failed to cleanup old data", { error: e }), !1;
|
|
4175
4182
|
}
|
|
4176
4183
|
}
|
|
4177
4184
|
/**
|
|
@@ -4245,7 +4252,7 @@ class Ir {
|
|
|
4245
4252
|
return;
|
|
4246
4253
|
}
|
|
4247
4254
|
} catch (r) {
|
|
4248
|
-
(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", {
|
|
4249
4256
|
error: r,
|
|
4250
4257
|
data: { key: e, valueSize: t.length }
|
|
4251
4258
|
});
|
|
@@ -4266,7 +4273,7 @@ class Ir {
|
|
|
4266
4273
|
this.fallbackSessionStorage.delete(e);
|
|
4267
4274
|
}
|
|
4268
4275
|
}
|
|
4269
|
-
class
|
|
4276
|
+
class Ar extends w {
|
|
4270
4277
|
eventManager;
|
|
4271
4278
|
reportedByNav = /* @__PURE__ */ new Map();
|
|
4272
4279
|
navigationHistory = [];
|
|
@@ -4277,7 +4284,7 @@ class wr extends w {
|
|
|
4277
4284
|
navigationCounter = 0;
|
|
4278
4285
|
// Counter for handling simultaneous navigations edge case
|
|
4279
4286
|
constructor(e) {
|
|
4280
|
-
super(), this.eventManager = e, this.vitalThresholds =
|
|
4287
|
+
super(), this.eventManager = e, this.vitalThresholds = je(Ie);
|
|
4281
4288
|
}
|
|
4282
4289
|
/**
|
|
4283
4290
|
* Starts tracking Web Vitals and performance metrics.
|
|
@@ -4294,8 +4301,8 @@ class wr extends w {
|
|
|
4294
4301
|
* @returns Promise that resolves when tracking is initialized
|
|
4295
4302
|
*/
|
|
4296
4303
|
async startTracking() {
|
|
4297
|
-
const e = this.get("config"), t = e?.webVitalsMode ??
|
|
4298
|
-
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();
|
|
4299
4306
|
}
|
|
4300
4307
|
/**
|
|
4301
4308
|
* Stops tracking Web Vitals and cleans up resources.
|
|
@@ -4311,7 +4318,7 @@ class wr extends w {
|
|
|
4311
4318
|
try {
|
|
4312
4319
|
e.disconnect();
|
|
4313
4320
|
} catch (r) {
|
|
4314
|
-
|
|
4321
|
+
a("debug", "Failed to disconnect performance observer", { error: r, data: { observerIndex: t } });
|
|
4315
4322
|
}
|
|
4316
4323
|
}), this.observers.length = 0, this.reportedByNav.clear(), this.navigationHistory.length = 0;
|
|
4317
4324
|
}
|
|
@@ -4335,8 +4342,8 @@ class wr extends w {
|
|
|
4335
4342
|
for (const o of i) {
|
|
4336
4343
|
if (o.hadRecentInput === !0)
|
|
4337
4344
|
continue;
|
|
4338
|
-
const
|
|
4339
|
-
e +=
|
|
4345
|
+
const l = typeof o.value == "number" ? o.value : 0;
|
|
4346
|
+
e += l;
|
|
4340
4347
|
}
|
|
4341
4348
|
this.sendVital({ type: "CLS", value: Number(e.toFixed(2)) });
|
|
4342
4349
|
},
|
|
@@ -4355,8 +4362,8 @@ class wr extends w {
|
|
|
4355
4362
|
let n = 0;
|
|
4356
4363
|
const i = r.getEntries();
|
|
4357
4364
|
for (const o of i) {
|
|
4358
|
-
const
|
|
4359
|
-
n = Math.max(n,
|
|
4365
|
+
const l = (o.processingEnd ?? 0) - (o.startTime ?? 0);
|
|
4366
|
+
n = Math.max(n, l);
|
|
4360
4367
|
}
|
|
4361
4368
|
n > 0 && this.sendVital({ type: "INP", value: Number(n.toFixed(2)) });
|
|
4362
4369
|
},
|
|
@@ -4365,13 +4372,13 @@ class wr extends w {
|
|
|
4365
4372
|
}
|
|
4366
4373
|
async initWebVitals() {
|
|
4367
4374
|
try {
|
|
4368
|
-
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) => {
|
|
4369
4376
|
const u = Number(c.value.toFixed(2));
|
|
4370
|
-
this.sendVital({ type:
|
|
4377
|
+
this.sendVital({ type: l, value: u });
|
|
4371
4378
|
};
|
|
4372
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 });
|
|
4373
4380
|
} catch (e) {
|
|
4374
|
-
|
|
4381
|
+
a("debug", "Failed to load web-vitals library, using fallback", { error: e }), this.observeWebVitalsFallback();
|
|
4375
4382
|
}
|
|
4376
4383
|
}
|
|
4377
4384
|
reportTTFB() {
|
|
@@ -4382,7 +4389,7 @@ class wr extends w {
|
|
|
4382
4389
|
const t = e.responseStart;
|
|
4383
4390
|
typeof t == "number" && Number.isFinite(t) && this.sendVital({ type: "TTFB", value: Number(t.toFixed(2)) });
|
|
4384
4391
|
} catch (e) {
|
|
4385
|
-
|
|
4392
|
+
a("debug", "Failed to report TTFB", { error: e });
|
|
4386
4393
|
}
|
|
4387
4394
|
}
|
|
4388
4395
|
observeLongTasks() {
|
|
@@ -4392,7 +4399,7 @@ class wr extends w {
|
|
|
4392
4399
|
const t = e.getEntries();
|
|
4393
4400
|
for (const r of t) {
|
|
4394
4401
|
const n = Number(r.duration.toFixed(2)), i = Date.now();
|
|
4395
|
-
i - this.lastLongTaskSentAt >=
|
|
4402
|
+
i - this.lastLongTaskSentAt >= jt && (this.shouldSendVital("LONG_TASK", n) && this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = i);
|
|
4396
4403
|
}
|
|
4397
4404
|
},
|
|
4398
4405
|
{ type: "longtask", buffered: !0 }
|
|
@@ -4408,7 +4415,7 @@ class wr extends w {
|
|
|
4408
4415
|
return;
|
|
4409
4416
|
if (r)
|
|
4410
4417
|
r.add(e.type);
|
|
4411
|
-
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) {
|
|
4412
4419
|
const i = this.navigationHistory.shift();
|
|
4413
4420
|
i && this.reportedByNav.delete(i);
|
|
4414
4421
|
}
|
|
@@ -4417,7 +4424,7 @@ class wr extends w {
|
|
|
4417
4424
|
}
|
|
4418
4425
|
trackWebVital(e, t) {
|
|
4419
4426
|
if (!Number.isFinite(t)) {
|
|
4420
|
-
|
|
4427
|
+
a("debug", "Invalid web vital value", { data: { type: e, value: t } });
|
|
4421
4428
|
return;
|
|
4422
4429
|
}
|
|
4423
4430
|
this.eventManager.track({
|
|
@@ -4457,7 +4464,7 @@ class wr extends w {
|
|
|
4457
4464
|
const t = e.startTime || performance.now(), r = ++this.navigationCounter, n = `${t.toFixed(2)}_${window.location.pathname}`;
|
|
4458
4465
|
return r > 1 ? `${n}_${r}` : n;
|
|
4459
4466
|
} catch (e) {
|
|
4460
|
-
return
|
|
4467
|
+
return a("debug", "Failed to get navigation ID", { error: e }), null;
|
|
4461
4468
|
}
|
|
4462
4469
|
}
|
|
4463
4470
|
isObserverSupported(e) {
|
|
@@ -4469,24 +4476,24 @@ class wr extends w {
|
|
|
4469
4476
|
try {
|
|
4470
4477
|
if (!this.isObserverSupported(e))
|
|
4471
4478
|
return !1;
|
|
4472
|
-
const i = new PerformanceObserver((o,
|
|
4479
|
+
const i = new PerformanceObserver((o, l) => {
|
|
4473
4480
|
try {
|
|
4474
|
-
t(o,
|
|
4481
|
+
t(o, l);
|
|
4475
4482
|
} catch (c) {
|
|
4476
|
-
|
|
4483
|
+
a("debug", "Observer callback failed", {
|
|
4477
4484
|
error: c,
|
|
4478
4485
|
data: { type: e }
|
|
4479
4486
|
});
|
|
4480
4487
|
}
|
|
4481
4488
|
if (n)
|
|
4482
4489
|
try {
|
|
4483
|
-
|
|
4490
|
+
l.disconnect();
|
|
4484
4491
|
} catch {
|
|
4485
4492
|
}
|
|
4486
4493
|
});
|
|
4487
4494
|
return i.observe(r ?? { type: e, buffered: !0 }), n || this.observers.push(i), !0;
|
|
4488
4495
|
} catch (i) {
|
|
4489
|
-
return
|
|
4496
|
+
return a("debug", "Failed to create performance observer", {
|
|
4490
4497
|
error: i,
|
|
4491
4498
|
data: { type: e }
|
|
4492
4499
|
}), !1;
|
|
@@ -4494,12 +4501,12 @@ class wr extends w {
|
|
|
4494
4501
|
}
|
|
4495
4502
|
shouldSendVital(e, t) {
|
|
4496
4503
|
if (typeof t != "number" || !Number.isFinite(t))
|
|
4497
|
-
return
|
|
4504
|
+
return a("debug", "Invalid web vital value", { data: { type: e, value: t } }), !1;
|
|
4498
4505
|
const r = this.vitalThresholds[e];
|
|
4499
4506
|
return !(typeof r == "number" && t <= r);
|
|
4500
4507
|
}
|
|
4501
4508
|
}
|
|
4502
|
-
class
|
|
4509
|
+
class Lr extends w {
|
|
4503
4510
|
eventManager;
|
|
4504
4511
|
recentErrors = /* @__PURE__ */ new Map();
|
|
4505
4512
|
errorBurstCounter = 0;
|
|
@@ -4535,24 +4542,24 @@ class yr extends w {
|
|
|
4535
4542
|
const e = Date.now();
|
|
4536
4543
|
if (e < this.burstBackoffUntil)
|
|
4537
4544
|
return !1;
|
|
4538
|
-
if (e - this.burstWindowStart >
|
|
4539
|
-
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", {
|
|
4540
4547
|
data: {
|
|
4541
4548
|
errorsInWindow: this.errorBurstCounter,
|
|
4542
|
-
cooldownMs:
|
|
4549
|
+
cooldownMs: Ge
|
|
4543
4550
|
}
|
|
4544
4551
|
}), !1;
|
|
4545
|
-
const r = this.get("config")?.errorSampling ??
|
|
4552
|
+
const r = this.get("config")?.errorSampling ?? it;
|
|
4546
4553
|
return Math.random() < r;
|
|
4547
4554
|
}
|
|
4548
4555
|
handleError = (e) => {
|
|
4549
4556
|
if (!this.shouldSample())
|
|
4550
4557
|
return;
|
|
4551
4558
|
const t = this.sanitize(e.message || "Unknown error");
|
|
4552
|
-
this.shouldSuppressError(
|
|
4559
|
+
this.shouldSuppressError(W.JS_ERROR, t) || this.eventManager.track({
|
|
4553
4560
|
type: d.ERROR,
|
|
4554
4561
|
error_data: {
|
|
4555
|
-
type:
|
|
4562
|
+
type: W.JS_ERROR,
|
|
4556
4563
|
message: t,
|
|
4557
4564
|
...e.filename && { filename: e.filename },
|
|
4558
4565
|
...e.lineno && { line: e.lineno },
|
|
@@ -4564,10 +4571,10 @@ class yr extends w {
|
|
|
4564
4571
|
if (!this.shouldSample())
|
|
4565
4572
|
return;
|
|
4566
4573
|
const t = this.extractRejectionMessage(e.reason), r = this.sanitize(t);
|
|
4567
|
-
this.shouldSuppressError(
|
|
4574
|
+
this.shouldSuppressError(W.PROMISE_REJECTION, r) || this.eventManager.track({
|
|
4568
4575
|
type: d.ERROR,
|
|
4569
4576
|
error_data: {
|
|
4570
|
-
type:
|
|
4577
|
+
type: W.PROMISE_REJECTION,
|
|
4571
4578
|
message: r
|
|
4572
4579
|
}
|
|
4573
4580
|
});
|
|
@@ -4586,8 +4593,8 @@ class yr extends w {
|
|
|
4586
4593
|
}
|
|
4587
4594
|
}
|
|
4588
4595
|
sanitize(e) {
|
|
4589
|
-
let t = e.length >
|
|
4590
|
-
for (const r of
|
|
4596
|
+
let t = e.length > Be ? e.slice(0, Be) + "..." : e;
|
|
4597
|
+
for (const r of nt) {
|
|
4591
4598
|
const n = new RegExp(r.source, r.flags);
|
|
4592
4599
|
t = t.replace(n, "[REDACTED]");
|
|
4593
4600
|
}
|
|
@@ -4595,26 +4602,26 @@ class yr extends w {
|
|
|
4595
4602
|
}
|
|
4596
4603
|
shouldSuppressError(e, t) {
|
|
4597
4604
|
const r = Date.now(), n = `${e}:${t}`, i = this.recentErrors.get(n);
|
|
4598
|
-
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));
|
|
4599
4606
|
}
|
|
4600
4607
|
pruneOldErrors() {
|
|
4601
4608
|
const e = Date.now();
|
|
4602
4609
|
for (const [n, i] of this.recentErrors.entries())
|
|
4603
|
-
e - i >
|
|
4604
|
-
if (this.recentErrors.size <=
|
|
4610
|
+
e - i > We && this.recentErrors.delete(n);
|
|
4611
|
+
if (this.recentErrors.size <= te)
|
|
4605
4612
|
return;
|
|
4606
|
-
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;
|
|
4607
4614
|
for (let n = 0; n < r; n += 1) {
|
|
4608
4615
|
const i = t[n];
|
|
4609
4616
|
i && this.recentErrors.delete(i[0]);
|
|
4610
4617
|
}
|
|
4611
4618
|
}
|
|
4612
4619
|
}
|
|
4613
|
-
class
|
|
4620
|
+
class Mr extends w {
|
|
4614
4621
|
isInitialized = !1;
|
|
4615
4622
|
suppressNextScrollTimer = null;
|
|
4616
4623
|
pageUnloadHandler = null;
|
|
4617
|
-
emitter = new
|
|
4624
|
+
emitter = new hr();
|
|
4618
4625
|
transformers = {};
|
|
4619
4626
|
customHeadersProvider;
|
|
4620
4627
|
managers = {};
|
|
@@ -4632,19 +4639,19 @@ class br extends w {
|
|
|
4632
4639
|
async init(e = {}) {
|
|
4633
4640
|
if (this.isInitialized)
|
|
4634
4641
|
return { sessionId: this.get("sessionId") ?? "" };
|
|
4635
|
-
this.managers.storage = new
|
|
4642
|
+
this.managers.storage = new br();
|
|
4636
4643
|
try {
|
|
4637
4644
|
this.setupState(e);
|
|
4638
4645
|
const t = e.integrations?.custom?.headers ?? {}, r = e.integrations?.custom?.fetchCredentials ?? "include";
|
|
4639
|
-
return this.managers.event = new
|
|
4646
|
+
return this.managers.event = new Er(
|
|
4640
4647
|
this.managers.storage,
|
|
4641
4648
|
this.emitter,
|
|
4642
4649
|
this.transformers,
|
|
4643
4650
|
t,
|
|
4644
4651
|
this.customHeadersProvider,
|
|
4645
4652
|
r
|
|
4646
|
-
), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((n) => {
|
|
4647
|
-
|
|
4653
|
+
), this.loadPersistedIdentity(), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((n) => {
|
|
4654
|
+
a("warn", "Failed to recover persisted events", { error: n });
|
|
4648
4655
|
}), this.isInitialized = !0, { sessionId: this.get("sessionId") ?? "" };
|
|
4649
4656
|
} catch (t) {
|
|
4650
4657
|
this.destroy(!0);
|
|
@@ -4661,16 +4668,16 @@ class br extends w {
|
|
|
4661
4668
|
*/
|
|
4662
4669
|
sendCustomEvent(e, t) {
|
|
4663
4670
|
if (!this.managers.event) {
|
|
4664
|
-
|
|
4671
|
+
a("warn", "Cannot send custom event: TraceLog not initialized", { data: { name: e } });
|
|
4665
4672
|
return;
|
|
4666
4673
|
}
|
|
4667
4674
|
let r = t;
|
|
4668
4675
|
t && typeof t == "object" && !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && (r = Object.assign({}, t));
|
|
4669
|
-
const { valid: n, error: i, sanitizedMetadata: o } =
|
|
4676
|
+
const { valid: n, error: i, sanitizedMetadata: o } = dr(e, r);
|
|
4670
4677
|
if (!n) {
|
|
4671
|
-
if (this.get("mode") ===
|
|
4678
|
+
if (this.get("mode") === se.QA)
|
|
4672
4679
|
throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${i}`);
|
|
4673
|
-
|
|
4680
|
+
a("warn", `Custom event "${e}" dropped: ${i}`);
|
|
4674
4681
|
return;
|
|
4675
4682
|
}
|
|
4676
4683
|
this.managers.event.track({
|
|
@@ -4730,20 +4737,20 @@ class br extends w {
|
|
|
4730
4737
|
try {
|
|
4731
4738
|
t.stopTracking();
|
|
4732
4739
|
} catch (r) {
|
|
4733
|
-
|
|
4740
|
+
a("warn", "Failed to stop tracking", { error: r });
|
|
4734
4741
|
}
|
|
4735
|
-
}), 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 = {});
|
|
4736
4743
|
}
|
|
4737
4744
|
setupState(e = {}) {
|
|
4738
4745
|
this.set("config", e);
|
|
4739
|
-
const t =
|
|
4746
|
+
const t = Sr.getId(this.managers.storage);
|
|
4740
4747
|
this.set("userId", t);
|
|
4741
|
-
const r =
|
|
4748
|
+
const r = sr(e);
|
|
4742
4749
|
this.set("collectApiUrls", r);
|
|
4743
|
-
const n =
|
|
4750
|
+
const n = Ft();
|
|
4744
4751
|
this.set("device", n);
|
|
4745
|
-
const i =
|
|
4746
|
-
this.set("pageUrl", i),
|
|
4752
|
+
const i = ve(window.location.href, e.sensitiveQueryParams);
|
|
4753
|
+
this.set("pageUrl", i), qt() && this.set("mode", se.QA);
|
|
4747
4754
|
}
|
|
4748
4755
|
/**
|
|
4749
4756
|
* Returns the current configuration object.
|
|
@@ -4794,7 +4801,7 @@ class br extends w {
|
|
|
4794
4801
|
valid: !1,
|
|
4795
4802
|
error: "Global metadata must be a plain object"
|
|
4796
4803
|
};
|
|
4797
|
-
const t =
|
|
4804
|
+
const t = ut("Global", e, "globalMetadata");
|
|
4798
4805
|
return t.valid ? { valid: !0 } : {
|
|
4799
4806
|
valid: !1,
|
|
4800
4807
|
error: t.error
|
|
@@ -4815,7 +4822,7 @@ class br extends w {
|
|
|
4815
4822
|
...this.get("config"),
|
|
4816
4823
|
globalMetadata: e
|
|
4817
4824
|
};
|
|
4818
|
-
this.set("config", n),
|
|
4825
|
+
this.set("config", n), a("debug", "Global metadata updated (replaced)", { data: { keys: Object.keys(e) } });
|
|
4819
4826
|
}
|
|
4820
4827
|
/**
|
|
4821
4828
|
* Merges new metadata with existing global metadata.
|
|
@@ -4835,7 +4842,133 @@ class br extends w {
|
|
|
4835
4842
|
...r,
|
|
4836
4843
|
globalMetadata: i
|
|
4837
4844
|
};
|
|
4838
|
-
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
|
+
}
|
|
4839
4972
|
}
|
|
4840
4973
|
setupPageLifecycleListeners() {
|
|
4841
4974
|
this.pageUnloadHandler = () => {
|
|
@@ -4844,7 +4977,7 @@ class br extends w {
|
|
|
4844
4977
|
}
|
|
4845
4978
|
initializeHandlers() {
|
|
4846
4979
|
const e = this.get("config");
|
|
4847
|
-
this.handlers.session = new
|
|
4980
|
+
this.handlers.session = new Ir(
|
|
4848
4981
|
this.managers.storage,
|
|
4849
4982
|
this.managers.event
|
|
4850
4983
|
), this.handlers.session.startTracking();
|
|
@@ -4853,25 +4986,25 @@ class br extends w {
|
|
|
4853
4986
|
this.set("suppressNextScroll", !1);
|
|
4854
4987
|
}, 500);
|
|
4855
4988
|
};
|
|
4856
|
-
this.handlers.pageView = new
|
|
4857
|
-
|
|
4858
|
-
}), 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());
|
|
4859
4992
|
}
|
|
4860
4993
|
}
|
|
4861
4994
|
const V = [], M = [];
|
|
4862
|
-
let D = null, h = null, R = !1,
|
|
4863
|
-
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 () => {
|
|
4864
4997
|
try {
|
|
4865
|
-
const e =
|
|
4998
|
+
const e = lr(s ?? {}), t = new Mr();
|
|
4866
4999
|
try {
|
|
4867
|
-
V.forEach(({ event: o, callback:
|
|
4868
|
-
t.on(o,
|
|
4869
|
-
}), V.length = 0, M.forEach(({ hook: o, fn:
|
|
4870
|
-
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);
|
|
4871
5004
|
}), M.length = 0, D && (t.setCustomHeaders(D), D = null);
|
|
4872
|
-
const r = t.init(e), n = new Promise((o,
|
|
5005
|
+
const r = t.init(e), n = new Promise((o, l) => {
|
|
4873
5006
|
setTimeout(() => {
|
|
4874
|
-
|
|
5007
|
+
l(new Error("[TraceLog] Initialization timeout after 10000ms"));
|
|
4875
5008
|
}, 1e4);
|
|
4876
5009
|
}), i = await Promise.race([r, n]);
|
|
4877
5010
|
return h = t, i;
|
|
@@ -4879,7 +5012,7 @@ const Ar = async (s) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
4879
5012
|
try {
|
|
4880
5013
|
t.destroy(!0);
|
|
4881
5014
|
} catch (n) {
|
|
4882
|
-
|
|
5015
|
+
a("error", "Failed to cleanup partially initialized app", { error: n });
|
|
4883
5016
|
}
|
|
4884
5017
|
throw r;
|
|
4885
5018
|
}
|
|
@@ -4888,15 +5021,15 @@ const Ar = async (s) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
4888
5021
|
} finally {
|
|
4889
5022
|
R = !1, P = null;
|
|
4890
5023
|
}
|
|
4891
|
-
})()), P)),
|
|
5024
|
+
})()), P)), Rr = (s, e) => {
|
|
4892
5025
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4893
5026
|
if (!h)
|
|
4894
5027
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4895
|
-
if (
|
|
5028
|
+
if (p)
|
|
4896
5029
|
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
4897
5030
|
h.sendCustomEvent(s, e);
|
|
4898
5031
|
}
|
|
4899
|
-
},
|
|
5032
|
+
}, Nr = (s, e) => {
|
|
4900
5033
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4901
5034
|
if (!h || R) {
|
|
4902
5035
|
V.push({ event: s, callback: e });
|
|
@@ -4904,7 +5037,7 @@ const Ar = async (s) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
4904
5037
|
}
|
|
4905
5038
|
h.on(s, e);
|
|
4906
5039
|
}
|
|
4907
|
-
},
|
|
5040
|
+
}, Or = (s, e) => {
|
|
4908
5041
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4909
5042
|
if (!h) {
|
|
4910
5043
|
const t = V.findIndex((r) => r.event === s && r.callback === e);
|
|
@@ -4914,7 +5047,7 @@ const Ar = async (s) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
4914
5047
|
h.off(s, e);
|
|
4915
5048
|
}
|
|
4916
5049
|
};
|
|
4917
|
-
function
|
|
5050
|
+
function Pr(s, e) {
|
|
4918
5051
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4919
5052
|
if (typeof e != "function")
|
|
4920
5053
|
throw new Error(`[TraceLog] Transformer must be a function, received: ${typeof e}`);
|
|
@@ -4923,23 +5056,23 @@ function Rr(s, e) {
|
|
|
4923
5056
|
t !== -1 && M.splice(t, 1), M.push({ hook: s, fn: e });
|
|
4924
5057
|
return;
|
|
4925
5058
|
}
|
|
4926
|
-
if (
|
|
5059
|
+
if (p)
|
|
4927
5060
|
throw new Error("[TraceLog] Cannot set transformers while TraceLog is being destroyed");
|
|
4928
5061
|
s === "beforeSend" ? h.setTransformer("beforeSend", e) : h.setTransformer("beforeBatch", e);
|
|
4929
5062
|
}
|
|
4930
5063
|
}
|
|
4931
|
-
const
|
|
5064
|
+
const Dr = (s) => {
|
|
4932
5065
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4933
5066
|
if (!h) {
|
|
4934
5067
|
const e = M.findIndex((t) => t.hook === s);
|
|
4935
5068
|
e !== -1 && M.splice(e, 1);
|
|
4936
5069
|
return;
|
|
4937
5070
|
}
|
|
4938
|
-
if (
|
|
5071
|
+
if (p)
|
|
4939
5072
|
throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
|
|
4940
5073
|
h.removeTransformer(s);
|
|
4941
5074
|
}
|
|
4942
|
-
},
|
|
5075
|
+
}, Vr = (s) => {
|
|
4943
5076
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4944
5077
|
if (typeof s != "function")
|
|
4945
5078
|
throw new Error(`[TraceLog] Custom headers provider must be a function, received: ${typeof s}`);
|
|
@@ -4947,83 +5080,126 @@ const Nr = (s) => {
|
|
|
4947
5080
|
D = s;
|
|
4948
5081
|
return;
|
|
4949
5082
|
}
|
|
4950
|
-
if (
|
|
5083
|
+
if (p)
|
|
4951
5084
|
throw new Error("[TraceLog] Cannot set custom headers while TraceLog is being destroyed");
|
|
4952
5085
|
h.setCustomHeaders(s);
|
|
4953
5086
|
}
|
|
4954
|
-
},
|
|
5087
|
+
}, kr = () => {
|
|
4955
5088
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4956
5089
|
if (!h) {
|
|
4957
5090
|
D = null;
|
|
4958
5091
|
return;
|
|
4959
5092
|
}
|
|
4960
|
-
if (
|
|
5093
|
+
if (p)
|
|
4961
5094
|
throw new Error("[TraceLog] Cannot remove custom headers while TraceLog is being destroyed");
|
|
4962
5095
|
h.removeCustomHeaders();
|
|
4963
5096
|
}
|
|
4964
|
-
},
|
|
5097
|
+
}, Ur = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, Hr = () => typeof window > "u" || typeof document > "u" || !h ? null : h.getSessionId(), xr = () => {
|
|
4965
5098
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4966
|
-
if (
|
|
5099
|
+
if (p)
|
|
4967
5100
|
throw new Error("[TraceLog] Destroy operation already in progress");
|
|
4968
5101
|
if (!h) {
|
|
4969
|
-
|
|
5102
|
+
p = !1;
|
|
4970
5103
|
return;
|
|
4971
5104
|
}
|
|
4972
|
-
|
|
5105
|
+
p = !0;
|
|
4973
5106
|
try {
|
|
4974
|
-
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;
|
|
4975
5108
|
} catch (s) {
|
|
4976
|
-
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 });
|
|
4977
5110
|
}
|
|
4978
5111
|
}
|
|
4979
|
-
},
|
|
4980
|
-
typeof window > "u" || typeof document > "u" ||
|
|
4981
|
-
},
|
|
5112
|
+
}, Fr = (s) => {
|
|
5113
|
+
typeof window > "u" || typeof document > "u" || Jt(s);
|
|
5114
|
+
}, $r = (s) => {
|
|
4982
5115
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4983
5116
|
if (!h)
|
|
4984
5117
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4985
|
-
if (
|
|
5118
|
+
if (p)
|
|
4986
5119
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
4987
5120
|
h.updateGlobalMetadata(s);
|
|
4988
5121
|
}
|
|
4989
|
-
},
|
|
5122
|
+
}, Br = (s) => {
|
|
4990
5123
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4991
5124
|
if (!h)
|
|
4992
5125
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4993
|
-
if (
|
|
5126
|
+
if (p)
|
|
4994
5127
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
4995
5128
|
h.mergeGlobalMetadata(s);
|
|
4996
5129
|
}
|
|
4997
|
-
},
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
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
|
|
5012
5188
|
};
|
|
5013
|
-
var
|
|
5189
|
+
var we, C, j, ft, ie, mt = -1, k = function(s) {
|
|
5014
5190
|
addEventListener("pageshow", (function(e) {
|
|
5015
|
-
e.persisted && (
|
|
5191
|
+
e.persisted && (mt = e.timeStamp, s(e));
|
|
5016
5192
|
}), !0);
|
|
5017
|
-
},
|
|
5193
|
+
}, Ne = function() {
|
|
5018
5194
|
var s = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
|
|
5019
5195
|
if (s && s.responseStart > 0 && s.responseStart < performance.now()) return s;
|
|
5020
|
-
},
|
|
5021
|
-
var s =
|
|
5196
|
+
}, ae = function() {
|
|
5197
|
+
var s = Ne();
|
|
5022
5198
|
return s && s.activationStart || 0;
|
|
5023
5199
|
}, _ = function(s, e) {
|
|
5024
|
-
var t =
|
|
5025
|
-
return
|
|
5026
|
-
},
|
|
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) {
|
|
5027
5203
|
try {
|
|
5028
5204
|
if (PerformanceObserver.supportedEntryTypes.includes(s)) {
|
|
5029
5205
|
var r = new PerformanceObserver((function(n) {
|
|
@@ -5035,63 +5211,63 @@ var _e, C, X, ct, ne, ut = -1, k = function(s) {
|
|
|
5035
5211
|
}
|
|
5036
5212
|
} catch {
|
|
5037
5213
|
}
|
|
5038
|
-
},
|
|
5214
|
+
}, y = function(s, e, t, r) {
|
|
5039
5215
|
var n, i;
|
|
5040
5216
|
return function(o) {
|
|
5041
|
-
e.value >= 0 && (o || r) && ((i = e.value - (n || 0)) || n === void 0) && (n = e.value, e.delta = i, e.rating = (function(
|
|
5042
|
-
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";
|
|
5043
5219
|
})(e.value, t), s(e));
|
|
5044
5220
|
};
|
|
5045
|
-
},
|
|
5221
|
+
}, Oe = function(s) {
|
|
5046
5222
|
requestAnimationFrame((function() {
|
|
5047
5223
|
return requestAnimationFrame((function() {
|
|
5048
5224
|
return s();
|
|
5049
5225
|
}));
|
|
5050
5226
|
}));
|
|
5051
|
-
},
|
|
5227
|
+
}, z = function(s) {
|
|
5052
5228
|
document.addEventListener("visibilitychange", (function() {
|
|
5053
5229
|
document.visibilityState === "hidden" && s();
|
|
5054
5230
|
}));
|
|
5055
|
-
},
|
|
5231
|
+
}, le = function(s) {
|
|
5056
5232
|
var e = !1;
|
|
5057
5233
|
return function() {
|
|
5058
5234
|
e || (s(), e = !0);
|
|
5059
5235
|
};
|
|
5060
|
-
},
|
|
5236
|
+
}, x = -1, qe = function() {
|
|
5061
5237
|
return document.visibilityState !== "hidden" || document.prerendering ? 1 / 0 : 0;
|
|
5062
|
-
},
|
|
5063
|
-
document.visibilityState === "hidden" &&
|
|
5064
|
-
},
|
|
5065
|
-
addEventListener("visibilitychange",
|
|
5066
|
-
},
|
|
5067
|
-
removeEventListener("visibilitychange",
|
|
5068
|
-
},
|
|
5069
|
-
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() {
|
|
5070
5246
|
setTimeout((function() {
|
|
5071
|
-
|
|
5247
|
+
x = qe(), Je();
|
|
5072
5248
|
}), 0);
|
|
5073
5249
|
}))), { get firstHiddenTime() {
|
|
5074
|
-
return
|
|
5250
|
+
return x;
|
|
5075
5251
|
} };
|
|
5076
|
-
},
|
|
5252
|
+
}, K = function(s) {
|
|
5077
5253
|
document.prerendering ? addEventListener("prerenderingchange", (function() {
|
|
5078
5254
|
return s();
|
|
5079
5255
|
}), !0) : s();
|
|
5080
|
-
},
|
|
5081
|
-
e = e || {},
|
|
5082
|
-
var t, r =
|
|
5083
|
-
o.forEach((function(
|
|
5084
|
-
|
|
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)));
|
|
5085
5261
|
}));
|
|
5086
5262
|
}));
|
|
5087
|
-
i && (t =
|
|
5088
|
-
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() {
|
|
5089
5265
|
n.value = performance.now() - o.timeStamp, t(!0);
|
|
5090
5266
|
}));
|
|
5091
5267
|
})));
|
|
5092
5268
|
}));
|
|
5093
|
-
},
|
|
5094
|
-
e = e || {},
|
|
5269
|
+
}, Ae = [0.1, 0.25], jr = function(s, e) {
|
|
5270
|
+
e = e || {}, gt(le((function() {
|
|
5095
5271
|
var t, r = _("CLS", 0), n = 0, i = [], o = function(c) {
|
|
5096
5272
|
c.forEach((function(u) {
|
|
5097
5273
|
if (!u.hadRecentInput) {
|
|
@@ -5099,191 +5275,191 @@ var _e, C, X, ct, ne, ut = -1, k = function(s) {
|
|
|
5099
5275
|
n && u.startTime - E.startTime < 1e3 && u.startTime - g.startTime < 5e3 ? (n += u.value, i.push(u)) : (n = u.value, i = [u]);
|
|
5100
5276
|
}
|
|
5101
5277
|
})), n > r.value && (r.value = n, r.entries = i, t());
|
|
5102
|
-
},
|
|
5103
|
-
|
|
5104
|
-
o(
|
|
5278
|
+
}, l = F("layout-shift", o);
|
|
5279
|
+
l && (t = y(s, r, Ae, e.reportAllChanges), z((function() {
|
|
5280
|
+
o(l.takeRecords()), t(!0);
|
|
5105
5281
|
})), k((function() {
|
|
5106
|
-
n = 0, r = _("CLS", 0), t =
|
|
5282
|
+
n = 0, r = _("CLS", 0), t = y(s, r, Ae, e.reportAllChanges), Oe((function() {
|
|
5107
5283
|
return t();
|
|
5108
5284
|
}));
|
|
5109
5285
|
})), setTimeout(t, 0));
|
|
5110
5286
|
})));
|
|
5111
|
-
},
|
|
5287
|
+
}, Et = 0, me = 1 / 0, Z = 0, Qr = function(s) {
|
|
5112
5288
|
s.forEach((function(e) {
|
|
5113
|
-
e.interactionId && (
|
|
5289
|
+
e.interactionId && (me = Math.min(me, e.interactionId), Z = Math.max(Z, e.interactionId), Et = Z ? (Z - me) / 7 + 1 : 0);
|
|
5114
5290
|
}));
|
|
5115
|
-
},
|
|
5116
|
-
return
|
|
5117
|
-
},
|
|
5118
|
-
"interactionCount" in performance ||
|
|
5119
|
-
}, A = [],
|
|
5120
|
-
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));
|
|
5121
5297
|
return A[s];
|
|
5122
|
-
},
|
|
5123
|
-
if (
|
|
5298
|
+
}, Yr = [], qr = function(s) {
|
|
5299
|
+
if (Yr.forEach((function(n) {
|
|
5124
5300
|
return n(s);
|
|
5125
5301
|
})), s.interactionId || s.entryType === "first-input") {
|
|
5126
|
-
var e = A[A.length - 1], t =
|
|
5302
|
+
var e = A[A.length - 1], t = re.get(s.interactionId);
|
|
5127
5303
|
if (t || A.length < 10 || s.duration > e.latency) {
|
|
5128
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);
|
|
5129
5305
|
else {
|
|
5130
5306
|
var r = { id: s.interactionId, latency: s.duration, entries: [s] };
|
|
5131
|
-
|
|
5307
|
+
re.set(r.id, r), A.push(r);
|
|
5132
5308
|
}
|
|
5133
5309
|
A.sort((function(n, i) {
|
|
5134
5310
|
return i.latency - n.latency;
|
|
5135
5311
|
})), A.length > 10 && A.splice(10).forEach((function(n) {
|
|
5136
|
-
return
|
|
5312
|
+
return re.delete(n.id);
|
|
5137
5313
|
}));
|
|
5138
5314
|
}
|
|
5139
5315
|
}
|
|
5140
|
-
},
|
|
5316
|
+
}, Tt = function(s) {
|
|
5141
5317
|
var e = self.requestIdleCallback || self.setTimeout, t = -1;
|
|
5142
|
-
return s =
|
|
5143
|
-
},
|
|
5144
|
-
"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() {
|
|
5145
5321
|
var t;
|
|
5146
|
-
|
|
5147
|
-
var r, n = _("INP"), i = function(
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
var c =
|
|
5322
|
+
zr();
|
|
5323
|
+
var r, n = _("INP"), i = function(l) {
|
|
5324
|
+
Tt((function() {
|
|
5325
|
+
l.forEach(qr);
|
|
5326
|
+
var c = Kr();
|
|
5151
5327
|
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, r());
|
|
5152
5328
|
}));
|
|
5153
|
-
}, o =
|
|
5154
|
-
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() {
|
|
5155
5331
|
i(o.takeRecords()), r(!0);
|
|
5156
5332
|
})), k((function() {
|
|
5157
|
-
|
|
5333
|
+
pt = St(), A.length = 0, re.clear(), n = _("INP"), r = y(s, n, Le, e.reportAllChanges);
|
|
5158
5334
|
})));
|
|
5159
5335
|
})));
|
|
5160
|
-
},
|
|
5161
|
-
e = e || {},
|
|
5162
|
-
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) {
|
|
5163
5339
|
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(u) {
|
|
5164
|
-
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());
|
|
5165
5341
|
}));
|
|
5166
|
-
}, o =
|
|
5342
|
+
}, o = F("largest-contentful-paint", i);
|
|
5167
5343
|
if (o) {
|
|
5168
|
-
t =
|
|
5169
|
-
var
|
|
5170
|
-
|
|
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));
|
|
5171
5347
|
}));
|
|
5172
5348
|
["keydown", "click"].forEach((function(c) {
|
|
5173
5349
|
addEventListener(c, (function() {
|
|
5174
|
-
return
|
|
5350
|
+
return Tt(l);
|
|
5175
5351
|
}), { once: !0, capture: !0 });
|
|
5176
|
-
})),
|
|
5177
|
-
n = _("LCP"), t =
|
|
5178
|
-
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);
|
|
5179
5355
|
}));
|
|
5180
5356
|
}));
|
|
5181
5357
|
}
|
|
5182
5358
|
}));
|
|
5183
|
-
},
|
|
5184
|
-
document.prerendering ?
|
|
5359
|
+
}, Ce = [800, 1800], es = function s(e) {
|
|
5360
|
+
document.prerendering ? K((function() {
|
|
5185
5361
|
return s(e);
|
|
5186
5362
|
})) : document.readyState !== "complete" ? addEventListener("load", (function() {
|
|
5187
5363
|
return s(e);
|
|
5188
5364
|
}), !0) : setTimeout(e, 0);
|
|
5189
|
-
},
|
|
5365
|
+
}, ts = function(s, e) {
|
|
5190
5366
|
e = e || {};
|
|
5191
|
-
var t = _("TTFB"), r =
|
|
5192
|
-
|
|
5193
|
-
var n =
|
|
5194
|
-
n && (t.value = Math.max(n.responseStart -
|
|
5195
|
-
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);
|
|
5196
5372
|
})));
|
|
5197
5373
|
}));
|
|
5198
|
-
},
|
|
5199
|
-
C || (C = e,
|
|
5200
|
-
},
|
|
5201
|
-
if (
|
|
5202
|
-
var s = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp +
|
|
5203
|
-
|
|
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) {
|
|
5204
5380
|
e(s);
|
|
5205
|
-
})),
|
|
5381
|
+
})), ie = [];
|
|
5206
5382
|
}
|
|
5207
|
-
},
|
|
5383
|
+
}, ss = function(s) {
|
|
5208
5384
|
if (s.cancelable) {
|
|
5209
5385
|
var e = (s.timeStamp > 1e12 ? /* @__PURE__ */ new Date() : performance.now()) - s.timeStamp;
|
|
5210
5386
|
s.type == "pointerdown" ? (function(t, r) {
|
|
5211
5387
|
var n = function() {
|
|
5212
|
-
|
|
5388
|
+
Ze(t, r), o();
|
|
5213
5389
|
}, i = function() {
|
|
5214
5390
|
o();
|
|
5215
5391
|
}, o = function() {
|
|
5216
|
-
removeEventListener("pointerup", n,
|
|
5392
|
+
removeEventListener("pointerup", n, G), removeEventListener("pointercancel", i, G);
|
|
5217
5393
|
};
|
|
5218
|
-
addEventListener("pointerup", n,
|
|
5219
|
-
})(e, s) :
|
|
5394
|
+
addEventListener("pointerup", n, G), addEventListener("pointercancel", i, G);
|
|
5395
|
+
})(e, s) : Ze(e, s);
|
|
5220
5396
|
}
|
|
5221
|
-
},
|
|
5397
|
+
}, vt = function(s) {
|
|
5222
5398
|
["mousedown", "keydown", "touchstart", "pointerdown"].forEach((function(e) {
|
|
5223
|
-
return s(e,
|
|
5399
|
+
return s(e, ss, G);
|
|
5224
5400
|
}));
|
|
5225
|
-
},
|
|
5226
|
-
e = e || {},
|
|
5227
|
-
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) {
|
|
5228
5404
|
c.startTime < r.firstHiddenTime && (n.value = c.processingStart - c.startTime, n.entries.push(c), t(!0));
|
|
5229
5405
|
}, o = function(c) {
|
|
5230
5406
|
c.forEach(i);
|
|
5231
|
-
},
|
|
5232
|
-
t =
|
|
5233
|
-
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();
|
|
5234
5410
|
}))), k((function() {
|
|
5235
5411
|
var c;
|
|
5236
|
-
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();
|
|
5237
5413
|
})));
|
|
5238
5414
|
}));
|
|
5239
5415
|
};
|
|
5240
|
-
const
|
|
5416
|
+
const is = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5241
5417
|
__proto__: null,
|
|
5242
|
-
CLSThresholds:
|
|
5243
|
-
FCPThresholds:
|
|
5244
|
-
FIDThresholds:
|
|
5245
|
-
INPThresholds:
|
|
5246
|
-
LCPThresholds:
|
|
5247
|
-
TTFBThresholds:
|
|
5248
|
-
onCLS:
|
|
5249
|
-
onFCP:
|
|
5250
|
-
onFID:
|
|
5251
|
-
onINP:
|
|
5252
|
-
onLCP:
|
|
5253
|
-
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
|
|
5254
5430
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
5255
5431
|
export {
|
|
5256
5432
|
f as AppConfigValidationError,
|
|
5257
|
-
|
|
5258
|
-
|
|
5433
|
+
os as DEFAULT_SESSION_TIMEOUT,
|
|
5434
|
+
Ie as DEFAULT_WEB_VITALS_MODE,
|
|
5259
5435
|
L as DeviceType,
|
|
5260
|
-
|
|
5261
|
-
|
|
5436
|
+
Se as EmitterEvent,
|
|
5437
|
+
W as ErrorType,
|
|
5262
5438
|
d as EventType,
|
|
5263
|
-
|
|
5439
|
+
Ss as InitializationTimeoutError,
|
|
5264
5440
|
U as IntegrationValidationError,
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
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,
|
|
5275
5451
|
N as PermanentError,
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5452
|
+
$e as SamplingRateValidationError,
|
|
5453
|
+
ee as ScrollDirection,
|
|
5454
|
+
Ct as SessionTimeoutValidationError,
|
|
5455
|
+
B as SpecialApiUrl,
|
|
5280
5456
|
O as TimeoutError,
|
|
5281
5457
|
Q as TraceLogValidationError,
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
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
|
|
5289
5465
|
};
|