@tracelog/lib 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/tracelog.esm.js +927 -861
- 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 +251 -130
- package/dist/public-api.cjs.map +1 -1
- package/dist/public-api.d.mts +25 -9
- package/dist/public-api.d.ts +25 -9
- package/dist/public-api.js +251 -130
- 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
|
|
1
|
+
const Or = 9e5;
|
|
2
|
+
const Pr = 120, Dr = 8192, Vr = 10, kr = 10, Ur = 20, xr = 1;
|
|
3
|
+
const Hr = 1e3, Fr = 500, $r = 100;
|
|
4
|
+
const w = "data-tlog", nt = [
|
|
5
5
|
"button",
|
|
6
6
|
"a",
|
|
7
7
|
'input[type="button"]',
|
|
@@ -33,7 +33,7 @@ const v = "data-tlog", tt = [
|
|
|
33
33
|
".menu-item",
|
|
34
34
|
"[data-testid]",
|
|
35
35
|
'[tabindex="0"]'
|
|
36
|
-
],
|
|
36
|
+
], it = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"], ot = [
|
|
37
37
|
"token",
|
|
38
38
|
"auth",
|
|
39
39
|
"key",
|
|
@@ -71,110 +71,157 @@ const m = {
|
|
|
71
71
|
INVALID_VIEWPORT_MIN_DWELL_TIME: "Viewport minDwellTime must be a non-negative number",
|
|
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
|
+
}, at = [
|
|
75
75
|
/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
|
76
76
|
/javascript:/gi,
|
|
77
77
|
/on\w+\s*=/gi,
|
|
78
78
|
/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
|
|
79
79
|
/<embed\b[^>]*>/gi,
|
|
80
80
|
/<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi
|
|
81
|
-
], I = "tlog",
|
|
82
|
-
var
|
|
83
|
-
class
|
|
81
|
+
], I = "tlog", x = `${I}:qa_mode`, Te = `${I}:uid`, xe = "tlog_mode", _e = "qa", ve = "qa_off", lt = (s) => s ? `${I}:${s}:queue` : `${I}:queue`, ct = (s) => s ? `${I}:${s}:session` : `${I}:session`, ut = (s) => s ? `${I}:${s}:broadcast` : `${I}:broadcast`, Ie = (s, e) => `${I}:${s}:session_counts:${e}`, we = 10080 * 60 * 1e3, ye = `${I}:session_counts_last_cleanup`, be = 3600 * 1e3;
|
|
82
|
+
var k = /* @__PURE__ */ ((s) => (s.Localhost = "localhost:8080", s.Fail = "localhost:9999", s))(k || {}), L = /* @__PURE__ */ ((s) => (s.Mobile = "mobile", s.Tablet = "tablet", s.Desktop = "desktop", s.Unknown = "unknown", s))(L || {}), ne = /* @__PURE__ */ ((s) => (s.EVENT = "event", s.QUEUE = "queue", s))(ne || {});
|
|
83
|
+
class N extends Error {
|
|
84
84
|
constructor(e, t) {
|
|
85
|
-
super(e), this.statusCode = t, this.name = "PermanentError", Error.captureStackTrace && Error.captureStackTrace(this,
|
|
85
|
+
super(e), this.statusCode = t, this.name = "PermanentError", Error.captureStackTrace && Error.captureStackTrace(this, N);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
var
|
|
89
|
-
const
|
|
90
|
-
class
|
|
88
|
+
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 || {}), X = /* @__PURE__ */ ((s) => (s.UP = "up", s.DOWN = "down", s))(X || {}), U = /* @__PURE__ */ ((s) => (s.JS_ERROR = "js_error", s.PROMISE_REJECTION = "promise_rejection", s))(U || {}), j = /* @__PURE__ */ ((s) => (s.QA = "qa", s))(j || {});
|
|
89
|
+
const Br = (s) => s.type === d.SCROLL && "scroll_data" in s && s.scroll_data.is_primary === !0, Wr = (s) => s.type === d.SCROLL && "scroll_data" in s && s.scroll_data.is_primary === !1;
|
|
90
|
+
class H extends Error {
|
|
91
91
|
constructor(e, t, r) {
|
|
92
92
|
super(e), this.errorCode = t, this.layer = r, this.name = this.constructor.name, Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
class h extends
|
|
95
|
+
class h extends H {
|
|
96
96
|
constructor(e, t = "config") {
|
|
97
97
|
super(e, "APP_CONFIG_INVALID", t);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
class
|
|
100
|
+
class dt extends H {
|
|
101
101
|
constructor(e, t = "config") {
|
|
102
102
|
super(e, "SESSION_TIMEOUT_INVALID", t);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
class
|
|
105
|
+
class Ae extends H {
|
|
106
106
|
constructor(e, t = "config") {
|
|
107
107
|
super(e, "SAMPLING_RATE_INVALID", t);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
class
|
|
110
|
+
class V extends H {
|
|
111
111
|
constructor(e, t = "config") {
|
|
112
112
|
super(e, "INTEGRATION_INVALID", t);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
class
|
|
115
|
+
class Gr extends H {
|
|
116
116
|
constructor(e, t, r = "runtime") {
|
|
117
117
|
super(e, "INITIALIZATION_TIMEOUT", r), this.timeoutMs = t;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
const
|
|
120
|
+
const He = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", Fe = "background: #9e9e9e; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", ht = "background: #d32f2f; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", ft = (s, e) => {
|
|
121
121
|
if (e) {
|
|
122
122
|
if (e instanceof Error) {
|
|
123
123
|
const t = e.message.replace(/\s+at\s+.*$/gm, "").replace(/\s*\([^()]+:\d+:\d+\)/g, "");
|
|
124
|
-
return `[TraceLog] ${
|
|
124
|
+
return `[TraceLog] ${s}: ${t}`;
|
|
125
125
|
}
|
|
126
126
|
if (e instanceof Error)
|
|
127
|
-
return `[TraceLog] ${
|
|
127
|
+
return `[TraceLog] ${s}: ${e.message}`;
|
|
128
128
|
if (typeof e == "string")
|
|
129
|
-
return `[TraceLog] ${
|
|
129
|
+
return `[TraceLog] ${s}: ${e}`;
|
|
130
130
|
if (typeof e == "object")
|
|
131
131
|
try {
|
|
132
|
-
return `[TraceLog] ${
|
|
132
|
+
return `[TraceLog] ${s}: ${JSON.stringify(e)}`;
|
|
133
133
|
} catch {
|
|
134
|
-
return `[TraceLog] ${
|
|
134
|
+
return `[TraceLog] ${s}: [Unable to serialize error]`;
|
|
135
135
|
}
|
|
136
|
-
return `[TraceLog] ${
|
|
136
|
+
return `[TraceLog] ${s}: ${String(e)}`;
|
|
137
137
|
}
|
|
138
|
-
return `[TraceLog] ${
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
return `[TraceLog] ${s}`;
|
|
139
|
+
}, mt = () => {
|
|
140
|
+
if (typeof window > "u" || typeof sessionStorage > "u")
|
|
141
|
+
return !1;
|
|
142
|
+
try {
|
|
143
|
+
return sessionStorage.getItem(x) === "true";
|
|
144
|
+
} catch {
|
|
145
|
+
return !1;
|
|
146
|
+
}
|
|
147
|
+
}, a = (s, e, t) => {
|
|
148
|
+
const { error: r, data: n, showToClient: i = !1, style: o, visibility: l } = t ?? {}, c = r ? ft(e, r) : `[TraceLog] ${e}`, u = s === "error" ? "error" : s === "warn" ? "warn" : "log";
|
|
149
|
+
if (!gt(l, i))
|
|
142
150
|
return;
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}, se = (n) => {
|
|
151
|
+
const g = Et(l, o), E = n !== void 0 ? ie(n) : void 0;
|
|
152
|
+
St(u, c, g, E);
|
|
153
|
+
}, gt = (s, e) => s === "critical" ? !0 : s === "qa" || e ? mt() : !1, Et = (s, e) => e !== void 0 && e !== "" ? e : s === "critical" ? ht : "", St = (s, e, t, r) => {
|
|
154
|
+
const n = t !== void 0 && t !== "", i = n ? `%c${e}` : e;
|
|
155
|
+
r !== void 0 ? n ? console[s](i, t, r) : console[s](i, r) : n ? console[s](i, t) : console[s](i);
|
|
156
|
+
}, ie = (s) => {
|
|
150
157
|
const e = {}, t = ["token", "password", "secret", "key", "apikey", "api_key", "sessionid", "session_id"];
|
|
151
|
-
for (const [r,
|
|
158
|
+
for (const [r, n] of Object.entries(s)) {
|
|
152
159
|
const i = r.toLowerCase();
|
|
153
160
|
if (t.some((o) => i.includes(o))) {
|
|
154
161
|
e[r] = "[REDACTED]";
|
|
155
162
|
continue;
|
|
156
163
|
}
|
|
157
|
-
|
|
158
|
-
(o) => o !== null && typeof o == "object" && !Array.isArray(o) ?
|
|
159
|
-
) : e[r] =
|
|
164
|
+
n !== null && typeof n == "object" && !Array.isArray(n) ? e[r] = ie(n) : Array.isArray(n) ? e[r] = n.map(
|
|
165
|
+
(o) => o !== null && typeof o == "object" && !Array.isArray(o) ? ie(o) : o
|
|
166
|
+
) : e[r] = n;
|
|
160
167
|
}
|
|
161
168
|
return e;
|
|
162
169
|
};
|
|
163
|
-
let
|
|
164
|
-
const
|
|
165
|
-
typeof window < "u" && !
|
|
166
|
-
},
|
|
170
|
+
let oe, $e;
|
|
171
|
+
const pt = () => {
|
|
172
|
+
typeof window < "u" && !oe && (oe = window.matchMedia("(pointer: coarse)"), $e = window.matchMedia("(hover: none)"));
|
|
173
|
+
}, K = "Unknown", Tt = (s) => {
|
|
174
|
+
const e = s.userAgentData?.platform;
|
|
175
|
+
if (e != null && e !== "") {
|
|
176
|
+
if (/windows/i.test(e)) return "Windows";
|
|
177
|
+
if (/macos/i.test(e)) return "macOS";
|
|
178
|
+
if (/android/i.test(e)) return "Android";
|
|
179
|
+
if (/linux/i.test(e)) return "Linux";
|
|
180
|
+
if (/chromeos/i.test(e)) return "ChromeOS";
|
|
181
|
+
if (/ios/i.test(e)) return "iOS";
|
|
182
|
+
}
|
|
183
|
+
const t = navigator.userAgent;
|
|
184
|
+
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" : K;
|
|
185
|
+
}, _t = (s) => {
|
|
186
|
+
const e = s.userAgentData?.brands;
|
|
187
|
+
if (e != null && e.length > 0) {
|
|
188
|
+
const n = e.filter((i) => !/not.?a.?brand|chromium/i.test(i.brand))[0];
|
|
189
|
+
if (n != null) {
|
|
190
|
+
const i = n.brand;
|
|
191
|
+
return /google chrome/i.test(i) ? "Chrome" : /microsoft edge/i.test(i) ? "Edge" : /opera/i.test(i) ? "Opera" : i;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const t = navigator.userAgent;
|
|
195
|
+
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" : K;
|
|
196
|
+
}, vt = () => {
|
|
197
|
+
try {
|
|
198
|
+
const s = navigator;
|
|
199
|
+
if (s.userAgentData != null && typeof s.userAgentData.mobile == "boolean") {
|
|
200
|
+
const c = s.userAgentData.platform;
|
|
201
|
+
return c != null && c !== "" && /ipad|tablet/i.test(c) ? L.Tablet : s.userAgentData.mobile ? L.Mobile : L.Desktop;
|
|
202
|
+
}
|
|
203
|
+
pt();
|
|
204
|
+
const e = window.innerWidth, t = oe?.matches ?? !1, r = $e?.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);
|
|
205
|
+
return e <= 767 || o && n ? L.Mobile : e >= 768 && e <= 1024 || l || t && r && n ? L.Tablet : L.Desktop;
|
|
206
|
+
} catch (s) {
|
|
207
|
+
return a("debug", "Device detection failed, defaulting to desktop", { error: s }), L.Desktop;
|
|
208
|
+
}
|
|
209
|
+
}, It = () => {
|
|
167
210
|
try {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
} catch (
|
|
175
|
-
return a("
|
|
176
|
-
|
|
177
|
-
|
|
211
|
+
const s = navigator;
|
|
212
|
+
return {
|
|
213
|
+
type: vt(),
|
|
214
|
+
os: Tt(s),
|
|
215
|
+
browser: _t(s)
|
|
216
|
+
};
|
|
217
|
+
} catch (s) {
|
|
218
|
+
return a("debug", "Device info detection failed, using defaults", { error: s }), {
|
|
219
|
+
type: L.Desktop,
|
|
220
|
+
os: K,
|
|
221
|
+
browser: K
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}, Be = [
|
|
178
225
|
// Email addresses
|
|
179
226
|
/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/gi,
|
|
180
227
|
// US Phone numbers (various formats)
|
|
@@ -189,7 +236,7 @@ const ut = () => {
|
|
|
189
236
|
/Bearer\s+[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)?(?:\.[A-Za-z0-9_-]+)?/gi,
|
|
190
237
|
// Passwords in connection strings (protocol://user:password@host)
|
|
191
238
|
/:\/\/[^:/]+:([^@]+)@/gi
|
|
192
|
-
],
|
|
239
|
+
], Le = 500, Me = 5e3, Q = 50, wt = Q * 2, We = 1, yt = 1e3, bt = 10, Ce = 5e3, At = 6e4, Xr = {
|
|
193
240
|
LCP: 2500,
|
|
194
241
|
// Good: ≤ 2.5s
|
|
195
242
|
FCP: 1800,
|
|
@@ -213,7 +260,7 @@ const ut = () => {
|
|
|
213
260
|
TTFB: 800,
|
|
214
261
|
// Needs improvement: > 800ms
|
|
215
262
|
LONG_TASK: 50
|
|
216
|
-
},
|
|
263
|
+
}, Lt = {
|
|
217
264
|
LCP: 4e3,
|
|
218
265
|
// Poor: > 4s
|
|
219
266
|
FCP: 3e3,
|
|
@@ -225,89 +272,87 @@ const ut = () => {
|
|
|
225
272
|
TTFB: 1800,
|
|
226
273
|
// Poor: > 1800ms
|
|
227
274
|
LONG_TASK: 50
|
|
228
|
-
},
|
|
229
|
-
switch (
|
|
275
|
+
}, ae = "needs-improvement", Ne = (s = ae) => {
|
|
276
|
+
switch (s) {
|
|
230
277
|
case "all":
|
|
231
278
|
return { LCP: 0, FCP: 0, CLS: 0, INP: 0, TTFB: 0, LONG_TASK: 0 };
|
|
232
279
|
// Track everything
|
|
233
280
|
case "needs-improvement":
|
|
234
281
|
return Re;
|
|
235
282
|
case "poor":
|
|
236
|
-
return
|
|
283
|
+
return Lt;
|
|
237
284
|
default:
|
|
238
285
|
return Re;
|
|
239
286
|
}
|
|
240
|
-
},
|
|
241
|
-
|
|
287
|
+
}, Mt = 1e3, Ct = 50, Rt = "2.0.3", Nt = Rt, Ge = () => typeof window < "u" && typeof sessionStorage < "u", Ot = () => {
|
|
288
|
+
try {
|
|
289
|
+
const s = new URLSearchParams(window.location.search);
|
|
290
|
+
s.delete(xe);
|
|
291
|
+
const e = s.toString(), t = window.location.pathname + (e ? "?" + e : "") + window.location.hash;
|
|
292
|
+
window.history.replaceState({}, "", t);
|
|
293
|
+
} catch {
|
|
294
|
+
}
|
|
295
|
+
}, Pt = () => {
|
|
296
|
+
if (!Ge())
|
|
242
297
|
return !1;
|
|
243
298
|
try {
|
|
244
|
-
const
|
|
299
|
+
const e = new URLSearchParams(window.location.search).get(xe), t = sessionStorage.getItem(x);
|
|
245
300
|
let r = null;
|
|
246
|
-
|
|
247
|
-
|
|
301
|
+
return e === _e ? (r = !0, sessionStorage.setItem(x, "true"), a("info", "QA Mode ACTIVE", {
|
|
302
|
+
visibility: "qa",
|
|
248
303
|
style: He
|
|
249
|
-
})) : e ===
|
|
250
|
-
|
|
304
|
+
})) : e === ve && (r = !1, sessionStorage.setItem(x, "false"), a("info", "QA Mode DISABLED", {
|
|
305
|
+
visibility: "qa",
|
|
251
306
|
style: Fe
|
|
252
|
-
})), e === _e || e ===
|
|
253
|
-
try {
|
|
254
|
-
n.delete(Te);
|
|
255
|
-
const s = n.toString(), i = window.location.pathname + (s ? "?" + s : "") + window.location.hash;
|
|
256
|
-
window.history.replaceState({}, "", i);
|
|
257
|
-
} catch {
|
|
258
|
-
}
|
|
259
|
-
return r ?? t === "true";
|
|
307
|
+
})), (e === _e || e === ve) && Ot(), r ?? t === "true";
|
|
260
308
|
} catch {
|
|
261
309
|
return !1;
|
|
262
310
|
}
|
|
263
|
-
},
|
|
264
|
-
if (
|
|
311
|
+
}, Dt = (s) => {
|
|
312
|
+
if (Ge())
|
|
265
313
|
try {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
style: He
|
|
269
|
-
})
|
|
270
|
-
showToClient: !0,
|
|
271
|
-
style: Fe
|
|
272
|
-
}));
|
|
314
|
+
sessionStorage.setItem(x, s ? "true" : "false"), a("info", s ? "QA Mode ACTIVE" : "QA Mode DISABLED", {
|
|
315
|
+
visibility: "qa",
|
|
316
|
+
style: s ? He : Fe
|
|
317
|
+
});
|
|
273
318
|
} catch {
|
|
274
|
-
a("
|
|
319
|
+
a("debug", "Cannot set QA mode: sessionStorage unavailable");
|
|
275
320
|
}
|
|
276
321
|
}, Oe = () => {
|
|
277
|
-
const
|
|
278
|
-
return
|
|
279
|
-
const
|
|
280
|
-
if (
|
|
322
|
+
const s = new URLSearchParams(window.location.search), e = {};
|
|
323
|
+
return it.forEach((r) => {
|
|
324
|
+
const n = s.get(r);
|
|
325
|
+
if (n) {
|
|
281
326
|
const i = r.split("utm_")[1];
|
|
282
|
-
e[i] =
|
|
327
|
+
e[i] = n;
|
|
283
328
|
}
|
|
284
329
|
}), Object.keys(e).length ? e : void 0;
|
|
285
|
-
},
|
|
330
|
+
}, Vt = () => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (s) => {
|
|
286
331
|
const e = Math.random() * 16 | 0;
|
|
287
|
-
return (
|
|
332
|
+
return (s === "x" ? e : e & 3 | 8).toString(16);
|
|
288
333
|
});
|
|
289
334
|
let B = 0, W = 0;
|
|
290
|
-
const
|
|
291
|
-
let
|
|
292
|
-
|
|
335
|
+
const kt = () => {
|
|
336
|
+
let s = Date.now();
|
|
337
|
+
s < W && (s = W), s === W ? B = (B + 1) % 1e3 : B = 0, W = s;
|
|
293
338
|
const e = B.toString().padStart(3, "0");
|
|
294
339
|
let t = "";
|
|
295
340
|
try {
|
|
296
341
|
if (typeof crypto < "u" && crypto.getRandomValues) {
|
|
297
342
|
const r = crypto.getRandomValues(new Uint8Array(3));
|
|
298
|
-
r && (t = Array.from(r, (
|
|
343
|
+
r && (t = Array.from(r, (n) => n.toString(16).padStart(2, "0")).join(""));
|
|
299
344
|
}
|
|
300
345
|
} catch {
|
|
301
346
|
}
|
|
302
|
-
return t || (t = Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")), `${
|
|
303
|
-
},
|
|
347
|
+
return t || (t = Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")), `${s}-${e}-${t}`;
|
|
348
|
+
}, Xe = (s, e = !1) => {
|
|
304
349
|
try {
|
|
305
|
-
const t = new URL(
|
|
306
|
-
return r || e &&
|
|
350
|
+
const t = new URL(s), r = t.protocol === "https:", n = t.protocol === "http:";
|
|
351
|
+
return r || e && n;
|
|
307
352
|
} catch {
|
|
308
353
|
return !1;
|
|
309
354
|
}
|
|
310
|
-
},
|
|
355
|
+
}, Ut = (s) => {
|
|
311
356
|
try {
|
|
312
357
|
const t = new URL(window.location.href).hostname;
|
|
313
358
|
if (!t || typeof t != "string")
|
|
@@ -321,146 +366,145 @@ const yt = () => {
|
|
|
321
366
|
throw new Error("Invalid hostname structure");
|
|
322
367
|
if (r.length === 1)
|
|
323
368
|
throw new Error("Single-part domain not supported for SaaS integration");
|
|
324
|
-
let
|
|
325
|
-
if (r.length === 2 ?
|
|
369
|
+
let n;
|
|
370
|
+
if (r.length === 2 ? n = r.join(".") : n = r.slice(-2).join("."), !n || n.split(".").length < 2)
|
|
326
371
|
throw new Error("Invalid domain structure for SaaS");
|
|
327
|
-
const i = `https://${
|
|
328
|
-
if (!
|
|
372
|
+
const i = `https://${s}.${n}/collect`;
|
|
373
|
+
if (!Xe(i))
|
|
329
374
|
throw new Error("Generated URL failed validation");
|
|
330
375
|
return i;
|
|
331
376
|
} catch (e) {
|
|
332
377
|
throw new Error(`Invalid SaaS URL configuration: ${e instanceof Error ? e.message : String(e)}`);
|
|
333
378
|
}
|
|
334
|
-
},
|
|
379
|
+
}, xt = (s) => {
|
|
335
380
|
const e = {};
|
|
336
|
-
|
|
337
|
-
const t =
|
|
381
|
+
s.integrations?.tracelog?.projectId && (e.saas = Ut(s.integrations.tracelog.projectId));
|
|
382
|
+
const t = s.integrations?.custom?.collectApiUrl;
|
|
338
383
|
if (t) {
|
|
339
|
-
const r =
|
|
340
|
-
if (!
|
|
384
|
+
const r = s.integrations?.custom?.allowHttp ?? !1;
|
|
385
|
+
if (!Xe(t, r))
|
|
341
386
|
throw new Error("Invalid custom API URL");
|
|
342
387
|
e.custom = t;
|
|
343
388
|
}
|
|
344
389
|
return e;
|
|
345
|
-
},
|
|
346
|
-
if (!
|
|
347
|
-
return a("warn", "Invalid URL provided to normalizeUrl", { data: {
|
|
390
|
+
}, le = (s, e = []) => {
|
|
391
|
+
if (!s || typeof s != "string")
|
|
392
|
+
return a("warn", "Invalid URL provided to normalizeUrl", { data: { type: typeof s } }), s || "";
|
|
348
393
|
try {
|
|
349
|
-
const t = new URL(
|
|
394
|
+
const t = new URL(s), r = t.searchParams, n = [.../* @__PURE__ */ new Set([...ot, ...e])];
|
|
350
395
|
let i = !1;
|
|
351
396
|
const o = [];
|
|
352
|
-
return
|
|
397
|
+
return n.forEach((c) => {
|
|
353
398
|
r.has(c) && (r.delete(c), i = !0, o.push(c));
|
|
354
|
-
}), !i &&
|
|
399
|
+
}), !i && s.includes("?") ? s : (t.search = r.toString(), t.toString());
|
|
355
400
|
} catch (t) {
|
|
356
|
-
|
|
357
|
-
return a("warn", "URL normalization failed, returning original", { error: t, data: { url: r } }), n;
|
|
401
|
+
return a("warn", "URL normalization failed, returning original", { error: t, data: { urlLength: s?.length } }), s;
|
|
358
402
|
}
|
|
359
|
-
}, Pe = (
|
|
360
|
-
if (!
|
|
403
|
+
}, Pe = (s) => {
|
|
404
|
+
if (!s || typeof s != "string" || s.trim().length === 0)
|
|
361
405
|
return "";
|
|
362
|
-
let e =
|
|
363
|
-
|
|
406
|
+
let e = s;
|
|
407
|
+
s.length > 1e3 && (e = s.slice(0, Math.max(0, 1e3)));
|
|
364
408
|
let t = 0;
|
|
365
|
-
for (const
|
|
409
|
+
for (const n of at) {
|
|
366
410
|
const i = e;
|
|
367
|
-
e = e.replace(
|
|
411
|
+
e = e.replace(n, ""), i !== e && t++;
|
|
368
412
|
}
|
|
369
413
|
return t > 0 && a("warn", "XSS patterns detected and removed", {
|
|
370
414
|
data: {
|
|
371
415
|
patternMatches: t,
|
|
372
|
-
|
|
416
|
+
valueLength: s.length
|
|
373
417
|
}
|
|
374
418
|
}), e = e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'").replaceAll("/", "/"), e.trim();
|
|
375
|
-
},
|
|
376
|
-
if (e > 3 ||
|
|
419
|
+
}, ce = (s, e = 0) => {
|
|
420
|
+
if (e > 3 || s == null)
|
|
377
421
|
return null;
|
|
378
|
-
if (typeof
|
|
379
|
-
return Pe(
|
|
380
|
-
if (typeof
|
|
381
|
-
return !Number.isFinite(
|
|
382
|
-
if (typeof
|
|
383
|
-
return
|
|
384
|
-
if (Array.isArray(
|
|
385
|
-
return
|
|
386
|
-
if (typeof
|
|
387
|
-
const t = {},
|
|
388
|
-
for (const [i, o] of
|
|
422
|
+
if (typeof s == "string")
|
|
423
|
+
return Pe(s);
|
|
424
|
+
if (typeof s == "number")
|
|
425
|
+
return !Number.isFinite(s) || s < -Number.MAX_SAFE_INTEGER || s > Number.MAX_SAFE_INTEGER ? 0 : s;
|
|
426
|
+
if (typeof s == "boolean")
|
|
427
|
+
return s;
|
|
428
|
+
if (Array.isArray(s))
|
|
429
|
+
return s.slice(0, 100).map((n) => ce(n, e + 1)).filter((n) => n !== null);
|
|
430
|
+
if (typeof s == "object") {
|
|
431
|
+
const t = {}, n = Object.entries(s).slice(0, 20);
|
|
432
|
+
for (const [i, o] of n) {
|
|
389
433
|
const l = Pe(i);
|
|
390
434
|
if (l) {
|
|
391
|
-
const c =
|
|
435
|
+
const c = ce(o, e + 1);
|
|
392
436
|
c !== null && (t[l] = c);
|
|
393
437
|
}
|
|
394
438
|
}
|
|
395
439
|
return t;
|
|
396
440
|
}
|
|
397
441
|
return null;
|
|
398
|
-
},
|
|
399
|
-
if (typeof
|
|
442
|
+
}, Ht = (s) => {
|
|
443
|
+
if (typeof s != "object" || s === null)
|
|
400
444
|
return {};
|
|
401
445
|
try {
|
|
402
|
-
const e =
|
|
446
|
+
const e = ce(s);
|
|
403
447
|
return typeof e == "object" && e !== null ? e : {};
|
|
404
448
|
} catch (e) {
|
|
405
449
|
const t = e instanceof Error ? e.message : String(e);
|
|
406
450
|
throw new Error(`[TraceLog] Metadata sanitization failed: ${t}`);
|
|
407
451
|
}
|
|
408
|
-
},
|
|
409
|
-
if (
|
|
452
|
+
}, Ft = (s) => {
|
|
453
|
+
if (s !== void 0 && (s === null || typeof s != "object"))
|
|
410
454
|
throw new h("Configuration must be an object", "config");
|
|
411
|
-
if (
|
|
412
|
-
if (
|
|
413
|
-
throw new
|
|
414
|
-
if (
|
|
455
|
+
if (s) {
|
|
456
|
+
if (s.sessionTimeout !== void 0 && (typeof s.sessionTimeout != "number" || s.sessionTimeout < 3e4 || s.sessionTimeout > 864e5))
|
|
457
|
+
throw new dt(m.INVALID_SESSION_TIMEOUT, "config");
|
|
458
|
+
if (s.globalMetadata !== void 0 && (typeof s.globalMetadata != "object" || s.globalMetadata === null))
|
|
415
459
|
throw new h(m.INVALID_GLOBAL_METADATA, "config");
|
|
416
|
-
if (
|
|
417
|
-
if (!Array.isArray(
|
|
460
|
+
if (s.integrations && Bt(s.integrations), s.sensitiveQueryParams !== void 0) {
|
|
461
|
+
if (!Array.isArray(s.sensitiveQueryParams))
|
|
418
462
|
throw new h(m.INVALID_SENSITIVE_QUERY_PARAMS, "config");
|
|
419
|
-
for (const e of
|
|
463
|
+
for (const e of s.sensitiveQueryParams)
|
|
420
464
|
if (typeof e != "string")
|
|
421
465
|
throw new h("All sensitive query params must be strings", "config");
|
|
422
466
|
}
|
|
423
|
-
if (
|
|
424
|
-
throw new
|
|
425
|
-
if (
|
|
426
|
-
throw new
|
|
427
|
-
if (
|
|
428
|
-
if (typeof
|
|
467
|
+
if (s.errorSampling !== void 0 && (typeof s.errorSampling != "number" || s.errorSampling < 0 || s.errorSampling > 1))
|
|
468
|
+
throw new Ae(m.INVALID_ERROR_SAMPLING_RATE, "config");
|
|
469
|
+
if (s.samplingRate !== void 0 && (typeof s.samplingRate != "number" || s.samplingRate < 0 || s.samplingRate > 1))
|
|
470
|
+
throw new Ae(m.INVALID_SAMPLING_RATE, "config");
|
|
471
|
+
if (s.primaryScrollSelector !== void 0) {
|
|
472
|
+
if (typeof s.primaryScrollSelector != "string" || !s.primaryScrollSelector.trim())
|
|
429
473
|
throw new h(m.INVALID_PRIMARY_SCROLL_SELECTOR, "config");
|
|
430
|
-
if (
|
|
474
|
+
if (s.primaryScrollSelector !== "window")
|
|
431
475
|
try {
|
|
432
|
-
document.querySelector(
|
|
476
|
+
document.querySelector(s.primaryScrollSelector);
|
|
433
477
|
} catch {
|
|
434
478
|
throw new h(
|
|
435
|
-
`${m.INVALID_PRIMARY_SCROLL_SELECTOR_SYNTAX}: "${
|
|
479
|
+
`${m.INVALID_PRIMARY_SCROLL_SELECTOR_SYNTAX}: "${s.primaryScrollSelector}"`,
|
|
436
480
|
"config"
|
|
437
481
|
);
|
|
438
482
|
}
|
|
439
483
|
}
|
|
440
|
-
if (
|
|
484
|
+
if (s.pageViewThrottleMs !== void 0 && (typeof s.pageViewThrottleMs != "number" || s.pageViewThrottleMs < 0))
|
|
441
485
|
throw new h(m.INVALID_PAGE_VIEW_THROTTLE, "config");
|
|
442
|
-
if (
|
|
486
|
+
if (s.clickThrottleMs !== void 0 && (typeof s.clickThrottleMs != "number" || s.clickThrottleMs < 0))
|
|
443
487
|
throw new h(m.INVALID_CLICK_THROTTLE, "config");
|
|
444
|
-
if (
|
|
488
|
+
if (s.maxSameEventPerMinute !== void 0 && (typeof s.maxSameEventPerMinute != "number" || s.maxSameEventPerMinute <= 0))
|
|
445
489
|
throw new h(m.INVALID_MAX_SAME_EVENT_PER_MINUTE, "config");
|
|
446
|
-
if (
|
|
447
|
-
if (typeof
|
|
490
|
+
if (s.viewport !== void 0 && $t(s.viewport), s.webVitalsMode !== void 0) {
|
|
491
|
+
if (typeof s.webVitalsMode != "string")
|
|
448
492
|
throw new h(
|
|
449
|
-
`Invalid webVitalsMode type: ${typeof
|
|
493
|
+
`Invalid webVitalsMode type: ${typeof s.webVitalsMode}. Must be a string`,
|
|
450
494
|
"config"
|
|
451
495
|
);
|
|
452
496
|
const e = ["all", "needs-improvement", "poor"];
|
|
453
|
-
if (!e.includes(
|
|
497
|
+
if (!e.includes(s.webVitalsMode))
|
|
454
498
|
throw new h(
|
|
455
|
-
`Invalid webVitalsMode: "${
|
|
499
|
+
`Invalid webVitalsMode: "${s.webVitalsMode}". Must be one of: ${e.join(", ")}`,
|
|
456
500
|
"config"
|
|
457
501
|
);
|
|
458
502
|
}
|
|
459
|
-
if (
|
|
460
|
-
if (typeof
|
|
503
|
+
if (s.webVitalsThresholds !== void 0) {
|
|
504
|
+
if (typeof s.webVitalsThresholds != "object" || s.webVitalsThresholds === null || Array.isArray(s.webVitalsThresholds))
|
|
461
505
|
throw new h("webVitalsThresholds must be an object", "config");
|
|
462
506
|
const e = ["LCP", "FCP", "CLS", "INP", "TTFB", "LONG_TASK"];
|
|
463
|
-
for (const [t, r] of Object.entries(
|
|
507
|
+
for (const [t, r] of Object.entries(s.webVitalsThresholds)) {
|
|
464
508
|
if (!e.includes(t))
|
|
465
509
|
throw new h(
|
|
466
510
|
`Invalid Web Vitals threshold key: "${t}". Must be one of: ${e.join(", ")}`,
|
|
@@ -474,15 +518,15 @@ const yt = () => {
|
|
|
474
518
|
}
|
|
475
519
|
}
|
|
476
520
|
}
|
|
477
|
-
},
|
|
478
|
-
if (typeof
|
|
521
|
+
}, $t = (s) => {
|
|
522
|
+
if (typeof s != "object" || s === null)
|
|
479
523
|
throw new h(m.INVALID_VIEWPORT_CONFIG, "config");
|
|
480
|
-
if (!
|
|
524
|
+
if (!s.elements || !Array.isArray(s.elements))
|
|
481
525
|
throw new h(m.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
482
|
-
if (
|
|
526
|
+
if (s.elements.length === 0)
|
|
483
527
|
throw new h(m.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
484
528
|
const e = /* @__PURE__ */ new Set();
|
|
485
|
-
for (const t of
|
|
529
|
+
for (const t of s.elements) {
|
|
486
530
|
if (!t.selector || typeof t.selector != "string" || !t.selector.trim())
|
|
487
531
|
throw new h(m.INVALID_VIEWPORT_ELEMENT, "config");
|
|
488
532
|
const r = t.selector.trim();
|
|
@@ -496,45 +540,45 @@ const yt = () => {
|
|
|
496
540
|
if (t.name !== void 0 && (typeof t.name != "string" || !t.name.trim()))
|
|
497
541
|
throw new h(m.INVALID_VIEWPORT_ELEMENT_NAME, "config");
|
|
498
542
|
}
|
|
499
|
-
if (
|
|
543
|
+
if (s.threshold !== void 0 && (typeof s.threshold != "number" || s.threshold < 0 || s.threshold > 1))
|
|
500
544
|
throw new h(m.INVALID_VIEWPORT_THRESHOLD, "config");
|
|
501
|
-
if (
|
|
545
|
+
if (s.minDwellTime !== void 0 && (typeof s.minDwellTime != "number" || s.minDwellTime < 0))
|
|
502
546
|
throw new h(m.INVALID_VIEWPORT_MIN_DWELL_TIME, "config");
|
|
503
|
-
if (
|
|
547
|
+
if (s.cooldownPeriod !== void 0 && (typeof s.cooldownPeriod != "number" || s.cooldownPeriod < 0))
|
|
504
548
|
throw new h(m.INVALID_VIEWPORT_COOLDOWN_PERIOD, "config");
|
|
505
|
-
if (
|
|
549
|
+
if (s.maxTrackedElements !== void 0 && (typeof s.maxTrackedElements != "number" || s.maxTrackedElements <= 0))
|
|
506
550
|
throw new h(m.INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS, "config");
|
|
507
|
-
},
|
|
508
|
-
if (
|
|
509
|
-
if (
|
|
510
|
-
throw new
|
|
511
|
-
if (
|
|
512
|
-
if (!
|
|
513
|
-
throw new
|
|
514
|
-
if (
|
|
515
|
-
throw new
|
|
516
|
-
const e =
|
|
551
|
+
}, Bt = (s) => {
|
|
552
|
+
if (s) {
|
|
553
|
+
if (s.tracelog && (!s.tracelog.projectId || typeof s.tracelog.projectId != "string" || s.tracelog.projectId.trim() === ""))
|
|
554
|
+
throw new V(m.INVALID_TRACELOG_PROJECT_ID, "config");
|
|
555
|
+
if (s.custom) {
|
|
556
|
+
if (!s.custom.collectApiUrl || typeof s.custom.collectApiUrl != "string" || s.custom.collectApiUrl.trim() === "")
|
|
557
|
+
throw new V(m.INVALID_CUSTOM_API_URL, "config");
|
|
558
|
+
if (s.custom.allowHttp !== void 0 && typeof s.custom.allowHttp != "boolean")
|
|
559
|
+
throw new V("allowHttp must be a boolean", "config");
|
|
560
|
+
const e = s.custom.collectApiUrl.trim();
|
|
517
561
|
if (!e.startsWith("http://") && !e.startsWith("https://"))
|
|
518
|
-
throw new
|
|
519
|
-
if (!(
|
|
520
|
-
throw new
|
|
562
|
+
throw new V('Custom API URL must start with "http://" or "https://"', "config");
|
|
563
|
+
if (!(s.custom.allowHttp ?? !1) && e.startsWith("http://"))
|
|
564
|
+
throw new V(
|
|
521
565
|
"Custom API URL must use HTTPS in production. Set allowHttp: true in integration config to allow HTTP (not recommended)",
|
|
522
566
|
"config"
|
|
523
567
|
);
|
|
524
568
|
}
|
|
525
569
|
}
|
|
526
|
-
},
|
|
527
|
-
|
|
570
|
+
}, Wt = (s) => {
|
|
571
|
+
Ft(s);
|
|
528
572
|
const e = {
|
|
529
|
-
...
|
|
530
|
-
sessionTimeout:
|
|
531
|
-
globalMetadata:
|
|
532
|
-
sensitiveQueryParams:
|
|
533
|
-
errorSampling:
|
|
534
|
-
samplingRate:
|
|
535
|
-
pageViewThrottleMs:
|
|
536
|
-
clickThrottleMs:
|
|
537
|
-
maxSameEventPerMinute:
|
|
573
|
+
...s ?? {},
|
|
574
|
+
sessionTimeout: s?.sessionTimeout ?? 9e5,
|
|
575
|
+
globalMetadata: s?.globalMetadata ?? {},
|
|
576
|
+
sensitiveQueryParams: s?.sensitiveQueryParams ?? [],
|
|
577
|
+
errorSampling: s?.errorSampling ?? We,
|
|
578
|
+
samplingRate: s?.samplingRate ?? 1,
|
|
579
|
+
pageViewThrottleMs: s?.pageViewThrottleMs ?? 1e3,
|
|
580
|
+
clickThrottleMs: s?.clickThrottleMs ?? 300,
|
|
581
|
+
maxSameEventPerMinute: s?.maxSameEventPerMinute ?? 60
|
|
538
582
|
};
|
|
539
583
|
return e.integrations?.custom && (e.integrations.custom = {
|
|
540
584
|
...e.integrations.custom,
|
|
@@ -546,11 +590,11 @@ const yt = () => {
|
|
|
546
590
|
cooldownPeriod: e.viewport.cooldownPeriod ?? 6e4,
|
|
547
591
|
maxTrackedElements: e.viewport.maxTrackedElements ?? 100
|
|
548
592
|
}), e;
|
|
549
|
-
},
|
|
550
|
-
if (typeof
|
|
593
|
+
}, Gt = (s) => {
|
|
594
|
+
if (typeof s == "string")
|
|
551
595
|
return !0;
|
|
552
|
-
if (typeof
|
|
553
|
-
const e = Object.entries(
|
|
596
|
+
if (typeof s == "object" && s !== null && !Array.isArray(s)) {
|
|
597
|
+
const e = Object.entries(s);
|
|
554
598
|
if (e.length > 20)
|
|
555
599
|
return !1;
|
|
556
600
|
for (const [, t] of e) {
|
|
@@ -563,10 +607,10 @@ const yt = () => {
|
|
|
563
607
|
return !0;
|
|
564
608
|
}
|
|
565
609
|
return !1;
|
|
566
|
-
},
|
|
567
|
-
if (typeof
|
|
610
|
+
}, Qe = (s, e = 0) => {
|
|
611
|
+
if (typeof s != "object" || s === null || e > 1)
|
|
568
612
|
return !1;
|
|
569
|
-
for (const t of Object.values(
|
|
613
|
+
for (const t of Object.values(s)) {
|
|
570
614
|
if (t == null)
|
|
571
615
|
continue;
|
|
572
616
|
const r = typeof t;
|
|
@@ -577,12 +621,12 @@ const yt = () => {
|
|
|
577
621
|
if (typeof t[0] == "string") {
|
|
578
622
|
if (!t.every((o) => typeof o == "string"))
|
|
579
623
|
return !1;
|
|
580
|
-
} else if (!t.every((o) =>
|
|
624
|
+
} else if (!t.every((o) => Gt(o)))
|
|
581
625
|
return !1;
|
|
582
626
|
continue;
|
|
583
627
|
}
|
|
584
628
|
if (r === "object" && e === 0) {
|
|
585
|
-
if (!
|
|
629
|
+
if (!Qe(t, e + 1))
|
|
586
630
|
return !1;
|
|
587
631
|
continue;
|
|
588
632
|
}
|
|
@@ -590,27 +634,27 @@ const yt = () => {
|
|
|
590
634
|
}
|
|
591
635
|
}
|
|
592
636
|
return !0;
|
|
593
|
-
},
|
|
637
|
+
}, Xt = (s) => typeof s != "string" ? {
|
|
594
638
|
valid: !1,
|
|
595
639
|
error: "Event name must be a string"
|
|
596
|
-
} :
|
|
640
|
+
} : s.length === 0 ? {
|
|
597
641
|
valid: !1,
|
|
598
642
|
error: "Event name cannot be empty"
|
|
599
|
-
} :
|
|
643
|
+
} : s.length > 120 ? {
|
|
600
644
|
valid: !1,
|
|
601
645
|
error: "Event name is too long (max 120 characters)"
|
|
602
|
-
} :
|
|
646
|
+
} : s.includes("<") || s.includes(">") || s.includes("&") ? {
|
|
603
647
|
valid: !1,
|
|
604
648
|
error: "Event name contains invalid characters"
|
|
605
|
-
} : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(
|
|
649
|
+
} : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(s.toLowerCase()) ? {
|
|
606
650
|
valid: !1,
|
|
607
651
|
error: "Event name cannot be a reserved word"
|
|
608
|
-
} : { valid: !0 }, De = (
|
|
609
|
-
const r =
|
|
610
|
-
if (!
|
|
652
|
+
} : { valid: !0 }, De = (s, e, t) => {
|
|
653
|
+
const r = Ht(e), n = t && t === "customEvent" ? `${t} "${s}" metadata error` : `${s} metadata error`;
|
|
654
|
+
if (!Qe(r))
|
|
611
655
|
return {
|
|
612
656
|
valid: !1,
|
|
613
|
-
error: `${
|
|
657
|
+
error: `${n}: object has invalid types. Valid types are string, number, boolean or string arrays.`
|
|
614
658
|
};
|
|
615
659
|
let i;
|
|
616
660
|
try {
|
|
@@ -618,58 +662,58 @@ const yt = () => {
|
|
|
618
662
|
} catch {
|
|
619
663
|
return {
|
|
620
664
|
valid: !1,
|
|
621
|
-
error: `${
|
|
665
|
+
error: `${n}: object contains circular references or cannot be serialized.`
|
|
622
666
|
};
|
|
623
667
|
}
|
|
624
668
|
if (i.length > 8192)
|
|
625
669
|
return {
|
|
626
670
|
valid: !1,
|
|
627
|
-
error: `${
|
|
671
|
+
error: `${n}: object is too large (max ${8192 / 1024} KB).`
|
|
628
672
|
};
|
|
629
673
|
if (Object.keys(r).length > 10)
|
|
630
674
|
return {
|
|
631
675
|
valid: !1,
|
|
632
|
-
error: `${
|
|
676
|
+
error: `${n}: object has too many keys (max 10 keys).`
|
|
633
677
|
};
|
|
634
678
|
for (const [l, c] of Object.entries(r)) {
|
|
635
679
|
if (Array.isArray(c)) {
|
|
636
680
|
if (c.length > 10)
|
|
637
681
|
return {
|
|
638
682
|
valid: !1,
|
|
639
|
-
error: `${
|
|
683
|
+
error: `${n}: array property "${l}" is too large (max 10 items).`
|
|
640
684
|
};
|
|
641
|
-
for (const
|
|
642
|
-
if (typeof
|
|
685
|
+
for (const u of c)
|
|
686
|
+
if (typeof u == "string" && u.length > 500)
|
|
643
687
|
return {
|
|
644
688
|
valid: !1,
|
|
645
|
-
error: `${
|
|
689
|
+
error: `${n}: array property "${l}" contains strings that are too long (max 500 characters).`
|
|
646
690
|
};
|
|
647
691
|
}
|
|
648
692
|
if (typeof c == "string" && c.length > 1e3)
|
|
649
693
|
return {
|
|
650
694
|
valid: !1,
|
|
651
|
-
error: `${
|
|
695
|
+
error: `${n}: property "${l}" is too long (max 1000 characters).`
|
|
652
696
|
};
|
|
653
697
|
}
|
|
654
698
|
return {
|
|
655
699
|
valid: !0,
|
|
656
700
|
sanitizedMetadata: r
|
|
657
701
|
};
|
|
658
|
-
},
|
|
702
|
+
}, ze = (s, e, t) => {
|
|
659
703
|
if (Array.isArray(e)) {
|
|
660
|
-
const r = [],
|
|
704
|
+
const r = [], n = t && t === "customEvent" ? `${t} "${s}" metadata error` : `${s} metadata error`;
|
|
661
705
|
for (let i = 0; i < e.length; i++) {
|
|
662
706
|
const o = e[i];
|
|
663
707
|
if (typeof o != "object" || o === null || Array.isArray(o))
|
|
664
708
|
return {
|
|
665
709
|
valid: !1,
|
|
666
|
-
error: `${
|
|
710
|
+
error: `${n}: array item at index ${i} must be an object.`
|
|
667
711
|
};
|
|
668
|
-
const l = De(
|
|
712
|
+
const l = De(s, o, t);
|
|
669
713
|
if (!l.valid)
|
|
670
714
|
return {
|
|
671
715
|
valid: !1,
|
|
672
|
-
error: `${
|
|
716
|
+
error: `${n}: array item at index ${i} is invalid: ${l.error}`
|
|
673
717
|
};
|
|
674
718
|
l.sanitizedMetadata && r.push(l.sanitizedMetadata);
|
|
675
719
|
}
|
|
@@ -678,26 +722,24 @@ const yt = () => {
|
|
|
678
722
|
sanitizedMetadata: r
|
|
679
723
|
};
|
|
680
724
|
}
|
|
681
|
-
return De(
|
|
682
|
-
},
|
|
683
|
-
const t =
|
|
725
|
+
return De(s, e, t);
|
|
726
|
+
}, Qt = (s, e) => {
|
|
727
|
+
const t = Xt(s);
|
|
684
728
|
if (!t.valid)
|
|
685
729
|
return a("error", "Event name validation failed", {
|
|
686
|
-
|
|
687
|
-
data: { eventName: n, error: t.error }
|
|
730
|
+
data: { eventName: s, error: t.error }
|
|
688
731
|
}), t;
|
|
689
732
|
if (!e)
|
|
690
733
|
return { valid: !0 };
|
|
691
|
-
const r =
|
|
734
|
+
const r = ze(s, e, "customEvent");
|
|
692
735
|
return r.valid || a("error", "Event metadata validation failed", {
|
|
693
|
-
showToClient: !0,
|
|
694
736
|
data: {
|
|
695
|
-
eventName:
|
|
737
|
+
eventName: s,
|
|
696
738
|
error: r.error
|
|
697
739
|
}
|
|
698
740
|
}), r;
|
|
699
741
|
};
|
|
700
|
-
class
|
|
742
|
+
class zt {
|
|
701
743
|
listeners = /* @__PURE__ */ new Map();
|
|
702
744
|
/**
|
|
703
745
|
* Subscribes to an event channel
|
|
@@ -750,8 +792,8 @@ class Vt {
|
|
|
750
792
|
off(e, t) {
|
|
751
793
|
const r = this.listeners.get(e);
|
|
752
794
|
if (r) {
|
|
753
|
-
const
|
|
754
|
-
|
|
795
|
+
const n = r.indexOf(t);
|
|
796
|
+
n > -1 && r.splice(n, 1);
|
|
755
797
|
}
|
|
756
798
|
}
|
|
757
799
|
/**
|
|
@@ -784,8 +826,8 @@ class Vt {
|
|
|
784
826
|
*/
|
|
785
827
|
emit(e, t) {
|
|
786
828
|
const r = this.listeners.get(e);
|
|
787
|
-
r && r.forEach((
|
|
788
|
-
|
|
829
|
+
r && r.forEach((n) => {
|
|
830
|
+
n(t);
|
|
789
831
|
});
|
|
790
832
|
}
|
|
791
833
|
/**
|
|
@@ -814,34 +856,38 @@ class Vt {
|
|
|
814
856
|
this.listeners.clear();
|
|
815
857
|
}
|
|
816
858
|
}
|
|
817
|
-
function
|
|
859
|
+
function je(s, e, t) {
|
|
818
860
|
try {
|
|
819
|
-
const r = e(
|
|
820
|
-
return r === null ? null : typeof r == "object" && r !== null && "type" in r ? r : (a("warn", `beforeSend transformer returned invalid data, using original [${t}]`),
|
|
861
|
+
const r = e(s);
|
|
862
|
+
return r === null ? null : typeof r == "object" && r !== null && "type" in r ? r : (a("warn", `beforeSend transformer returned invalid data, using original [${t}]`), s);
|
|
821
863
|
} catch (r) {
|
|
822
|
-
return a("error", `beforeSend transformer threw error, using original event [${t}]`, {
|
|
864
|
+
return a("error", `beforeSend transformer threw error, using original event [${t}]`, {
|
|
865
|
+
error: r,
|
|
866
|
+
visibility: "critical"
|
|
867
|
+
}), s;
|
|
823
868
|
}
|
|
824
869
|
}
|
|
825
|
-
function
|
|
826
|
-
return
|
|
870
|
+
function jt(s, e, t) {
|
|
871
|
+
return s.map((r) => je(r, e, t)).filter((r) => r !== null);
|
|
827
872
|
}
|
|
828
|
-
function
|
|
873
|
+
function Ke(s, e, t) {
|
|
829
874
|
try {
|
|
830
|
-
const r = e(
|
|
875
|
+
const r = e(s);
|
|
831
876
|
return r === null ? (a("debug", `Batch filtered by beforeBatch transformer [${t}]`, {
|
|
832
|
-
data: { eventCount:
|
|
877
|
+
data: { eventCount: s.events.length }
|
|
833
878
|
}), null) : typeof r == "object" && r !== null && Array.isArray(r.events) ? r : (a("warn", `beforeBatch transformer returned invalid data, using original [${t}]`, {
|
|
834
|
-
data: { eventCount:
|
|
835
|
-
}),
|
|
879
|
+
data: { eventCount: s.events.length }
|
|
880
|
+
}), s);
|
|
836
881
|
} catch (r) {
|
|
837
882
|
return a("error", `beforeBatch transformer threw error, using original batch [${t}]`, {
|
|
838
883
|
error: r,
|
|
839
|
-
data: { eventCount:
|
|
840
|
-
|
|
884
|
+
data: { eventCount: s.events.length },
|
|
885
|
+
visibility: "critical"
|
|
886
|
+
}), s;
|
|
841
887
|
}
|
|
842
888
|
}
|
|
843
|
-
const
|
|
844
|
-
class
|
|
889
|
+
const te = {};
|
|
890
|
+
class _ {
|
|
845
891
|
/**
|
|
846
892
|
* Retrieves a value from global state.
|
|
847
893
|
*
|
|
@@ -859,7 +905,7 @@ class p {
|
|
|
859
905
|
* ```
|
|
860
906
|
*/
|
|
861
907
|
get(e) {
|
|
862
|
-
return
|
|
908
|
+
return te[e];
|
|
863
909
|
}
|
|
864
910
|
/**
|
|
865
911
|
* Sets a value in global state.
|
|
@@ -879,7 +925,7 @@ class p {
|
|
|
879
925
|
* ```
|
|
880
926
|
*/
|
|
881
927
|
set(e, t) {
|
|
882
|
-
|
|
928
|
+
te[e] = t;
|
|
883
929
|
}
|
|
884
930
|
/**
|
|
885
931
|
* Returns an immutable snapshot of the entire global state.
|
|
@@ -896,10 +942,10 @@ class p {
|
|
|
896
942
|
* ```
|
|
897
943
|
*/
|
|
898
944
|
getState() {
|
|
899
|
-
return { ...
|
|
945
|
+
return { ...te };
|
|
900
946
|
}
|
|
901
947
|
}
|
|
902
|
-
class Ve extends
|
|
948
|
+
class Ve extends _ {
|
|
903
949
|
storeManager;
|
|
904
950
|
integrationId;
|
|
905
951
|
apiUrl;
|
|
@@ -920,10 +966,10 @@ class Ve extends p {
|
|
|
920
966
|
* @param transformers - Optional event transformation hooks
|
|
921
967
|
* @throws Error if integrationId and apiUrl are not both provided or both undefined
|
|
922
968
|
*/
|
|
923
|
-
constructor(e, t, r,
|
|
969
|
+
constructor(e, t, r, n = {}) {
|
|
924
970
|
if (super(), t && !r || !t && r)
|
|
925
971
|
throw new Error("SenderManager: integrationId and apiUrl must either both be provided or both be undefined");
|
|
926
|
-
this.storeManager = e, this.integrationId = t, this.apiUrl = r, this.transformers =
|
|
972
|
+
this.storeManager = e, this.integrationId = t, this.apiUrl = r, this.transformers = n;
|
|
927
973
|
}
|
|
928
974
|
/**
|
|
929
975
|
* Get the integration ID for this sender
|
|
@@ -933,7 +979,7 @@ class Ve extends p {
|
|
|
933
979
|
return this.integrationId;
|
|
934
980
|
}
|
|
935
981
|
getQueueStorageKey() {
|
|
936
|
-
const e = this.get("userId") || "anonymous", t =
|
|
982
|
+
const e = this.get("userId") || "anonymous", t = lt(e);
|
|
937
983
|
return this.integrationId ? `${t}:${this.integrationId}` : t;
|
|
938
984
|
}
|
|
939
985
|
/**
|
|
@@ -965,13 +1011,13 @@ class Ve extends p {
|
|
|
965
1011
|
* @see src/managers/README.md (lines 82-139) for send details
|
|
966
1012
|
*/
|
|
967
1013
|
sendEventsQueueSync(e) {
|
|
968
|
-
return this.shouldSkipSend() ? !0 : this.apiUrl?.includes(
|
|
1014
|
+
return this.shouldSkipSend() ? !0 : this.apiUrl?.includes(k.Fail) ? (a(
|
|
969
1015
|
"warn",
|
|
970
1016
|
`Fail mode: simulating network failure (sync)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
971
1017
|
{
|
|
972
1018
|
data: { events: e.events.length }
|
|
973
1019
|
}
|
|
974
|
-
), !1) : this.apiUrl?.includes(
|
|
1020
|
+
), !1) : this.apiUrl?.includes(k.Localhost) ? (a(
|
|
975
1021
|
"debug",
|
|
976
1022
|
`Success mode: simulating successful send (sync)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
977
1023
|
{
|
|
@@ -1013,7 +1059,7 @@ class Ve extends p {
|
|
|
1013
1059
|
const r = await this.send(e);
|
|
1014
1060
|
return r ? (this.clearPersistedEvents(), t?.onSuccess?.(e.events.length, e.events, e)) : (this.persistEvents(e), t?.onFailure?.()), r;
|
|
1015
1061
|
} catch (r) {
|
|
1016
|
-
return r instanceof
|
|
1062
|
+
return r instanceof N ? (this.logPermanentError("Permanent error, not retrying", r), this.clearPersistedEvents(), t?.onFailure?.(), !1) : (this.persistEvents(e), t?.onFailure?.(), !1);
|
|
1017
1063
|
}
|
|
1018
1064
|
}
|
|
1019
1065
|
/**
|
|
@@ -1080,7 +1126,7 @@ class Ve extends p {
|
|
|
1080
1126
|
const r = this.createRecoveryBody(t);
|
|
1081
1127
|
await this.send(r) ? (this.clearPersistedEvents(), e?.onSuccess?.(t.events.length, t.events, r)) : e?.onFailure?.();
|
|
1082
1128
|
} catch (t) {
|
|
1083
|
-
if (t instanceof
|
|
1129
|
+
if (t instanceof N) {
|
|
1084
1130
|
this.logPermanentError("Permanent error during recovery, clearing persisted events", t), this.clearPersistedEvents(), e?.onFailure?.();
|
|
1085
1131
|
return;
|
|
1086
1132
|
}
|
|
@@ -1134,7 +1180,7 @@ class Ve extends p {
|
|
|
1134
1180
|
const t = this.transformers.beforeSend;
|
|
1135
1181
|
if (!t)
|
|
1136
1182
|
return e;
|
|
1137
|
-
const r =
|
|
1183
|
+
const r = jt(
|
|
1138
1184
|
e.events,
|
|
1139
1185
|
t,
|
|
1140
1186
|
this.integrationId || "SenderManager"
|
|
@@ -1179,7 +1225,7 @@ class Ve extends p {
|
|
|
1179
1225
|
if (this.integrationId === "saas")
|
|
1180
1226
|
return e;
|
|
1181
1227
|
const t = this.transformers.beforeBatch;
|
|
1182
|
-
return t ?
|
|
1228
|
+
return t ? Ke(e, t, this.integrationId || "SenderManager") : e;
|
|
1183
1229
|
}
|
|
1184
1230
|
/**
|
|
1185
1231
|
* Calculates exponential backoff delay with jitter for retry attempts.
|
|
@@ -1201,8 +1247,8 @@ class Ve extends p {
|
|
|
1201
1247
|
* @returns Promise that resolves after calculated delay
|
|
1202
1248
|
*/
|
|
1203
1249
|
async backoffDelay(e) {
|
|
1204
|
-
const t = 100 * Math.pow(2, e), r = Math.random() * 100,
|
|
1205
|
-
return new Promise((i) => setTimeout(i,
|
|
1250
|
+
const t = 100 * Math.pow(2, e), r = Math.random() * 100, n = t + r;
|
|
1251
|
+
return new Promise((i) => setTimeout(i, n));
|
|
1206
1252
|
}
|
|
1207
1253
|
/**
|
|
1208
1254
|
* Sends event queue with automatic retry logic for transient failures.
|
|
@@ -1247,18 +1293,18 @@ class Ve extends p {
|
|
|
1247
1293
|
const r = this.applyBeforeBatchTransformer(t);
|
|
1248
1294
|
if (!r)
|
|
1249
1295
|
return !0;
|
|
1250
|
-
if (this.apiUrl?.includes(
|
|
1251
|
-
return a("
|
|
1296
|
+
if (this.apiUrl?.includes(k.Fail))
|
|
1297
|
+
return a("debug", `Fail mode: simulating network failure${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1252
1298
|
data: { events: r.events.length }
|
|
1253
1299
|
}), !1;
|
|
1254
|
-
if (this.apiUrl?.includes(
|
|
1300
|
+
if (this.apiUrl?.includes(k.Localhost))
|
|
1255
1301
|
return a("debug", `Success mode: simulating successful send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1256
1302
|
data: { events: r.events.length }
|
|
1257
1303
|
}), !0;
|
|
1258
|
-
const { url:
|
|
1304
|
+
const { url: n, payload: i } = this.prepareRequest(r);
|
|
1259
1305
|
for (let o = 1; o <= 3; o++)
|
|
1260
1306
|
try {
|
|
1261
|
-
return (await this.sendWithTimeout(
|
|
1307
|
+
return (await this.sendWithTimeout(n, i)).ok ? (o > 1 && a(
|
|
1262
1308
|
"info",
|
|
1263
1309
|
`Send succeeded after ${o - 1} retry attempt(s)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1264
1310
|
{
|
|
@@ -1267,7 +1313,7 @@ class Ve extends p {
|
|
|
1267
1313
|
), !0) : !1;
|
|
1268
1314
|
} catch (l) {
|
|
1269
1315
|
const c = o === 3;
|
|
1270
|
-
if (l instanceof
|
|
1316
|
+
if (l instanceof N)
|
|
1271
1317
|
throw l;
|
|
1272
1318
|
if (a(
|
|
1273
1319
|
c ? "error" : "warn",
|
|
@@ -1276,7 +1322,7 @@ class Ve extends p {
|
|
|
1276
1322
|
error: l,
|
|
1277
1323
|
data: {
|
|
1278
1324
|
events: e.events.length,
|
|
1279
|
-
url:
|
|
1325
|
+
url: n.replace(/\/\/[^/]+/, "//[DOMAIN]"),
|
|
1280
1326
|
attempt: o,
|
|
1281
1327
|
maxAttempts: 3
|
|
1282
1328
|
}
|
|
@@ -1313,7 +1359,7 @@ class Ve extends p {
|
|
|
1313
1359
|
async sendWithTimeout(e, t) {
|
|
1314
1360
|
const r = new AbortController();
|
|
1315
1361
|
this.pendingControllers.add(r);
|
|
1316
|
-
const
|
|
1362
|
+
const n = setTimeout(() => {
|
|
1317
1363
|
r.abort();
|
|
1318
1364
|
}, 15e3);
|
|
1319
1365
|
try {
|
|
@@ -1328,10 +1374,10 @@ class Ve extends p {
|
|
|
1328
1374
|
}
|
|
1329
1375
|
});
|
|
1330
1376
|
if (!i.ok)
|
|
1331
|
-
throw i.status >= 400 && i.status < 500 && i.status !== 408 && i.status !== 429 ? new
|
|
1377
|
+
throw i.status >= 400 && i.status < 500 && i.status !== 408 && i.status !== 429 ? new N(`HTTP ${i.status}: ${i.statusText}`, i.status) : new Error(`HTTP ${i.status}: ${i.statusText}`);
|
|
1332
1378
|
return i;
|
|
1333
1379
|
} finally {
|
|
1334
|
-
clearTimeout(
|
|
1380
|
+
clearTimeout(n), this.pendingControllers.delete(r);
|
|
1335
1381
|
}
|
|
1336
1382
|
}
|
|
1337
1383
|
/**
|
|
@@ -1361,7 +1407,7 @@ class Ve extends p {
|
|
|
1361
1407
|
const r = this.applyBeforeBatchTransformer(t);
|
|
1362
1408
|
if (!r)
|
|
1363
1409
|
return !0;
|
|
1364
|
-
const { url:
|
|
1410
|
+
const { url: n, payload: i } = this.prepareRequest(r);
|
|
1365
1411
|
if (i.length > 65536)
|
|
1366
1412
|
return a(
|
|
1367
1413
|
"warn",
|
|
@@ -1380,7 +1426,7 @@ class Ve extends p {
|
|
|
1380
1426
|
"warn",
|
|
1381
1427
|
`sendBeacon not available, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1382
1428
|
), this.persistEvents(r), !1;
|
|
1383
|
-
const l = navigator.sendBeacon(
|
|
1429
|
+
const l = navigator.sendBeacon(n, o);
|
|
1384
1430
|
return l || (a(
|
|
1385
1431
|
"warn",
|
|
1386
1432
|
`sendBeacon rejected request, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
@@ -1412,7 +1458,7 @@ class Ve extends p {
|
|
|
1412
1458
|
_metadata: {
|
|
1413
1459
|
referer: typeof window < "u" ? window.location.href : void 0,
|
|
1414
1460
|
timestamp: t,
|
|
1415
|
-
client_version:
|
|
1461
|
+
client_version: Nt
|
|
1416
1462
|
}
|
|
1417
1463
|
};
|
|
1418
1464
|
return {
|
|
@@ -1438,7 +1484,7 @@ class Ve extends p {
|
|
|
1438
1484
|
if (t)
|
|
1439
1485
|
return JSON.parse(t);
|
|
1440
1486
|
} catch (e) {
|
|
1441
|
-
a("
|
|
1487
|
+
a("debug", `Failed to parse persisted data${this.integrationId ? ` [${this.integrationId}]` : ""}`, { error: e }), this.clearPersistedEvents();
|
|
1442
1488
|
}
|
|
1443
1489
|
return null;
|
|
1444
1490
|
}
|
|
@@ -1505,10 +1551,10 @@ class Ve extends p {
|
|
|
1505
1551
|
const r = {
|
|
1506
1552
|
...e,
|
|
1507
1553
|
timestamp: Date.now()
|
|
1508
|
-
},
|
|
1509
|
-
return this.storeManager.setItem(
|
|
1554
|
+
}, n = this.getQueueStorageKey();
|
|
1555
|
+
return this.storeManager.setItem(n, JSON.stringify(r)), !!this.storeManager.getItem(n);
|
|
1510
1556
|
} catch (t) {
|
|
1511
|
-
return a("
|
|
1557
|
+
return a("debug", `Failed to persist events${this.integrationId ? ` [${this.integrationId}]` : ""}`, { error: t }), !1;
|
|
1512
1558
|
}
|
|
1513
1559
|
}
|
|
1514
1560
|
clearPersistedEvents() {
|
|
@@ -1516,7 +1562,9 @@ class Ve extends p {
|
|
|
1516
1562
|
const e = this.getQueueStorageKey();
|
|
1517
1563
|
this.storeManager.removeItem(e);
|
|
1518
1564
|
} catch (e) {
|
|
1519
|
-
a("
|
|
1565
|
+
a("debug", `Failed to clear persisted events${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1566
|
+
error: e
|
|
1567
|
+
});
|
|
1520
1568
|
}
|
|
1521
1569
|
}
|
|
1522
1570
|
shouldSkipSend() {
|
|
@@ -1531,12 +1579,12 @@ class Ve extends p {
|
|
|
1531
1579
|
}
|
|
1532
1580
|
logPermanentError(e, t) {
|
|
1533
1581
|
const r = Date.now();
|
|
1534
|
-
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || r - this.lastPermanentErrorLog.timestamp >=
|
|
1582
|
+
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || r - this.lastPermanentErrorLog.timestamp >= At) && (a("error", `${e}${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1535
1583
|
data: { status: t.statusCode, message: t.message }
|
|
1536
1584
|
}), this.lastPermanentErrorLog = { statusCode: t.statusCode, timestamp: r });
|
|
1537
1585
|
}
|
|
1538
1586
|
}
|
|
1539
|
-
class
|
|
1587
|
+
class Kt extends _ {
|
|
1540
1588
|
bootTime;
|
|
1541
1589
|
bootTimestamp;
|
|
1542
1590
|
hasPerformanceNow;
|
|
@@ -1566,7 +1614,7 @@ class Ut extends p {
|
|
|
1566
1614
|
bootTime: this.bootTime.toFixed(3),
|
|
1567
1615
|
bootTimestamp: this.bootTimestamp
|
|
1568
1616
|
}
|
|
1569
|
-
})) : (this.bootTime = 0, this.bootTimestamp = Date.now(), a("
|
|
1617
|
+
})) : (this.bootTime = 0, this.bootTimestamp = Date.now(), a("debug", "performance.now() not available, falling back to Date.now()"));
|
|
1570
1618
|
}
|
|
1571
1619
|
/**
|
|
1572
1620
|
* Returns current timestamp in milliseconds since epoch.
|
|
@@ -1663,10 +1711,10 @@ class Ut extends p {
|
|
|
1663
1711
|
* ```
|
|
1664
1712
|
*/
|
|
1665
1713
|
validateTimestamp(e) {
|
|
1666
|
-
const r = this.now(),
|
|
1667
|
-
return
|
|
1714
|
+
const r = this.now(), n = e - r;
|
|
1715
|
+
return n > 12e4 ? {
|
|
1668
1716
|
valid: !1,
|
|
1669
|
-
error: `Timestamp is ${(
|
|
1717
|
+
error: `Timestamp is ${(n / 1e3 / 60).toFixed(2)} minutes in the future (max allowed: 2 minutes)`
|
|
1670
1718
|
} : { valid: !0 };
|
|
1671
1719
|
}
|
|
1672
1720
|
/**
|
|
@@ -1685,7 +1733,7 @@ class Ut extends p {
|
|
|
1685
1733
|
};
|
|
1686
1734
|
}
|
|
1687
1735
|
}
|
|
1688
|
-
class
|
|
1736
|
+
class Yt extends _ {
|
|
1689
1737
|
dataSenders;
|
|
1690
1738
|
emitter;
|
|
1691
1739
|
transformers;
|
|
@@ -1700,11 +1748,11 @@ class xt extends p {
|
|
|
1700
1748
|
lastSessionId = null;
|
|
1701
1749
|
sessionEventCounts = {
|
|
1702
1750
|
total: 0,
|
|
1703
|
-
[
|
|
1704
|
-
[
|
|
1705
|
-
[
|
|
1706
|
-
[
|
|
1707
|
-
[
|
|
1751
|
+
[d.CLICK]: 0,
|
|
1752
|
+
[d.PAGE_VIEW]: 0,
|
|
1753
|
+
[d.CUSTOM]: 0,
|
|
1754
|
+
[d.VIEWPORT_VISIBLE]: 0,
|
|
1755
|
+
[d.SCROLL]: 0
|
|
1708
1756
|
};
|
|
1709
1757
|
saveSessionCountsDebounced = null;
|
|
1710
1758
|
/**
|
|
@@ -1719,9 +1767,9 @@ class xt extends p {
|
|
|
1719
1767
|
* @param transformers - Optional event transformation hooks
|
|
1720
1768
|
*/
|
|
1721
1769
|
constructor(e, t = null, r = {}) {
|
|
1722
|
-
super(), this.emitter = t, this.transformers = r, this.timeManager = new
|
|
1723
|
-
const
|
|
1724
|
-
|
|
1770
|
+
super(), this.emitter = t, this.transformers = r, this.timeManager = new Kt(), this.dataSenders = [];
|
|
1771
|
+
const n = this.get("collectApiUrls");
|
|
1772
|
+
n?.saas && this.dataSenders.push(new Ve(e, "saas", n.saas, r)), n?.custom && this.dataSenders.push(new Ve(e, "custom", n.custom, r)), this.saveSessionCountsDebounced = this.debounce((i) => {
|
|
1725
1773
|
this.saveSessionCounts(i);
|
|
1726
1774
|
}, 500), this.cleanupExpiredSessionCounts();
|
|
1727
1775
|
}
|
|
@@ -1752,14 +1800,14 @@ class xt extends p {
|
|
|
1752
1800
|
async recoverPersistedEvents() {
|
|
1753
1801
|
const e = this.dataSenders.map(
|
|
1754
1802
|
async (t) => t.recoverPersistedEvents({
|
|
1755
|
-
onSuccess: (r,
|
|
1756
|
-
if (
|
|
1757
|
-
const o =
|
|
1803
|
+
onSuccess: (r, n, i) => {
|
|
1804
|
+
if (n && n.length > 0) {
|
|
1805
|
+
const o = n.map((l) => l.id);
|
|
1758
1806
|
this.removeProcessedEvents(o), i && this.emitEventsQueue(i);
|
|
1759
1807
|
}
|
|
1760
1808
|
},
|
|
1761
1809
|
onFailure: () => {
|
|
1762
|
-
a("
|
|
1810
|
+
a("debug", "Failed to recover persisted events");
|
|
1763
1811
|
}
|
|
1764
1812
|
})
|
|
1765
1813
|
);
|
|
@@ -1828,12 +1876,13 @@ class xt extends p {
|
|
|
1828
1876
|
type: e,
|
|
1829
1877
|
page_url: t,
|
|
1830
1878
|
from_page_url: r,
|
|
1831
|
-
scroll_data:
|
|
1879
|
+
scroll_data: n,
|
|
1832
1880
|
click_data: i,
|
|
1833
1881
|
custom_event: o,
|
|
1834
1882
|
web_vitals: l,
|
|
1835
1883
|
error_data: c,
|
|
1836
|
-
viewport_data:
|
|
1884
|
+
viewport_data: u,
|
|
1885
|
+
page_view: S
|
|
1837
1886
|
}) {
|
|
1838
1887
|
if (!e) {
|
|
1839
1888
|
a("error", "Event type is required - event will be ignored");
|
|
@@ -1841,47 +1890,48 @@ class xt extends p {
|
|
|
1841
1890
|
}
|
|
1842
1891
|
const g = this.get("sessionId");
|
|
1843
1892
|
if (!g) {
|
|
1844
|
-
this.pendingEventsBuffer.length >= 100 && (this.pendingEventsBuffer.shift(), a("
|
|
1893
|
+
this.pendingEventsBuffer.length >= 100 && (this.pendingEventsBuffer.shift(), a("debug", "Pending events buffer full - dropping oldest event", {
|
|
1845
1894
|
data: { maxBufferSize: 100 }
|
|
1846
1895
|
})), this.pendingEventsBuffer.push({
|
|
1847
1896
|
type: e,
|
|
1848
1897
|
page_url: t,
|
|
1849
1898
|
from_page_url: r,
|
|
1850
|
-
scroll_data:
|
|
1899
|
+
scroll_data: n,
|
|
1851
1900
|
click_data: i,
|
|
1852
1901
|
custom_event: o,
|
|
1853
1902
|
web_vitals: l,
|
|
1854
1903
|
error_data: c,
|
|
1855
|
-
viewport_data:
|
|
1904
|
+
viewport_data: u,
|
|
1905
|
+
page_view: S
|
|
1856
1906
|
});
|
|
1857
1907
|
return;
|
|
1858
1908
|
}
|
|
1859
1909
|
this.lastSessionId !== g && (this.lastSessionId = g, this.sessionEventCounts = this.loadSessionCounts(g));
|
|
1860
|
-
const E = e ===
|
|
1910
|
+
const E = e === d.SESSION_START;
|
|
1861
1911
|
if (E && a("debug", "Processing SESSION_START event", {
|
|
1862
1912
|
data: { sessionId: g }
|
|
1863
1913
|
}), !E && !this.checkRateLimit())
|
|
1864
1914
|
return;
|
|
1865
|
-
const
|
|
1915
|
+
const p = e;
|
|
1866
1916
|
if (!E) {
|
|
1867
1917
|
if (this.sessionEventCounts.total >= 1e3) {
|
|
1868
1918
|
a("warn", "Session event limit reached", {
|
|
1869
1919
|
data: {
|
|
1870
|
-
type:
|
|
1920
|
+
type: p,
|
|
1871
1921
|
total: this.sessionEventCounts.total,
|
|
1872
1922
|
limit: 1e3
|
|
1873
1923
|
}
|
|
1874
1924
|
});
|
|
1875
1925
|
return;
|
|
1876
1926
|
}
|
|
1877
|
-
const T = this.getTypeLimitForEvent(
|
|
1927
|
+
const T = this.getTypeLimitForEvent(p);
|
|
1878
1928
|
if (T) {
|
|
1879
|
-
const
|
|
1880
|
-
if (
|
|
1929
|
+
const ee = this.sessionEventCounts[p];
|
|
1930
|
+
if (ee !== void 0 && ee >= T) {
|
|
1881
1931
|
a("warn", "Session event type limit reached", {
|
|
1882
1932
|
data: {
|
|
1883
|
-
type:
|
|
1884
|
-
count:
|
|
1933
|
+
type: p,
|
|
1934
|
+
count: ee,
|
|
1885
1935
|
limit: T
|
|
1886
1936
|
}
|
|
1887
1937
|
});
|
|
@@ -1889,50 +1939,67 @@ class xt extends p {
|
|
|
1889
1939
|
}
|
|
1890
1940
|
}
|
|
1891
1941
|
}
|
|
1892
|
-
if (
|
|
1942
|
+
if (p === d.CUSTOM && o?.name) {
|
|
1893
1943
|
const T = this.get("config")?.maxSameEventPerMinute ?? 60;
|
|
1894
1944
|
if (!this.checkPerEventRateLimit(o.name, T))
|
|
1895
1945
|
return;
|
|
1896
1946
|
}
|
|
1897
|
-
const
|
|
1898
|
-
type:
|
|
1899
|
-
page_url:
|
|
1947
|
+
const $ = p === d.SESSION_START, st = t || this.get("pageUrl"), D = this.buildEventPayload({
|
|
1948
|
+
type: p,
|
|
1949
|
+
page_url: st,
|
|
1900
1950
|
from_page_url: r,
|
|
1901
|
-
scroll_data:
|
|
1951
|
+
scroll_data: n,
|
|
1902
1952
|
click_data: i,
|
|
1903
1953
|
custom_event: o,
|
|
1904
1954
|
web_vitals: l,
|
|
1905
1955
|
error_data: c,
|
|
1906
|
-
viewport_data:
|
|
1956
|
+
viewport_data: u,
|
|
1957
|
+
page_view: S
|
|
1907
1958
|
});
|
|
1908
|
-
if (
|
|
1909
|
-
if (
|
|
1959
|
+
if (D && !(!E && !this.shouldSample())) {
|
|
1960
|
+
if ($) {
|
|
1910
1961
|
const T = this.get("sessionId");
|
|
1911
1962
|
if (!T) {
|
|
1912
1963
|
a("error", "Session start event requires sessionId - event will be ignored");
|
|
1913
1964
|
return;
|
|
1914
1965
|
}
|
|
1915
1966
|
if (this.get("hasStartSession")) {
|
|
1916
|
-
a("
|
|
1967
|
+
a("debug", "Duplicate session_start detected", {
|
|
1917
1968
|
data: { sessionId: T }
|
|
1918
1969
|
});
|
|
1919
1970
|
return;
|
|
1920
1971
|
}
|
|
1921
1972
|
this.set("hasStartSession", !0);
|
|
1922
1973
|
}
|
|
1923
|
-
if (!this.isDuplicateEvent(
|
|
1924
|
-
if (this.get("mode") === j.QA
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1974
|
+
if (!this.isDuplicateEvent(D)) {
|
|
1975
|
+
if (this.get("mode") === j.QA) {
|
|
1976
|
+
if (p === d.CUSTOM && o) {
|
|
1977
|
+
a("info", `Custom Event: ${o.name}`, {
|
|
1978
|
+
visibility: "qa",
|
|
1979
|
+
data: {
|
|
1980
|
+
name: o.name,
|
|
1981
|
+
...o.metadata && { metadata: o.metadata }
|
|
1982
|
+
}
|
|
1983
|
+
}), this.emitEvent(D);
|
|
1984
|
+
return;
|
|
1985
|
+
}
|
|
1986
|
+
if (p === d.VIEWPORT_VISIBLE && u) {
|
|
1987
|
+
const T = u.name || u.id || u.selector;
|
|
1988
|
+
a("info", `Viewport Visible: ${T}`, {
|
|
1989
|
+
visibility: "qa",
|
|
1990
|
+
data: {
|
|
1991
|
+
selector: u.selector,
|
|
1992
|
+
...u.name && { name: u.name },
|
|
1993
|
+
...u.id && { id: u.id },
|
|
1994
|
+
visibilityRatio: u.visibilityRatio,
|
|
1995
|
+
dwellTime: u.dwellTime
|
|
1996
|
+
}
|
|
1997
|
+
}), this.emitEvent(D);
|
|
1998
|
+
return;
|
|
1999
|
+
}
|
|
1933
2000
|
}
|
|
1934
|
-
if (this.addToQueue(
|
|
1935
|
-
this.sessionEventCounts.total++, this.sessionEventCounts[
|
|
2001
|
+
if (this.addToQueue(D), !E) {
|
|
2002
|
+
this.sessionEventCounts.total++, this.sessionEventCounts[p] !== void 0 && this.sessionEventCounts[p]++;
|
|
1936
2003
|
const T = this.get("sessionId");
|
|
1937
2004
|
T && this.saveSessionCountsDebounced && this.saveSessionCountsDebounced(T);
|
|
1938
2005
|
}
|
|
@@ -1978,11 +2045,11 @@ class xt extends p {
|
|
|
1978
2045
|
const e = this.get("sessionId");
|
|
1979
2046
|
e && this.saveSessionCounts(e), this.eventsQueue = [], this.pendingEventsBuffer = [], this.recentEventFingerprints.clear(), this.rateLimitCounter = 0, this.rateLimitWindowStart = 0, this.perEventRateLimits.clear(), this.sessionEventCounts = {
|
|
1980
2047
|
total: 0,
|
|
1981
|
-
[
|
|
1982
|
-
[
|
|
1983
|
-
[
|
|
1984
|
-
[
|
|
1985
|
-
[
|
|
2048
|
+
[d.CLICK]: 0,
|
|
2049
|
+
[d.PAGE_VIEW]: 0,
|
|
2050
|
+
[d.CUSTOM]: 0,
|
|
2051
|
+
[d.VIEWPORT_VISIBLE]: 0,
|
|
2052
|
+
[d.SCROLL]: 0
|
|
1986
2053
|
}, this.lastSessionId = null, this.set("hasStartSession", !1), this.dataSenders.forEach((t) => {
|
|
1987
2054
|
t.stop();
|
|
1988
2055
|
});
|
|
@@ -2160,7 +2227,7 @@ class xt extends p {
|
|
|
2160
2227
|
if (this.pendingEventsBuffer.length === 0)
|
|
2161
2228
|
return;
|
|
2162
2229
|
if (!this.get("sessionId")) {
|
|
2163
|
-
a("
|
|
2230
|
+
a("debug", "Cannot flush pending events: session not initialized - keeping in buffer", {
|
|
2164
2231
|
data: { bufferedEventCount: this.pendingEventsBuffer.length }
|
|
2165
2232
|
});
|
|
2166
2233
|
return;
|
|
@@ -2179,13 +2246,13 @@ class xt extends p {
|
|
|
2179
2246
|
flushEvents(e) {
|
|
2180
2247
|
if (this.eventsQueue.length === 0)
|
|
2181
2248
|
return e ? !0 : Promise.resolve(!0);
|
|
2182
|
-
const t = this.buildEventsPayload(), r = [...this.eventsQueue],
|
|
2249
|
+
const t = this.buildEventsPayload(), r = [...this.eventsQueue], n = r.map((i) => i.id);
|
|
2183
2250
|
if (this.dataSenders.length === 0)
|
|
2184
|
-
return this.removeProcessedEvents(
|
|
2251
|
+
return this.removeProcessedEvents(n), this.clearSendInterval(), this.emitEventsQueue(t), e ? !0 : Promise.resolve(!0);
|
|
2185
2252
|
if (e) {
|
|
2186
2253
|
const o = this.dataSenders.map((l) => l.sendEventsQueueSync(t)).some((l) => l);
|
|
2187
|
-
return o ? (this.removeProcessedEvents(
|
|
2188
|
-
data: { eventCount:
|
|
2254
|
+
return o ? (this.removeProcessedEvents(n), this.clearSendInterval(), this.emitEventsQueue(t)) : (this.clearSendInterval(), a("debug", "Sync flush complete failure, events kept in queue for retry", {
|
|
2255
|
+
data: { eventCount: n.length }
|
|
2189
2256
|
})), o;
|
|
2190
2257
|
} else {
|
|
2191
2258
|
const i = this.dataSenders.map(
|
|
@@ -2198,7 +2265,7 @@ class xt extends p {
|
|
|
2198
2265
|
);
|
|
2199
2266
|
return Promise.allSettled(i).then((o) => {
|
|
2200
2267
|
const l = o.some((c) => this.isSuccessfulResult(c));
|
|
2201
|
-
return l ? (this.removeProcessedEvents(
|
|
2268
|
+
return l ? (this.removeProcessedEvents(n), this.clearSendInterval(), this.emitEventsQueue(t)) : a("debug", "Async flush complete failure, events kept in queue for retry", {
|
|
2202
2269
|
data: { eventCount: r.length }
|
|
2203
2270
|
}), l;
|
|
2204
2271
|
});
|
|
@@ -2212,22 +2279,22 @@ class xt extends p {
|
|
|
2212
2279
|
this.emitEventsQueue(e);
|
|
2213
2280
|
return;
|
|
2214
2281
|
}
|
|
2215
|
-
const t = [...this.eventsQueue], r = t.map((l) => l.id),
|
|
2282
|
+
const t = [...this.eventsQueue], r = t.map((l) => l.id), n = this.dataSenders.map(
|
|
2216
2283
|
async (l) => l.sendEventsQueue(e, {
|
|
2217
2284
|
onSuccess: () => {
|
|
2218
2285
|
},
|
|
2219
2286
|
onFailure: () => {
|
|
2220
2287
|
}
|
|
2221
2288
|
})
|
|
2222
|
-
), i = await Promise.allSettled(
|
|
2289
|
+
), i = await Promise.allSettled(n);
|
|
2223
2290
|
if (i.some((l) => this.isSuccessfulResult(l))) {
|
|
2224
2291
|
this.removeProcessedEvents(r), this.emitEventsQueue(e);
|
|
2225
2292
|
const l = i.filter((c) => !this.isSuccessfulResult(c)).length;
|
|
2226
|
-
l > 0 && a("
|
|
2293
|
+
l > 0 && a("debug", "Periodic send completed with some failures, removed from queue and persisted per-integration", {
|
|
2227
2294
|
data: { eventCount: t.length, failedCount: l }
|
|
2228
2295
|
});
|
|
2229
2296
|
} else
|
|
2230
|
-
a("
|
|
2297
|
+
a("debug", "Periodic send complete failure, events kept in queue for retry", {
|
|
2231
2298
|
data: { eventCount: t.length }
|
|
2232
2299
|
});
|
|
2233
2300
|
this.eventsQueue.length === 0 && this.clearSendInterval();
|
|
@@ -2235,11 +2302,11 @@ class xt extends p {
|
|
|
2235
2302
|
buildEventsPayload() {
|
|
2236
2303
|
const e = /* @__PURE__ */ new Map(), t = [];
|
|
2237
2304
|
for (const c of this.eventsQueue) {
|
|
2238
|
-
const
|
|
2239
|
-
e.has(
|
|
2305
|
+
const u = this.createEventSignature(c);
|
|
2306
|
+
e.has(u) || t.push(u), e.set(u, c);
|
|
2240
2307
|
}
|
|
2241
|
-
const r = t.map((c) => e.get(c)).filter((c) => !!c).sort((c,
|
|
2242
|
-
let
|
|
2308
|
+
const r = t.map((c) => e.get(c)).filter((c) => !!c).sort((c, u) => c.type === d.SESSION_START && u.type !== d.SESSION_START ? -1 : u.type === d.SESSION_START && c.type !== d.SESSION_START ? 1 : c.timestamp - u.timestamp);
|
|
2309
|
+
let n = {
|
|
2243
2310
|
user_id: this.get("userId"),
|
|
2244
2311
|
session_id: this.get("sessionId"),
|
|
2245
2312
|
device: this.get("device"),
|
|
@@ -2248,21 +2315,21 @@ class xt extends p {
|
|
|
2248
2315
|
};
|
|
2249
2316
|
const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas), l = this.transformers.beforeBatch;
|
|
2250
2317
|
if (!o && l) {
|
|
2251
|
-
const c =
|
|
2252
|
-
c !== null && (
|
|
2318
|
+
const c = Ke(n, l, "EventManager");
|
|
2319
|
+
c !== null && (n = c);
|
|
2253
2320
|
}
|
|
2254
|
-
return
|
|
2321
|
+
return n;
|
|
2255
2322
|
}
|
|
2256
2323
|
buildEventPayload(e) {
|
|
2257
|
-
const t = e.type ===
|
|
2324
|
+
const t = e.type === d.SESSION_START, r = e.page_url ?? this.get("pageUrl"), n = this.timeManager.now(), i = this.timeManager.validateTimestamp(n);
|
|
2258
2325
|
i.valid || a("warn", "Event timestamp validation failed", {
|
|
2259
2326
|
data: { type: e.type, error: i.error }
|
|
2260
2327
|
});
|
|
2261
2328
|
let o = {
|
|
2262
|
-
id:
|
|
2329
|
+
id: kt(),
|
|
2263
2330
|
type: e.type,
|
|
2264
2331
|
page_url: r,
|
|
2265
|
-
timestamp:
|
|
2332
|
+
timestamp: n,
|
|
2266
2333
|
...t && { referrer: document.referrer || "Direct" },
|
|
2267
2334
|
...e.from_page_url && { from_page_url: e.from_page_url },
|
|
2268
2335
|
...e.scroll_data && { scroll_data: e.scroll_data },
|
|
@@ -2271,27 +2338,28 @@ class xt extends p {
|
|
|
2271
2338
|
...e.web_vitals && { web_vitals: e.web_vitals },
|
|
2272
2339
|
...e.error_data && { error_data: e.error_data },
|
|
2273
2340
|
...e.viewport_data && { viewport_data: e.viewport_data },
|
|
2341
|
+
...e.page_view && { page_view: e.page_view },
|
|
2274
2342
|
...t && Oe() && { utm: Oe() }
|
|
2275
2343
|
};
|
|
2276
|
-
const l = this.get("collectApiUrls"), c = !!l?.custom,
|
|
2277
|
-
if (
|
|
2278
|
-
const
|
|
2279
|
-
if (
|
|
2344
|
+
const l = this.get("collectApiUrls"), c = !!l?.custom, u = !!l?.saas, S = c || u, g = c && u, E = this.transformers.beforeSend;
|
|
2345
|
+
if (E && (!S || c && !g)) {
|
|
2346
|
+
const $ = je(o, E, "EventManager");
|
|
2347
|
+
if ($ === null)
|
|
2280
2348
|
return null;
|
|
2281
|
-
o =
|
|
2349
|
+
o = $;
|
|
2282
2350
|
}
|
|
2283
2351
|
return o;
|
|
2284
2352
|
}
|
|
2285
2353
|
isDuplicateEvent(e) {
|
|
2286
|
-
const t = Date.now(), r = this.createEventFingerprint(e),
|
|
2287
|
-
return
|
|
2354
|
+
const t = Date.now(), r = this.createEventFingerprint(e), n = this.recentEventFingerprints.get(r);
|
|
2355
|
+
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", {
|
|
2288
2356
|
data: { hardLimit: 3e3 }
|
|
2289
2357
|
})), !1);
|
|
2290
2358
|
}
|
|
2291
2359
|
pruneOldFingerprints() {
|
|
2292
2360
|
const e = Date.now(), t = 1e3 * 10;
|
|
2293
|
-
for (const [r,
|
|
2294
|
-
e -
|
|
2361
|
+
for (const [r, n] of this.recentEventFingerprints.entries())
|
|
2362
|
+
e - n > t && this.recentEventFingerprints.delete(r);
|
|
2295
2363
|
a("debug", "Pruned old event fingerprints", {
|
|
2296
2364
|
data: {
|
|
2297
2365
|
remaining: this.recentEventFingerprints.size,
|
|
@@ -2302,8 +2370,8 @@ class xt extends p {
|
|
|
2302
2370
|
createEventFingerprint(e) {
|
|
2303
2371
|
let t = `${e.type}_${e.page_url}`;
|
|
2304
2372
|
if (e.click_data) {
|
|
2305
|
-
const r = Math.round((e.click_data.x || 0) / 10) * 10,
|
|
2306
|
-
t += `_click_${r}_${
|
|
2373
|
+
const r = Math.round((e.click_data.x || 0) / 10) * 10, n = Math.round((e.click_data.y || 0) / 10) * 10;
|
|
2374
|
+
t += `_click_${r}_${n}`;
|
|
2307
2375
|
}
|
|
2308
2376
|
return e.scroll_data && (t += `_scroll_${e.scroll_data.depth}_${e.scroll_data.direction}`), e.custom_event && (t += `_custom_${e.custom_event.name}`), e.web_vitals && (t += `_vitals_${e.web_vitals.type}`), e.error_data && (t += `_error_${e.error_data.type}_${e.error_data.message}`), t;
|
|
2309
2377
|
}
|
|
@@ -2312,13 +2380,13 @@ class xt extends p {
|
|
|
2312
2380
|
}
|
|
2313
2381
|
addToQueue(e) {
|
|
2314
2382
|
if (this.emitEvent(e), this.eventsQueue.push(e), this.eventsQueue.length > 100) {
|
|
2315
|
-
const t = this.eventsQueue.findIndex((
|
|
2383
|
+
const t = this.eventsQueue.findIndex((n) => n.type !== d.SESSION_START), r = t >= 0 ? this.eventsQueue.splice(t, 1)[0] : this.eventsQueue.shift();
|
|
2316
2384
|
a("warn", "Event queue overflow, oldest non-critical event removed", {
|
|
2317
2385
|
data: {
|
|
2318
2386
|
maxLength: 100,
|
|
2319
2387
|
currentLength: this.eventsQueue.length,
|
|
2320
2388
|
removedEventType: r?.type,
|
|
2321
|
-
wasCritical: r?.type ===
|
|
2389
|
+
wasCritical: r?.type === d.SESSION_START
|
|
2322
2390
|
}
|
|
2323
2391
|
});
|
|
2324
2392
|
}
|
|
@@ -2349,11 +2417,11 @@ class xt extends p {
|
|
|
2349
2417
|
}
|
|
2350
2418
|
getTypeLimitForEvent(e) {
|
|
2351
2419
|
return {
|
|
2352
|
-
[
|
|
2353
|
-
[
|
|
2354
|
-
[
|
|
2355
|
-
[
|
|
2356
|
-
[
|
|
2420
|
+
[d.CLICK]: 500,
|
|
2421
|
+
[d.PAGE_VIEW]: 100,
|
|
2422
|
+
[d.CUSTOM]: 500,
|
|
2423
|
+
[d.VIEWPORT_VISIBLE]: 200,
|
|
2424
|
+
[d.SCROLL]: 120
|
|
2357
2425
|
}[e] ?? null;
|
|
2358
2426
|
}
|
|
2359
2427
|
removeProcessedEvents(e) {
|
|
@@ -2388,9 +2456,9 @@ class xt extends p {
|
|
|
2388
2456
|
*/
|
|
2389
2457
|
debounce(e, t) {
|
|
2390
2458
|
let r = null;
|
|
2391
|
-
return ((...
|
|
2459
|
+
return ((...n) => {
|
|
2392
2460
|
r !== null && clearTimeout(r), r = setTimeout(() => {
|
|
2393
|
-
e(...
|
|
2461
|
+
e(...n), r = null;
|
|
2394
2462
|
}, t);
|
|
2395
2463
|
});
|
|
2396
2464
|
}
|
|
@@ -2407,11 +2475,11 @@ class xt extends p {
|
|
|
2407
2475
|
getInitialCounts() {
|
|
2408
2476
|
return {
|
|
2409
2477
|
total: 0,
|
|
2410
|
-
[
|
|
2411
|
-
[
|
|
2412
|
-
[
|
|
2413
|
-
[
|
|
2414
|
-
[
|
|
2478
|
+
[d.CLICK]: 0,
|
|
2479
|
+
[d.PAGE_VIEW]: 0,
|
|
2480
|
+
[d.CUSTOM]: 0,
|
|
2481
|
+
[d.VIEWPORT_VISIBLE]: 0,
|
|
2482
|
+
[d.SCROLL]: 0
|
|
2415
2483
|
};
|
|
2416
2484
|
}
|
|
2417
2485
|
/**
|
|
@@ -2440,29 +2508,29 @@ class xt extends p {
|
|
|
2440
2508
|
loadSessionCounts(e) {
|
|
2441
2509
|
if (typeof window > "u" || typeof localStorage > "u")
|
|
2442
2510
|
return this.getInitialCounts();
|
|
2443
|
-
const t = this.get("userId") || "anonymous", r =
|
|
2511
|
+
const t = this.get("userId") || "anonymous", r = Ie(t, e);
|
|
2444
2512
|
try {
|
|
2445
|
-
const
|
|
2446
|
-
if (!
|
|
2513
|
+
const n = localStorage.getItem(r);
|
|
2514
|
+
if (!n)
|
|
2447
2515
|
return this.getInitialCounts();
|
|
2448
|
-
const i = JSON.parse(
|
|
2516
|
+
const i = JSON.parse(n);
|
|
2449
2517
|
return i._timestamp && Date.now() - i._timestamp > we ? (a("debug", "Session counts expired, clearing", {
|
|
2450
2518
|
data: { sessionId: e, age: Date.now() - i._timestamp }
|
|
2451
|
-
}), localStorage.removeItem(r), this.getInitialCounts()) : typeof i.total == "number" && typeof i[
|
|
2519
|
+
}), 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" ? {
|
|
2452
2520
|
total: i.total,
|
|
2453
|
-
[
|
|
2454
|
-
[
|
|
2455
|
-
[
|
|
2456
|
-
[
|
|
2457
|
-
[
|
|
2521
|
+
[d.CLICK]: i[d.CLICK],
|
|
2522
|
+
[d.PAGE_VIEW]: i[d.PAGE_VIEW],
|
|
2523
|
+
[d.CUSTOM]: i[d.CUSTOM],
|
|
2524
|
+
[d.VIEWPORT_VISIBLE]: i[d.VIEWPORT_VISIBLE],
|
|
2525
|
+
[d.SCROLL]: i[d.SCROLL]
|
|
2458
2526
|
} : (a("warn", "Invalid session counts structure in localStorage, resetting", {
|
|
2459
2527
|
data: { sessionId: e, parsed: i }
|
|
2460
2528
|
}), localStorage.removeItem(r), a("debug", "Session counts removed due to invalid/corrupted data", {
|
|
2461
2529
|
data: { sessionId: e, parsed: i }
|
|
2462
2530
|
}), this.getInitialCounts());
|
|
2463
|
-
} catch (
|
|
2531
|
+
} catch (n) {
|
|
2464
2532
|
return a("warn", "Failed to load session counts from localStorage", {
|
|
2465
|
-
error:
|
|
2533
|
+
error: n,
|
|
2466
2534
|
data: { sessionId: e }
|
|
2467
2535
|
}), this.getInitialCounts();
|
|
2468
2536
|
}
|
|
@@ -2494,14 +2562,14 @@ class xt extends p {
|
|
|
2494
2562
|
const e = localStorage.getItem(ye);
|
|
2495
2563
|
if (e) {
|
|
2496
2564
|
const i = Date.now() - parseInt(e, 10);
|
|
2497
|
-
if (i <
|
|
2565
|
+
if (i < be) {
|
|
2498
2566
|
a("debug", "Skipping session counts cleanup (throttled)", {
|
|
2499
|
-
data: { timeSinceLastCleanup: i, throttleMs:
|
|
2567
|
+
data: { timeSinceLastCleanup: i, throttleMs: be }
|
|
2500
2568
|
});
|
|
2501
2569
|
return;
|
|
2502
2570
|
}
|
|
2503
2571
|
}
|
|
2504
|
-
const t = this.get("userId") || "anonymous", r = `${I}:${t}:session_counts:`,
|
|
2572
|
+
const t = this.get("userId") || "anonymous", r = `${I}:${t}:session_counts:`, n = [];
|
|
2505
2573
|
for (let i = 0; i < localStorage.length; i++) {
|
|
2506
2574
|
const o = localStorage.key(i);
|
|
2507
2575
|
if (o?.startsWith(r))
|
|
@@ -2509,14 +2577,14 @@ class xt extends p {
|
|
|
2509
2577
|
const l = localStorage.getItem(o);
|
|
2510
2578
|
if (l) {
|
|
2511
2579
|
const c = JSON.parse(l);
|
|
2512
|
-
c._timestamp && Date.now() - c._timestamp > we &&
|
|
2580
|
+
c._timestamp && Date.now() - c._timestamp > we && n.push(o);
|
|
2513
2581
|
}
|
|
2514
2582
|
} catch {
|
|
2515
2583
|
}
|
|
2516
2584
|
}
|
|
2517
|
-
|
|
2585
|
+
n.forEach((i) => {
|
|
2518
2586
|
localStorage.removeItem(i), a("debug", "Cleaned up expired session counts", { data: { key: i } });
|
|
2519
|
-
}),
|
|
2587
|
+
}), n.length > 0 && a("info", `Cleaned up ${n.length} expired session counts entries`), localStorage.setItem(ye, Date.now().toString());
|
|
2520
2588
|
} catch (e) {
|
|
2521
2589
|
a("warn", "Failed to cleanup expired session counts", { error: e });
|
|
2522
2590
|
}
|
|
@@ -2550,23 +2618,23 @@ class xt extends p {
|
|
|
2550
2618
|
* @internal
|
|
2551
2619
|
*/
|
|
2552
2620
|
saveSessionCounts(e) {
|
|
2553
|
-
const t = this.get("userId") || "anonymous", r =
|
|
2621
|
+
const t = this.get("userId") || "anonymous", r = Ie(t, e);
|
|
2554
2622
|
try {
|
|
2555
|
-
const
|
|
2623
|
+
const n = {
|
|
2556
2624
|
...this.sessionEventCounts,
|
|
2557
2625
|
_timestamp: Date.now(),
|
|
2558
2626
|
_version: 1
|
|
2559
2627
|
};
|
|
2560
|
-
localStorage.setItem(r, JSON.stringify(
|
|
2561
|
-
} catch (
|
|
2628
|
+
localStorage.setItem(r, JSON.stringify(n));
|
|
2629
|
+
} catch (n) {
|
|
2562
2630
|
a("warn", "Failed to persist session counts to localStorage", {
|
|
2563
|
-
error:
|
|
2631
|
+
error: n,
|
|
2564
2632
|
data: { sessionId: e }
|
|
2565
2633
|
});
|
|
2566
2634
|
}
|
|
2567
2635
|
}
|
|
2568
2636
|
}
|
|
2569
|
-
class
|
|
2637
|
+
class qt {
|
|
2570
2638
|
/**
|
|
2571
2639
|
* Gets or creates a unique user ID.
|
|
2572
2640
|
*
|
|
@@ -2584,15 +2652,15 @@ class Ht {
|
|
|
2584
2652
|
* @returns Persistent unique user ID (UUID v4 format)
|
|
2585
2653
|
*/
|
|
2586
2654
|
static getId(e) {
|
|
2587
|
-
const t = e.getItem(
|
|
2655
|
+
const t = e.getItem(Te);
|
|
2588
2656
|
if (t)
|
|
2589
2657
|
return t;
|
|
2590
|
-
const r =
|
|
2591
|
-
return e.setItem(
|
|
2658
|
+
const r = Vt();
|
|
2659
|
+
return e.setItem(Te, r), r;
|
|
2592
2660
|
}
|
|
2593
2661
|
}
|
|
2594
|
-
const
|
|
2595
|
-
class
|
|
2662
|
+
const Jt = /^\d{13}-[a-z0-9]{9}$/;
|
|
2663
|
+
class Zt extends _ {
|
|
2596
2664
|
storageManager;
|
|
2597
2665
|
eventManager;
|
|
2598
2666
|
projectId;
|
|
@@ -2613,13 +2681,13 @@ class $t extends p {
|
|
|
2613
2681
|
}
|
|
2614
2682
|
initCrossTabSync() {
|
|
2615
2683
|
if (typeof BroadcastChannel > "u") {
|
|
2616
|
-
a("
|
|
2684
|
+
a("debug", "BroadcastChannel not supported");
|
|
2617
2685
|
return;
|
|
2618
2686
|
}
|
|
2619
2687
|
const e = this.getProjectId();
|
|
2620
|
-
this.broadcastChannel = new BroadcastChannel(
|
|
2621
|
-
const { action: r, sessionId:
|
|
2622
|
-
o === e && (r === "session_start" &&
|
|
2688
|
+
this.broadcastChannel = new BroadcastChannel(ut(e)), this.broadcastChannel.onmessage = (t) => {
|
|
2689
|
+
const { action: r, sessionId: n, timestamp: i, projectId: o } = t.data ?? {};
|
|
2690
|
+
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 } }));
|
|
2623
2691
|
};
|
|
2624
2692
|
}
|
|
2625
2693
|
shareSession(e) {
|
|
@@ -2637,7 +2705,7 @@ class $t extends p {
|
|
|
2637
2705
|
const e = this.loadStoredSession();
|
|
2638
2706
|
if (!e)
|
|
2639
2707
|
return null;
|
|
2640
|
-
if (!
|
|
2708
|
+
if (!Jt.test(e.id))
|
|
2641
2709
|
return a("warn", "Invalid session ID format recovered from storage, clearing", {
|
|
2642
2710
|
data: { sessionId: e.id }
|
|
2643
2711
|
}), this.clearStoredSession(), null;
|
|
@@ -2670,7 +2738,7 @@ class $t extends p {
|
|
|
2670
2738
|
this.storageManager.setItem(t, JSON.stringify(e));
|
|
2671
2739
|
}
|
|
2672
2740
|
getSessionStorageKey() {
|
|
2673
|
-
return
|
|
2741
|
+
return ct(this.getProjectId());
|
|
2674
2742
|
}
|
|
2675
2743
|
getProjectId() {
|
|
2676
2744
|
return this.projectId;
|
|
@@ -2728,7 +2796,7 @@ class $t extends p {
|
|
|
2728
2796
|
*/
|
|
2729
2797
|
startTracking() {
|
|
2730
2798
|
if (this.isTracking) {
|
|
2731
|
-
a("
|
|
2799
|
+
a("debug", "Session tracking already active");
|
|
2732
2800
|
return;
|
|
2733
2801
|
}
|
|
2734
2802
|
const e = this.recoverSession(), t = e ?? this.generateSessionId();
|
|
@@ -2743,7 +2811,7 @@ class $t extends p {
|
|
|
2743
2811
|
this.set("sessionId", t), this.persistSession(t), this.initCrossTabSync(), this.shareSession(t), a("debug", "Emitting SESSION_START event", {
|
|
2744
2812
|
data: { sessionId: t }
|
|
2745
2813
|
}), this.eventManager.track({
|
|
2746
|
-
type:
|
|
2814
|
+
type: d.SESSION_START
|
|
2747
2815
|
}), this.setupSessionTimeout(), this.setupActivityListeners(), this.setupLifecycleListeners();
|
|
2748
2816
|
} catch (r) {
|
|
2749
2817
|
throw this.isTracking = !1, this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupLifecycleListeners(), this.cleanupCrossTabSync(), this.set("sessionId", null), r;
|
|
@@ -2853,7 +2921,7 @@ class $t extends p {
|
|
|
2853
2921
|
this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupCrossTabSync(), this.cleanupLifecycleListeners(), this.isTracking = !1, this.set("hasStartSession", !1);
|
|
2854
2922
|
}
|
|
2855
2923
|
}
|
|
2856
|
-
class
|
|
2924
|
+
class er extends _ {
|
|
2857
2925
|
eventManager;
|
|
2858
2926
|
storageManager;
|
|
2859
2927
|
sessionManager = null;
|
|
@@ -2883,12 +2951,12 @@ class Bt extends p {
|
|
|
2883
2951
|
if (this.isActive())
|
|
2884
2952
|
return;
|
|
2885
2953
|
if (this.destroyed) {
|
|
2886
|
-
a("
|
|
2954
|
+
a("debug", "Cannot start tracking on destroyed handler");
|
|
2887
2955
|
return;
|
|
2888
2956
|
}
|
|
2889
2957
|
const t = this.get("config")?.integrations?.tracelog?.projectId ?? "custom";
|
|
2890
2958
|
try {
|
|
2891
|
-
this.sessionManager = new
|
|
2959
|
+
this.sessionManager = new Zt(this.storageManager, this.eventManager, t), this.sessionManager.startTracking(), this.eventManager.flushPendingEvents();
|
|
2892
2960
|
} catch (r) {
|
|
2893
2961
|
if (this.sessionManager) {
|
|
2894
2962
|
try {
|
|
@@ -2941,7 +3009,7 @@ class Bt extends p {
|
|
|
2941
3009
|
this.destroyed || (this.sessionManager && (this.sessionManager.destroy(), this.sessionManager = null), this.destroyed = !0);
|
|
2942
3010
|
}
|
|
2943
3011
|
}
|
|
2944
|
-
class
|
|
3012
|
+
class tr extends _ {
|
|
2945
3013
|
eventManager;
|
|
2946
3014
|
onTrack;
|
|
2947
3015
|
originalPushState;
|
|
@@ -2981,35 +3049,35 @@ class Wt extends p {
|
|
|
2981
3049
|
};
|
|
2982
3050
|
}
|
|
2983
3051
|
trackCurrentPage = () => {
|
|
2984
|
-
const e = window.location.href, t =
|
|
3052
|
+
const e = window.location.href, t = le(e, this.get("config").sensitiveQueryParams);
|
|
2985
3053
|
if (this.get("pageUrl") === t)
|
|
2986
3054
|
return;
|
|
2987
|
-
const r = Date.now(),
|
|
2988
|
-
if (r - this.lastPageViewTime <
|
|
3055
|
+
const r = Date.now(), n = this.get("config").pageViewThrottleMs ?? 1e3;
|
|
3056
|
+
if (r - this.lastPageViewTime < n)
|
|
2989
3057
|
return;
|
|
2990
3058
|
this.lastPageViewTime = r, this.onTrack();
|
|
2991
3059
|
const i = this.get("pageUrl");
|
|
2992
3060
|
this.set("pageUrl", t);
|
|
2993
3061
|
const o = this.extractPageViewData();
|
|
2994
3062
|
this.eventManager.track({
|
|
2995
|
-
type:
|
|
3063
|
+
type: d.PAGE_VIEW,
|
|
2996
3064
|
page_url: this.get("pageUrl"),
|
|
2997
3065
|
from_page_url: i,
|
|
2998
3066
|
...o && { page_view: o }
|
|
2999
3067
|
});
|
|
3000
3068
|
};
|
|
3001
3069
|
trackInitialPageView() {
|
|
3002
|
-
const e =
|
|
3070
|
+
const e = le(window.location.href, this.get("config").sensitiveQueryParams), t = this.extractPageViewData();
|
|
3003
3071
|
this.lastPageViewTime = Date.now(), this.eventManager.track({
|
|
3004
|
-
type:
|
|
3072
|
+
type: d.PAGE_VIEW,
|
|
3005
3073
|
page_url: e,
|
|
3006
3074
|
...t && { page_view: t }
|
|
3007
3075
|
}), this.onTrack();
|
|
3008
3076
|
}
|
|
3009
3077
|
extractPageViewData() {
|
|
3010
|
-
const { pathname: e, search: t, hash: r } = window.location, { referrer:
|
|
3011
|
-
return !
|
|
3012
|
-
...
|
|
3078
|
+
const { pathname: e, search: t, hash: r } = window.location, { referrer: n } = document, { title: i } = document;
|
|
3079
|
+
return !n && !i && !e && !t && !r ? void 0 : {
|
|
3080
|
+
...n && { referrer: n },
|
|
3013
3081
|
...i && { title: i },
|
|
3014
3082
|
...e && { pathname: e },
|
|
3015
3083
|
...t && { search: t },
|
|
@@ -3017,7 +3085,7 @@ class Wt extends p {
|
|
|
3017
3085
|
};
|
|
3018
3086
|
}
|
|
3019
3087
|
}
|
|
3020
|
-
class
|
|
3088
|
+
class rr extends _ {
|
|
3021
3089
|
eventManager;
|
|
3022
3090
|
lastClickTimes = /* @__PURE__ */ new Map();
|
|
3023
3091
|
clickHandler;
|
|
@@ -3040,34 +3108,34 @@ class Gt extends p {
|
|
|
3040
3108
|
*/
|
|
3041
3109
|
startTracking() {
|
|
3042
3110
|
this.clickHandler || (this.clickHandler = (e) => {
|
|
3043
|
-
const t = e, r = t.target,
|
|
3044
|
-
if (!
|
|
3045
|
-
a("
|
|
3111
|
+
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;
|
|
3112
|
+
if (!n) {
|
|
3113
|
+
a("debug", "Click target not found or not an element");
|
|
3046
3114
|
return;
|
|
3047
3115
|
}
|
|
3048
|
-
if (this.shouldIgnoreElement(
|
|
3116
|
+
if (this.shouldIgnoreElement(n))
|
|
3049
3117
|
return;
|
|
3050
3118
|
const i = this.get("config")?.clickThrottleMs ?? 300;
|
|
3051
|
-
if (i > 0 && !this.checkClickThrottle(
|
|
3119
|
+
if (i > 0 && !this.checkClickThrottle(n, i))
|
|
3052
3120
|
return;
|
|
3053
|
-
const o = this.findTrackingElement(
|
|
3121
|
+
const o = this.findTrackingElement(n), l = this.getRelevantClickElement(n), c = this.calculateClickCoordinates(t, n);
|
|
3054
3122
|
if (o) {
|
|
3055
|
-
const
|
|
3056
|
-
if (
|
|
3057
|
-
const
|
|
3123
|
+
const S = this.extractTrackingData(o);
|
|
3124
|
+
if (S) {
|
|
3125
|
+
const g = this.createCustomEventData(S);
|
|
3058
3126
|
this.eventManager.track({
|
|
3059
|
-
type:
|
|
3127
|
+
type: d.CUSTOM,
|
|
3060
3128
|
custom_event: {
|
|
3061
|
-
name:
|
|
3062
|
-
...
|
|
3129
|
+
name: g.name,
|
|
3130
|
+
...g.value && { metadata: { value: g.value } }
|
|
3063
3131
|
}
|
|
3064
3132
|
});
|
|
3065
3133
|
}
|
|
3066
3134
|
}
|
|
3067
|
-
const
|
|
3135
|
+
const u = this.generateClickData(n, l, c);
|
|
3068
3136
|
this.eventManager.track({
|
|
3069
|
-
type:
|
|
3070
|
-
click_data:
|
|
3137
|
+
type: d.CLICK,
|
|
3138
|
+
click_data: u
|
|
3071
3139
|
});
|
|
3072
3140
|
}, window.addEventListener("click", this.clickHandler, !0));
|
|
3073
3141
|
}
|
|
@@ -3081,22 +3149,22 @@ class Gt extends p {
|
|
|
3081
3149
|
this.clickHandler && (window.removeEventListener("click", this.clickHandler, !0), this.clickHandler = void 0), this.lastClickTimes.clear(), this.lastPruneTime = 0;
|
|
3082
3150
|
}
|
|
3083
3151
|
shouldIgnoreElement(e) {
|
|
3084
|
-
return e.hasAttribute(`${
|
|
3152
|
+
return e.hasAttribute(`${w}-ignore`) ? !0 : e.closest(`[${w}-ignore]`) !== null;
|
|
3085
3153
|
}
|
|
3086
3154
|
/**
|
|
3087
3155
|
* Checks per-element click throttling to prevent double-clicks and rapid spam
|
|
3088
3156
|
* Returns true if the click should be tracked, false if throttled
|
|
3089
3157
|
*/
|
|
3090
3158
|
checkClickThrottle(e, t) {
|
|
3091
|
-
const r = this.getElementSignature(e),
|
|
3092
|
-
this.pruneThrottleCache(
|
|
3159
|
+
const r = this.getElementSignature(e), n = Date.now();
|
|
3160
|
+
this.pruneThrottleCache(n);
|
|
3093
3161
|
const i = this.lastClickTimes.get(r);
|
|
3094
|
-
return i !== void 0 &&
|
|
3162
|
+
return i !== void 0 && n - i < t ? (a("debug", "ClickHandler: Click suppressed by throttle", {
|
|
3095
3163
|
data: {
|
|
3096
3164
|
signature: r,
|
|
3097
|
-
throttleRemaining: t - (
|
|
3165
|
+
throttleRemaining: t - (n - i)
|
|
3098
3166
|
}
|
|
3099
|
-
}), !1) : (this.lastClickTimes.set(r,
|
|
3167
|
+
}), !1) : (this.lastClickTimes.set(r, n), !0);
|
|
3100
3168
|
}
|
|
3101
3169
|
/**
|
|
3102
3170
|
* Prunes stale entries from the throttle cache to prevent memory leaks
|
|
@@ -3108,10 +3176,10 @@ class Gt extends p {
|
|
|
3108
3176
|
return;
|
|
3109
3177
|
this.lastPruneTime = e;
|
|
3110
3178
|
const t = e - 3e5;
|
|
3111
|
-
for (const [r,
|
|
3112
|
-
|
|
3179
|
+
for (const [r, n] of this.lastClickTimes.entries())
|
|
3180
|
+
n < t && this.lastClickTimes.delete(r);
|
|
3113
3181
|
if (this.lastClickTimes.size > 1e3) {
|
|
3114
|
-
const r = Array.from(this.lastClickTimes.entries()).sort((o, l) => o[1] - l[1]),
|
|
3182
|
+
const r = Array.from(this.lastClickTimes.entries()).sort((o, l) => o[1] - l[1]), n = this.lastClickTimes.size - 1e3, i = r.slice(0, n);
|
|
3115
3183
|
for (const [o] of i)
|
|
3116
3184
|
this.lastClickTimes.delete(o);
|
|
3117
3185
|
a("debug", "ClickHandler: Pruned throttle cache", {
|
|
@@ -3132,8 +3200,8 @@ class Gt extends p {
|
|
|
3132
3200
|
const t = e.getAttribute("data-testid");
|
|
3133
3201
|
if (t)
|
|
3134
3202
|
return `[data-testid="${t}"]`;
|
|
3135
|
-
const r = e.getAttribute(`${
|
|
3136
|
-
return r ? `[${
|
|
3203
|
+
const r = e.getAttribute(`${w}-name`);
|
|
3204
|
+
return r ? `[${w}-name="${r}"]` : this.getElementPath(e);
|
|
3137
3205
|
}
|
|
3138
3206
|
/**
|
|
3139
3207
|
* Generates a DOM path for an element (e.g., "body>div>button")
|
|
@@ -3142,20 +3210,20 @@ class Gt extends p {
|
|
|
3142
3210
|
const t = [];
|
|
3143
3211
|
let r = e;
|
|
3144
3212
|
for (; r && r !== document.body; ) {
|
|
3145
|
-
let
|
|
3213
|
+
let n = r.tagName.toLowerCase();
|
|
3146
3214
|
if (r.className) {
|
|
3147
3215
|
const i = r.className.split(" ")[0];
|
|
3148
|
-
i && (
|
|
3216
|
+
i && (n += `.${i}`);
|
|
3149
3217
|
}
|
|
3150
|
-
t.unshift(
|
|
3218
|
+
t.unshift(n), r = r.parentElement;
|
|
3151
3219
|
}
|
|
3152
3220
|
return t.join(">") || "unknown";
|
|
3153
3221
|
}
|
|
3154
3222
|
findTrackingElement(e) {
|
|
3155
|
-
return e.hasAttribute(`${
|
|
3223
|
+
return e.hasAttribute(`${w}-name`) ? e : e.closest(`[${w}-name]`);
|
|
3156
3224
|
}
|
|
3157
3225
|
getRelevantClickElement(e) {
|
|
3158
|
-
for (const t of
|
|
3226
|
+
for (const t of nt)
|
|
3159
3227
|
try {
|
|
3160
3228
|
if (e.matches(t))
|
|
3161
3229
|
return e;
|
|
@@ -3163,7 +3231,7 @@ class Gt extends p {
|
|
|
3163
3231
|
if (r)
|
|
3164
3232
|
return r;
|
|
3165
3233
|
} catch (r) {
|
|
3166
|
-
a("
|
|
3234
|
+
a("debug", "Invalid selector in element search", { error: r, data: { selector: t } });
|
|
3167
3235
|
continue;
|
|
3168
3236
|
}
|
|
3169
3237
|
return e;
|
|
@@ -3183,11 +3251,11 @@ class Gt extends p {
|
|
|
3183
3251
|
return Math.max(0, Math.min(1, Number(e.toFixed(3))));
|
|
3184
3252
|
}
|
|
3185
3253
|
calculateClickCoordinates(e, t) {
|
|
3186
|
-
const r = t.getBoundingClientRect(),
|
|
3187
|
-
return { x:
|
|
3254
|
+
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;
|
|
3255
|
+
return { x: n, y: i, relativeX: o, relativeY: l };
|
|
3188
3256
|
}
|
|
3189
3257
|
extractTrackingData(e) {
|
|
3190
|
-
const t = e.getAttribute(`${
|
|
3258
|
+
const t = e.getAttribute(`${w}-name`), r = e.getAttribute(`${w}-value`);
|
|
3191
3259
|
if (t)
|
|
3192
3260
|
return {
|
|
3193
3261
|
element: e,
|
|
@@ -3196,9 +3264,9 @@ class Gt extends p {
|
|
|
3196
3264
|
};
|
|
3197
3265
|
}
|
|
3198
3266
|
generateClickData(e, t, r) {
|
|
3199
|
-
const { x:
|
|
3267
|
+
const { x: n, y: i, relativeX: o, relativeY: l } = r, c = this.getRelevantText(e, t), u = this.extractElementAttributes(t);
|
|
3200
3268
|
return {
|
|
3201
|
-
x:
|
|
3269
|
+
x: n,
|
|
3202
3270
|
y: i,
|
|
3203
3271
|
relativeX: o,
|
|
3204
3272
|
relativeY: l,
|
|
@@ -3206,12 +3274,12 @@ class Gt extends p {
|
|
|
3206
3274
|
...t.id && { id: t.id },
|
|
3207
3275
|
...t.className && { class: t.className },
|
|
3208
3276
|
...c && { text: c },
|
|
3209
|
-
...
|
|
3210
|
-
...
|
|
3211
|
-
...
|
|
3212
|
-
...
|
|
3213
|
-
...
|
|
3214
|
-
...Object.keys(
|
|
3277
|
+
...u.href && { href: u.href },
|
|
3278
|
+
...u.title && { title: u.title },
|
|
3279
|
+
...u.alt && { alt: u.alt },
|
|
3280
|
+
...u.role && { role: u.role },
|
|
3281
|
+
...u["aria-label"] && { ariaLabel: u["aria-label"] },
|
|
3282
|
+
...Object.keys(u).length > 0 && { dataAttributes: u }
|
|
3215
3283
|
};
|
|
3216
3284
|
}
|
|
3217
3285
|
/**
|
|
@@ -3235,18 +3303,18 @@ class Gt extends p {
|
|
|
3235
3303
|
*/
|
|
3236
3304
|
sanitizeText(e) {
|
|
3237
3305
|
let t = e;
|
|
3238
|
-
for (const r of
|
|
3239
|
-
const
|
|
3240
|
-
t = t.replace(
|
|
3306
|
+
for (const r of Be) {
|
|
3307
|
+
const n = new RegExp(r.source, r.flags);
|
|
3308
|
+
t = t.replace(n, "[REDACTED]");
|
|
3241
3309
|
}
|
|
3242
3310
|
return t;
|
|
3243
3311
|
}
|
|
3244
3312
|
getRelevantText(e, t) {
|
|
3245
|
-
const r = e.textContent?.trim() ?? "",
|
|
3246
|
-
if (!r && !
|
|
3313
|
+
const r = e.textContent?.trim() ?? "", n = t.textContent?.trim() ?? "";
|
|
3314
|
+
if (!r && !n)
|
|
3247
3315
|
return "";
|
|
3248
3316
|
let i = "";
|
|
3249
|
-
return r && r.length <= 255 ? i = r :
|
|
3317
|
+
return r && r.length <= 255 ? i = r : n.length <= 255 ? i = n : i = n.slice(0, 252) + "...", this.sanitizeText(i);
|
|
3250
3318
|
}
|
|
3251
3319
|
extractElementAttributes(e) {
|
|
3252
3320
|
const t = [
|
|
@@ -3261,9 +3329,9 @@ class Gt extends p {
|
|
|
3261
3329
|
"alt",
|
|
3262
3330
|
"role"
|
|
3263
3331
|
], r = {};
|
|
3264
|
-
for (const
|
|
3265
|
-
const i = e.getAttribute(
|
|
3266
|
-
i && (r[
|
|
3332
|
+
for (const n of t) {
|
|
3333
|
+
const i = e.getAttribute(n);
|
|
3334
|
+
i && (r[n] = i);
|
|
3267
3335
|
}
|
|
3268
3336
|
return r;
|
|
3269
3337
|
}
|
|
@@ -3274,7 +3342,7 @@ class Gt extends p {
|
|
|
3274
3342
|
};
|
|
3275
3343
|
}
|
|
3276
3344
|
}
|
|
3277
|
-
class
|
|
3345
|
+
class sr extends _ {
|
|
3278
3346
|
eventManager;
|
|
3279
3347
|
containers = [];
|
|
3280
3348
|
limitWarningLogged = !1;
|
|
@@ -3321,8 +3389,8 @@ class Xt extends p {
|
|
|
3321
3389
|
const t = this.findScrollableElements();
|
|
3322
3390
|
if (this.isWindowScrollable() && this.setupScrollContainer(window, "window"), t.length > 0) {
|
|
3323
3391
|
for (const r of t) {
|
|
3324
|
-
const
|
|
3325
|
-
this.setupScrollContainer(r,
|
|
3392
|
+
const n = this.getElementSelector(r);
|
|
3393
|
+
this.setupScrollContainer(r, n);
|
|
3326
3394
|
}
|
|
3327
3395
|
this.applyPrimaryScrollSelectorIfConfigured();
|
|
3328
3396
|
return;
|
|
@@ -3343,8 +3411,8 @@ class Xt extends p {
|
|
|
3343
3411
|
if (!document.body)
|
|
3344
3412
|
return [];
|
|
3345
3413
|
const e = [], t = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT, {
|
|
3346
|
-
acceptNode: (
|
|
3347
|
-
const i =
|
|
3414
|
+
acceptNode: (n) => {
|
|
3415
|
+
const i = n;
|
|
3348
3416
|
if (!i.isConnected || !i.offsetParent)
|
|
3349
3417
|
return NodeFilter.FILTER_SKIP;
|
|
3350
3418
|
const o = getComputedStyle(i);
|
|
@@ -3353,8 +3421,8 @@ class Xt extends p {
|
|
|
3353
3421
|
});
|
|
3354
3422
|
let r;
|
|
3355
3423
|
for (; (r = t.nextNode()) && e.length < 10; ) {
|
|
3356
|
-
const
|
|
3357
|
-
this.isElementScrollable(
|
|
3424
|
+
const n = r;
|
|
3425
|
+
this.isElementScrollable(n) && e.push(n);
|
|
3358
3426
|
}
|
|
3359
3427
|
return e;
|
|
3360
3428
|
}
|
|
@@ -3365,7 +3433,7 @@ class Xt extends p {
|
|
|
3365
3433
|
if (t.id)
|
|
3366
3434
|
return `#${t.id}`;
|
|
3367
3435
|
if (t.className && typeof t.className == "string") {
|
|
3368
|
-
const r = t.className.split(" ").filter((
|
|
3436
|
+
const r = t.className.split(" ").filter((n) => n.trim())[0];
|
|
3369
3437
|
if (r)
|
|
3370
3438
|
return `.${r}`;
|
|
3371
3439
|
}
|
|
@@ -3375,17 +3443,17 @@ class Xt extends p {
|
|
|
3375
3443
|
return this.isWindowScrollable() ? e === window : this.containers.length === 0;
|
|
3376
3444
|
}
|
|
3377
3445
|
setupScrollContainer(e, t) {
|
|
3378
|
-
if (this.containers.some((
|
|
3446
|
+
if (this.containers.some((u) => u.element === e) || e !== window && !this.isElementScrollable(e))
|
|
3379
3447
|
return;
|
|
3380
|
-
const
|
|
3381
|
-
|
|
3448
|
+
const n = this.getScrollTop(e), i = this.calculateScrollDepth(
|
|
3449
|
+
n,
|
|
3382
3450
|
this.getScrollHeight(e),
|
|
3383
3451
|
this.getViewportHeight(e)
|
|
3384
3452
|
), o = this.determineIfPrimary(e), l = {
|
|
3385
3453
|
element: e,
|
|
3386
3454
|
selector: t,
|
|
3387
3455
|
isPrimary: o,
|
|
3388
|
-
lastScrollPos:
|
|
3456
|
+
lastScrollPos: n,
|
|
3389
3457
|
lastDepth: i,
|
|
3390
3458
|
lastDirection: X.DOWN,
|
|
3391
3459
|
lastEventTime: 0,
|
|
@@ -3395,10 +3463,10 @@ class Xt extends p {
|
|
|
3395
3463
|
listener: null
|
|
3396
3464
|
}, c = () => {
|
|
3397
3465
|
this.get("suppressNextScroll") || (l.firstScrollEventTime === null && (l.firstScrollEventTime = Date.now()), this.clearContainerTimer(l), l.debounceTimer = window.setTimeout(() => {
|
|
3398
|
-
const
|
|
3399
|
-
if (
|
|
3400
|
-
const
|
|
3401
|
-
this.processScrollEvent(l,
|
|
3466
|
+
const u = this.calculateScrollData(l);
|
|
3467
|
+
if (u) {
|
|
3468
|
+
const S = Date.now();
|
|
3469
|
+
this.processScrollEvent(l, u, S);
|
|
3402
3470
|
}
|
|
3403
3471
|
l.debounceTimer = null;
|
|
3404
3472
|
}, 250));
|
|
@@ -3409,9 +3477,9 @@ class Xt extends p {
|
|
|
3409
3477
|
if (!this.shouldEmitScrollEvent(e, t, r))
|
|
3410
3478
|
return;
|
|
3411
3479
|
e.lastEventTime = r, e.lastDepth = t.depth, e.lastDirection = t.direction;
|
|
3412
|
-
const
|
|
3413
|
-
this.set("scrollEventCount",
|
|
3414
|
-
type:
|
|
3480
|
+
const n = this.get("scrollEventCount") ?? 0;
|
|
3481
|
+
this.set("scrollEventCount", n + 1), this.eventManager.track({
|
|
3482
|
+
type: d.SCROLL,
|
|
3415
3483
|
scroll_data: {
|
|
3416
3484
|
...t,
|
|
3417
3485
|
container_selector: e.selector,
|
|
@@ -3432,7 +3500,7 @@ class Xt extends p {
|
|
|
3432
3500
|
return Math.abs(t - e.lastDepth) >= this.minDepthChange;
|
|
3433
3501
|
}
|
|
3434
3502
|
logLimitOnce() {
|
|
3435
|
-
this.limitWarningLogged || (this.limitWarningLogged = !0, a("
|
|
3503
|
+
this.limitWarningLogged || (this.limitWarningLogged = !0, a("debug", "Max scroll events per session reached", {
|
|
3436
3504
|
data: { limit: this.maxEventsPerSession }
|
|
3437
3505
|
}));
|
|
3438
3506
|
}
|
|
@@ -3451,21 +3519,21 @@ class Xt extends p {
|
|
|
3451
3519
|
calculateScrollDepth(e, t, r) {
|
|
3452
3520
|
if (t <= r)
|
|
3453
3521
|
return 0;
|
|
3454
|
-
const
|
|
3455
|
-
return Math.min(100, Math.max(0, Math.floor(e /
|
|
3522
|
+
const n = t - r;
|
|
3523
|
+
return Math.min(100, Math.max(0, Math.floor(e / n * 100)));
|
|
3456
3524
|
}
|
|
3457
3525
|
calculateScrollData(e) {
|
|
3458
|
-
const { element: t, lastScrollPos: r, lastEventTime:
|
|
3526
|
+
const { element: t, lastScrollPos: r, lastEventTime: n } = e, i = this.getScrollTop(t), o = Date.now(), l = Math.abs(i - r);
|
|
3459
3527
|
if (l < 10 || t === window && !this.isWindowScrollable())
|
|
3460
3528
|
return null;
|
|
3461
|
-
const c = this.getViewportHeight(t),
|
|
3462
|
-
let
|
|
3463
|
-
|
|
3464
|
-
const
|
|
3465
|
-
return
|
|
3466
|
-
depth:
|
|
3467
|
-
direction:
|
|
3468
|
-
velocity:
|
|
3529
|
+
const c = this.getViewportHeight(t), u = this.getScrollHeight(t), S = this.getScrollDirection(i, r), g = this.calculateScrollDepth(i, u, c);
|
|
3530
|
+
let E;
|
|
3531
|
+
n > 0 ? E = o - n : e.firstScrollEventTime !== null ? E = o - e.firstScrollEventTime : E = 250;
|
|
3532
|
+
const p = Math.round(l / E * 1e3);
|
|
3533
|
+
return g > e.maxDepthReached && (e.maxDepthReached = g), e.lastScrollPos = i, {
|
|
3534
|
+
depth: g,
|
|
3535
|
+
direction: S,
|
|
3536
|
+
velocity: p,
|
|
3469
3537
|
max_depth_reached: e.maxDepthReached
|
|
3470
3538
|
};
|
|
3471
3539
|
}
|
|
@@ -3479,30 +3547,30 @@ class Xt extends p {
|
|
|
3479
3547
|
return e === window ? document.documentElement.scrollHeight : e.scrollHeight;
|
|
3480
3548
|
}
|
|
3481
3549
|
isElementScrollable(e) {
|
|
3482
|
-
const t = getComputedStyle(e), r = t.overflowY === "auto" || t.overflowY === "scroll" || t.overflow === "auto" || t.overflow === "scroll",
|
|
3483
|
-
return r &&
|
|
3550
|
+
const t = getComputedStyle(e), r = t.overflowY === "auto" || t.overflowY === "scroll" || t.overflow === "auto" || t.overflow === "scroll", n = e.scrollHeight > e.clientHeight;
|
|
3551
|
+
return r && n;
|
|
3484
3552
|
}
|
|
3485
3553
|
applyPrimaryScrollSelector(e) {
|
|
3486
3554
|
let t;
|
|
3487
3555
|
if (e === "window")
|
|
3488
3556
|
t = window;
|
|
3489
3557
|
else {
|
|
3490
|
-
const
|
|
3491
|
-
if (!(
|
|
3492
|
-
a("
|
|
3558
|
+
const n = document.querySelector(e);
|
|
3559
|
+
if (!(n instanceof HTMLElement)) {
|
|
3560
|
+
a("debug", `Selector "${e}" did not match an HTMLElement`);
|
|
3493
3561
|
return;
|
|
3494
3562
|
}
|
|
3495
|
-
t =
|
|
3563
|
+
t = n;
|
|
3496
3564
|
}
|
|
3497
|
-
this.containers.forEach((
|
|
3498
|
-
this.updateContainerPrimary(
|
|
3499
|
-
}), !this.containers.some((
|
|
3565
|
+
this.containers.forEach((n) => {
|
|
3566
|
+
this.updateContainerPrimary(n, n.element === t);
|
|
3567
|
+
}), !this.containers.some((n) => n.element === t) && t instanceof HTMLElement && this.isElementScrollable(t) && this.setupScrollContainer(t, e);
|
|
3500
3568
|
}
|
|
3501
3569
|
updateContainerPrimary(e, t) {
|
|
3502
3570
|
e.isPrimary = t;
|
|
3503
3571
|
}
|
|
3504
3572
|
}
|
|
3505
|
-
class
|
|
3573
|
+
class nr extends _ {
|
|
3506
3574
|
eventManager;
|
|
3507
3575
|
trackedElements = /* @__PURE__ */ new Map();
|
|
3508
3576
|
observer = null;
|
|
@@ -3521,15 +3589,15 @@ class Qt extends p {
|
|
|
3521
3589
|
return;
|
|
3522
3590
|
const t = this.config.threshold ?? 0.5, r = this.config.minDwellTime ?? 1e3;
|
|
3523
3591
|
if (t < 0 || t > 1) {
|
|
3524
|
-
a("
|
|
3592
|
+
a("debug", "ViewportHandler: Invalid threshold, must be between 0 and 1");
|
|
3525
3593
|
return;
|
|
3526
3594
|
}
|
|
3527
3595
|
if (r < 0) {
|
|
3528
|
-
a("
|
|
3596
|
+
a("debug", "ViewportHandler: Invalid minDwellTime, must be non-negative");
|
|
3529
3597
|
return;
|
|
3530
3598
|
}
|
|
3531
3599
|
if (typeof IntersectionObserver > "u") {
|
|
3532
|
-
a("
|
|
3600
|
+
a("debug", "ViewportHandler: IntersectionObserver not supported in this browser");
|
|
3533
3601
|
return;
|
|
3534
3602
|
}
|
|
3535
3603
|
this.observer = new IntersectionObserver(this.handleIntersection, {
|
|
@@ -3554,10 +3622,10 @@ class Qt extends p {
|
|
|
3554
3622
|
let t = this.trackedElements.size;
|
|
3555
3623
|
for (const r of this.config.elements)
|
|
3556
3624
|
try {
|
|
3557
|
-
const
|
|
3558
|
-
for (const i of Array.from(
|
|
3625
|
+
const n = document.querySelectorAll(r.selector);
|
|
3626
|
+
for (const i of Array.from(n)) {
|
|
3559
3627
|
if (t >= e) {
|
|
3560
|
-
a("
|
|
3628
|
+
a("debug", "ViewportHandler: Maximum tracked elements reached", {
|
|
3561
3629
|
data: {
|
|
3562
3630
|
limit: e,
|
|
3563
3631
|
selector: r.selector,
|
|
@@ -3566,7 +3634,7 @@ class Qt extends p {
|
|
|
3566
3634
|
});
|
|
3567
3635
|
return;
|
|
3568
3636
|
}
|
|
3569
|
-
i.hasAttribute(`${
|
|
3637
|
+
i.hasAttribute(`${w}-ignore`) || this.trackedElements.has(i) || (this.trackedElements.set(i, {
|
|
3570
3638
|
element: i,
|
|
3571
3639
|
selector: r.selector,
|
|
3572
3640
|
id: r.id,
|
|
@@ -3576,8 +3644,8 @@ class Qt extends p {
|
|
|
3576
3644
|
lastFiredTime: null
|
|
3577
3645
|
}), this.observer?.observe(i), t++);
|
|
3578
3646
|
}
|
|
3579
|
-
} catch (
|
|
3580
|
-
a("
|
|
3647
|
+
} catch (n) {
|
|
3648
|
+
a("debug", `ViewportHandler: Invalid selector "${r.selector}"`, { error: n });
|
|
3581
3649
|
}
|
|
3582
3650
|
a("debug", "ViewportHandler: Elements tracked", {
|
|
3583
3651
|
data: { count: t, limit: e }
|
|
@@ -3590,11 +3658,11 @@ class Qt extends p {
|
|
|
3590
3658
|
if (!this.config) return;
|
|
3591
3659
|
const t = this.config.minDwellTime ?? 1e3;
|
|
3592
3660
|
for (const r of e) {
|
|
3593
|
-
const
|
|
3594
|
-
|
|
3661
|
+
const n = this.trackedElements.get(r.target);
|
|
3662
|
+
n && (r.isIntersecting ? n.startTime === null && (n.startTime = performance.now(), n.timeoutId = window.setTimeout(() => {
|
|
3595
3663
|
const i = Math.round(r.intersectionRatio * 100) / 100;
|
|
3596
|
-
this.fireViewportEvent(
|
|
3597
|
-
}, t)) :
|
|
3664
|
+
this.fireViewportEvent(n, i);
|
|
3665
|
+
}, t)) : n.startTime !== null && (n.timeoutId !== null && (window.clearTimeout(n.timeoutId), n.timeoutId = null), n.startTime = null));
|
|
3598
3666
|
}
|
|
3599
3667
|
};
|
|
3600
3668
|
/**
|
|
@@ -3603,14 +3671,14 @@ class Qt extends p {
|
|
|
3603
3671
|
fireViewportEvent(e, t) {
|
|
3604
3672
|
if (e.startTime === null) return;
|
|
3605
3673
|
const r = Math.round(performance.now() - e.startTime);
|
|
3606
|
-
if (e.element.hasAttribute(`${
|
|
3674
|
+
if (e.element.hasAttribute(`${w}-ignore`))
|
|
3607
3675
|
return;
|
|
3608
|
-
const
|
|
3609
|
-
if (e.lastFiredTime !== null && i - e.lastFiredTime <
|
|
3676
|
+
const n = this.config?.cooldownPeriod ?? 6e4, i = Date.now();
|
|
3677
|
+
if (e.lastFiredTime !== null && i - e.lastFiredTime < n) {
|
|
3610
3678
|
a("debug", "ViewportHandler: Event suppressed by cooldown period", {
|
|
3611
3679
|
data: {
|
|
3612
3680
|
selector: e.selector,
|
|
3613
|
-
cooldownRemaining:
|
|
3681
|
+
cooldownRemaining: n - (i - e.lastFiredTime)
|
|
3614
3682
|
}
|
|
3615
3683
|
}), e.startTime = null, e.timeoutId = null;
|
|
3616
3684
|
return;
|
|
@@ -3623,7 +3691,7 @@ class Qt extends p {
|
|
|
3623
3691
|
...e.name !== void 0 && { name: e.name }
|
|
3624
3692
|
};
|
|
3625
3693
|
this.eventManager.track({
|
|
3626
|
-
type:
|
|
3694
|
+
type: d.VIEWPORT_VISIBLE,
|
|
3627
3695
|
viewport_data: o
|
|
3628
3696
|
}), e.startTime = null, e.timeoutId = null, e.lastFiredTime = i;
|
|
3629
3697
|
}
|
|
@@ -3633,7 +3701,7 @@ class Qt extends p {
|
|
|
3633
3701
|
setupMutationObserver() {
|
|
3634
3702
|
if (!(!this.config || typeof MutationObserver > "u")) {
|
|
3635
3703
|
if (!document.body) {
|
|
3636
|
-
a("
|
|
3704
|
+
a("debug", "ViewportHandler: document.body not available, skipping MutationObserver setup");
|
|
3637
3705
|
return;
|
|
3638
3706
|
}
|
|
3639
3707
|
this.mutationObserver = new MutationObserver((e) => {
|
|
@@ -3655,22 +3723,22 @@ class Qt extends p {
|
|
|
3655
3723
|
cleanupRemovedNodes(e) {
|
|
3656
3724
|
e.forEach((t) => {
|
|
3657
3725
|
if (t.nodeType !== 1) return;
|
|
3658
|
-
const r = t,
|
|
3659
|
-
|
|
3726
|
+
const r = t, n = this.trackedElements.get(r);
|
|
3727
|
+
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) => {
|
|
3660
3728
|
const l = this.trackedElements.get(o);
|
|
3661
3729
|
l && l.timeoutId !== null && window.clearTimeout(l.timeoutId), this.observer?.unobserve(o), this.trackedElements.delete(o);
|
|
3662
3730
|
});
|
|
3663
3731
|
});
|
|
3664
3732
|
}
|
|
3665
3733
|
}
|
|
3666
|
-
class
|
|
3734
|
+
class ir {
|
|
3667
3735
|
storage;
|
|
3668
3736
|
sessionStorageRef;
|
|
3669
3737
|
fallbackStorage = /* @__PURE__ */ new Map();
|
|
3670
3738
|
fallbackSessionStorage = /* @__PURE__ */ new Map();
|
|
3671
3739
|
hasQuotaExceededError = !1;
|
|
3672
3740
|
constructor() {
|
|
3673
|
-
this.storage = this.initializeStorage("localStorage"), this.sessionStorageRef = this.initializeStorage("sessionStorage"), this.storage || a("
|
|
3741
|
+
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");
|
|
3674
3742
|
}
|
|
3675
3743
|
/**
|
|
3676
3744
|
* Retrieves an item from localStorage.
|
|
@@ -3843,8 +3911,8 @@ class zt {
|
|
|
3843
3911
|
} catch {
|
|
3844
3912
|
}
|
|
3845
3913
|
}), !0;
|
|
3846
|
-
const r = ["tracelog_session_", "tracelog_user_id", "tracelog_device_id", "tracelog_config"],
|
|
3847
|
-
return
|
|
3914
|
+
const r = ["tracelog_session_", "tracelog_user_id", "tracelog_device_id", "tracelog_config"], n = e.filter((i) => !r.some((o) => i.startsWith(o)));
|
|
3915
|
+
return n.length > 0 ? (n.slice(0, 5).forEach((o) => {
|
|
3848
3916
|
try {
|
|
3849
3917
|
this.storage.removeItem(o);
|
|
3850
3918
|
} catch {
|
|
@@ -3946,7 +4014,7 @@ class zt {
|
|
|
3946
4014
|
this.fallbackSessionStorage.delete(e);
|
|
3947
4015
|
}
|
|
3948
4016
|
}
|
|
3949
|
-
class
|
|
4017
|
+
class or extends _ {
|
|
3950
4018
|
eventManager;
|
|
3951
4019
|
reportedByNav = /* @__PURE__ */ new Map();
|
|
3952
4020
|
navigationHistory = [];
|
|
@@ -3957,7 +4025,7 @@ class jt extends p {
|
|
|
3957
4025
|
navigationCounter = 0;
|
|
3958
4026
|
// Counter for handling simultaneous navigations edge case
|
|
3959
4027
|
constructor(e) {
|
|
3960
|
-
super(), this.eventManager = e, this.vitalThresholds = Ne(
|
|
4028
|
+
super(), this.eventManager = e, this.vitalThresholds = Ne(ae);
|
|
3961
4029
|
}
|
|
3962
4030
|
/**
|
|
3963
4031
|
* Starts tracking Web Vitals and performance metrics.
|
|
@@ -3974,7 +4042,7 @@ class jt extends p {
|
|
|
3974
4042
|
* @returns Promise that resolves when tracking is initialized
|
|
3975
4043
|
*/
|
|
3976
4044
|
async startTracking() {
|
|
3977
|
-
const e = this.get("config"), t = e?.webVitalsMode ??
|
|
4045
|
+
const e = this.get("config"), t = e?.webVitalsMode ?? ae;
|
|
3978
4046
|
this.vitalThresholds = Ne(t), e?.webVitalsThresholds && (this.vitalThresholds = { ...this.vitalThresholds, ...e.webVitalsThresholds }), await this.initWebVitals(), this.observeLongTasks();
|
|
3979
4047
|
}
|
|
3980
4048
|
/**
|
|
@@ -3991,7 +4059,7 @@ class jt extends p {
|
|
|
3991
4059
|
try {
|
|
3992
4060
|
e.disconnect();
|
|
3993
4061
|
} catch (r) {
|
|
3994
|
-
a("
|
|
4062
|
+
a("debug", "Failed to disconnect performance observer", { error: r, data: { observerIndex: t } });
|
|
3995
4063
|
}
|
|
3996
4064
|
}), this.observers.length = 0, this.reportedByNav.clear(), this.navigationHistory.length = 0;
|
|
3997
4065
|
}
|
|
@@ -3999,7 +4067,7 @@ class jt extends p {
|
|
|
3999
4067
|
this.reportTTFB(), this.safeObserve(
|
|
4000
4068
|
"largest-contentful-paint",
|
|
4001
4069
|
(r) => {
|
|
4002
|
-
const
|
|
4070
|
+
const n = r.getEntries(), i = n[n.length - 1];
|
|
4003
4071
|
i && this.sendVital({ type: "LCP", value: Number(i.startTime.toFixed(2)) });
|
|
4004
4072
|
},
|
|
4005
4073
|
{ type: "largest-contentful-paint", buffered: !0 },
|
|
@@ -4009,8 +4077,8 @@ class jt extends p {
|
|
|
4009
4077
|
this.safeObserve(
|
|
4010
4078
|
"layout-shift",
|
|
4011
4079
|
(r) => {
|
|
4012
|
-
const
|
|
4013
|
-
|
|
4080
|
+
const n = this.getNavigationId();
|
|
4081
|
+
n !== t && (e = 0, t = n);
|
|
4014
4082
|
const i = r.getEntries();
|
|
4015
4083
|
for (const o of i) {
|
|
4016
4084
|
if (o.hadRecentInput === !0)
|
|
@@ -4024,34 +4092,34 @@ class jt extends p {
|
|
|
4024
4092
|
), this.safeObserve(
|
|
4025
4093
|
"paint",
|
|
4026
4094
|
(r) => {
|
|
4027
|
-
for (const
|
|
4028
|
-
|
|
4095
|
+
for (const n of r.getEntries())
|
|
4096
|
+
n.name === "first-contentful-paint" && this.sendVital({ type: "FCP", value: Number(n.startTime.toFixed(2)) });
|
|
4029
4097
|
},
|
|
4030
4098
|
{ type: "paint", buffered: !0 },
|
|
4031
4099
|
!0
|
|
4032
4100
|
), this.safeObserve(
|
|
4033
4101
|
"event",
|
|
4034
4102
|
(r) => {
|
|
4035
|
-
let
|
|
4103
|
+
let n = 0;
|
|
4036
4104
|
const i = r.getEntries();
|
|
4037
4105
|
for (const o of i) {
|
|
4038
4106
|
const l = (o.processingEnd ?? 0) - (o.startTime ?? 0);
|
|
4039
|
-
|
|
4107
|
+
n = Math.max(n, l);
|
|
4040
4108
|
}
|
|
4041
|
-
|
|
4109
|
+
n > 0 && this.sendVital({ type: "INP", value: Number(n.toFixed(2)) });
|
|
4042
4110
|
},
|
|
4043
4111
|
{ type: "event", buffered: !0 }
|
|
4044
4112
|
);
|
|
4045
4113
|
}
|
|
4046
4114
|
async initWebVitals() {
|
|
4047
4115
|
try {
|
|
4048
|
-
const { onLCP: e, onCLS: t, onFCP: r, onTTFB:
|
|
4049
|
-
const
|
|
4050
|
-
this.sendVital({ type: l, value:
|
|
4116
|
+
const { onLCP: e, onCLS: t, onFCP: r, onTTFB: n, onINP: i } = await Promise.resolve().then(() => Nr), o = (l) => (c) => {
|
|
4117
|
+
const u = Number(c.value.toFixed(2));
|
|
4118
|
+
this.sendVital({ type: l, value: u });
|
|
4051
4119
|
};
|
|
4052
|
-
e(o("LCP"), { reportAllChanges: !1 }), t(o("CLS"), { reportAllChanges: !1 }), r(o("FCP"), { reportAllChanges: !1 }),
|
|
4120
|
+
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 });
|
|
4053
4121
|
} catch (e) {
|
|
4054
|
-
a("
|
|
4122
|
+
a("debug", "Failed to load web-vitals library, using fallback", { error: e }), this.observeWebVitalsFallback();
|
|
4055
4123
|
}
|
|
4056
4124
|
}
|
|
4057
4125
|
reportTTFB() {
|
|
@@ -4062,7 +4130,7 @@ class jt extends p {
|
|
|
4062
4130
|
const t = e.responseStart;
|
|
4063
4131
|
typeof t == "number" && Number.isFinite(t) && this.sendVital({ type: "TTFB", value: Number(t.toFixed(2)) });
|
|
4064
4132
|
} catch (e) {
|
|
4065
|
-
a("
|
|
4133
|
+
a("debug", "Failed to report TTFB", { error: e });
|
|
4066
4134
|
}
|
|
4067
4135
|
}
|
|
4068
4136
|
observeLongTasks() {
|
|
@@ -4071,8 +4139,8 @@ class jt extends p {
|
|
|
4071
4139
|
(e) => {
|
|
4072
4140
|
const t = e.getEntries();
|
|
4073
4141
|
for (const r of t) {
|
|
4074
|
-
const
|
|
4075
|
-
i - this.lastLongTaskSentAt >=
|
|
4142
|
+
const n = Number(r.duration.toFixed(2)), i = Date.now();
|
|
4143
|
+
i - this.lastLongTaskSentAt >= Mt && (this.shouldSendVital("LONG_TASK", n) && this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = i);
|
|
4076
4144
|
}
|
|
4077
4145
|
},
|
|
4078
4146
|
{ type: "longtask", buffered: !0 }
|
|
@@ -4088,7 +4156,7 @@ class jt extends p {
|
|
|
4088
4156
|
return;
|
|
4089
4157
|
if (r)
|
|
4090
4158
|
r.add(e.type);
|
|
4091
|
-
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length >
|
|
4159
|
+
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length > Ct) {
|
|
4092
4160
|
const i = this.navigationHistory.shift();
|
|
4093
4161
|
i && this.reportedByNav.delete(i);
|
|
4094
4162
|
}
|
|
@@ -4097,11 +4165,11 @@ class jt extends p {
|
|
|
4097
4165
|
}
|
|
4098
4166
|
trackWebVital(e, t) {
|
|
4099
4167
|
if (!Number.isFinite(t)) {
|
|
4100
|
-
a("
|
|
4168
|
+
a("debug", "Invalid web vital value", { data: { type: e, value: t } });
|
|
4101
4169
|
return;
|
|
4102
4170
|
}
|
|
4103
4171
|
this.eventManager.track({
|
|
4104
|
-
type:
|
|
4172
|
+
type: d.WEB_VITALS,
|
|
4105
4173
|
web_vitals: {
|
|
4106
4174
|
type: e,
|
|
4107
4175
|
value: t
|
|
@@ -4134,10 +4202,10 @@ class jt extends p {
|
|
|
4134
4202
|
const e = performance.getEntriesByType("navigation")[0];
|
|
4135
4203
|
if (!e)
|
|
4136
4204
|
return null;
|
|
4137
|
-
const t = e.startTime || performance.now(), r = ++this.navigationCounter,
|
|
4138
|
-
return r > 1 ? `${
|
|
4205
|
+
const t = e.startTime || performance.now(), r = ++this.navigationCounter, n = `${t.toFixed(2)}_${window.location.pathname}`;
|
|
4206
|
+
return r > 1 ? `${n}_${r}` : n;
|
|
4139
4207
|
} catch (e) {
|
|
4140
|
-
return a("
|
|
4208
|
+
return a("debug", "Failed to get navigation ID", { error: e }), null;
|
|
4141
4209
|
}
|
|
4142
4210
|
}
|
|
4143
4211
|
isObserverSupported(e) {
|
|
@@ -4145,7 +4213,7 @@ class jt extends p {
|
|
|
4145
4213
|
const t = PerformanceObserver.supportedEntryTypes;
|
|
4146
4214
|
return !t || t.includes(e);
|
|
4147
4215
|
}
|
|
4148
|
-
safeObserve(e, t, r,
|
|
4216
|
+
safeObserve(e, t, r, n = !1) {
|
|
4149
4217
|
try {
|
|
4150
4218
|
if (!this.isObserverSupported(e))
|
|
4151
4219
|
return !1;
|
|
@@ -4153,20 +4221,20 @@ class jt extends p {
|
|
|
4153
4221
|
try {
|
|
4154
4222
|
t(o, l);
|
|
4155
4223
|
} catch (c) {
|
|
4156
|
-
a("
|
|
4224
|
+
a("debug", "Observer callback failed", {
|
|
4157
4225
|
error: c,
|
|
4158
4226
|
data: { type: e }
|
|
4159
4227
|
});
|
|
4160
4228
|
}
|
|
4161
|
-
if (
|
|
4229
|
+
if (n)
|
|
4162
4230
|
try {
|
|
4163
4231
|
l.disconnect();
|
|
4164
4232
|
} catch {
|
|
4165
4233
|
}
|
|
4166
4234
|
});
|
|
4167
|
-
return i.observe(r ?? { type: e, buffered: !0 }),
|
|
4235
|
+
return i.observe(r ?? { type: e, buffered: !0 }), n || this.observers.push(i), !0;
|
|
4168
4236
|
} catch (i) {
|
|
4169
|
-
return a("
|
|
4237
|
+
return a("debug", "Failed to create performance observer", {
|
|
4170
4238
|
error: i,
|
|
4171
4239
|
data: { type: e }
|
|
4172
4240
|
}), !1;
|
|
@@ -4174,12 +4242,12 @@ class jt extends p {
|
|
|
4174
4242
|
}
|
|
4175
4243
|
shouldSendVital(e, t) {
|
|
4176
4244
|
if (typeof t != "number" || !Number.isFinite(t))
|
|
4177
|
-
return a("
|
|
4245
|
+
return a("debug", "Invalid web vital value", { data: { type: e, value: t } }), !1;
|
|
4178
4246
|
const r = this.vitalThresholds[e];
|
|
4179
4247
|
return !(typeof r == "number" && t <= r);
|
|
4180
4248
|
}
|
|
4181
4249
|
}
|
|
4182
|
-
class
|
|
4250
|
+
class ar extends _ {
|
|
4183
4251
|
eventManager;
|
|
4184
4252
|
recentErrors = /* @__PURE__ */ new Map();
|
|
4185
4253
|
errorBurstCounter = 0;
|
|
@@ -4215,24 +4283,24 @@ class Kt extends p {
|
|
|
4215
4283
|
const e = Date.now();
|
|
4216
4284
|
if (e < this.burstBackoffUntil)
|
|
4217
4285
|
return !1;
|
|
4218
|
-
if (e - this.burstWindowStart >
|
|
4219
|
-
return this.burstBackoffUntil = e + Ce, a("
|
|
4286
|
+
if (e - this.burstWindowStart > yt && (this.errorBurstCounter = 0, this.burstWindowStart = e), this.errorBurstCounter++, this.errorBurstCounter > bt)
|
|
4287
|
+
return this.burstBackoffUntil = e + Ce, a("debug", "Error burst detected - entering cooldown", {
|
|
4220
4288
|
data: {
|
|
4221
4289
|
errorsInWindow: this.errorBurstCounter,
|
|
4222
4290
|
cooldownMs: Ce
|
|
4223
4291
|
}
|
|
4224
4292
|
}), !1;
|
|
4225
|
-
const r = this.get("config")?.errorSampling ??
|
|
4293
|
+
const r = this.get("config")?.errorSampling ?? We;
|
|
4226
4294
|
return Math.random() < r;
|
|
4227
4295
|
}
|
|
4228
4296
|
handleError = (e) => {
|
|
4229
4297
|
if (!this.shouldSample())
|
|
4230
4298
|
return;
|
|
4231
4299
|
const t = this.sanitize(e.message || "Unknown error");
|
|
4232
|
-
this.shouldSuppressError(
|
|
4233
|
-
type:
|
|
4300
|
+
this.shouldSuppressError(U.JS_ERROR, t) || this.eventManager.track({
|
|
4301
|
+
type: d.ERROR,
|
|
4234
4302
|
error_data: {
|
|
4235
|
-
type:
|
|
4303
|
+
type: U.JS_ERROR,
|
|
4236
4304
|
message: t,
|
|
4237
4305
|
...e.filename && { filename: e.filename },
|
|
4238
4306
|
...e.lineno && { line: e.lineno },
|
|
@@ -4244,10 +4312,10 @@ class Kt extends p {
|
|
|
4244
4312
|
if (!this.shouldSample())
|
|
4245
4313
|
return;
|
|
4246
4314
|
const t = this.extractRejectionMessage(e.reason), r = this.sanitize(t);
|
|
4247
|
-
this.shouldSuppressError(
|
|
4248
|
-
type:
|
|
4315
|
+
this.shouldSuppressError(U.PROMISE_REJECTION, r) || this.eventManager.track({
|
|
4316
|
+
type: d.ERROR,
|
|
4249
4317
|
error_data: {
|
|
4250
|
-
type:
|
|
4318
|
+
type: U.PROMISE_REJECTION,
|
|
4251
4319
|
message: r
|
|
4252
4320
|
}
|
|
4253
4321
|
});
|
|
@@ -4266,34 +4334,34 @@ class Kt extends p {
|
|
|
4266
4334
|
}
|
|
4267
4335
|
}
|
|
4268
4336
|
sanitize(e) {
|
|
4269
|
-
let t = e.length >
|
|
4270
|
-
for (const r of
|
|
4271
|
-
const
|
|
4272
|
-
t = t.replace(
|
|
4337
|
+
let t = e.length > Le ? e.slice(0, Le) + "..." : e;
|
|
4338
|
+
for (const r of Be) {
|
|
4339
|
+
const n = new RegExp(r.source, r.flags);
|
|
4340
|
+
t = t.replace(n, "[REDACTED]");
|
|
4273
4341
|
}
|
|
4274
4342
|
return t;
|
|
4275
4343
|
}
|
|
4276
4344
|
shouldSuppressError(e, t) {
|
|
4277
|
-
const r = Date.now(),
|
|
4278
|
-
return i && r - i <
|
|
4345
|
+
const r = Date.now(), n = `${e}:${t}`, i = this.recentErrors.get(n);
|
|
4346
|
+
return i && r - i < Me ? (this.recentErrors.set(n, r), !0) : (this.recentErrors.set(n, r), this.recentErrors.size > wt ? (this.recentErrors.clear(), this.recentErrors.set(n, r), !1) : (this.recentErrors.size > Q && this.pruneOldErrors(), !1));
|
|
4279
4347
|
}
|
|
4280
4348
|
pruneOldErrors() {
|
|
4281
4349
|
const e = Date.now();
|
|
4282
|
-
for (const [
|
|
4283
|
-
e - i >
|
|
4350
|
+
for (const [n, i] of this.recentErrors.entries())
|
|
4351
|
+
e - i > Me && this.recentErrors.delete(n);
|
|
4284
4352
|
if (this.recentErrors.size <= Q)
|
|
4285
4353
|
return;
|
|
4286
|
-
const t = Array.from(this.recentErrors.entries()).sort((
|
|
4287
|
-
for (let
|
|
4288
|
-
const i = t[
|
|
4354
|
+
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), r = this.recentErrors.size - Q;
|
|
4355
|
+
for (let n = 0; n < r; n += 1) {
|
|
4356
|
+
const i = t[n];
|
|
4289
4357
|
i && this.recentErrors.delete(i[0]);
|
|
4290
4358
|
}
|
|
4291
4359
|
}
|
|
4292
4360
|
}
|
|
4293
|
-
class
|
|
4361
|
+
class lr extends _ {
|
|
4294
4362
|
isInitialized = !1;
|
|
4295
4363
|
suppressNextScrollTimer = null;
|
|
4296
|
-
emitter = new
|
|
4364
|
+
emitter = new zt();
|
|
4297
4365
|
transformers = {};
|
|
4298
4366
|
managers = {};
|
|
4299
4367
|
handlers = {};
|
|
@@ -4309,9 +4377,9 @@ class Yt extends p {
|
|
|
4309
4377
|
*/
|
|
4310
4378
|
async init(e = {}) {
|
|
4311
4379
|
if (!this.isInitialized) {
|
|
4312
|
-
this.managers.storage = new
|
|
4380
|
+
this.managers.storage = new ir();
|
|
4313
4381
|
try {
|
|
4314
|
-
this.setupState(e), this.managers.event = new
|
|
4382
|
+
this.setupState(e), this.managers.event = new Yt(this.managers.storage, this.emitter, this.transformers), this.initializeHandlers(), await this.managers.event.recoverPersistedEvents().catch((t) => {
|
|
4315
4383
|
a("warn", "Failed to recover persisted events", { error: t });
|
|
4316
4384
|
}), this.isInitialized = !0;
|
|
4317
4385
|
} catch (t) {
|
|
@@ -4335,14 +4403,14 @@ class Yt extends p {
|
|
|
4335
4403
|
}
|
|
4336
4404
|
let r = t;
|
|
4337
4405
|
t && typeof t == "object" && !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && (r = Object.assign({}, t));
|
|
4338
|
-
const { valid:
|
|
4339
|
-
if (!
|
|
4406
|
+
const { valid: n, error: i, sanitizedMetadata: o } = Qt(e, r);
|
|
4407
|
+
if (!n) {
|
|
4340
4408
|
if (this.get("mode") === j.QA)
|
|
4341
4409
|
throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${i}`);
|
|
4342
4410
|
return;
|
|
4343
4411
|
}
|
|
4344
4412
|
this.managers.event.track({
|
|
4345
|
-
type:
|
|
4413
|
+
type: d.CUSTOM,
|
|
4346
4414
|
custom_event: {
|
|
4347
4415
|
name: e,
|
|
4348
4416
|
...o && { metadata: o }
|
|
@@ -4383,16 +4451,14 @@ class Yt extends p {
|
|
|
4383
4451
|
}
|
|
4384
4452
|
setupState(e = {}) {
|
|
4385
4453
|
this.set("config", e);
|
|
4386
|
-
const t =
|
|
4454
|
+
const t = qt.getId(this.managers.storage);
|
|
4387
4455
|
this.set("userId", t);
|
|
4388
|
-
const r =
|
|
4456
|
+
const r = xt(e);
|
|
4389
4457
|
this.set("collectApiUrls", r);
|
|
4390
|
-
const
|
|
4391
|
-
this.set("device",
|
|
4392
|
-
const i =
|
|
4393
|
-
this.set("pageUrl", i);
|
|
4394
|
-
const o = It() ? j.QA : void 0;
|
|
4395
|
-
o && this.set("mode", o);
|
|
4458
|
+
const n = It();
|
|
4459
|
+
this.set("device", n);
|
|
4460
|
+
const i = le(window.location.href, e.sensitiveQueryParams);
|
|
4461
|
+
this.set("pageUrl", i), Pt() && this.set("mode", j.QA);
|
|
4396
4462
|
}
|
|
4397
4463
|
/**
|
|
4398
4464
|
* Returns the current configuration object.
|
|
@@ -4434,7 +4500,7 @@ class Yt extends p {
|
|
|
4434
4500
|
valid: !1,
|
|
4435
4501
|
error: "Global metadata must be a plain object"
|
|
4436
4502
|
};
|
|
4437
|
-
const t =
|
|
4503
|
+
const t = ze("Global", e, "globalMetadata");
|
|
4438
4504
|
return t.valid ? { valid: !0 } : {
|
|
4439
4505
|
valid: !1,
|
|
4440
4506
|
error: t.error
|
|
@@ -4451,11 +4517,11 @@ class Yt extends p {
|
|
|
4451
4517
|
const t = this.validateGlobalMetadata(e);
|
|
4452
4518
|
if (!t.valid)
|
|
4453
4519
|
throw new Error(`[TraceLog] Invalid global metadata: ${t.error}`);
|
|
4454
|
-
const
|
|
4520
|
+
const n = {
|
|
4455
4521
|
...this.get("config"),
|
|
4456
4522
|
globalMetadata: e
|
|
4457
4523
|
};
|
|
4458
|
-
this.set("config",
|
|
4524
|
+
this.set("config", n), a("debug", "Global metadata updated (replaced)", { data: { keys: Object.keys(e) } });
|
|
4459
4525
|
}
|
|
4460
4526
|
/**
|
|
4461
4527
|
* Merges new metadata with existing global metadata.
|
|
@@ -4479,7 +4545,7 @@ class Yt extends p {
|
|
|
4479
4545
|
}
|
|
4480
4546
|
initializeHandlers() {
|
|
4481
4547
|
const e = this.get("config");
|
|
4482
|
-
this.handlers.session = new
|
|
4548
|
+
this.handlers.session = new er(
|
|
4483
4549
|
this.managers.storage,
|
|
4484
4550
|
this.managers.event
|
|
4485
4551
|
), this.handlers.session.startTracking();
|
|
@@ -4488,372 +4554,372 @@ class Yt extends p {
|
|
|
4488
4554
|
this.set("suppressNextScroll", !1);
|
|
4489
4555
|
}, 500);
|
|
4490
4556
|
};
|
|
4491
|
-
this.handlers.pageView = new
|
|
4557
|
+
this.handlers.pageView = new tr(this.managers.event, t), this.handlers.pageView.startTracking(), this.handlers.click = new rr(this.managers.event), this.handlers.click.startTracking(), this.handlers.scroll = new sr(this.managers.event), this.handlers.scroll.startTracking(), this.handlers.performance = new or(this.managers.event), this.handlers.performance.startTracking().catch((r) => {
|
|
4492
4558
|
a("warn", "Failed to start performance tracking", { error: r });
|
|
4493
|
-
}), this.handlers.error = new
|
|
4559
|
+
}), this.handlers.error = new ar(this.managers.event), this.handlers.error.startTracking(), e.viewport && (this.handlers.viewport = new nr(this.managers.event), this.handlers.viewport.startTracking());
|
|
4494
4560
|
}
|
|
4495
4561
|
}
|
|
4496
|
-
const
|
|
4497
|
-
let f = null,
|
|
4498
|
-
const
|
|
4499
|
-
if (!(typeof window > "u" || typeof document > "u") && (
|
|
4500
|
-
|
|
4562
|
+
const R = [], M = [];
|
|
4563
|
+
let f = null, C = !1, v = !1;
|
|
4564
|
+
const cr = async (s) => {
|
|
4565
|
+
if (!(typeof window > "u" || typeof document > "u") && (v = !1, window.__traceLogDisabled !== !0 && !f && !C)) {
|
|
4566
|
+
C = !0;
|
|
4501
4567
|
try {
|
|
4502
|
-
const e =
|
|
4568
|
+
const e = Wt(s ?? {}), t = new lr();
|
|
4503
4569
|
try {
|
|
4504
|
-
|
|
4570
|
+
R.forEach(({ event: i, callback: o }) => {
|
|
4505
4571
|
t.on(i, o);
|
|
4506
|
-
}),
|
|
4572
|
+
}), R.length = 0, M.forEach(({ hook: i, fn: o }) => {
|
|
4507
4573
|
i === "beforeSend" ? t.setTransformer("beforeSend", o) : t.setTransformer("beforeBatch", o);
|
|
4508
|
-
}),
|
|
4509
|
-
const r = t.init(e),
|
|
4574
|
+
}), M.length = 0;
|
|
4575
|
+
const r = t.init(e), n = new Promise((i, o) => {
|
|
4510
4576
|
setTimeout(() => {
|
|
4511
4577
|
o(new Error("[TraceLog] Initialization timeout after 10000ms"));
|
|
4512
4578
|
}, 1e4);
|
|
4513
4579
|
});
|
|
4514
|
-
await Promise.race([r,
|
|
4580
|
+
await Promise.race([r, n]), f = t;
|
|
4515
4581
|
} catch (r) {
|
|
4516
4582
|
try {
|
|
4517
4583
|
t.destroy(!0);
|
|
4518
|
-
} catch (
|
|
4519
|
-
a("error", "Failed to cleanup partially initialized app", { error:
|
|
4584
|
+
} catch (n) {
|
|
4585
|
+
a("error", "Failed to cleanup partially initialized app", { error: n });
|
|
4520
4586
|
}
|
|
4521
4587
|
throw r;
|
|
4522
4588
|
}
|
|
4523
4589
|
} catch (e) {
|
|
4524
4590
|
throw f = null, e;
|
|
4525
4591
|
} finally {
|
|
4526
|
-
|
|
4592
|
+
C = !1;
|
|
4527
4593
|
}
|
|
4528
4594
|
}
|
|
4529
|
-
},
|
|
4595
|
+
}, ur = (s, e) => {
|
|
4530
4596
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4531
4597
|
if (!f)
|
|
4532
4598
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4533
|
-
if (
|
|
4599
|
+
if (v)
|
|
4534
4600
|
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
4535
|
-
f.sendCustomEvent(
|
|
4601
|
+
f.sendCustomEvent(s, e);
|
|
4536
4602
|
}
|
|
4537
|
-
},
|
|
4603
|
+
}, dr = (s, e) => {
|
|
4538
4604
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4539
|
-
if (!f ||
|
|
4540
|
-
|
|
4605
|
+
if (!f || C) {
|
|
4606
|
+
R.push({ event: s, callback: e });
|
|
4541
4607
|
return;
|
|
4542
4608
|
}
|
|
4543
|
-
f.on(
|
|
4609
|
+
f.on(s, e);
|
|
4544
4610
|
}
|
|
4545
|
-
},
|
|
4611
|
+
}, hr = (s, e) => {
|
|
4546
4612
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4547
4613
|
if (!f) {
|
|
4548
|
-
const t =
|
|
4549
|
-
t !== -1 &&
|
|
4614
|
+
const t = R.findIndex((r) => r.event === s && r.callback === e);
|
|
4615
|
+
t !== -1 && R.splice(t, 1);
|
|
4550
4616
|
return;
|
|
4551
4617
|
}
|
|
4552
|
-
f.off(
|
|
4618
|
+
f.off(s, e);
|
|
4553
4619
|
}
|
|
4554
4620
|
};
|
|
4555
|
-
function
|
|
4621
|
+
function fr(s, e) {
|
|
4556
4622
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4557
4623
|
if (typeof e != "function")
|
|
4558
4624
|
throw new Error(`[TraceLog] Transformer must be a function, received: ${typeof e}`);
|
|
4559
|
-
if (!f ||
|
|
4560
|
-
const t =
|
|
4561
|
-
t !== -1 &&
|
|
4625
|
+
if (!f || C) {
|
|
4626
|
+
const t = M.findIndex((r) => r.hook === s);
|
|
4627
|
+
t !== -1 && M.splice(t, 1), M.push({ hook: s, fn: e });
|
|
4562
4628
|
return;
|
|
4563
4629
|
}
|
|
4564
|
-
if (
|
|
4630
|
+
if (v)
|
|
4565
4631
|
throw new Error("[TraceLog] Cannot set transformers while TraceLog is being destroyed");
|
|
4566
|
-
|
|
4632
|
+
s === "beforeSend" ? f.setTransformer("beforeSend", e) : f.setTransformer("beforeBatch", e);
|
|
4567
4633
|
}
|
|
4568
4634
|
}
|
|
4569
|
-
const
|
|
4635
|
+
const mr = (s) => {
|
|
4570
4636
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4571
4637
|
if (!f) {
|
|
4572
|
-
const e =
|
|
4573
|
-
e !== -1 &&
|
|
4638
|
+
const e = M.findIndex((t) => t.hook === s);
|
|
4639
|
+
e !== -1 && M.splice(e, 1);
|
|
4574
4640
|
return;
|
|
4575
4641
|
}
|
|
4576
|
-
if (
|
|
4642
|
+
if (v)
|
|
4577
4643
|
throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
|
|
4578
|
-
f.removeTransformer(
|
|
4644
|
+
f.removeTransformer(s);
|
|
4579
4645
|
}
|
|
4580
|
-
},
|
|
4646
|
+
}, gr = () => typeof window > "u" || typeof document > "u" ? !1 : f !== null, Er = () => {
|
|
4581
4647
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4582
|
-
if (
|
|
4648
|
+
if (v)
|
|
4583
4649
|
throw new Error("[TraceLog] Destroy operation already in progress");
|
|
4584
4650
|
if (!f) {
|
|
4585
|
-
|
|
4651
|
+
v = !1;
|
|
4586
4652
|
return;
|
|
4587
4653
|
}
|
|
4588
|
-
|
|
4654
|
+
v = !0;
|
|
4589
4655
|
try {
|
|
4590
|
-
f.destroy(), f = null,
|
|
4591
|
-
} catch (
|
|
4592
|
-
f = null,
|
|
4656
|
+
f.destroy(), f = null, C = !1, R.length = 0, M.length = 0, v = !1;
|
|
4657
|
+
} catch (s) {
|
|
4658
|
+
f = null, C = !1, R.length = 0, M.length = 0, v = !1, a("warn", "Error during destroy, forced cleanup completed", { error: s });
|
|
4593
4659
|
}
|
|
4594
4660
|
}
|
|
4595
|
-
},
|
|
4596
|
-
typeof window > "u" || typeof document > "u" ||
|
|
4597
|
-
},
|
|
4661
|
+
}, Sr = (s) => {
|
|
4662
|
+
typeof window > "u" || typeof document > "u" || Dt(s);
|
|
4663
|
+
}, pr = (s) => {
|
|
4598
4664
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4599
4665
|
if (!f)
|
|
4600
4666
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4601
|
-
if (
|
|
4667
|
+
if (v)
|
|
4602
4668
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
4603
|
-
f.updateGlobalMetadata(
|
|
4669
|
+
f.updateGlobalMetadata(s);
|
|
4604
4670
|
}
|
|
4605
|
-
},
|
|
4671
|
+
}, Tr = (s) => {
|
|
4606
4672
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4607
4673
|
if (!f)
|
|
4608
4674
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4609
|
-
if (
|
|
4675
|
+
if (v)
|
|
4610
4676
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
4611
|
-
f.mergeGlobalMetadata(
|
|
4612
|
-
}
|
|
4613
|
-
},
|
|
4614
|
-
init:
|
|
4615
|
-
event:
|
|
4616
|
-
on:
|
|
4617
|
-
off:
|
|
4618
|
-
setTransformer:
|
|
4619
|
-
removeTransformer:
|
|
4620
|
-
isInitialized:
|
|
4621
|
-
destroy:
|
|
4622
|
-
setQaMode:
|
|
4623
|
-
updateGlobalMetadata:
|
|
4624
|
-
mergeGlobalMetadata:
|
|
4677
|
+
f.mergeGlobalMetadata(s);
|
|
4678
|
+
}
|
|
4679
|
+
}, Qr = {
|
|
4680
|
+
init: cr,
|
|
4681
|
+
event: ur,
|
|
4682
|
+
on: dr,
|
|
4683
|
+
off: hr,
|
|
4684
|
+
setTransformer: fr,
|
|
4685
|
+
removeTransformer: mr,
|
|
4686
|
+
isInitialized: gr,
|
|
4687
|
+
destroy: Er,
|
|
4688
|
+
setQaMode: Sr,
|
|
4689
|
+
updateGlobalMetadata: pr,
|
|
4690
|
+
mergeGlobalMetadata: Tr
|
|
4625
4691
|
};
|
|
4626
|
-
var
|
|
4692
|
+
var ue, Ye = -1, P = function(s) {
|
|
4627
4693
|
addEventListener("pageshow", (function(e) {
|
|
4628
|
-
e.persisted && (
|
|
4694
|
+
e.persisted && (Ye = e.timeStamp, s(e));
|
|
4629
4695
|
}), !0);
|
|
4630
|
-
},
|
|
4631
|
-
var
|
|
4632
|
-
if (
|
|
4633
|
-
},
|
|
4634
|
-
var
|
|
4635
|
-
return
|
|
4636
|
-
},
|
|
4637
|
-
var t =
|
|
4638
|
-
return
|
|
4639
|
-
},
|
|
4696
|
+
}, Ee = function() {
|
|
4697
|
+
var s = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
|
|
4698
|
+
if (s && s.responseStart > 0 && s.responseStart < performance.now()) return s;
|
|
4699
|
+
}, q = function() {
|
|
4700
|
+
var s = Ee();
|
|
4701
|
+
return s && s.activationStart || 0;
|
|
4702
|
+
}, b = function(s, e) {
|
|
4703
|
+
var t = Ee(), r = "navigate";
|
|
4704
|
+
return Ye >= 0 ? r = "back-forward-cache" : t && (document.prerendering || q() > 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 };
|
|
4705
|
+
}, F = function(s, e, t) {
|
|
4640
4706
|
try {
|
|
4641
|
-
if (PerformanceObserver.supportedEntryTypes.includes(
|
|
4642
|
-
var r = new PerformanceObserver((function(
|
|
4707
|
+
if (PerformanceObserver.supportedEntryTypes.includes(s)) {
|
|
4708
|
+
var r = new PerformanceObserver((function(n) {
|
|
4643
4709
|
Promise.resolve().then((function() {
|
|
4644
|
-
e(
|
|
4710
|
+
e(n.getEntries());
|
|
4645
4711
|
}));
|
|
4646
4712
|
}));
|
|
4647
|
-
return r.observe(Object.assign({ type:
|
|
4713
|
+
return r.observe(Object.assign({ type: s, buffered: !0 }, t || {})), r;
|
|
4648
4714
|
}
|
|
4649
4715
|
} catch {
|
|
4650
4716
|
}
|
|
4651
|
-
}, A = function(
|
|
4652
|
-
var
|
|
4717
|
+
}, A = function(s, e, t, r) {
|
|
4718
|
+
var n, i;
|
|
4653
4719
|
return function(o) {
|
|
4654
|
-
e.value >= 0 && (o || r) && ((i = e.value - (
|
|
4720
|
+
e.value >= 0 && (o || r) && ((i = e.value - (n || 0)) || n === void 0) && (n = e.value, e.delta = i, e.rating = (function(l, c) {
|
|
4655
4721
|
return l > c[1] ? "poor" : l > c[0] ? "needs-improvement" : "good";
|
|
4656
|
-
})(e.value, t),
|
|
4722
|
+
})(e.value, t), s(e));
|
|
4657
4723
|
};
|
|
4658
|
-
},
|
|
4724
|
+
}, Se = function(s) {
|
|
4659
4725
|
requestAnimationFrame((function() {
|
|
4660
4726
|
return requestAnimationFrame((function() {
|
|
4661
|
-
return
|
|
4727
|
+
return s();
|
|
4662
4728
|
}));
|
|
4663
4729
|
}));
|
|
4664
|
-
},
|
|
4730
|
+
}, J = function(s) {
|
|
4665
4731
|
document.addEventListener("visibilitychange", (function() {
|
|
4666
|
-
document.visibilityState === "hidden" &&
|
|
4732
|
+
document.visibilityState === "hidden" && s();
|
|
4667
4733
|
}));
|
|
4668
|
-
},
|
|
4734
|
+
}, pe = function(s) {
|
|
4669
4735
|
var e = !1;
|
|
4670
4736
|
return function() {
|
|
4671
|
-
e || (
|
|
4737
|
+
e || (s(), e = !0);
|
|
4672
4738
|
};
|
|
4673
|
-
},
|
|
4739
|
+
}, O = -1, ke = function() {
|
|
4674
4740
|
return document.visibilityState !== "hidden" || document.prerendering ? 1 / 0 : 0;
|
|
4675
|
-
},
|
|
4676
|
-
document.visibilityState === "hidden" &&
|
|
4741
|
+
}, Y = function(s) {
|
|
4742
|
+
document.visibilityState === "hidden" && O > -1 && (O = s.type === "visibilitychange" ? s.timeStamp : 0, _r());
|
|
4677
4743
|
}, Ue = function() {
|
|
4678
|
-
addEventListener("visibilitychange",
|
|
4679
|
-
},
|
|
4680
|
-
removeEventListener("visibilitychange",
|
|
4681
|
-
},
|
|
4682
|
-
return
|
|
4744
|
+
addEventListener("visibilitychange", Y, !0), addEventListener("prerenderingchange", Y, !0);
|
|
4745
|
+
}, _r = function() {
|
|
4746
|
+
removeEventListener("visibilitychange", Y, !0), removeEventListener("prerenderingchange", Y, !0);
|
|
4747
|
+
}, qe = function() {
|
|
4748
|
+
return O < 0 && (O = ke(), Ue(), P((function() {
|
|
4683
4749
|
setTimeout((function() {
|
|
4684
|
-
|
|
4750
|
+
O = ke(), Ue();
|
|
4685
4751
|
}), 0);
|
|
4686
4752
|
}))), { get firstHiddenTime() {
|
|
4687
|
-
return
|
|
4753
|
+
return O;
|
|
4688
4754
|
} };
|
|
4689
|
-
},
|
|
4755
|
+
}, Z = function(s) {
|
|
4690
4756
|
document.prerendering ? addEventListener("prerenderingchange", (function() {
|
|
4691
|
-
return
|
|
4692
|
-
}), !0) :
|
|
4693
|
-
},
|
|
4694
|
-
e = e || {},
|
|
4695
|
-
var t, r =
|
|
4757
|
+
return s();
|
|
4758
|
+
}), !0) : s();
|
|
4759
|
+
}, de = [1800, 3e3], Je = function(s, e) {
|
|
4760
|
+
e = e || {}, Z((function() {
|
|
4761
|
+
var t, r = qe(), n = b("FCP"), i = F("paint", (function(o) {
|
|
4696
4762
|
o.forEach((function(l) {
|
|
4697
|
-
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime < r.firstHiddenTime && (
|
|
4763
|
+
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime < r.firstHiddenTime && (n.value = Math.max(l.startTime - q(), 0), n.entries.push(l), t(!0)));
|
|
4698
4764
|
}));
|
|
4699
4765
|
}));
|
|
4700
|
-
i && (t = A(
|
|
4701
|
-
|
|
4702
|
-
|
|
4766
|
+
i && (t = A(s, n, de, e.reportAllChanges), P((function(o) {
|
|
4767
|
+
n = b("FCP"), t = A(s, n, de, e.reportAllChanges), Se((function() {
|
|
4768
|
+
n.value = performance.now() - o.timeStamp, t(!0);
|
|
4703
4769
|
}));
|
|
4704
4770
|
})));
|
|
4705
4771
|
}));
|
|
4706
|
-
},
|
|
4707
|
-
e = e || {},
|
|
4708
|
-
var t, r =
|
|
4709
|
-
c.forEach((function(
|
|
4710
|
-
if (!
|
|
4711
|
-
var
|
|
4712
|
-
|
|
4772
|
+
}, he = [0.1, 0.25], vr = function(s, e) {
|
|
4773
|
+
e = e || {}, Je(pe((function() {
|
|
4774
|
+
var t, r = b("CLS", 0), n = 0, i = [], o = function(c) {
|
|
4775
|
+
c.forEach((function(u) {
|
|
4776
|
+
if (!u.hadRecentInput) {
|
|
4777
|
+
var S = i[0], g = i[i.length - 1];
|
|
4778
|
+
n && u.startTime - g.startTime < 1e3 && u.startTime - S.startTime < 5e3 ? (n += u.value, i.push(u)) : (n = u.value, i = [u]);
|
|
4713
4779
|
}
|
|
4714
|
-
})),
|
|
4715
|
-
}, l =
|
|
4716
|
-
l && (t = A(
|
|
4780
|
+
})), n > r.value && (r.value = n, r.entries = i, t());
|
|
4781
|
+
}, l = F("layout-shift", o);
|
|
4782
|
+
l && (t = A(s, r, he, e.reportAllChanges), J((function() {
|
|
4717
4783
|
o(l.takeRecords()), t(!0);
|
|
4718
|
-
})),
|
|
4719
|
-
|
|
4784
|
+
})), P((function() {
|
|
4785
|
+
n = 0, r = b("CLS", 0), t = A(s, r, he, e.reportAllChanges), Se((function() {
|
|
4720
4786
|
return t();
|
|
4721
4787
|
}));
|
|
4722
4788
|
})), setTimeout(t, 0));
|
|
4723
4789
|
})));
|
|
4724
|
-
},
|
|
4725
|
-
|
|
4726
|
-
e.interactionId && (
|
|
4790
|
+
}, Ze = 0, re = 1 / 0, G = 0, Ir = function(s) {
|
|
4791
|
+
s.forEach((function(e) {
|
|
4792
|
+
e.interactionId && (re = Math.min(re, e.interactionId), G = Math.max(G, e.interactionId), Ze = G ? (G - re) / 7 + 1 : 0);
|
|
4727
4793
|
}));
|
|
4728
|
-
},
|
|
4729
|
-
return
|
|
4730
|
-
},
|
|
4731
|
-
"interactionCount" in performance ||
|
|
4732
|
-
},
|
|
4733
|
-
var
|
|
4734
|
-
return
|
|
4735
|
-
},
|
|
4736
|
-
if (
|
|
4737
|
-
return s
|
|
4738
|
-
})),
|
|
4739
|
-
var e =
|
|
4740
|
-
if (t ||
|
|
4741
|
-
if (t)
|
|
4794
|
+
}, et = function() {
|
|
4795
|
+
return ue ? Ze : performance.interactionCount || 0;
|
|
4796
|
+
}, wr = function() {
|
|
4797
|
+
"interactionCount" in performance || ue || (ue = F("event", Ir, { type: "event", buffered: !0, durationThreshold: 0 }));
|
|
4798
|
+
}, y = [], z = /* @__PURE__ */ new Map(), tt = 0, yr = function() {
|
|
4799
|
+
var s = Math.min(y.length - 1, Math.floor((et() - tt) / 50));
|
|
4800
|
+
return y[s];
|
|
4801
|
+
}, br = [], Ar = function(s) {
|
|
4802
|
+
if (br.forEach((function(n) {
|
|
4803
|
+
return n(s);
|
|
4804
|
+
})), s.interactionId || s.entryType === "first-input") {
|
|
4805
|
+
var e = y[y.length - 1], t = z.get(s.interactionId);
|
|
4806
|
+
if (t || y.length < 10 || s.duration > e.latency) {
|
|
4807
|
+
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);
|
|
4742
4808
|
else {
|
|
4743
|
-
var r = { id:
|
|
4744
|
-
z.set(r.id, r),
|
|
4809
|
+
var r = { id: s.interactionId, latency: s.duration, entries: [s] };
|
|
4810
|
+
z.set(r.id, r), y.push(r);
|
|
4745
4811
|
}
|
|
4746
|
-
|
|
4747
|
-
return i.latency -
|
|
4748
|
-
})),
|
|
4749
|
-
return z.delete(
|
|
4812
|
+
y.sort((function(n, i) {
|
|
4813
|
+
return i.latency - n.latency;
|
|
4814
|
+
})), y.length > 10 && y.splice(10).forEach((function(n) {
|
|
4815
|
+
return z.delete(n.id);
|
|
4750
4816
|
}));
|
|
4751
4817
|
}
|
|
4752
4818
|
}
|
|
4753
|
-
},
|
|
4819
|
+
}, rt = function(s) {
|
|
4754
4820
|
var e = self.requestIdleCallback || self.setTimeout, t = -1;
|
|
4755
|
-
return
|
|
4756
|
-
},
|
|
4757
|
-
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {},
|
|
4821
|
+
return s = pe(s), document.visibilityState === "hidden" ? s() : (t = e(s), J(s)), t;
|
|
4822
|
+
}, fe = [200, 500], Lr = function(s, e) {
|
|
4823
|
+
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, Z((function() {
|
|
4758
4824
|
var t;
|
|
4759
|
-
|
|
4760
|
-
var r,
|
|
4761
|
-
|
|
4762
|
-
l.forEach(
|
|
4763
|
-
var c =
|
|
4764
|
-
c && c.latency !==
|
|
4825
|
+
wr();
|
|
4826
|
+
var r, n = b("INP"), i = function(l) {
|
|
4827
|
+
rt((function() {
|
|
4828
|
+
l.forEach(Ar);
|
|
4829
|
+
var c = yr();
|
|
4830
|
+
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, r());
|
|
4765
4831
|
}));
|
|
4766
|
-
}, o =
|
|
4767
|
-
r = A(
|
|
4832
|
+
}, o = F("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
|
|
4833
|
+
r = A(s, n, fe, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), J((function() {
|
|
4768
4834
|
i(o.takeRecords()), r(!0);
|
|
4769
|
-
})),
|
|
4770
|
-
|
|
4835
|
+
})), P((function() {
|
|
4836
|
+
tt = et(), y.length = 0, z.clear(), n = b("INP"), r = A(s, n, fe, e.reportAllChanges);
|
|
4771
4837
|
})));
|
|
4772
4838
|
})));
|
|
4773
|
-
},
|
|
4774
|
-
e = e || {},
|
|
4775
|
-
var t, r =
|
|
4776
|
-
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(
|
|
4777
|
-
|
|
4839
|
+
}, me = [2500, 4e3], se = {}, Mr = function(s, e) {
|
|
4840
|
+
e = e || {}, Z((function() {
|
|
4841
|
+
var t, r = qe(), n = b("LCP"), i = function(c) {
|
|
4842
|
+
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(u) {
|
|
4843
|
+
u.startTime < r.firstHiddenTime && (n.value = Math.max(u.startTime - q(), 0), n.entries = [u], t());
|
|
4778
4844
|
}));
|
|
4779
|
-
}, o =
|
|
4845
|
+
}, o = F("largest-contentful-paint", i);
|
|
4780
4846
|
if (o) {
|
|
4781
|
-
t = A(
|
|
4782
|
-
var l =
|
|
4783
|
-
|
|
4847
|
+
t = A(s, n, me, e.reportAllChanges);
|
|
4848
|
+
var l = pe((function() {
|
|
4849
|
+
se[n.id] || (i(o.takeRecords()), o.disconnect(), se[n.id] = !0, t(!0));
|
|
4784
4850
|
}));
|
|
4785
4851
|
["keydown", "click"].forEach((function(c) {
|
|
4786
4852
|
addEventListener(c, (function() {
|
|
4787
|
-
return
|
|
4853
|
+
return rt(l);
|
|
4788
4854
|
}), { once: !0, capture: !0 });
|
|
4789
|
-
})),
|
|
4790
|
-
|
|
4791
|
-
|
|
4855
|
+
})), J(l), P((function(c) {
|
|
4856
|
+
n = b("LCP"), t = A(s, n, me, e.reportAllChanges), Se((function() {
|
|
4857
|
+
n.value = performance.now() - c.timeStamp, se[n.id] = !0, t(!0);
|
|
4792
4858
|
}));
|
|
4793
4859
|
}));
|
|
4794
4860
|
}
|
|
4795
4861
|
}));
|
|
4796
|
-
},
|
|
4797
|
-
document.prerendering ?
|
|
4798
|
-
return
|
|
4862
|
+
}, ge = [800, 1800], Cr = function s(e) {
|
|
4863
|
+
document.prerendering ? Z((function() {
|
|
4864
|
+
return s(e);
|
|
4799
4865
|
})) : document.readyState !== "complete" ? addEventListener("load", (function() {
|
|
4800
|
-
return
|
|
4866
|
+
return s(e);
|
|
4801
4867
|
}), !0) : setTimeout(e, 0);
|
|
4802
|
-
},
|
|
4868
|
+
}, Rr = function(s, e) {
|
|
4803
4869
|
e = e || {};
|
|
4804
|
-
var t =
|
|
4805
|
-
|
|
4806
|
-
var
|
|
4807
|
-
|
|
4808
|
-
t =
|
|
4870
|
+
var t = b("TTFB"), r = A(s, t, ge, e.reportAllChanges);
|
|
4871
|
+
Cr((function() {
|
|
4872
|
+
var n = Ee();
|
|
4873
|
+
n && (t.value = Math.max(n.responseStart - q(), 0), t.entries = [n], r(!0), P((function() {
|
|
4874
|
+
t = b("TTFB", 0), (r = A(s, t, ge, e.reportAllChanges))(!0);
|
|
4809
4875
|
})));
|
|
4810
4876
|
}));
|
|
4811
4877
|
};
|
|
4812
|
-
const
|
|
4878
|
+
const Nr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4813
4879
|
__proto__: null,
|
|
4814
|
-
CLSThresholds:
|
|
4815
|
-
FCPThresholds:
|
|
4816
|
-
INPThresholds:
|
|
4817
|
-
LCPThresholds:
|
|
4818
|
-
TTFBThresholds:
|
|
4819
|
-
onCLS:
|
|
4820
|
-
onFCP:
|
|
4821
|
-
onINP:
|
|
4822
|
-
onLCP:
|
|
4823
|
-
onTTFB:
|
|
4880
|
+
CLSThresholds: he,
|
|
4881
|
+
FCPThresholds: de,
|
|
4882
|
+
INPThresholds: fe,
|
|
4883
|
+
LCPThresholds: me,
|
|
4884
|
+
TTFBThresholds: ge,
|
|
4885
|
+
onCLS: vr,
|
|
4886
|
+
onFCP: Je,
|
|
4887
|
+
onINP: Lr,
|
|
4888
|
+
onLCP: Mr,
|
|
4889
|
+
onTTFB: Rr
|
|
4824
4890
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
4825
4891
|
export {
|
|
4826
4892
|
h as AppConfigValidationError,
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4893
|
+
Or as DEFAULT_SESSION_TIMEOUT,
|
|
4894
|
+
ae as DEFAULT_WEB_VITALS_MODE,
|
|
4895
|
+
L as DeviceType,
|
|
4830
4896
|
ne as EmitterEvent,
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4897
|
+
U as ErrorType,
|
|
4898
|
+
d as EventType,
|
|
4899
|
+
Gr as InitializationTimeoutError,
|
|
4900
|
+
V as IntegrationValidationError,
|
|
4901
|
+
$r as MAX_ARRAY_LENGTH,
|
|
4902
|
+
kr as MAX_CUSTOM_EVENT_ARRAY_SIZE,
|
|
4903
|
+
Vr as MAX_CUSTOM_EVENT_KEYS,
|
|
4904
|
+
Pr as MAX_CUSTOM_EVENT_NAME_LENGTH,
|
|
4905
|
+
Dr as MAX_CUSTOM_EVENT_STRING_SIZE,
|
|
4906
|
+
xr as MAX_METADATA_NESTING_DEPTH,
|
|
4907
|
+
Ur as MAX_NESTED_OBJECT_KEYS,
|
|
4908
|
+
Hr as MAX_STRING_LENGTH,
|
|
4909
|
+
Fr as MAX_STRING_LENGTH_IN_ARRAY,
|
|
4844
4910
|
j as Mode,
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4911
|
+
Be as PII_PATTERNS,
|
|
4912
|
+
N as PermanentError,
|
|
4913
|
+
Ae as SamplingRateValidationError,
|
|
4848
4914
|
X as ScrollDirection,
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4915
|
+
dt as SessionTimeoutValidationError,
|
|
4916
|
+
k as SpecialApiUrl,
|
|
4917
|
+
H as TraceLogValidationError,
|
|
4918
|
+
Xr as WEB_VITALS_GOOD_THRESHOLDS,
|
|
4853
4919
|
Re as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
|
|
4854
|
-
|
|
4920
|
+
Lt as WEB_VITALS_POOR_THRESHOLDS,
|
|
4855
4921
|
Ne as getWebVitalsThresholds,
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4922
|
+
Br as isPrimaryScrollEvent,
|
|
4923
|
+
Wr as isSecondaryScrollEvent,
|
|
4924
|
+
Qr as tracelog
|
|
4859
4925
|
};
|