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