@tracelog/lib 2.0.2 → 2.0.3-rc.73.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @tracelog/lib might be problematic. Click here for more details.
- package/README.md +70 -25
- package/dist/browser/tracelog.esm.js +915 -874
- 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 +253 -177
- package/dist/public-api.cjs.map +1 -1
- package/dist/public-api.d.mts +83 -86
- package/dist/public-api.d.ts +83 -86
- package/dist/public-api.js +253 -177
- 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 Nr = 9e5;
|
|
2
|
+
const Or = 120, Pr = 8192, Dr = 10, Vr = 10, kr = 20, Ur = 1;
|
|
3
|
+
const xr = 1e3, Hr = 500, Fr = 100;
|
|
4
|
+
const v = "data-tlog", st = [
|
|
5
5
|
"button",
|
|
6
6
|
"a",
|
|
7
7
|
'input[type="button"]',
|
|
@@ -33,7 +33,7 @@ const I = "data-tlog", rt = [
|
|
|
33
33
|
".menu-item",
|
|
34
34
|
"[data-testid]",
|
|
35
35
|
'[tabindex="0"]'
|
|
36
|
-
], nt = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"],
|
|
36
|
+
], nt = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"], it = [
|
|
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
|
+
}, ot = [
|
|
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
|
-
],
|
|
82
|
-
var
|
|
81
|
+
], I = "tlog", U = `${I}:qa_mode`, Te = `${I}:uid`, xe = "tlog_mode", _e = "qa", Ie = "qa_off", at = (s) => s ? `${I}:${s}:queue` : `${I}:queue`, lt = (s) => s ? `${I}:${s}:session` : `${I}:session`, ct = (s) => s ? `${I}:${s}:broadcast` : `${I}:broadcast`, ve = (s, e) => `${I}:${s}:session_counts:${e}`, we = 10080 * 60 * 1e3, ye = `${I}:session_counts_last_cleanup`, be = 3600 * 1e3;
|
|
82
|
+
var V = /* @__PURE__ */ ((s) => (s.Localhost = "localhost:8080", s.Fail = "localhost:9999", s))(V || {}), A = /* @__PURE__ */ ((s) => (s.Mobile = "mobile", s.Tablet = "tablet", s.Desktop = "desktop", s.Unknown = "unknown", s))(A || {}), ne = /* @__PURE__ */ ((s) => (s.EVENT = "event", s.QUEUE = "queue", s))(ne || {});
|
|
83
83
|
class R extends Error {
|
|
84
84
|
constructor(e, t) {
|
|
85
85
|
super(e), this.statusCode = t, this.name = "PermanentError", Error.captureStackTrace && Error.captureStackTrace(this, R);
|
|
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 || {}), k = /* @__PURE__ */ ((s) => (s.JS_ERROR = "js_error", s.PROMISE_REJECTION = "promise_rejection", s))(k || {}), j = /* @__PURE__ */ ((s) => (s.QA = "qa", s))(j || {});
|
|
89
|
+
const $r = (s) => s.type === d.SCROLL && "scroll_data" in s && s.scroll_data.is_primary === !0, Br = (s) => s.type === d.SCROLL && "scroll_data" in s && s.scroll_data.is_primary === !1;
|
|
90
|
+
class x 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 x {
|
|
96
96
|
constructor(e, t = "config") {
|
|
97
97
|
super(e, "APP_CONFIG_INVALID", t);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
class
|
|
100
|
+
class ut extends x {
|
|
101
101
|
constructor(e, t = "config") {
|
|
102
102
|
super(e, "SESSION_TIMEOUT_INVALID", t);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
class Ae extends
|
|
105
|
+
class Ae extends x {
|
|
106
106
|
constructor(e, t = "config") {
|
|
107
107
|
super(e, "SAMPLING_RATE_INVALID", t);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
class
|
|
110
|
+
class D extends x {
|
|
111
111
|
constructor(e, t = "config") {
|
|
112
112
|
super(e, "INTEGRATION_INVALID", t);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
class
|
|
115
|
+
class Wr extends x {
|
|
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;", dt = "background: #d32f2f; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", ht = (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
|
+
}, ft = () => {
|
|
140
|
+
if (typeof window > "u" || typeof sessionStorage > "u")
|
|
141
|
+
return !1;
|
|
142
|
+
try {
|
|
143
|
+
return sessionStorage.getItem(U) === "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 ? ht(e, r) : `[TraceLog] ${e}`, u = s === "error" ? "error" : s === "warn" ? "warn" : "log";
|
|
149
|
+
if (!mt(l, i))
|
|
142
150
|
return;
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}, se = (n) => {
|
|
151
|
+
const E = gt(l, o), g = n !== void 0 ? ie(n) : void 0;
|
|
152
|
+
Et(u, c, E, g);
|
|
153
|
+
}, mt = (s, e) => s === "critical" ? !0 : s === "qa" || e ? ft() : !1, gt = (s, e) => e !== void 0 && e !== "" ? e : s === "critical" ? dt : "", Et = (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 St = () => {
|
|
172
|
+
typeof window < "u" && !oe && (oe = window.matchMedia("(pointer: coarse)"), $e = window.matchMedia("(hover: none)"));
|
|
173
|
+
}, K = "Unknown", pt = (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
|
+
}, Tt = (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
|
+
}, _t = () => {
|
|
167
197
|
try {
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return
|
|
176
|
-
}
|
|
177
|
-
|
|
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) ? A.Tablet : s.userAgentData.mobile ? A.Mobile : A.Desktop;
|
|
202
|
+
}
|
|
203
|
+
St();
|
|
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 ? A.Mobile : e >= 768 && e <= 1024 || l || t && r && n ? A.Tablet : A.Desktop;
|
|
206
|
+
} catch (s) {
|
|
207
|
+
return a("debug", "Device detection failed, defaulting to desktop", { error: s }), A.Desktop;
|
|
208
|
+
}
|
|
209
|
+
}, It = () => {
|
|
210
|
+
try {
|
|
211
|
+
const s = navigator;
|
|
212
|
+
return {
|
|
213
|
+
type: _t(),
|
|
214
|
+
os: pt(s),
|
|
215
|
+
browser: Tt(s)
|
|
216
|
+
};
|
|
217
|
+
} catch (s) {
|
|
218
|
+
return a("debug", "Device info detection failed, using defaults", { error: s }), {
|
|
219
|
+
type: A.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 dt = () => {
|
|
|
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
|
-
], Le = 500,
|
|
239
|
+
], Le = 500, Me = 5e3, Q = 50, vt = Q * 2, We = 1, wt = 1e3, yt = 10, Ce = 5e3, bt = 6e4, Gr = {
|
|
193
240
|
LCP: 2500,
|
|
194
241
|
// Good: ≤ 2.5s
|
|
195
242
|
FCP: 1800,
|
|
@@ -201,7 +248,7 @@ const dt = () => {
|
|
|
201
248
|
TTFB: 800,
|
|
202
249
|
// Good: ≤ 800ms
|
|
203
250
|
LONG_TASK: 50
|
|
204
|
-
},
|
|
251
|
+
}, Re = {
|
|
205
252
|
LCP: 2500,
|
|
206
253
|
// Needs improvement: > 2.5s (same as good boundary)
|
|
207
254
|
FCP: 1800,
|
|
@@ -213,7 +260,7 @@ const dt = () => {
|
|
|
213
260
|
TTFB: 800,
|
|
214
261
|
// Needs improvement: > 800ms
|
|
215
262
|
LONG_TASK: 50
|
|
216
|
-
},
|
|
263
|
+
}, At = {
|
|
217
264
|
LCP: 4e3,
|
|
218
265
|
// Poor: > 4s
|
|
219
266
|
FCP: 3e3,
|
|
@@ -225,89 +272,87 @@ const dt = () => {
|
|
|
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
|
-
return
|
|
281
|
+
return Re;
|
|
235
282
|
case "poor":
|
|
236
|
-
return
|
|
283
|
+
return At;
|
|
237
284
|
default:
|
|
238
|
-
return
|
|
285
|
+
return Re;
|
|
239
286
|
}
|
|
240
|
-
},
|
|
241
|
-
|
|
287
|
+
}, Lt = 1e3, Mt = 50, Ct = "2.0.3", Rt = Ct, Ge = () => typeof window < "u" && typeof sessionStorage < "u", Nt = () => {
|
|
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
|
+
}, Ot = () => {
|
|
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(U);
|
|
245
300
|
let r = null;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
style:
|
|
249
|
-
})) : e ===
|
|
250
|
-
|
|
301
|
+
return e === _e ? (r = !0, sessionStorage.setItem(U, "true"), a("info", "QA Mode ACTIVE", {
|
|
302
|
+
visibility: "qa",
|
|
303
|
+
style: He
|
|
304
|
+
})) : e === Ie && (r = !1, sessionStorage.setItem(U, "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 === Ie) && Nt(), r ?? t === "true";
|
|
260
308
|
} catch {
|
|
261
309
|
return !1;
|
|
262
310
|
}
|
|
263
|
-
},
|
|
264
|
-
if (
|
|
311
|
+
}, Pt = (s) => {
|
|
312
|
+
if (Ge())
|
|
265
313
|
try {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
style:
|
|
269
|
-
})
|
|
270
|
-
showToClient: !0,
|
|
271
|
-
style: Fe
|
|
272
|
-
}));
|
|
314
|
+
sessionStorage.setItem(U, 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
|
-
},
|
|
277
|
-
const
|
|
321
|
+
}, Oe = () => {
|
|
322
|
+
const s = new URLSearchParams(window.location.search), e = {};
|
|
278
323
|
return nt.forEach((r) => {
|
|
279
|
-
const
|
|
280
|
-
if (
|
|
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
|
+
}, Dt = () => 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 Vt = () => {
|
|
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
|
+
}, kt = (s) => {
|
|
311
356
|
try {
|
|
312
357
|
const t = new URL(window.location.href).hostname;
|
|
313
358
|
if (!t || typeof t != "string")
|
|
@@ -321,166 +366,145 @@ const bt = () => {
|
|
|
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
|
+
}, Ut = (s) => {
|
|
335
380
|
const e = {};
|
|
336
|
-
|
|
337
|
-
const t =
|
|
381
|
+
s.integrations?.tracelog?.projectId && (e.saas = kt(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([...it, ...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
|
-
},
|
|
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 ot) {
|
|
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
|
|
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
|
|
389
|
-
const l =
|
|
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) {
|
|
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
|
+
}, xt = (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
|
+
}, Ht = (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 ut(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 && $t(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 (
|
|
467
|
+
if (s.errorSampling !== void 0 && (typeof s.errorSampling != "number" || s.errorSampling < 0 || s.errorSampling > 1))
|
|
424
468
|
throw new Ae(m.INVALID_ERROR_SAMPLING_RATE, "config");
|
|
425
|
-
if (
|
|
469
|
+
if (s.samplingRate !== void 0 && (typeof s.samplingRate != "number" || s.samplingRate < 0 || s.samplingRate > 1))
|
|
426
470
|
throw new Ae(m.INVALID_SAMPLING_RATE, "config");
|
|
427
|
-
if (
|
|
428
|
-
if (typeof
|
|
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 (
|
|
448
|
-
throw new h("disabledEvents must be an array", "config");
|
|
449
|
-
const e = /* @__PURE__ */ new Set();
|
|
450
|
-
for (const t of n.disabledEvents) {
|
|
451
|
-
if (typeof t != "string")
|
|
452
|
-
throw new h("All disabled event types must be strings", "config");
|
|
453
|
-
if (!Me.includes(t))
|
|
454
|
-
throw new h(
|
|
455
|
-
`Invalid disabled event type: "${t}". Must be one of: ${Me.join(", ")}`,
|
|
456
|
-
"config"
|
|
457
|
-
);
|
|
458
|
-
if (e.has(t))
|
|
459
|
-
throw new h(
|
|
460
|
-
`Duplicate disabled event type found: "${t}". Each event type should appear only once.`,
|
|
461
|
-
"config"
|
|
462
|
-
);
|
|
463
|
-
e.add(t);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
if (n.webVitalsMode !== void 0) {
|
|
467
|
-
if (typeof n.webVitalsMode != "string")
|
|
490
|
+
if (s.viewport !== void 0 && Ft(s.viewport), s.webVitalsMode !== void 0) {
|
|
491
|
+
if (typeof s.webVitalsMode != "string")
|
|
468
492
|
throw new h(
|
|
469
|
-
`Invalid webVitalsMode type: ${typeof
|
|
493
|
+
`Invalid webVitalsMode type: ${typeof s.webVitalsMode}. Must be a string`,
|
|
470
494
|
"config"
|
|
471
495
|
);
|
|
472
496
|
const e = ["all", "needs-improvement", "poor"];
|
|
473
|
-
if (!e.includes(
|
|
497
|
+
if (!e.includes(s.webVitalsMode))
|
|
474
498
|
throw new h(
|
|
475
|
-
`Invalid webVitalsMode: "${
|
|
499
|
+
`Invalid webVitalsMode: "${s.webVitalsMode}". Must be one of: ${e.join(", ")}`,
|
|
476
500
|
"config"
|
|
477
501
|
);
|
|
478
502
|
}
|
|
479
|
-
if (
|
|
480
|
-
if (typeof
|
|
503
|
+
if (s.webVitalsThresholds !== void 0) {
|
|
504
|
+
if (typeof s.webVitalsThresholds != "object" || s.webVitalsThresholds === null || Array.isArray(s.webVitalsThresholds))
|
|
481
505
|
throw new h("webVitalsThresholds must be an object", "config");
|
|
482
506
|
const e = ["LCP", "FCP", "CLS", "INP", "TTFB", "LONG_TASK"];
|
|
483
|
-
for (const [t, r] of Object.entries(
|
|
507
|
+
for (const [t, r] of Object.entries(s.webVitalsThresholds)) {
|
|
484
508
|
if (!e.includes(t))
|
|
485
509
|
throw new h(
|
|
486
510
|
`Invalid Web Vitals threshold key: "${t}". Must be one of: ${e.join(", ")}`,
|
|
@@ -494,15 +518,15 @@ const bt = () => {
|
|
|
494
518
|
}
|
|
495
519
|
}
|
|
496
520
|
}
|
|
497
|
-
},
|
|
498
|
-
if (typeof
|
|
521
|
+
}, Ft = (s) => {
|
|
522
|
+
if (typeof s != "object" || s === null)
|
|
499
523
|
throw new h(m.INVALID_VIEWPORT_CONFIG, "config");
|
|
500
|
-
if (!
|
|
524
|
+
if (!s.elements || !Array.isArray(s.elements))
|
|
501
525
|
throw new h(m.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
502
|
-
if (
|
|
526
|
+
if (s.elements.length === 0)
|
|
503
527
|
throw new h(m.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
504
528
|
const e = /* @__PURE__ */ new Set();
|
|
505
|
-
for (const t of
|
|
529
|
+
for (const t of s.elements) {
|
|
506
530
|
if (!t.selector || typeof t.selector != "string" || !t.selector.trim())
|
|
507
531
|
throw new h(m.INVALID_VIEWPORT_ELEMENT, "config");
|
|
508
532
|
const r = t.selector.trim();
|
|
@@ -516,46 +540,45 @@ const bt = () => {
|
|
|
516
540
|
if (t.name !== void 0 && (typeof t.name != "string" || !t.name.trim()))
|
|
517
541
|
throw new h(m.INVALID_VIEWPORT_ELEMENT_NAME, "config");
|
|
518
542
|
}
|
|
519
|
-
if (
|
|
543
|
+
if (s.threshold !== void 0 && (typeof s.threshold != "number" || s.threshold < 0 || s.threshold > 1))
|
|
520
544
|
throw new h(m.INVALID_VIEWPORT_THRESHOLD, "config");
|
|
521
|
-
if (
|
|
545
|
+
if (s.minDwellTime !== void 0 && (typeof s.minDwellTime != "number" || s.minDwellTime < 0))
|
|
522
546
|
throw new h(m.INVALID_VIEWPORT_MIN_DWELL_TIME, "config");
|
|
523
|
-
if (
|
|
547
|
+
if (s.cooldownPeriod !== void 0 && (typeof s.cooldownPeriod != "number" || s.cooldownPeriod < 0))
|
|
524
548
|
throw new h(m.INVALID_VIEWPORT_COOLDOWN_PERIOD, "config");
|
|
525
|
-
if (
|
|
549
|
+
if (s.maxTrackedElements !== void 0 && (typeof s.maxTrackedElements != "number" || s.maxTrackedElements <= 0))
|
|
526
550
|
throw new h(m.INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS, "config");
|
|
527
|
-
},
|
|
528
|
-
if (
|
|
529
|
-
if (
|
|
530
|
-
throw new
|
|
531
|
-
if (
|
|
532
|
-
if (!
|
|
533
|
-
throw new
|
|
534
|
-
if (
|
|
535
|
-
throw new
|
|
536
|
-
const e =
|
|
551
|
+
}, $t = (s) => {
|
|
552
|
+
if (s) {
|
|
553
|
+
if (s.tracelog && (!s.tracelog.projectId || typeof s.tracelog.projectId != "string" || s.tracelog.projectId.trim() === ""))
|
|
554
|
+
throw new D(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 D(m.INVALID_CUSTOM_API_URL, "config");
|
|
558
|
+
if (s.custom.allowHttp !== void 0 && typeof s.custom.allowHttp != "boolean")
|
|
559
|
+
throw new D("allowHttp must be a boolean", "config");
|
|
560
|
+
const e = s.custom.collectApiUrl.trim();
|
|
537
561
|
if (!e.startsWith("http://") && !e.startsWith("https://"))
|
|
538
|
-
throw new
|
|
539
|
-
if (!(
|
|
540
|
-
throw new
|
|
562
|
+
throw new D('Custom API URL must start with "http://" or "https://"', "config");
|
|
563
|
+
if (!(s.custom.allowHttp ?? !1) && e.startsWith("http://"))
|
|
564
|
+
throw new D(
|
|
541
565
|
"Custom API URL must use HTTPS in production. Set allowHttp: true in integration config to allow HTTP (not recommended)",
|
|
542
566
|
"config"
|
|
543
567
|
);
|
|
544
568
|
}
|
|
545
569
|
}
|
|
546
|
-
},
|
|
547
|
-
|
|
570
|
+
}, Bt = (s) => {
|
|
571
|
+
Ht(s);
|
|
548
572
|
const e = {
|
|
549
|
-
...
|
|
550
|
-
sessionTimeout:
|
|
551
|
-
globalMetadata:
|
|
552
|
-
sensitiveQueryParams:
|
|
553
|
-
errorSampling:
|
|
554
|
-
samplingRate:
|
|
555
|
-
pageViewThrottleMs:
|
|
556
|
-
clickThrottleMs:
|
|
557
|
-
maxSameEventPerMinute:
|
|
558
|
-
disabledEvents: n?.disabledEvents ?? []
|
|
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
|
|
559
582
|
};
|
|
560
583
|
return e.integrations?.custom && (e.integrations.custom = {
|
|
561
584
|
...e.integrations.custom,
|
|
@@ -567,11 +590,11 @@ const bt = () => {
|
|
|
567
590
|
cooldownPeriod: e.viewport.cooldownPeriod ?? 6e4,
|
|
568
591
|
maxTrackedElements: e.viewport.maxTrackedElements ?? 100
|
|
569
592
|
}), e;
|
|
570
|
-
},
|
|
571
|
-
if (typeof
|
|
593
|
+
}, Wt = (s) => {
|
|
594
|
+
if (typeof s == "string")
|
|
572
595
|
return !0;
|
|
573
|
-
if (typeof
|
|
574
|
-
const e = Object.entries(
|
|
596
|
+
if (typeof s == "object" && s !== null && !Array.isArray(s)) {
|
|
597
|
+
const e = Object.entries(s);
|
|
575
598
|
if (e.length > 20)
|
|
576
599
|
return !1;
|
|
577
600
|
for (const [, t] of e) {
|
|
@@ -584,10 +607,10 @@ const bt = () => {
|
|
|
584
607
|
return !0;
|
|
585
608
|
}
|
|
586
609
|
return !1;
|
|
587
|
-
},
|
|
588
|
-
if (typeof
|
|
610
|
+
}, Qe = (s, e = 0) => {
|
|
611
|
+
if (typeof s != "object" || s === null || e > 1)
|
|
589
612
|
return !1;
|
|
590
|
-
for (const t of Object.values(
|
|
613
|
+
for (const t of Object.values(s)) {
|
|
591
614
|
if (t == null)
|
|
592
615
|
continue;
|
|
593
616
|
const r = typeof t;
|
|
@@ -598,12 +621,12 @@ const bt = () => {
|
|
|
598
621
|
if (typeof t[0] == "string") {
|
|
599
622
|
if (!t.every((o) => typeof o == "string"))
|
|
600
623
|
return !1;
|
|
601
|
-
} else if (!t.every((o) =>
|
|
624
|
+
} else if (!t.every((o) => Wt(o)))
|
|
602
625
|
return !1;
|
|
603
626
|
continue;
|
|
604
627
|
}
|
|
605
628
|
if (r === "object" && e === 0) {
|
|
606
|
-
if (!
|
|
629
|
+
if (!Qe(t, e + 1))
|
|
607
630
|
return !1;
|
|
608
631
|
continue;
|
|
609
632
|
}
|
|
@@ -611,27 +634,27 @@ const bt = () => {
|
|
|
611
634
|
}
|
|
612
635
|
}
|
|
613
636
|
return !0;
|
|
614
|
-
},
|
|
637
|
+
}, Gt = (s) => typeof s != "string" ? {
|
|
615
638
|
valid: !1,
|
|
616
639
|
error: "Event name must be a string"
|
|
617
|
-
} :
|
|
640
|
+
} : s.length === 0 ? {
|
|
618
641
|
valid: !1,
|
|
619
642
|
error: "Event name cannot be empty"
|
|
620
|
-
} :
|
|
643
|
+
} : s.length > 120 ? {
|
|
621
644
|
valid: !1,
|
|
622
645
|
error: "Event name is too long (max 120 characters)"
|
|
623
|
-
} :
|
|
646
|
+
} : s.includes("<") || s.includes(">") || s.includes("&") ? {
|
|
624
647
|
valid: !1,
|
|
625
648
|
error: "Event name contains invalid characters"
|
|
626
|
-
} : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(
|
|
649
|
+
} : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(s.toLowerCase()) ? {
|
|
627
650
|
valid: !1,
|
|
628
651
|
error: "Event name cannot be a reserved word"
|
|
629
|
-
} : { valid: !0 },
|
|
630
|
-
const r =
|
|
631
|
-
if (!
|
|
652
|
+
} : { valid: !0 }, De = (s, e, t) => {
|
|
653
|
+
const r = xt(e), n = t && t === "customEvent" ? `${t} "${s}" metadata error` : `${s} metadata error`;
|
|
654
|
+
if (!Qe(r))
|
|
632
655
|
return {
|
|
633
656
|
valid: !1,
|
|
634
|
-
error: `${
|
|
657
|
+
error: `${n}: object has invalid types. Valid types are string, number, boolean or string arrays.`
|
|
635
658
|
};
|
|
636
659
|
let i;
|
|
637
660
|
try {
|
|
@@ -639,58 +662,58 @@ const bt = () => {
|
|
|
639
662
|
} catch {
|
|
640
663
|
return {
|
|
641
664
|
valid: !1,
|
|
642
|
-
error: `${
|
|
665
|
+
error: `${n}: object contains circular references or cannot be serialized.`
|
|
643
666
|
};
|
|
644
667
|
}
|
|
645
668
|
if (i.length > 8192)
|
|
646
669
|
return {
|
|
647
670
|
valid: !1,
|
|
648
|
-
error: `${
|
|
671
|
+
error: `${n}: object is too large (max ${8192 / 1024} KB).`
|
|
649
672
|
};
|
|
650
673
|
if (Object.keys(r).length > 10)
|
|
651
674
|
return {
|
|
652
675
|
valid: !1,
|
|
653
|
-
error: `${
|
|
676
|
+
error: `${n}: object has too many keys (max 10 keys).`
|
|
654
677
|
};
|
|
655
678
|
for (const [l, c] of Object.entries(r)) {
|
|
656
679
|
if (Array.isArray(c)) {
|
|
657
680
|
if (c.length > 10)
|
|
658
681
|
return {
|
|
659
682
|
valid: !1,
|
|
660
|
-
error: `${
|
|
683
|
+
error: `${n}: array property "${l}" is too large (max 10 items).`
|
|
661
684
|
};
|
|
662
|
-
for (const
|
|
663
|
-
if (typeof
|
|
685
|
+
for (const u of c)
|
|
686
|
+
if (typeof u == "string" && u.length > 500)
|
|
664
687
|
return {
|
|
665
688
|
valid: !1,
|
|
666
|
-
error: `${
|
|
689
|
+
error: `${n}: array property "${l}" contains strings that are too long (max 500 characters).`
|
|
667
690
|
};
|
|
668
691
|
}
|
|
669
692
|
if (typeof c == "string" && c.length > 1e3)
|
|
670
693
|
return {
|
|
671
694
|
valid: !1,
|
|
672
|
-
error: `${
|
|
695
|
+
error: `${n}: property "${l}" is too long (max 1000 characters).`
|
|
673
696
|
};
|
|
674
697
|
}
|
|
675
698
|
return {
|
|
676
699
|
valid: !0,
|
|
677
700
|
sanitizedMetadata: r
|
|
678
701
|
};
|
|
679
|
-
},
|
|
702
|
+
}, ze = (s, e, t) => {
|
|
680
703
|
if (Array.isArray(e)) {
|
|
681
|
-
const r = [],
|
|
704
|
+
const r = [], n = t && t === "customEvent" ? `${t} "${s}" metadata error` : `${s} metadata error`;
|
|
682
705
|
for (let i = 0; i < e.length; i++) {
|
|
683
706
|
const o = e[i];
|
|
684
707
|
if (typeof o != "object" || o === null || Array.isArray(o))
|
|
685
708
|
return {
|
|
686
709
|
valid: !1,
|
|
687
|
-
error: `${
|
|
710
|
+
error: `${n}: array item at index ${i} must be an object.`
|
|
688
711
|
};
|
|
689
|
-
const l =
|
|
712
|
+
const l = De(s, o, t);
|
|
690
713
|
if (!l.valid)
|
|
691
714
|
return {
|
|
692
715
|
valid: !1,
|
|
693
|
-
error: `${
|
|
716
|
+
error: `${n}: array item at index ${i} is invalid: ${l.error}`
|
|
694
717
|
};
|
|
695
718
|
l.sanitizedMetadata && r.push(l.sanitizedMetadata);
|
|
696
719
|
}
|
|
@@ -699,26 +722,24 @@ const bt = () => {
|
|
|
699
722
|
sanitizedMetadata: r
|
|
700
723
|
};
|
|
701
724
|
}
|
|
702
|
-
return
|
|
703
|
-
},
|
|
704
|
-
const t =
|
|
725
|
+
return De(s, e, t);
|
|
726
|
+
}, Xt = (s, e) => {
|
|
727
|
+
const t = Gt(s);
|
|
705
728
|
if (!t.valid)
|
|
706
729
|
return a("error", "Event name validation failed", {
|
|
707
|
-
|
|
708
|
-
data: { eventName: n, error: t.error }
|
|
730
|
+
data: { eventName: s, error: t.error }
|
|
709
731
|
}), t;
|
|
710
732
|
if (!e)
|
|
711
733
|
return { valid: !0 };
|
|
712
|
-
const r =
|
|
734
|
+
const r = ze(s, e, "customEvent");
|
|
713
735
|
return r.valid || a("error", "Event metadata validation failed", {
|
|
714
|
-
showToClient: !0,
|
|
715
736
|
data: {
|
|
716
|
-
eventName:
|
|
737
|
+
eventName: s,
|
|
717
738
|
error: r.error
|
|
718
739
|
}
|
|
719
740
|
}), r;
|
|
720
741
|
};
|
|
721
|
-
class
|
|
742
|
+
class Qt {
|
|
722
743
|
listeners = /* @__PURE__ */ new Map();
|
|
723
744
|
/**
|
|
724
745
|
* Subscribes to an event channel
|
|
@@ -771,8 +792,8 @@ class kt {
|
|
|
771
792
|
off(e, t) {
|
|
772
793
|
const r = this.listeners.get(e);
|
|
773
794
|
if (r) {
|
|
774
|
-
const
|
|
775
|
-
|
|
795
|
+
const n = r.indexOf(t);
|
|
796
|
+
n > -1 && r.splice(n, 1);
|
|
776
797
|
}
|
|
777
798
|
}
|
|
778
799
|
/**
|
|
@@ -805,8 +826,8 @@ class kt {
|
|
|
805
826
|
*/
|
|
806
827
|
emit(e, t) {
|
|
807
828
|
const r = this.listeners.get(e);
|
|
808
|
-
r && r.forEach((
|
|
809
|
-
|
|
829
|
+
r && r.forEach((n) => {
|
|
830
|
+
n(t);
|
|
810
831
|
});
|
|
811
832
|
}
|
|
812
833
|
/**
|
|
@@ -835,34 +856,38 @@ class kt {
|
|
|
835
856
|
this.listeners.clear();
|
|
836
857
|
}
|
|
837
858
|
}
|
|
838
|
-
function je(
|
|
859
|
+
function je(s, e, t) {
|
|
839
860
|
try {
|
|
840
|
-
const r = e(
|
|
841
|
-
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);
|
|
842
863
|
} catch (r) {
|
|
843
|
-
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;
|
|
844
868
|
}
|
|
845
869
|
}
|
|
846
|
-
function
|
|
847
|
-
return
|
|
870
|
+
function zt(s, e, t) {
|
|
871
|
+
return s.map((r) => je(r, e, t)).filter((r) => r !== null);
|
|
848
872
|
}
|
|
849
|
-
function
|
|
873
|
+
function Ke(s, e, t) {
|
|
850
874
|
try {
|
|
851
|
-
const r = e(
|
|
875
|
+
const r = e(s);
|
|
852
876
|
return r === null ? (a("debug", `Batch filtered by beforeBatch transformer [${t}]`, {
|
|
853
|
-
data: { eventCount:
|
|
877
|
+
data: { eventCount: s.events.length }
|
|
854
878
|
}), null) : typeof r == "object" && r !== null && Array.isArray(r.events) ? r : (a("warn", `beforeBatch transformer returned invalid data, using original [${t}]`, {
|
|
855
|
-
data: { eventCount:
|
|
856
|
-
}),
|
|
879
|
+
data: { eventCount: s.events.length }
|
|
880
|
+
}), s);
|
|
857
881
|
} catch (r) {
|
|
858
882
|
return a("error", `beforeBatch transformer threw error, using original batch [${t}]`, {
|
|
859
883
|
error: r,
|
|
860
|
-
data: { eventCount:
|
|
861
|
-
|
|
884
|
+
data: { eventCount: s.events.length },
|
|
885
|
+
visibility: "critical"
|
|
886
|
+
}), s;
|
|
862
887
|
}
|
|
863
888
|
}
|
|
864
|
-
const
|
|
865
|
-
class
|
|
889
|
+
const te = {};
|
|
890
|
+
class T {
|
|
866
891
|
/**
|
|
867
892
|
* Retrieves a value from global state.
|
|
868
893
|
*
|
|
@@ -880,7 +905,7 @@ class p {
|
|
|
880
905
|
* ```
|
|
881
906
|
*/
|
|
882
907
|
get(e) {
|
|
883
|
-
return
|
|
908
|
+
return te[e];
|
|
884
909
|
}
|
|
885
910
|
/**
|
|
886
911
|
* Sets a value in global state.
|
|
@@ -900,7 +925,7 @@ class p {
|
|
|
900
925
|
* ```
|
|
901
926
|
*/
|
|
902
927
|
set(e, t) {
|
|
903
|
-
|
|
928
|
+
te[e] = t;
|
|
904
929
|
}
|
|
905
930
|
/**
|
|
906
931
|
* Returns an immutable snapshot of the entire global state.
|
|
@@ -917,10 +942,10 @@ class p {
|
|
|
917
942
|
* ```
|
|
918
943
|
*/
|
|
919
944
|
getState() {
|
|
920
|
-
return { ...
|
|
945
|
+
return { ...te };
|
|
921
946
|
}
|
|
922
947
|
}
|
|
923
|
-
class
|
|
948
|
+
class Ve extends T {
|
|
924
949
|
storeManager;
|
|
925
950
|
integrationId;
|
|
926
951
|
apiUrl;
|
|
@@ -941,10 +966,10 @@ class ke extends p {
|
|
|
941
966
|
* @param transformers - Optional event transformation hooks
|
|
942
967
|
* @throws Error if integrationId and apiUrl are not both provided or both undefined
|
|
943
968
|
*/
|
|
944
|
-
constructor(e, t, r,
|
|
969
|
+
constructor(e, t, r, n = {}) {
|
|
945
970
|
if (super(), t && !r || !t && r)
|
|
946
971
|
throw new Error("SenderManager: integrationId and apiUrl must either both be provided or both be undefined");
|
|
947
|
-
this.storeManager = e, this.integrationId = t, this.apiUrl = r, this.transformers =
|
|
972
|
+
this.storeManager = e, this.integrationId = t, this.apiUrl = r, this.transformers = n;
|
|
948
973
|
}
|
|
949
974
|
/**
|
|
950
975
|
* Get the integration ID for this sender
|
|
@@ -954,7 +979,7 @@ class ke extends p {
|
|
|
954
979
|
return this.integrationId;
|
|
955
980
|
}
|
|
956
981
|
getQueueStorageKey() {
|
|
957
|
-
const e = this.get("userId") || "anonymous", t =
|
|
982
|
+
const e = this.get("userId") || "anonymous", t = at(e);
|
|
958
983
|
return this.integrationId ? `${t}:${this.integrationId}` : t;
|
|
959
984
|
}
|
|
960
985
|
/**
|
|
@@ -986,13 +1011,13 @@ class ke extends p {
|
|
|
986
1011
|
* @see src/managers/README.md (lines 82-139) for send details
|
|
987
1012
|
*/
|
|
988
1013
|
sendEventsQueueSync(e) {
|
|
989
|
-
return this.shouldSkipSend() ? !0 : this.apiUrl?.includes(
|
|
1014
|
+
return this.shouldSkipSend() ? !0 : this.apiUrl?.includes(V.Fail) ? (a(
|
|
990
1015
|
"warn",
|
|
991
1016
|
`Fail mode: simulating network failure (sync)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
992
1017
|
{
|
|
993
1018
|
data: { events: e.events.length }
|
|
994
1019
|
}
|
|
995
|
-
), !1) : this.apiUrl?.includes(
|
|
1020
|
+
), !1) : this.apiUrl?.includes(V.Localhost) ? (a(
|
|
996
1021
|
"debug",
|
|
997
1022
|
`Success mode: simulating successful send (sync)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
998
1023
|
{
|
|
@@ -1155,7 +1180,7 @@ class ke extends p {
|
|
|
1155
1180
|
const t = this.transformers.beforeSend;
|
|
1156
1181
|
if (!t)
|
|
1157
1182
|
return e;
|
|
1158
|
-
const r =
|
|
1183
|
+
const r = zt(
|
|
1159
1184
|
e.events,
|
|
1160
1185
|
t,
|
|
1161
1186
|
this.integrationId || "SenderManager"
|
|
@@ -1200,7 +1225,7 @@ class ke extends p {
|
|
|
1200
1225
|
if (this.integrationId === "saas")
|
|
1201
1226
|
return e;
|
|
1202
1227
|
const t = this.transformers.beforeBatch;
|
|
1203
|
-
return t ?
|
|
1228
|
+
return t ? Ke(e, t, this.integrationId || "SenderManager") : e;
|
|
1204
1229
|
}
|
|
1205
1230
|
/**
|
|
1206
1231
|
* Calculates exponential backoff delay with jitter for retry attempts.
|
|
@@ -1222,8 +1247,8 @@ class ke extends p {
|
|
|
1222
1247
|
* @returns Promise that resolves after calculated delay
|
|
1223
1248
|
*/
|
|
1224
1249
|
async backoffDelay(e) {
|
|
1225
|
-
const t = 100 * Math.pow(2, e), r = Math.random() * 100,
|
|
1226
|
-
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));
|
|
1227
1252
|
}
|
|
1228
1253
|
/**
|
|
1229
1254
|
* Sends event queue with automatic retry logic for transient failures.
|
|
@@ -1268,18 +1293,18 @@ class ke extends p {
|
|
|
1268
1293
|
const r = this.applyBeforeBatchTransformer(t);
|
|
1269
1294
|
if (!r)
|
|
1270
1295
|
return !0;
|
|
1271
|
-
if (this.apiUrl?.includes(
|
|
1272
|
-
return a("
|
|
1296
|
+
if (this.apiUrl?.includes(V.Fail))
|
|
1297
|
+
return a("debug", `Fail mode: simulating network failure${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1273
1298
|
data: { events: r.events.length }
|
|
1274
1299
|
}), !1;
|
|
1275
|
-
if (this.apiUrl?.includes(
|
|
1300
|
+
if (this.apiUrl?.includes(V.Localhost))
|
|
1276
1301
|
return a("debug", `Success mode: simulating successful send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1277
1302
|
data: { events: r.events.length }
|
|
1278
1303
|
}), !0;
|
|
1279
|
-
const { url:
|
|
1304
|
+
const { url: n, payload: i } = this.prepareRequest(r);
|
|
1280
1305
|
for (let o = 1; o <= 3; o++)
|
|
1281
1306
|
try {
|
|
1282
|
-
return (await this.sendWithTimeout(
|
|
1307
|
+
return (await this.sendWithTimeout(n, i)).ok ? (o > 1 && a(
|
|
1283
1308
|
"info",
|
|
1284
1309
|
`Send succeeded after ${o - 1} retry attempt(s)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1285
1310
|
{
|
|
@@ -1297,7 +1322,7 @@ class ke extends p {
|
|
|
1297
1322
|
error: l,
|
|
1298
1323
|
data: {
|
|
1299
1324
|
events: e.events.length,
|
|
1300
|
-
url:
|
|
1325
|
+
url: n.replace(/\/\/[^/]+/, "//[DOMAIN]"),
|
|
1301
1326
|
attempt: o,
|
|
1302
1327
|
maxAttempts: 3
|
|
1303
1328
|
}
|
|
@@ -1334,7 +1359,7 @@ class ke extends p {
|
|
|
1334
1359
|
async sendWithTimeout(e, t) {
|
|
1335
1360
|
const r = new AbortController();
|
|
1336
1361
|
this.pendingControllers.add(r);
|
|
1337
|
-
const
|
|
1362
|
+
const n = setTimeout(() => {
|
|
1338
1363
|
r.abort();
|
|
1339
1364
|
}, 15e3);
|
|
1340
1365
|
try {
|
|
@@ -1352,7 +1377,7 @@ class ke extends p {
|
|
|
1352
1377
|
throw i.status >= 400 && i.status < 500 && i.status !== 408 && i.status !== 429 ? new R(`HTTP ${i.status}: ${i.statusText}`, i.status) : new Error(`HTTP ${i.status}: ${i.statusText}`);
|
|
1353
1378
|
return i;
|
|
1354
1379
|
} finally {
|
|
1355
|
-
clearTimeout(
|
|
1380
|
+
clearTimeout(n), this.pendingControllers.delete(r);
|
|
1356
1381
|
}
|
|
1357
1382
|
}
|
|
1358
1383
|
/**
|
|
@@ -1382,7 +1407,7 @@ class ke extends p {
|
|
|
1382
1407
|
const r = this.applyBeforeBatchTransformer(t);
|
|
1383
1408
|
if (!r)
|
|
1384
1409
|
return !0;
|
|
1385
|
-
const { url:
|
|
1410
|
+
const { url: n, payload: i } = this.prepareRequest(r);
|
|
1386
1411
|
if (i.length > 65536)
|
|
1387
1412
|
return a(
|
|
1388
1413
|
"warn",
|
|
@@ -1401,7 +1426,7 @@ class ke extends p {
|
|
|
1401
1426
|
"warn",
|
|
1402
1427
|
`sendBeacon not available, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1403
1428
|
), this.persistEvents(r), !1;
|
|
1404
|
-
const l = navigator.sendBeacon(
|
|
1429
|
+
const l = navigator.sendBeacon(n, o);
|
|
1405
1430
|
return l || (a(
|
|
1406
1431
|
"warn",
|
|
1407
1432
|
`sendBeacon rejected request, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
@@ -1433,7 +1458,7 @@ class ke extends p {
|
|
|
1433
1458
|
_metadata: {
|
|
1434
1459
|
referer: typeof window < "u" ? window.location.href : void 0,
|
|
1435
1460
|
timestamp: t,
|
|
1436
|
-
client_version:
|
|
1461
|
+
client_version: Rt
|
|
1437
1462
|
}
|
|
1438
1463
|
};
|
|
1439
1464
|
return {
|
|
@@ -1459,7 +1484,7 @@ class ke extends p {
|
|
|
1459
1484
|
if (t)
|
|
1460
1485
|
return JSON.parse(t);
|
|
1461
1486
|
} catch (e) {
|
|
1462
|
-
a("
|
|
1487
|
+
a("debug", `Failed to parse persisted data${this.integrationId ? ` [${this.integrationId}]` : ""}`, { error: e }), this.clearPersistedEvents();
|
|
1463
1488
|
}
|
|
1464
1489
|
return null;
|
|
1465
1490
|
}
|
|
@@ -1526,10 +1551,10 @@ class ke extends p {
|
|
|
1526
1551
|
const r = {
|
|
1527
1552
|
...e,
|
|
1528
1553
|
timestamp: Date.now()
|
|
1529
|
-
},
|
|
1530
|
-
return this.storeManager.setItem(
|
|
1554
|
+
}, n = this.getQueueStorageKey();
|
|
1555
|
+
return this.storeManager.setItem(n, JSON.stringify(r)), !!this.storeManager.getItem(n);
|
|
1531
1556
|
} catch (t) {
|
|
1532
|
-
return a("
|
|
1557
|
+
return a("debug", `Failed to persist events${this.integrationId ? ` [${this.integrationId}]` : ""}`, { error: t }), !1;
|
|
1533
1558
|
}
|
|
1534
1559
|
}
|
|
1535
1560
|
clearPersistedEvents() {
|
|
@@ -1537,7 +1562,9 @@ class ke extends p {
|
|
|
1537
1562
|
const e = this.getQueueStorageKey();
|
|
1538
1563
|
this.storeManager.removeItem(e);
|
|
1539
1564
|
} catch (e) {
|
|
1540
|
-
a("
|
|
1565
|
+
a("debug", `Failed to clear persisted events${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1566
|
+
error: e
|
|
1567
|
+
});
|
|
1541
1568
|
}
|
|
1542
1569
|
}
|
|
1543
1570
|
shouldSkipSend() {
|
|
@@ -1552,12 +1579,12 @@ class ke extends p {
|
|
|
1552
1579
|
}
|
|
1553
1580
|
logPermanentError(e, t) {
|
|
1554
1581
|
const r = Date.now();
|
|
1555
|
-
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || r - this.lastPermanentErrorLog.timestamp >=
|
|
1582
|
+
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || r - this.lastPermanentErrorLog.timestamp >= bt) && (a("error", `${e}${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1556
1583
|
data: { status: t.statusCode, message: t.message }
|
|
1557
1584
|
}), this.lastPermanentErrorLog = { statusCode: t.statusCode, timestamp: r });
|
|
1558
1585
|
}
|
|
1559
1586
|
}
|
|
1560
|
-
class
|
|
1587
|
+
class jt extends T {
|
|
1561
1588
|
bootTime;
|
|
1562
1589
|
bootTimestamp;
|
|
1563
1590
|
hasPerformanceNow;
|
|
@@ -1587,7 +1614,7 @@ class xt extends p {
|
|
|
1587
1614
|
bootTime: this.bootTime.toFixed(3),
|
|
1588
1615
|
bootTimestamp: this.bootTimestamp
|
|
1589
1616
|
}
|
|
1590
|
-
})) : (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()"));
|
|
1591
1618
|
}
|
|
1592
1619
|
/**
|
|
1593
1620
|
* Returns current timestamp in milliseconds since epoch.
|
|
@@ -1684,10 +1711,10 @@ class xt extends p {
|
|
|
1684
1711
|
* ```
|
|
1685
1712
|
*/
|
|
1686
1713
|
validateTimestamp(e) {
|
|
1687
|
-
const r = this.now(),
|
|
1688
|
-
return
|
|
1714
|
+
const r = this.now(), n = e - r;
|
|
1715
|
+
return n > 12e4 ? {
|
|
1689
1716
|
valid: !1,
|
|
1690
|
-
error: `Timestamp is ${(
|
|
1717
|
+
error: `Timestamp is ${(n / 1e3 / 60).toFixed(2)} minutes in the future (max allowed: 2 minutes)`
|
|
1691
1718
|
} : { valid: !0 };
|
|
1692
1719
|
}
|
|
1693
1720
|
/**
|
|
@@ -1706,7 +1733,7 @@ class xt extends p {
|
|
|
1706
1733
|
};
|
|
1707
1734
|
}
|
|
1708
1735
|
}
|
|
1709
|
-
class
|
|
1736
|
+
class Kt extends T {
|
|
1710
1737
|
dataSenders;
|
|
1711
1738
|
emitter;
|
|
1712
1739
|
transformers;
|
|
@@ -1721,11 +1748,11 @@ class Ht extends p {
|
|
|
1721
1748
|
lastSessionId = null;
|
|
1722
1749
|
sessionEventCounts = {
|
|
1723
1750
|
total: 0,
|
|
1724
|
-
[
|
|
1725
|
-
[
|
|
1726
|
-
[
|
|
1727
|
-
[
|
|
1728
|
-
[
|
|
1751
|
+
[d.CLICK]: 0,
|
|
1752
|
+
[d.PAGE_VIEW]: 0,
|
|
1753
|
+
[d.CUSTOM]: 0,
|
|
1754
|
+
[d.VIEWPORT_VISIBLE]: 0,
|
|
1755
|
+
[d.SCROLL]: 0
|
|
1729
1756
|
};
|
|
1730
1757
|
saveSessionCountsDebounced = null;
|
|
1731
1758
|
/**
|
|
@@ -1740,9 +1767,9 @@ class Ht extends p {
|
|
|
1740
1767
|
* @param transformers - Optional event transformation hooks
|
|
1741
1768
|
*/
|
|
1742
1769
|
constructor(e, t = null, r = {}) {
|
|
1743
|
-
super(), this.emitter = t, this.transformers = r, this.timeManager = new
|
|
1744
|
-
const
|
|
1745
|
-
|
|
1770
|
+
super(), this.emitter = t, this.transformers = r, this.timeManager = new jt(), 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) => {
|
|
1746
1773
|
this.saveSessionCounts(i);
|
|
1747
1774
|
}, 500), this.cleanupExpiredSessionCounts();
|
|
1748
1775
|
}
|
|
@@ -1773,14 +1800,14 @@ class Ht extends p {
|
|
|
1773
1800
|
async recoverPersistedEvents() {
|
|
1774
1801
|
const e = this.dataSenders.map(
|
|
1775
1802
|
async (t) => t.recoverPersistedEvents({
|
|
1776
|
-
onSuccess: (r,
|
|
1777
|
-
if (
|
|
1778
|
-
const o =
|
|
1803
|
+
onSuccess: (r, n, i) => {
|
|
1804
|
+
if (n && n.length > 0) {
|
|
1805
|
+
const o = n.map((l) => l.id);
|
|
1779
1806
|
this.removeProcessedEvents(o), i && this.emitEventsQueue(i);
|
|
1780
1807
|
}
|
|
1781
1808
|
},
|
|
1782
1809
|
onFailure: () => {
|
|
1783
|
-
a("
|
|
1810
|
+
a("debug", "Failed to recover persisted events");
|
|
1784
1811
|
}
|
|
1785
1812
|
})
|
|
1786
1813
|
);
|
|
@@ -1849,113 +1876,129 @@ class Ht extends p {
|
|
|
1849
1876
|
type: e,
|
|
1850
1877
|
page_url: t,
|
|
1851
1878
|
from_page_url: r,
|
|
1852
|
-
scroll_data:
|
|
1879
|
+
scroll_data: n,
|
|
1853
1880
|
click_data: i,
|
|
1854
1881
|
custom_event: o,
|
|
1855
1882
|
web_vitals: l,
|
|
1856
1883
|
error_data: c,
|
|
1857
|
-
viewport_data:
|
|
1884
|
+
viewport_data: u
|
|
1858
1885
|
}) {
|
|
1859
1886
|
if (!e) {
|
|
1860
1887
|
a("error", "Event type is required - event will be ignored");
|
|
1861
1888
|
return;
|
|
1862
1889
|
}
|
|
1863
|
-
const
|
|
1864
|
-
if (!
|
|
1865
|
-
this.pendingEventsBuffer.length >= 100 && (this.pendingEventsBuffer.shift(), a("
|
|
1890
|
+
const S = this.get("sessionId");
|
|
1891
|
+
if (!S) {
|
|
1892
|
+
this.pendingEventsBuffer.length >= 100 && (this.pendingEventsBuffer.shift(), a("debug", "Pending events buffer full - dropping oldest event", {
|
|
1866
1893
|
data: { maxBufferSize: 100 }
|
|
1867
1894
|
})), this.pendingEventsBuffer.push({
|
|
1868
1895
|
type: e,
|
|
1869
1896
|
page_url: t,
|
|
1870
1897
|
from_page_url: r,
|
|
1871
|
-
scroll_data:
|
|
1898
|
+
scroll_data: n,
|
|
1872
1899
|
click_data: i,
|
|
1873
1900
|
custom_event: o,
|
|
1874
1901
|
web_vitals: l,
|
|
1875
1902
|
error_data: c,
|
|
1876
|
-
viewport_data:
|
|
1903
|
+
viewport_data: u
|
|
1877
1904
|
});
|
|
1878
1905
|
return;
|
|
1879
1906
|
}
|
|
1880
|
-
this.lastSessionId !==
|
|
1881
|
-
const E = e ===
|
|
1907
|
+
this.lastSessionId !== S && (this.lastSessionId = S, this.sessionEventCounts = this.loadSessionCounts(S));
|
|
1908
|
+
const E = e === d.SESSION_START;
|
|
1882
1909
|
if (E && a("debug", "Processing SESSION_START event", {
|
|
1883
|
-
data: { sessionId:
|
|
1910
|
+
data: { sessionId: S }
|
|
1884
1911
|
}), !E && !this.checkRateLimit())
|
|
1885
1912
|
return;
|
|
1886
|
-
const
|
|
1913
|
+
const g = e;
|
|
1887
1914
|
if (!E) {
|
|
1888
1915
|
if (this.sessionEventCounts.total >= 1e3) {
|
|
1889
1916
|
a("warn", "Session event limit reached", {
|
|
1890
1917
|
data: {
|
|
1891
|
-
type:
|
|
1918
|
+
type: g,
|
|
1892
1919
|
total: this.sessionEventCounts.total,
|
|
1893
1920
|
limit: 1e3
|
|
1894
1921
|
}
|
|
1895
1922
|
});
|
|
1896
1923
|
return;
|
|
1897
1924
|
}
|
|
1898
|
-
const
|
|
1899
|
-
if (
|
|
1900
|
-
const
|
|
1901
|
-
if (
|
|
1925
|
+
const p = this.getTypeLimitForEvent(g);
|
|
1926
|
+
if (p) {
|
|
1927
|
+
const ee = this.sessionEventCounts[g];
|
|
1928
|
+
if (ee !== void 0 && ee >= p) {
|
|
1902
1929
|
a("warn", "Session event type limit reached", {
|
|
1903
1930
|
data: {
|
|
1904
|
-
type:
|
|
1905
|
-
count:
|
|
1906
|
-
limit:
|
|
1931
|
+
type: g,
|
|
1932
|
+
count: ee,
|
|
1933
|
+
limit: p
|
|
1907
1934
|
}
|
|
1908
1935
|
});
|
|
1909
1936
|
return;
|
|
1910
1937
|
}
|
|
1911
1938
|
}
|
|
1912
1939
|
}
|
|
1913
|
-
if (
|
|
1914
|
-
const
|
|
1915
|
-
if (!this.checkPerEventRateLimit(o.name,
|
|
1940
|
+
if (g === d.CUSTOM && o?.name) {
|
|
1941
|
+
const p = this.get("config")?.maxSameEventPerMinute ?? 60;
|
|
1942
|
+
if (!this.checkPerEventRateLimit(o.name, p))
|
|
1916
1943
|
return;
|
|
1917
1944
|
}
|
|
1918
|
-
const
|
|
1919
|
-
type:
|
|
1945
|
+
const F = g === d.SESSION_START, $ = t || this.get("pageUrl"), P = this.buildEventPayload({
|
|
1946
|
+
type: g,
|
|
1920
1947
|
page_url: $,
|
|
1921
1948
|
from_page_url: r,
|
|
1922
|
-
scroll_data:
|
|
1949
|
+
scroll_data: n,
|
|
1923
1950
|
click_data: i,
|
|
1924
1951
|
custom_event: o,
|
|
1925
1952
|
web_vitals: l,
|
|
1926
1953
|
error_data: c,
|
|
1927
|
-
viewport_data:
|
|
1954
|
+
viewport_data: u
|
|
1928
1955
|
});
|
|
1929
|
-
if (
|
|
1930
|
-
if (
|
|
1931
|
-
const
|
|
1932
|
-
if (!
|
|
1956
|
+
if (P && !(!E && !this.shouldSample())) {
|
|
1957
|
+
if (F) {
|
|
1958
|
+
const p = this.get("sessionId");
|
|
1959
|
+
if (!p) {
|
|
1933
1960
|
a("error", "Session start event requires sessionId - event will be ignored");
|
|
1934
1961
|
return;
|
|
1935
1962
|
}
|
|
1936
1963
|
if (this.get("hasStartSession")) {
|
|
1937
|
-
a("
|
|
1938
|
-
data: { sessionId:
|
|
1964
|
+
a("debug", "Duplicate session_start detected", {
|
|
1965
|
+
data: { sessionId: p }
|
|
1939
1966
|
});
|
|
1940
1967
|
return;
|
|
1941
1968
|
}
|
|
1942
1969
|
this.set("hasStartSession", !0);
|
|
1943
1970
|
}
|
|
1944
|
-
if (!this.isDuplicateEvent(
|
|
1945
|
-
if (this.get("mode") ===
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1971
|
+
if (!this.isDuplicateEvent(P)) {
|
|
1972
|
+
if (this.get("mode") === j.QA) {
|
|
1973
|
+
if (g === d.CUSTOM && o) {
|
|
1974
|
+
a("info", `Custom Event: ${o.name}`, {
|
|
1975
|
+
visibility: "qa",
|
|
1976
|
+
data: {
|
|
1977
|
+
name: o.name,
|
|
1978
|
+
...o.metadata && { metadata: o.metadata }
|
|
1979
|
+
}
|
|
1980
|
+
}), this.emitEvent(P);
|
|
1981
|
+
return;
|
|
1982
|
+
}
|
|
1983
|
+
if (g === d.VIEWPORT_VISIBLE && u) {
|
|
1984
|
+
const p = u.name || u.id || u.selector;
|
|
1985
|
+
a("info", `Viewport Visible: ${p}`, {
|
|
1986
|
+
visibility: "qa",
|
|
1987
|
+
data: {
|
|
1988
|
+
selector: u.selector,
|
|
1989
|
+
...u.name && { name: u.name },
|
|
1990
|
+
...u.id && { id: u.id },
|
|
1991
|
+
visibilityRatio: u.visibilityRatio,
|
|
1992
|
+
dwellTime: u.dwellTime
|
|
1993
|
+
}
|
|
1994
|
+
}), this.emitEvent(P);
|
|
1995
|
+
return;
|
|
1996
|
+
}
|
|
1954
1997
|
}
|
|
1955
|
-
if (this.addToQueue(
|
|
1956
|
-
this.sessionEventCounts.total++, this.sessionEventCounts[
|
|
1957
|
-
const
|
|
1958
|
-
|
|
1998
|
+
if (this.addToQueue(P), !E) {
|
|
1999
|
+
this.sessionEventCounts.total++, this.sessionEventCounts[g] !== void 0 && this.sessionEventCounts[g]++;
|
|
2000
|
+
const p = this.get("sessionId");
|
|
2001
|
+
p && this.saveSessionCountsDebounced && this.saveSessionCountsDebounced(p);
|
|
1959
2002
|
}
|
|
1960
2003
|
}
|
|
1961
2004
|
}
|
|
@@ -1999,11 +2042,11 @@ class Ht extends p {
|
|
|
1999
2042
|
const e = this.get("sessionId");
|
|
2000
2043
|
e && this.saveSessionCounts(e), this.eventsQueue = [], this.pendingEventsBuffer = [], this.recentEventFingerprints.clear(), this.rateLimitCounter = 0, this.rateLimitWindowStart = 0, this.perEventRateLimits.clear(), this.sessionEventCounts = {
|
|
2001
2044
|
total: 0,
|
|
2002
|
-
[
|
|
2003
|
-
[
|
|
2004
|
-
[
|
|
2005
|
-
[
|
|
2006
|
-
[
|
|
2045
|
+
[d.CLICK]: 0,
|
|
2046
|
+
[d.PAGE_VIEW]: 0,
|
|
2047
|
+
[d.CUSTOM]: 0,
|
|
2048
|
+
[d.VIEWPORT_VISIBLE]: 0,
|
|
2049
|
+
[d.SCROLL]: 0
|
|
2007
2050
|
}, this.lastSessionId = null, this.set("hasStartSession", !1), this.dataSenders.forEach((t) => {
|
|
2008
2051
|
t.stop();
|
|
2009
2052
|
});
|
|
@@ -2181,7 +2224,7 @@ class Ht extends p {
|
|
|
2181
2224
|
if (this.pendingEventsBuffer.length === 0)
|
|
2182
2225
|
return;
|
|
2183
2226
|
if (!this.get("sessionId")) {
|
|
2184
|
-
a("
|
|
2227
|
+
a("debug", "Cannot flush pending events: session not initialized - keeping in buffer", {
|
|
2185
2228
|
data: { bufferedEventCount: this.pendingEventsBuffer.length }
|
|
2186
2229
|
});
|
|
2187
2230
|
return;
|
|
@@ -2200,13 +2243,13 @@ class Ht extends p {
|
|
|
2200
2243
|
flushEvents(e) {
|
|
2201
2244
|
if (this.eventsQueue.length === 0)
|
|
2202
2245
|
return e ? !0 : Promise.resolve(!0);
|
|
2203
|
-
const t = this.buildEventsPayload(), r = [...this.eventsQueue],
|
|
2246
|
+
const t = this.buildEventsPayload(), r = [...this.eventsQueue], n = r.map((i) => i.id);
|
|
2204
2247
|
if (this.dataSenders.length === 0)
|
|
2205
|
-
return this.removeProcessedEvents(
|
|
2248
|
+
return this.removeProcessedEvents(n), this.clearSendInterval(), this.emitEventsQueue(t), e ? !0 : Promise.resolve(!0);
|
|
2206
2249
|
if (e) {
|
|
2207
2250
|
const o = this.dataSenders.map((l) => l.sendEventsQueueSync(t)).some((l) => l);
|
|
2208
|
-
return o ? (this.removeProcessedEvents(
|
|
2209
|
-
data: { eventCount:
|
|
2251
|
+
return o ? (this.removeProcessedEvents(n), this.clearSendInterval(), this.emitEventsQueue(t)) : (this.clearSendInterval(), a("debug", "Sync flush complete failure, events kept in queue for retry", {
|
|
2252
|
+
data: { eventCount: n.length }
|
|
2210
2253
|
})), o;
|
|
2211
2254
|
} else {
|
|
2212
2255
|
const i = this.dataSenders.map(
|
|
@@ -2219,7 +2262,7 @@ class Ht extends p {
|
|
|
2219
2262
|
);
|
|
2220
2263
|
return Promise.allSettled(i).then((o) => {
|
|
2221
2264
|
const l = o.some((c) => this.isSuccessfulResult(c));
|
|
2222
|
-
return l ? (this.removeProcessedEvents(
|
|
2265
|
+
return l ? (this.removeProcessedEvents(n), this.clearSendInterval(), this.emitEventsQueue(t)) : a("debug", "Async flush complete failure, events kept in queue for retry", {
|
|
2223
2266
|
data: { eventCount: r.length }
|
|
2224
2267
|
}), l;
|
|
2225
2268
|
});
|
|
@@ -2233,22 +2276,22 @@ class Ht extends p {
|
|
|
2233
2276
|
this.emitEventsQueue(e);
|
|
2234
2277
|
return;
|
|
2235
2278
|
}
|
|
2236
|
-
const t = [...this.eventsQueue], r = t.map((l) => l.id),
|
|
2279
|
+
const t = [...this.eventsQueue], r = t.map((l) => l.id), n = this.dataSenders.map(
|
|
2237
2280
|
async (l) => l.sendEventsQueue(e, {
|
|
2238
2281
|
onSuccess: () => {
|
|
2239
2282
|
},
|
|
2240
2283
|
onFailure: () => {
|
|
2241
2284
|
}
|
|
2242
2285
|
})
|
|
2243
|
-
), i = await Promise.allSettled(
|
|
2286
|
+
), i = await Promise.allSettled(n);
|
|
2244
2287
|
if (i.some((l) => this.isSuccessfulResult(l))) {
|
|
2245
2288
|
this.removeProcessedEvents(r), this.emitEventsQueue(e);
|
|
2246
2289
|
const l = i.filter((c) => !this.isSuccessfulResult(c)).length;
|
|
2247
|
-
l > 0 && a("
|
|
2290
|
+
l > 0 && a("debug", "Periodic send completed with some failures, removed from queue and persisted per-integration", {
|
|
2248
2291
|
data: { eventCount: t.length, failedCount: l }
|
|
2249
2292
|
});
|
|
2250
2293
|
} else
|
|
2251
|
-
a("
|
|
2294
|
+
a("debug", "Periodic send complete failure, events kept in queue for retry", {
|
|
2252
2295
|
data: { eventCount: t.length }
|
|
2253
2296
|
});
|
|
2254
2297
|
this.eventsQueue.length === 0 && this.clearSendInterval();
|
|
@@ -2256,11 +2299,11 @@ class Ht extends p {
|
|
|
2256
2299
|
buildEventsPayload() {
|
|
2257
2300
|
const e = /* @__PURE__ */ new Map(), t = [];
|
|
2258
2301
|
for (const c of this.eventsQueue) {
|
|
2259
|
-
const
|
|
2260
|
-
e.has(
|
|
2302
|
+
const u = this.createEventSignature(c);
|
|
2303
|
+
e.has(u) || t.push(u), e.set(u, c);
|
|
2261
2304
|
}
|
|
2262
|
-
const r = t.map((c) => e.get(c)).filter((c) => !!c).sort((c,
|
|
2263
|
-
let
|
|
2305
|
+
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);
|
|
2306
|
+
let n = {
|
|
2264
2307
|
user_id: this.get("userId"),
|
|
2265
2308
|
session_id: this.get("sessionId"),
|
|
2266
2309
|
device: this.get("device"),
|
|
@@ -2269,21 +2312,21 @@ class Ht extends p {
|
|
|
2269
2312
|
};
|
|
2270
2313
|
const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas), l = this.transformers.beforeBatch;
|
|
2271
2314
|
if (!o && l) {
|
|
2272
|
-
const c =
|
|
2273
|
-
c !== null && (
|
|
2315
|
+
const c = Ke(n, l, "EventManager");
|
|
2316
|
+
c !== null && (n = c);
|
|
2274
2317
|
}
|
|
2275
|
-
return
|
|
2318
|
+
return n;
|
|
2276
2319
|
}
|
|
2277
2320
|
buildEventPayload(e) {
|
|
2278
|
-
const t = e.type ===
|
|
2321
|
+
const t = e.type === d.SESSION_START, r = e.page_url ?? this.get("pageUrl"), n = this.timeManager.now(), i = this.timeManager.validateTimestamp(n);
|
|
2279
2322
|
i.valid || a("warn", "Event timestamp validation failed", {
|
|
2280
2323
|
data: { type: e.type, error: i.error }
|
|
2281
2324
|
});
|
|
2282
2325
|
let o = {
|
|
2283
|
-
id:
|
|
2326
|
+
id: Vt(),
|
|
2284
2327
|
type: e.type,
|
|
2285
2328
|
page_url: r,
|
|
2286
|
-
timestamp:
|
|
2329
|
+
timestamp: n,
|
|
2287
2330
|
...t && { referrer: document.referrer || "Direct" },
|
|
2288
2331
|
...e.from_page_url && { from_page_url: e.from_page_url },
|
|
2289
2332
|
...e.scroll_data && { scroll_data: e.scroll_data },
|
|
@@ -2292,11 +2335,11 @@ class Ht extends p {
|
|
|
2292
2335
|
...e.web_vitals && { web_vitals: e.web_vitals },
|
|
2293
2336
|
...e.error_data && { error_data: e.error_data },
|
|
2294
2337
|
...e.viewport_data && { viewport_data: e.viewport_data },
|
|
2295
|
-
...t &&
|
|
2338
|
+
...t && Oe() && { utm: Oe() }
|
|
2296
2339
|
};
|
|
2297
|
-
const l = this.get("collectApiUrls"), c = !!l?.custom,
|
|
2298
|
-
if (
|
|
2299
|
-
const $ = je(o,
|
|
2340
|
+
const l = this.get("collectApiUrls"), c = !!l?.custom, u = !!l?.saas, S = c || u, E = c && u, g = this.transformers.beforeSend;
|
|
2341
|
+
if (g && (!S || c && !E)) {
|
|
2342
|
+
const $ = je(o, g, "EventManager");
|
|
2300
2343
|
if ($ === null)
|
|
2301
2344
|
return null;
|
|
2302
2345
|
o = $;
|
|
@@ -2304,15 +2347,15 @@ class Ht extends p {
|
|
|
2304
2347
|
return o;
|
|
2305
2348
|
}
|
|
2306
2349
|
isDuplicateEvent(e) {
|
|
2307
|
-
const t = Date.now(), r = this.createEventFingerprint(e),
|
|
2308
|
-
return
|
|
2350
|
+
const t = Date.now(), r = this.createEventFingerprint(e), n = this.recentEventFingerprints.get(r);
|
|
2351
|
+
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", {
|
|
2309
2352
|
data: { hardLimit: 3e3 }
|
|
2310
2353
|
})), !1);
|
|
2311
2354
|
}
|
|
2312
2355
|
pruneOldFingerprints() {
|
|
2313
2356
|
const e = Date.now(), t = 1e3 * 10;
|
|
2314
|
-
for (const [r,
|
|
2315
|
-
e -
|
|
2357
|
+
for (const [r, n] of this.recentEventFingerprints.entries())
|
|
2358
|
+
e - n > t && this.recentEventFingerprints.delete(r);
|
|
2316
2359
|
a("debug", "Pruned old event fingerprints", {
|
|
2317
2360
|
data: {
|
|
2318
2361
|
remaining: this.recentEventFingerprints.size,
|
|
@@ -2323,8 +2366,8 @@ class Ht extends p {
|
|
|
2323
2366
|
createEventFingerprint(e) {
|
|
2324
2367
|
let t = `${e.type}_${e.page_url}`;
|
|
2325
2368
|
if (e.click_data) {
|
|
2326
|
-
const r = Math.round((e.click_data.x || 0) / 10) * 10,
|
|
2327
|
-
t += `_click_${r}_${
|
|
2369
|
+
const r = Math.round((e.click_data.x || 0) / 10) * 10, n = Math.round((e.click_data.y || 0) / 10) * 10;
|
|
2370
|
+
t += `_click_${r}_${n}`;
|
|
2328
2371
|
}
|
|
2329
2372
|
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;
|
|
2330
2373
|
}
|
|
@@ -2333,13 +2376,13 @@ class Ht extends p {
|
|
|
2333
2376
|
}
|
|
2334
2377
|
addToQueue(e) {
|
|
2335
2378
|
if (this.emitEvent(e), this.eventsQueue.push(e), this.eventsQueue.length > 100) {
|
|
2336
|
-
const t = this.eventsQueue.findIndex((
|
|
2379
|
+
const t = this.eventsQueue.findIndex((n) => n.type !== d.SESSION_START), r = t >= 0 ? this.eventsQueue.splice(t, 1)[0] : this.eventsQueue.shift();
|
|
2337
2380
|
a("warn", "Event queue overflow, oldest non-critical event removed", {
|
|
2338
2381
|
data: {
|
|
2339
2382
|
maxLength: 100,
|
|
2340
2383
|
currentLength: this.eventsQueue.length,
|
|
2341
2384
|
removedEventType: r?.type,
|
|
2342
|
-
wasCritical: r?.type ===
|
|
2385
|
+
wasCritical: r?.type === d.SESSION_START
|
|
2343
2386
|
}
|
|
2344
2387
|
});
|
|
2345
2388
|
}
|
|
@@ -2370,11 +2413,11 @@ class Ht extends p {
|
|
|
2370
2413
|
}
|
|
2371
2414
|
getTypeLimitForEvent(e) {
|
|
2372
2415
|
return {
|
|
2373
|
-
[
|
|
2374
|
-
[
|
|
2375
|
-
[
|
|
2376
|
-
[
|
|
2377
|
-
[
|
|
2416
|
+
[d.CLICK]: 500,
|
|
2417
|
+
[d.PAGE_VIEW]: 100,
|
|
2418
|
+
[d.CUSTOM]: 500,
|
|
2419
|
+
[d.VIEWPORT_VISIBLE]: 200,
|
|
2420
|
+
[d.SCROLL]: 120
|
|
2378
2421
|
}[e] ?? null;
|
|
2379
2422
|
}
|
|
2380
2423
|
removeProcessedEvents(e) {
|
|
@@ -2409,9 +2452,9 @@ class Ht extends p {
|
|
|
2409
2452
|
*/
|
|
2410
2453
|
debounce(e, t) {
|
|
2411
2454
|
let r = null;
|
|
2412
|
-
return ((...
|
|
2455
|
+
return ((...n) => {
|
|
2413
2456
|
r !== null && clearTimeout(r), r = setTimeout(() => {
|
|
2414
|
-
e(...
|
|
2457
|
+
e(...n), r = null;
|
|
2415
2458
|
}, t);
|
|
2416
2459
|
});
|
|
2417
2460
|
}
|
|
@@ -2428,11 +2471,11 @@ class Ht extends p {
|
|
|
2428
2471
|
getInitialCounts() {
|
|
2429
2472
|
return {
|
|
2430
2473
|
total: 0,
|
|
2431
|
-
[
|
|
2432
|
-
[
|
|
2433
|
-
[
|
|
2434
|
-
[
|
|
2435
|
-
[
|
|
2474
|
+
[d.CLICK]: 0,
|
|
2475
|
+
[d.PAGE_VIEW]: 0,
|
|
2476
|
+
[d.CUSTOM]: 0,
|
|
2477
|
+
[d.VIEWPORT_VISIBLE]: 0,
|
|
2478
|
+
[d.SCROLL]: 0
|
|
2436
2479
|
};
|
|
2437
2480
|
}
|
|
2438
2481
|
/**
|
|
@@ -2461,29 +2504,29 @@ class Ht extends p {
|
|
|
2461
2504
|
loadSessionCounts(e) {
|
|
2462
2505
|
if (typeof window > "u" || typeof localStorage > "u")
|
|
2463
2506
|
return this.getInitialCounts();
|
|
2464
|
-
const t = this.get("userId") || "anonymous", r =
|
|
2507
|
+
const t = this.get("userId") || "anonymous", r = ve(t, e);
|
|
2465
2508
|
try {
|
|
2466
|
-
const
|
|
2467
|
-
if (!
|
|
2509
|
+
const n = localStorage.getItem(r);
|
|
2510
|
+
if (!n)
|
|
2468
2511
|
return this.getInitialCounts();
|
|
2469
|
-
const i = JSON.parse(
|
|
2512
|
+
const i = JSON.parse(n);
|
|
2470
2513
|
return i._timestamp && Date.now() - i._timestamp > we ? (a("debug", "Session counts expired, clearing", {
|
|
2471
2514
|
data: { sessionId: e, age: Date.now() - i._timestamp }
|
|
2472
|
-
}), localStorage.removeItem(r), this.getInitialCounts()) : typeof i.total == "number" && typeof i[
|
|
2515
|
+
}), 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" ? {
|
|
2473
2516
|
total: i.total,
|
|
2474
|
-
[
|
|
2475
|
-
[
|
|
2476
|
-
[
|
|
2477
|
-
[
|
|
2478
|
-
[
|
|
2517
|
+
[d.CLICK]: i[d.CLICK],
|
|
2518
|
+
[d.PAGE_VIEW]: i[d.PAGE_VIEW],
|
|
2519
|
+
[d.CUSTOM]: i[d.CUSTOM],
|
|
2520
|
+
[d.VIEWPORT_VISIBLE]: i[d.VIEWPORT_VISIBLE],
|
|
2521
|
+
[d.SCROLL]: i[d.SCROLL]
|
|
2479
2522
|
} : (a("warn", "Invalid session counts structure in localStorage, resetting", {
|
|
2480
2523
|
data: { sessionId: e, parsed: i }
|
|
2481
2524
|
}), localStorage.removeItem(r), a("debug", "Session counts removed due to invalid/corrupted data", {
|
|
2482
2525
|
data: { sessionId: e, parsed: i }
|
|
2483
2526
|
}), this.getInitialCounts());
|
|
2484
|
-
} catch (
|
|
2527
|
+
} catch (n) {
|
|
2485
2528
|
return a("warn", "Failed to load session counts from localStorage", {
|
|
2486
|
-
error:
|
|
2529
|
+
error: n,
|
|
2487
2530
|
data: { sessionId: e }
|
|
2488
2531
|
}), this.getInitialCounts();
|
|
2489
2532
|
}
|
|
@@ -2522,7 +2565,7 @@ class Ht extends p {
|
|
|
2522
2565
|
return;
|
|
2523
2566
|
}
|
|
2524
2567
|
}
|
|
2525
|
-
const t = this.get("userId") || "anonymous", r = `${
|
|
2568
|
+
const t = this.get("userId") || "anonymous", r = `${I}:${t}:session_counts:`, n = [];
|
|
2526
2569
|
for (let i = 0; i < localStorage.length; i++) {
|
|
2527
2570
|
const o = localStorage.key(i);
|
|
2528
2571
|
if (o?.startsWith(r))
|
|
@@ -2530,14 +2573,14 @@ class Ht extends p {
|
|
|
2530
2573
|
const l = localStorage.getItem(o);
|
|
2531
2574
|
if (l) {
|
|
2532
2575
|
const c = JSON.parse(l);
|
|
2533
|
-
c._timestamp && Date.now() - c._timestamp > we &&
|
|
2576
|
+
c._timestamp && Date.now() - c._timestamp > we && n.push(o);
|
|
2534
2577
|
}
|
|
2535
2578
|
} catch {
|
|
2536
2579
|
}
|
|
2537
2580
|
}
|
|
2538
|
-
|
|
2581
|
+
n.forEach((i) => {
|
|
2539
2582
|
localStorage.removeItem(i), a("debug", "Cleaned up expired session counts", { data: { key: i } });
|
|
2540
|
-
}),
|
|
2583
|
+
}), n.length > 0 && a("info", `Cleaned up ${n.length} expired session counts entries`), localStorage.setItem(ye, Date.now().toString());
|
|
2541
2584
|
} catch (e) {
|
|
2542
2585
|
a("warn", "Failed to cleanup expired session counts", { error: e });
|
|
2543
2586
|
}
|
|
@@ -2571,23 +2614,23 @@ class Ht extends p {
|
|
|
2571
2614
|
* @internal
|
|
2572
2615
|
*/
|
|
2573
2616
|
saveSessionCounts(e) {
|
|
2574
|
-
const t = this.get("userId") || "anonymous", r =
|
|
2617
|
+
const t = this.get("userId") || "anonymous", r = ve(t, e);
|
|
2575
2618
|
try {
|
|
2576
|
-
const
|
|
2619
|
+
const n = {
|
|
2577
2620
|
...this.sessionEventCounts,
|
|
2578
2621
|
_timestamp: Date.now(),
|
|
2579
2622
|
_version: 1
|
|
2580
2623
|
};
|
|
2581
|
-
localStorage.setItem(r, JSON.stringify(
|
|
2582
|
-
} catch (
|
|
2624
|
+
localStorage.setItem(r, JSON.stringify(n));
|
|
2625
|
+
} catch (n) {
|
|
2583
2626
|
a("warn", "Failed to persist session counts to localStorage", {
|
|
2584
|
-
error:
|
|
2627
|
+
error: n,
|
|
2585
2628
|
data: { sessionId: e }
|
|
2586
2629
|
});
|
|
2587
2630
|
}
|
|
2588
2631
|
}
|
|
2589
2632
|
}
|
|
2590
|
-
class
|
|
2633
|
+
class Yt {
|
|
2591
2634
|
/**
|
|
2592
2635
|
* Gets or creates a unique user ID.
|
|
2593
2636
|
*
|
|
@@ -2605,15 +2648,15 @@ class $t {
|
|
|
2605
2648
|
* @returns Persistent unique user ID (UUID v4 format)
|
|
2606
2649
|
*/
|
|
2607
2650
|
static getId(e) {
|
|
2608
|
-
const t = e.getItem(
|
|
2651
|
+
const t = e.getItem(Te);
|
|
2609
2652
|
if (t)
|
|
2610
2653
|
return t;
|
|
2611
|
-
const r =
|
|
2612
|
-
return e.setItem(
|
|
2654
|
+
const r = Dt();
|
|
2655
|
+
return e.setItem(Te, r), r;
|
|
2613
2656
|
}
|
|
2614
2657
|
}
|
|
2615
|
-
const
|
|
2616
|
-
class
|
|
2658
|
+
const qt = /^\d{13}-[a-z0-9]{9}$/;
|
|
2659
|
+
class Jt extends T {
|
|
2617
2660
|
storageManager;
|
|
2618
2661
|
eventManager;
|
|
2619
2662
|
projectId;
|
|
@@ -2634,13 +2677,13 @@ class Bt extends p {
|
|
|
2634
2677
|
}
|
|
2635
2678
|
initCrossTabSync() {
|
|
2636
2679
|
if (typeof BroadcastChannel > "u") {
|
|
2637
|
-
a("
|
|
2680
|
+
a("debug", "BroadcastChannel not supported");
|
|
2638
2681
|
return;
|
|
2639
2682
|
}
|
|
2640
2683
|
const e = this.getProjectId();
|
|
2641
|
-
this.broadcastChannel = new BroadcastChannel(
|
|
2642
|
-
const { action: r, sessionId:
|
|
2643
|
-
o === e && (r === "session_start" &&
|
|
2684
|
+
this.broadcastChannel = new BroadcastChannel(ct(e)), this.broadcastChannel.onmessage = (t) => {
|
|
2685
|
+
const { action: r, sessionId: n, timestamp: i, projectId: o } = t.data ?? {};
|
|
2686
|
+
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 } }));
|
|
2644
2687
|
};
|
|
2645
2688
|
}
|
|
2646
2689
|
shareSession(e) {
|
|
@@ -2658,7 +2701,7 @@ class Bt extends p {
|
|
|
2658
2701
|
const e = this.loadStoredSession();
|
|
2659
2702
|
if (!e)
|
|
2660
2703
|
return null;
|
|
2661
|
-
if (!
|
|
2704
|
+
if (!qt.test(e.id))
|
|
2662
2705
|
return a("warn", "Invalid session ID format recovered from storage, clearing", {
|
|
2663
2706
|
data: { sessionId: e.id }
|
|
2664
2707
|
}), this.clearStoredSession(), null;
|
|
@@ -2691,7 +2734,7 @@ class Bt extends p {
|
|
|
2691
2734
|
this.storageManager.setItem(t, JSON.stringify(e));
|
|
2692
2735
|
}
|
|
2693
2736
|
getSessionStorageKey() {
|
|
2694
|
-
return
|
|
2737
|
+
return lt(this.getProjectId());
|
|
2695
2738
|
}
|
|
2696
2739
|
getProjectId() {
|
|
2697
2740
|
return this.projectId;
|
|
@@ -2749,7 +2792,7 @@ class Bt extends p {
|
|
|
2749
2792
|
*/
|
|
2750
2793
|
startTracking() {
|
|
2751
2794
|
if (this.isTracking) {
|
|
2752
|
-
a("
|
|
2795
|
+
a("debug", "Session tracking already active");
|
|
2753
2796
|
return;
|
|
2754
2797
|
}
|
|
2755
2798
|
const e = this.recoverSession(), t = e ?? this.generateSessionId();
|
|
@@ -2764,7 +2807,7 @@ class Bt extends p {
|
|
|
2764
2807
|
this.set("sessionId", t), this.persistSession(t), this.initCrossTabSync(), this.shareSession(t), a("debug", "Emitting SESSION_START event", {
|
|
2765
2808
|
data: { sessionId: t }
|
|
2766
2809
|
}), this.eventManager.track({
|
|
2767
|
-
type:
|
|
2810
|
+
type: d.SESSION_START
|
|
2768
2811
|
}), this.setupSessionTimeout(), this.setupActivityListeners(), this.setupLifecycleListeners();
|
|
2769
2812
|
} catch (r) {
|
|
2770
2813
|
throw this.isTracking = !1, this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupLifecycleListeners(), this.cleanupCrossTabSync(), this.set("sessionId", null), r;
|
|
@@ -2874,7 +2917,7 @@ class Bt extends p {
|
|
|
2874
2917
|
this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupCrossTabSync(), this.cleanupLifecycleListeners(), this.isTracking = !1, this.set("hasStartSession", !1);
|
|
2875
2918
|
}
|
|
2876
2919
|
}
|
|
2877
|
-
class
|
|
2920
|
+
class Zt extends T {
|
|
2878
2921
|
eventManager;
|
|
2879
2922
|
storageManager;
|
|
2880
2923
|
sessionManager = null;
|
|
@@ -2904,12 +2947,12 @@ class Wt extends p {
|
|
|
2904
2947
|
if (this.isActive())
|
|
2905
2948
|
return;
|
|
2906
2949
|
if (this.destroyed) {
|
|
2907
|
-
a("
|
|
2950
|
+
a("debug", "Cannot start tracking on destroyed handler");
|
|
2908
2951
|
return;
|
|
2909
2952
|
}
|
|
2910
2953
|
const t = this.get("config")?.integrations?.tracelog?.projectId ?? "custom";
|
|
2911
2954
|
try {
|
|
2912
|
-
this.sessionManager = new
|
|
2955
|
+
this.sessionManager = new Jt(this.storageManager, this.eventManager, t), this.sessionManager.startTracking(), this.eventManager.flushPendingEvents();
|
|
2913
2956
|
} catch (r) {
|
|
2914
2957
|
if (this.sessionManager) {
|
|
2915
2958
|
try {
|
|
@@ -2962,7 +3005,7 @@ class Wt extends p {
|
|
|
2962
3005
|
this.destroyed || (this.sessionManager && (this.sessionManager.destroy(), this.sessionManager = null), this.destroyed = !0);
|
|
2963
3006
|
}
|
|
2964
3007
|
}
|
|
2965
|
-
class
|
|
3008
|
+
class er extends T {
|
|
2966
3009
|
eventManager;
|
|
2967
3010
|
onTrack;
|
|
2968
3011
|
originalPushState;
|
|
@@ -3002,35 +3045,35 @@ class Gt extends p {
|
|
|
3002
3045
|
};
|
|
3003
3046
|
}
|
|
3004
3047
|
trackCurrentPage = () => {
|
|
3005
|
-
const e = window.location.href, t =
|
|
3048
|
+
const e = window.location.href, t = le(e, this.get("config").sensitiveQueryParams);
|
|
3006
3049
|
if (this.get("pageUrl") === t)
|
|
3007
3050
|
return;
|
|
3008
|
-
const r = Date.now(),
|
|
3009
|
-
if (r - this.lastPageViewTime <
|
|
3051
|
+
const r = Date.now(), n = this.get("config").pageViewThrottleMs ?? 1e3;
|
|
3052
|
+
if (r - this.lastPageViewTime < n)
|
|
3010
3053
|
return;
|
|
3011
3054
|
this.lastPageViewTime = r, this.onTrack();
|
|
3012
3055
|
const i = this.get("pageUrl");
|
|
3013
3056
|
this.set("pageUrl", t);
|
|
3014
3057
|
const o = this.extractPageViewData();
|
|
3015
3058
|
this.eventManager.track({
|
|
3016
|
-
type:
|
|
3059
|
+
type: d.PAGE_VIEW,
|
|
3017
3060
|
page_url: this.get("pageUrl"),
|
|
3018
3061
|
from_page_url: i,
|
|
3019
3062
|
...o && { page_view: o }
|
|
3020
3063
|
});
|
|
3021
3064
|
};
|
|
3022
3065
|
trackInitialPageView() {
|
|
3023
|
-
const e =
|
|
3066
|
+
const e = le(window.location.href, this.get("config").sensitiveQueryParams), t = this.extractPageViewData();
|
|
3024
3067
|
this.lastPageViewTime = Date.now(), this.eventManager.track({
|
|
3025
|
-
type:
|
|
3068
|
+
type: d.PAGE_VIEW,
|
|
3026
3069
|
page_url: e,
|
|
3027
3070
|
...t && { page_view: t }
|
|
3028
3071
|
}), this.onTrack();
|
|
3029
3072
|
}
|
|
3030
3073
|
extractPageViewData() {
|
|
3031
|
-
const { pathname: e, search: t, hash: r } = window.location, { referrer:
|
|
3032
|
-
return !
|
|
3033
|
-
...
|
|
3074
|
+
const { pathname: e, search: t, hash: r } = window.location, { referrer: n } = document, { title: i } = document;
|
|
3075
|
+
return !n && !i && !e && !t && !r ? void 0 : {
|
|
3076
|
+
...n && { referrer: n },
|
|
3034
3077
|
...i && { title: i },
|
|
3035
3078
|
...e && { pathname: e },
|
|
3036
3079
|
...t && { search: t },
|
|
@@ -3038,7 +3081,7 @@ class Gt extends p {
|
|
|
3038
3081
|
};
|
|
3039
3082
|
}
|
|
3040
3083
|
}
|
|
3041
|
-
class
|
|
3084
|
+
class tr extends T {
|
|
3042
3085
|
eventManager;
|
|
3043
3086
|
lastClickTimes = /* @__PURE__ */ new Map();
|
|
3044
3087
|
clickHandler;
|
|
@@ -3061,23 +3104,23 @@ class Xt extends p {
|
|
|
3061
3104
|
*/
|
|
3062
3105
|
startTracking() {
|
|
3063
3106
|
this.clickHandler || (this.clickHandler = (e) => {
|
|
3064
|
-
const t = e, r = t.target,
|
|
3065
|
-
if (!
|
|
3066
|
-
a("
|
|
3107
|
+
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;
|
|
3108
|
+
if (!n) {
|
|
3109
|
+
a("debug", "Click target not found or not an element");
|
|
3067
3110
|
return;
|
|
3068
3111
|
}
|
|
3069
|
-
if (this.shouldIgnoreElement(
|
|
3112
|
+
if (this.shouldIgnoreElement(n))
|
|
3070
3113
|
return;
|
|
3071
3114
|
const i = this.get("config")?.clickThrottleMs ?? 300;
|
|
3072
|
-
if (i > 0 && !this.checkClickThrottle(
|
|
3115
|
+
if (i > 0 && !this.checkClickThrottle(n, i))
|
|
3073
3116
|
return;
|
|
3074
|
-
const o = this.findTrackingElement(
|
|
3117
|
+
const o = this.findTrackingElement(n), l = this.getRelevantClickElement(n), c = this.calculateClickCoordinates(t, n);
|
|
3075
3118
|
if (o) {
|
|
3076
|
-
const
|
|
3077
|
-
if (
|
|
3078
|
-
const E = this.createCustomEventData(
|
|
3119
|
+
const S = this.extractTrackingData(o);
|
|
3120
|
+
if (S) {
|
|
3121
|
+
const E = this.createCustomEventData(S);
|
|
3079
3122
|
this.eventManager.track({
|
|
3080
|
-
type:
|
|
3123
|
+
type: d.CUSTOM,
|
|
3081
3124
|
custom_event: {
|
|
3082
3125
|
name: E.name,
|
|
3083
3126
|
...E.value && { metadata: { value: E.value } }
|
|
@@ -3085,10 +3128,10 @@ class Xt extends p {
|
|
|
3085
3128
|
});
|
|
3086
3129
|
}
|
|
3087
3130
|
}
|
|
3088
|
-
const
|
|
3131
|
+
const u = this.generateClickData(n, l, c);
|
|
3089
3132
|
this.eventManager.track({
|
|
3090
|
-
type:
|
|
3091
|
-
click_data:
|
|
3133
|
+
type: d.CLICK,
|
|
3134
|
+
click_data: u
|
|
3092
3135
|
});
|
|
3093
3136
|
}, window.addEventListener("click", this.clickHandler, !0));
|
|
3094
3137
|
}
|
|
@@ -3102,22 +3145,22 @@ class Xt extends p {
|
|
|
3102
3145
|
this.clickHandler && (window.removeEventListener("click", this.clickHandler, !0), this.clickHandler = void 0), this.lastClickTimes.clear(), this.lastPruneTime = 0;
|
|
3103
3146
|
}
|
|
3104
3147
|
shouldIgnoreElement(e) {
|
|
3105
|
-
return e.hasAttribute(`${
|
|
3148
|
+
return e.hasAttribute(`${v}-ignore`) ? !0 : e.closest(`[${v}-ignore]`) !== null;
|
|
3106
3149
|
}
|
|
3107
3150
|
/**
|
|
3108
3151
|
* Checks per-element click throttling to prevent double-clicks and rapid spam
|
|
3109
3152
|
* Returns true if the click should be tracked, false if throttled
|
|
3110
3153
|
*/
|
|
3111
3154
|
checkClickThrottle(e, t) {
|
|
3112
|
-
const r = this.getElementSignature(e),
|
|
3113
|
-
this.pruneThrottleCache(
|
|
3155
|
+
const r = this.getElementSignature(e), n = Date.now();
|
|
3156
|
+
this.pruneThrottleCache(n);
|
|
3114
3157
|
const i = this.lastClickTimes.get(r);
|
|
3115
|
-
return i !== void 0 &&
|
|
3158
|
+
return i !== void 0 && n - i < t ? (a("debug", "ClickHandler: Click suppressed by throttle", {
|
|
3116
3159
|
data: {
|
|
3117
3160
|
signature: r,
|
|
3118
|
-
throttleRemaining: t - (
|
|
3161
|
+
throttleRemaining: t - (n - i)
|
|
3119
3162
|
}
|
|
3120
|
-
}), !1) : (this.lastClickTimes.set(r,
|
|
3163
|
+
}), !1) : (this.lastClickTimes.set(r, n), !0);
|
|
3121
3164
|
}
|
|
3122
3165
|
/**
|
|
3123
3166
|
* Prunes stale entries from the throttle cache to prevent memory leaks
|
|
@@ -3129,10 +3172,10 @@ class Xt extends p {
|
|
|
3129
3172
|
return;
|
|
3130
3173
|
this.lastPruneTime = e;
|
|
3131
3174
|
const t = e - 3e5;
|
|
3132
|
-
for (const [r,
|
|
3133
|
-
|
|
3175
|
+
for (const [r, n] of this.lastClickTimes.entries())
|
|
3176
|
+
n < t && this.lastClickTimes.delete(r);
|
|
3134
3177
|
if (this.lastClickTimes.size > 1e3) {
|
|
3135
|
-
const r = Array.from(this.lastClickTimes.entries()).sort((o, l) => o[1] - l[1]),
|
|
3178
|
+
const r = Array.from(this.lastClickTimes.entries()).sort((o, l) => o[1] - l[1]), n = this.lastClickTimes.size - 1e3, i = r.slice(0, n);
|
|
3136
3179
|
for (const [o] of i)
|
|
3137
3180
|
this.lastClickTimes.delete(o);
|
|
3138
3181
|
a("debug", "ClickHandler: Pruned throttle cache", {
|
|
@@ -3153,8 +3196,8 @@ class Xt extends p {
|
|
|
3153
3196
|
const t = e.getAttribute("data-testid");
|
|
3154
3197
|
if (t)
|
|
3155
3198
|
return `[data-testid="${t}"]`;
|
|
3156
|
-
const r = e.getAttribute(`${
|
|
3157
|
-
return r ? `[${
|
|
3199
|
+
const r = e.getAttribute(`${v}-name`);
|
|
3200
|
+
return r ? `[${v}-name="${r}"]` : this.getElementPath(e);
|
|
3158
3201
|
}
|
|
3159
3202
|
/**
|
|
3160
3203
|
* Generates a DOM path for an element (e.g., "body>div>button")
|
|
@@ -3163,20 +3206,20 @@ class Xt extends p {
|
|
|
3163
3206
|
const t = [];
|
|
3164
3207
|
let r = e;
|
|
3165
3208
|
for (; r && r !== document.body; ) {
|
|
3166
|
-
let
|
|
3209
|
+
let n = r.tagName.toLowerCase();
|
|
3167
3210
|
if (r.className) {
|
|
3168
3211
|
const i = r.className.split(" ")[0];
|
|
3169
|
-
i && (
|
|
3212
|
+
i && (n += `.${i}`);
|
|
3170
3213
|
}
|
|
3171
|
-
t.unshift(
|
|
3214
|
+
t.unshift(n), r = r.parentElement;
|
|
3172
3215
|
}
|
|
3173
3216
|
return t.join(">") || "unknown";
|
|
3174
3217
|
}
|
|
3175
3218
|
findTrackingElement(e) {
|
|
3176
|
-
return e.hasAttribute(`${
|
|
3219
|
+
return e.hasAttribute(`${v}-name`) ? e : e.closest(`[${v}-name]`);
|
|
3177
3220
|
}
|
|
3178
3221
|
getRelevantClickElement(e) {
|
|
3179
|
-
for (const t of
|
|
3222
|
+
for (const t of st)
|
|
3180
3223
|
try {
|
|
3181
3224
|
if (e.matches(t))
|
|
3182
3225
|
return e;
|
|
@@ -3184,7 +3227,7 @@ class Xt extends p {
|
|
|
3184
3227
|
if (r)
|
|
3185
3228
|
return r;
|
|
3186
3229
|
} catch (r) {
|
|
3187
|
-
a("
|
|
3230
|
+
a("debug", "Invalid selector in element search", { error: r, data: { selector: t } });
|
|
3188
3231
|
continue;
|
|
3189
3232
|
}
|
|
3190
3233
|
return e;
|
|
@@ -3204,11 +3247,11 @@ class Xt extends p {
|
|
|
3204
3247
|
return Math.max(0, Math.min(1, Number(e.toFixed(3))));
|
|
3205
3248
|
}
|
|
3206
3249
|
calculateClickCoordinates(e, t) {
|
|
3207
|
-
const r = t.getBoundingClientRect(),
|
|
3208
|
-
return { x:
|
|
3250
|
+
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;
|
|
3251
|
+
return { x: n, y: i, relativeX: o, relativeY: l };
|
|
3209
3252
|
}
|
|
3210
3253
|
extractTrackingData(e) {
|
|
3211
|
-
const t = e.getAttribute(`${
|
|
3254
|
+
const t = e.getAttribute(`${v}-name`), r = e.getAttribute(`${v}-value`);
|
|
3212
3255
|
if (t)
|
|
3213
3256
|
return {
|
|
3214
3257
|
element: e,
|
|
@@ -3217,9 +3260,9 @@ class Xt extends p {
|
|
|
3217
3260
|
};
|
|
3218
3261
|
}
|
|
3219
3262
|
generateClickData(e, t, r) {
|
|
3220
|
-
const { x:
|
|
3263
|
+
const { x: n, y: i, relativeX: o, relativeY: l } = r, c = this.getRelevantText(e, t), u = this.extractElementAttributes(t);
|
|
3221
3264
|
return {
|
|
3222
|
-
x:
|
|
3265
|
+
x: n,
|
|
3223
3266
|
y: i,
|
|
3224
3267
|
relativeX: o,
|
|
3225
3268
|
relativeY: l,
|
|
@@ -3227,12 +3270,12 @@ class Xt extends p {
|
|
|
3227
3270
|
...t.id && { id: t.id },
|
|
3228
3271
|
...t.className && { class: t.className },
|
|
3229
3272
|
...c && { text: c },
|
|
3230
|
-
...
|
|
3231
|
-
...
|
|
3232
|
-
...
|
|
3233
|
-
...
|
|
3234
|
-
...
|
|
3235
|
-
...Object.keys(
|
|
3273
|
+
...u.href && { href: u.href },
|
|
3274
|
+
...u.title && { title: u.title },
|
|
3275
|
+
...u.alt && { alt: u.alt },
|
|
3276
|
+
...u.role && { role: u.role },
|
|
3277
|
+
...u["aria-label"] && { ariaLabel: u["aria-label"] },
|
|
3278
|
+
...Object.keys(u).length > 0 && { dataAttributes: u }
|
|
3236
3279
|
};
|
|
3237
3280
|
}
|
|
3238
3281
|
/**
|
|
@@ -3257,17 +3300,17 @@ class Xt extends p {
|
|
|
3257
3300
|
sanitizeText(e) {
|
|
3258
3301
|
let t = e;
|
|
3259
3302
|
for (const r of Be) {
|
|
3260
|
-
const
|
|
3261
|
-
t = t.replace(
|
|
3303
|
+
const n = new RegExp(r.source, r.flags);
|
|
3304
|
+
t = t.replace(n, "[REDACTED]");
|
|
3262
3305
|
}
|
|
3263
3306
|
return t;
|
|
3264
3307
|
}
|
|
3265
3308
|
getRelevantText(e, t) {
|
|
3266
|
-
const r = e.textContent?.trim() ?? "",
|
|
3267
|
-
if (!r && !
|
|
3309
|
+
const r = e.textContent?.trim() ?? "", n = t.textContent?.trim() ?? "";
|
|
3310
|
+
if (!r && !n)
|
|
3268
3311
|
return "";
|
|
3269
3312
|
let i = "";
|
|
3270
|
-
return r && r.length <= 255 ? i = r :
|
|
3313
|
+
return r && r.length <= 255 ? i = r : n.length <= 255 ? i = n : i = n.slice(0, 252) + "...", this.sanitizeText(i);
|
|
3271
3314
|
}
|
|
3272
3315
|
extractElementAttributes(e) {
|
|
3273
3316
|
const t = [
|
|
@@ -3282,9 +3325,9 @@ class Xt extends p {
|
|
|
3282
3325
|
"alt",
|
|
3283
3326
|
"role"
|
|
3284
3327
|
], r = {};
|
|
3285
|
-
for (const
|
|
3286
|
-
const i = e.getAttribute(
|
|
3287
|
-
i && (r[
|
|
3328
|
+
for (const n of t) {
|
|
3329
|
+
const i = e.getAttribute(n);
|
|
3330
|
+
i && (r[n] = i);
|
|
3288
3331
|
}
|
|
3289
3332
|
return r;
|
|
3290
3333
|
}
|
|
@@ -3295,7 +3338,7 @@ class Xt extends p {
|
|
|
3295
3338
|
};
|
|
3296
3339
|
}
|
|
3297
3340
|
}
|
|
3298
|
-
class
|
|
3341
|
+
class rr extends T {
|
|
3299
3342
|
eventManager;
|
|
3300
3343
|
containers = [];
|
|
3301
3344
|
limitWarningLogged = !1;
|
|
@@ -3342,8 +3385,8 @@ class Qt extends p {
|
|
|
3342
3385
|
const t = this.findScrollableElements();
|
|
3343
3386
|
if (this.isWindowScrollable() && this.setupScrollContainer(window, "window"), t.length > 0) {
|
|
3344
3387
|
for (const r of t) {
|
|
3345
|
-
const
|
|
3346
|
-
this.setupScrollContainer(r,
|
|
3388
|
+
const n = this.getElementSelector(r);
|
|
3389
|
+
this.setupScrollContainer(r, n);
|
|
3347
3390
|
}
|
|
3348
3391
|
this.applyPrimaryScrollSelectorIfConfigured();
|
|
3349
3392
|
return;
|
|
@@ -3364,8 +3407,8 @@ class Qt extends p {
|
|
|
3364
3407
|
if (!document.body)
|
|
3365
3408
|
return [];
|
|
3366
3409
|
const e = [], t = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT, {
|
|
3367
|
-
acceptNode: (
|
|
3368
|
-
const i =
|
|
3410
|
+
acceptNode: (n) => {
|
|
3411
|
+
const i = n;
|
|
3369
3412
|
if (!i.isConnected || !i.offsetParent)
|
|
3370
3413
|
return NodeFilter.FILTER_SKIP;
|
|
3371
3414
|
const o = getComputedStyle(i);
|
|
@@ -3374,8 +3417,8 @@ class Qt extends p {
|
|
|
3374
3417
|
});
|
|
3375
3418
|
let r;
|
|
3376
3419
|
for (; (r = t.nextNode()) && e.length < 10; ) {
|
|
3377
|
-
const
|
|
3378
|
-
this.isElementScrollable(
|
|
3420
|
+
const n = r;
|
|
3421
|
+
this.isElementScrollable(n) && e.push(n);
|
|
3379
3422
|
}
|
|
3380
3423
|
return e;
|
|
3381
3424
|
}
|
|
@@ -3386,7 +3429,7 @@ class Qt extends p {
|
|
|
3386
3429
|
if (t.id)
|
|
3387
3430
|
return `#${t.id}`;
|
|
3388
3431
|
if (t.className && typeof t.className == "string") {
|
|
3389
|
-
const r = t.className.split(" ").filter((
|
|
3432
|
+
const r = t.className.split(" ").filter((n) => n.trim())[0];
|
|
3390
3433
|
if (r)
|
|
3391
3434
|
return `.${r}`;
|
|
3392
3435
|
}
|
|
@@ -3396,17 +3439,17 @@ class Qt extends p {
|
|
|
3396
3439
|
return this.isWindowScrollable() ? e === window : this.containers.length === 0;
|
|
3397
3440
|
}
|
|
3398
3441
|
setupScrollContainer(e, t) {
|
|
3399
|
-
if (this.containers.some((
|
|
3442
|
+
if (this.containers.some((u) => u.element === e) || e !== window && !this.isElementScrollable(e))
|
|
3400
3443
|
return;
|
|
3401
|
-
const
|
|
3402
|
-
|
|
3444
|
+
const n = this.getScrollTop(e), i = this.calculateScrollDepth(
|
|
3445
|
+
n,
|
|
3403
3446
|
this.getScrollHeight(e),
|
|
3404
3447
|
this.getViewportHeight(e)
|
|
3405
3448
|
), o = this.determineIfPrimary(e), l = {
|
|
3406
3449
|
element: e,
|
|
3407
3450
|
selector: t,
|
|
3408
3451
|
isPrimary: o,
|
|
3409
|
-
lastScrollPos:
|
|
3452
|
+
lastScrollPos: n,
|
|
3410
3453
|
lastDepth: i,
|
|
3411
3454
|
lastDirection: X.DOWN,
|
|
3412
3455
|
lastEventTime: 0,
|
|
@@ -3416,10 +3459,10 @@ class Qt extends p {
|
|
|
3416
3459
|
listener: null
|
|
3417
3460
|
}, c = () => {
|
|
3418
3461
|
this.get("suppressNextScroll") || (l.firstScrollEventTime === null && (l.firstScrollEventTime = Date.now()), this.clearContainerTimer(l), l.debounceTimer = window.setTimeout(() => {
|
|
3419
|
-
const
|
|
3420
|
-
if (
|
|
3421
|
-
const
|
|
3422
|
-
this.processScrollEvent(l,
|
|
3462
|
+
const u = this.calculateScrollData(l);
|
|
3463
|
+
if (u) {
|
|
3464
|
+
const S = Date.now();
|
|
3465
|
+
this.processScrollEvent(l, u, S);
|
|
3423
3466
|
}
|
|
3424
3467
|
l.debounceTimer = null;
|
|
3425
3468
|
}, 250));
|
|
@@ -3430,9 +3473,9 @@ class Qt extends p {
|
|
|
3430
3473
|
if (!this.shouldEmitScrollEvent(e, t, r))
|
|
3431
3474
|
return;
|
|
3432
3475
|
e.lastEventTime = r, e.lastDepth = t.depth, e.lastDirection = t.direction;
|
|
3433
|
-
const
|
|
3434
|
-
this.set("scrollEventCount",
|
|
3435
|
-
type:
|
|
3476
|
+
const n = this.get("scrollEventCount") ?? 0;
|
|
3477
|
+
this.set("scrollEventCount", n + 1), this.eventManager.track({
|
|
3478
|
+
type: d.SCROLL,
|
|
3436
3479
|
scroll_data: {
|
|
3437
3480
|
...t,
|
|
3438
3481
|
container_selector: e.selector,
|
|
@@ -3453,7 +3496,7 @@ class Qt extends p {
|
|
|
3453
3496
|
return Math.abs(t - e.lastDepth) >= this.minDepthChange;
|
|
3454
3497
|
}
|
|
3455
3498
|
logLimitOnce() {
|
|
3456
|
-
this.limitWarningLogged || (this.limitWarningLogged = !0, a("
|
|
3499
|
+
this.limitWarningLogged || (this.limitWarningLogged = !0, a("debug", "Max scroll events per session reached", {
|
|
3457
3500
|
data: { limit: this.maxEventsPerSession }
|
|
3458
3501
|
}));
|
|
3459
3502
|
}
|
|
@@ -3472,21 +3515,21 @@ class Qt extends p {
|
|
|
3472
3515
|
calculateScrollDepth(e, t, r) {
|
|
3473
3516
|
if (t <= r)
|
|
3474
3517
|
return 0;
|
|
3475
|
-
const
|
|
3476
|
-
return Math.min(100, Math.max(0, Math.floor(e /
|
|
3518
|
+
const n = t - r;
|
|
3519
|
+
return Math.min(100, Math.max(0, Math.floor(e / n * 100)));
|
|
3477
3520
|
}
|
|
3478
3521
|
calculateScrollData(e) {
|
|
3479
|
-
const { element: t, lastScrollPos: r, lastEventTime:
|
|
3522
|
+
const { element: t, lastScrollPos: r, lastEventTime: n } = e, i = this.getScrollTop(t), o = Date.now(), l = Math.abs(i - r);
|
|
3480
3523
|
if (l < 10 || t === window && !this.isWindowScrollable())
|
|
3481
3524
|
return null;
|
|
3482
|
-
const c = this.getViewportHeight(t),
|
|
3483
|
-
let
|
|
3484
|
-
|
|
3485
|
-
const
|
|
3525
|
+
const c = this.getViewportHeight(t), u = this.getScrollHeight(t), S = this.getScrollDirection(i, r), E = this.calculateScrollDepth(i, u, c);
|
|
3526
|
+
let g;
|
|
3527
|
+
n > 0 ? g = o - n : e.firstScrollEventTime !== null ? g = o - e.firstScrollEventTime : g = 250;
|
|
3528
|
+
const F = Math.round(l / g * 1e3);
|
|
3486
3529
|
return E > e.maxDepthReached && (e.maxDepthReached = E), e.lastScrollPos = i, {
|
|
3487
3530
|
depth: E,
|
|
3488
|
-
direction:
|
|
3489
|
-
velocity:
|
|
3531
|
+
direction: S,
|
|
3532
|
+
velocity: F,
|
|
3490
3533
|
max_depth_reached: e.maxDepthReached
|
|
3491
3534
|
};
|
|
3492
3535
|
}
|
|
@@ -3500,30 +3543,30 @@ class Qt extends p {
|
|
|
3500
3543
|
return e === window ? document.documentElement.scrollHeight : e.scrollHeight;
|
|
3501
3544
|
}
|
|
3502
3545
|
isElementScrollable(e) {
|
|
3503
|
-
const t = getComputedStyle(e), r = t.overflowY === "auto" || t.overflowY === "scroll" || t.overflow === "auto" || t.overflow === "scroll",
|
|
3504
|
-
return r &&
|
|
3546
|
+
const t = getComputedStyle(e), r = t.overflowY === "auto" || t.overflowY === "scroll" || t.overflow === "auto" || t.overflow === "scroll", n = e.scrollHeight > e.clientHeight;
|
|
3547
|
+
return r && n;
|
|
3505
3548
|
}
|
|
3506
3549
|
applyPrimaryScrollSelector(e) {
|
|
3507
3550
|
let t;
|
|
3508
3551
|
if (e === "window")
|
|
3509
3552
|
t = window;
|
|
3510
3553
|
else {
|
|
3511
|
-
const
|
|
3512
|
-
if (!(
|
|
3513
|
-
a("
|
|
3554
|
+
const n = document.querySelector(e);
|
|
3555
|
+
if (!(n instanceof HTMLElement)) {
|
|
3556
|
+
a("debug", `Selector "${e}" did not match an HTMLElement`);
|
|
3514
3557
|
return;
|
|
3515
3558
|
}
|
|
3516
|
-
t =
|
|
3559
|
+
t = n;
|
|
3517
3560
|
}
|
|
3518
|
-
this.containers.forEach((
|
|
3519
|
-
this.updateContainerPrimary(
|
|
3520
|
-
}), !this.containers.some((
|
|
3561
|
+
this.containers.forEach((n) => {
|
|
3562
|
+
this.updateContainerPrimary(n, n.element === t);
|
|
3563
|
+
}), !this.containers.some((n) => n.element === t) && t instanceof HTMLElement && this.isElementScrollable(t) && this.setupScrollContainer(t, e);
|
|
3521
3564
|
}
|
|
3522
3565
|
updateContainerPrimary(e, t) {
|
|
3523
3566
|
e.isPrimary = t;
|
|
3524
3567
|
}
|
|
3525
3568
|
}
|
|
3526
|
-
class
|
|
3569
|
+
class sr extends T {
|
|
3527
3570
|
eventManager;
|
|
3528
3571
|
trackedElements = /* @__PURE__ */ new Map();
|
|
3529
3572
|
observer = null;
|
|
@@ -3542,15 +3585,15 @@ class jt extends p {
|
|
|
3542
3585
|
return;
|
|
3543
3586
|
const t = this.config.threshold ?? 0.5, r = this.config.minDwellTime ?? 1e3;
|
|
3544
3587
|
if (t < 0 || t > 1) {
|
|
3545
|
-
a("
|
|
3588
|
+
a("debug", "ViewportHandler: Invalid threshold, must be between 0 and 1");
|
|
3546
3589
|
return;
|
|
3547
3590
|
}
|
|
3548
3591
|
if (r < 0) {
|
|
3549
|
-
a("
|
|
3592
|
+
a("debug", "ViewportHandler: Invalid minDwellTime, must be non-negative");
|
|
3550
3593
|
return;
|
|
3551
3594
|
}
|
|
3552
3595
|
if (typeof IntersectionObserver > "u") {
|
|
3553
|
-
a("
|
|
3596
|
+
a("debug", "ViewportHandler: IntersectionObserver not supported in this browser");
|
|
3554
3597
|
return;
|
|
3555
3598
|
}
|
|
3556
3599
|
this.observer = new IntersectionObserver(this.handleIntersection, {
|
|
@@ -3575,10 +3618,10 @@ class jt extends p {
|
|
|
3575
3618
|
let t = this.trackedElements.size;
|
|
3576
3619
|
for (const r of this.config.elements)
|
|
3577
3620
|
try {
|
|
3578
|
-
const
|
|
3579
|
-
for (const i of Array.from(
|
|
3621
|
+
const n = document.querySelectorAll(r.selector);
|
|
3622
|
+
for (const i of Array.from(n)) {
|
|
3580
3623
|
if (t >= e) {
|
|
3581
|
-
a("
|
|
3624
|
+
a("debug", "ViewportHandler: Maximum tracked elements reached", {
|
|
3582
3625
|
data: {
|
|
3583
3626
|
limit: e,
|
|
3584
3627
|
selector: r.selector,
|
|
@@ -3587,7 +3630,7 @@ class jt extends p {
|
|
|
3587
3630
|
});
|
|
3588
3631
|
return;
|
|
3589
3632
|
}
|
|
3590
|
-
i.hasAttribute(`${
|
|
3633
|
+
i.hasAttribute(`${v}-ignore`) || this.trackedElements.has(i) || (this.trackedElements.set(i, {
|
|
3591
3634
|
element: i,
|
|
3592
3635
|
selector: r.selector,
|
|
3593
3636
|
id: r.id,
|
|
@@ -3597,8 +3640,8 @@ class jt extends p {
|
|
|
3597
3640
|
lastFiredTime: null
|
|
3598
3641
|
}), this.observer?.observe(i), t++);
|
|
3599
3642
|
}
|
|
3600
|
-
} catch (
|
|
3601
|
-
a("
|
|
3643
|
+
} catch (n) {
|
|
3644
|
+
a("debug", `ViewportHandler: Invalid selector "${r.selector}"`, { error: n });
|
|
3602
3645
|
}
|
|
3603
3646
|
a("debug", "ViewportHandler: Elements tracked", {
|
|
3604
3647
|
data: { count: t, limit: e }
|
|
@@ -3611,11 +3654,11 @@ class jt extends p {
|
|
|
3611
3654
|
if (!this.config) return;
|
|
3612
3655
|
const t = this.config.minDwellTime ?? 1e3;
|
|
3613
3656
|
for (const r of e) {
|
|
3614
|
-
const
|
|
3615
|
-
|
|
3657
|
+
const n = this.trackedElements.get(r.target);
|
|
3658
|
+
n && (r.isIntersecting ? n.startTime === null && (n.startTime = performance.now(), n.timeoutId = window.setTimeout(() => {
|
|
3616
3659
|
const i = Math.round(r.intersectionRatio * 100) / 100;
|
|
3617
|
-
this.fireViewportEvent(
|
|
3618
|
-
}, t)) :
|
|
3660
|
+
this.fireViewportEvent(n, i);
|
|
3661
|
+
}, t)) : n.startTime !== null && (n.timeoutId !== null && (window.clearTimeout(n.timeoutId), n.timeoutId = null), n.startTime = null));
|
|
3619
3662
|
}
|
|
3620
3663
|
};
|
|
3621
3664
|
/**
|
|
@@ -3624,14 +3667,14 @@ class jt extends p {
|
|
|
3624
3667
|
fireViewportEvent(e, t) {
|
|
3625
3668
|
if (e.startTime === null) return;
|
|
3626
3669
|
const r = Math.round(performance.now() - e.startTime);
|
|
3627
|
-
if (e.element.hasAttribute(`${
|
|
3670
|
+
if (e.element.hasAttribute(`${v}-ignore`))
|
|
3628
3671
|
return;
|
|
3629
|
-
const
|
|
3630
|
-
if (e.lastFiredTime !== null && i - e.lastFiredTime <
|
|
3672
|
+
const n = this.config?.cooldownPeriod ?? 6e4, i = Date.now();
|
|
3673
|
+
if (e.lastFiredTime !== null && i - e.lastFiredTime < n) {
|
|
3631
3674
|
a("debug", "ViewportHandler: Event suppressed by cooldown period", {
|
|
3632
3675
|
data: {
|
|
3633
3676
|
selector: e.selector,
|
|
3634
|
-
cooldownRemaining:
|
|
3677
|
+
cooldownRemaining: n - (i - e.lastFiredTime)
|
|
3635
3678
|
}
|
|
3636
3679
|
}), e.startTime = null, e.timeoutId = null;
|
|
3637
3680
|
return;
|
|
@@ -3644,7 +3687,7 @@ class jt extends p {
|
|
|
3644
3687
|
...e.name !== void 0 && { name: e.name }
|
|
3645
3688
|
};
|
|
3646
3689
|
this.eventManager.track({
|
|
3647
|
-
type:
|
|
3690
|
+
type: d.VIEWPORT_VISIBLE,
|
|
3648
3691
|
viewport_data: o
|
|
3649
3692
|
}), e.startTime = null, e.timeoutId = null, e.lastFiredTime = i;
|
|
3650
3693
|
}
|
|
@@ -3654,7 +3697,7 @@ class jt extends p {
|
|
|
3654
3697
|
setupMutationObserver() {
|
|
3655
3698
|
if (!(!this.config || typeof MutationObserver > "u")) {
|
|
3656
3699
|
if (!document.body) {
|
|
3657
|
-
a("
|
|
3700
|
+
a("debug", "ViewportHandler: document.body not available, skipping MutationObserver setup");
|
|
3658
3701
|
return;
|
|
3659
3702
|
}
|
|
3660
3703
|
this.mutationObserver = new MutationObserver((e) => {
|
|
@@ -3676,22 +3719,22 @@ class jt extends p {
|
|
|
3676
3719
|
cleanupRemovedNodes(e) {
|
|
3677
3720
|
e.forEach((t) => {
|
|
3678
3721
|
if (t.nodeType !== 1) return;
|
|
3679
|
-
const r = t,
|
|
3680
|
-
|
|
3722
|
+
const r = t, n = this.trackedElements.get(r);
|
|
3723
|
+
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) => {
|
|
3681
3724
|
const l = this.trackedElements.get(o);
|
|
3682
3725
|
l && l.timeoutId !== null && window.clearTimeout(l.timeoutId), this.observer?.unobserve(o), this.trackedElements.delete(o);
|
|
3683
3726
|
});
|
|
3684
3727
|
});
|
|
3685
3728
|
}
|
|
3686
3729
|
}
|
|
3687
|
-
class
|
|
3730
|
+
class nr {
|
|
3688
3731
|
storage;
|
|
3689
3732
|
sessionStorageRef;
|
|
3690
3733
|
fallbackStorage = /* @__PURE__ */ new Map();
|
|
3691
3734
|
fallbackSessionStorage = /* @__PURE__ */ new Map();
|
|
3692
3735
|
hasQuotaExceededError = !1;
|
|
3693
3736
|
constructor() {
|
|
3694
|
-
this.storage = this.initializeStorage("localStorage"), this.sessionStorageRef = this.initializeStorage("sessionStorage"), this.storage || a("
|
|
3737
|
+
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");
|
|
3695
3738
|
}
|
|
3696
3739
|
/**
|
|
3697
3740
|
* Retrieves an item from localStorage.
|
|
@@ -3864,8 +3907,8 @@ class zt {
|
|
|
3864
3907
|
} catch {
|
|
3865
3908
|
}
|
|
3866
3909
|
}), !0;
|
|
3867
|
-
const r = ["tracelog_session_", "tracelog_user_id", "tracelog_device_id", "tracelog_config"],
|
|
3868
|
-
return
|
|
3910
|
+
const r = ["tracelog_session_", "tracelog_user_id", "tracelog_device_id", "tracelog_config"], n = e.filter((i) => !r.some((o) => i.startsWith(o)));
|
|
3911
|
+
return n.length > 0 ? (n.slice(0, 5).forEach((o) => {
|
|
3869
3912
|
try {
|
|
3870
3913
|
this.storage.removeItem(o);
|
|
3871
3914
|
} catch {
|
|
@@ -3967,7 +4010,7 @@ class zt {
|
|
|
3967
4010
|
this.fallbackSessionStorage.delete(e);
|
|
3968
4011
|
}
|
|
3969
4012
|
}
|
|
3970
|
-
class
|
|
4013
|
+
class ir extends T {
|
|
3971
4014
|
eventManager;
|
|
3972
4015
|
reportedByNav = /* @__PURE__ */ new Map();
|
|
3973
4016
|
navigationHistory = [];
|
|
@@ -3978,7 +4021,7 @@ class Kt extends p {
|
|
|
3978
4021
|
navigationCounter = 0;
|
|
3979
4022
|
// Counter for handling simultaneous navigations edge case
|
|
3980
4023
|
constructor(e) {
|
|
3981
|
-
super(), this.eventManager = e, this.vitalThresholds =
|
|
4024
|
+
super(), this.eventManager = e, this.vitalThresholds = Ne(ae);
|
|
3982
4025
|
}
|
|
3983
4026
|
/**
|
|
3984
4027
|
* Starts tracking Web Vitals and performance metrics.
|
|
@@ -3995,8 +4038,8 @@ class Kt extends p {
|
|
|
3995
4038
|
* @returns Promise that resolves when tracking is initialized
|
|
3996
4039
|
*/
|
|
3997
4040
|
async startTracking() {
|
|
3998
|
-
const e = this.get("config"), t = e?.webVitalsMode ??
|
|
3999
|
-
this.vitalThresholds =
|
|
4041
|
+
const e = this.get("config"), t = e?.webVitalsMode ?? ae;
|
|
4042
|
+
this.vitalThresholds = Ne(t), e?.webVitalsThresholds && (this.vitalThresholds = { ...this.vitalThresholds, ...e.webVitalsThresholds }), await this.initWebVitals(), this.observeLongTasks();
|
|
4000
4043
|
}
|
|
4001
4044
|
/**
|
|
4002
4045
|
* Stops tracking Web Vitals and cleans up resources.
|
|
@@ -4012,7 +4055,7 @@ class Kt extends p {
|
|
|
4012
4055
|
try {
|
|
4013
4056
|
e.disconnect();
|
|
4014
4057
|
} catch (r) {
|
|
4015
|
-
a("
|
|
4058
|
+
a("debug", "Failed to disconnect performance observer", { error: r, data: { observerIndex: t } });
|
|
4016
4059
|
}
|
|
4017
4060
|
}), this.observers.length = 0, this.reportedByNav.clear(), this.navigationHistory.length = 0;
|
|
4018
4061
|
}
|
|
@@ -4020,7 +4063,7 @@ class Kt extends p {
|
|
|
4020
4063
|
this.reportTTFB(), this.safeObserve(
|
|
4021
4064
|
"largest-contentful-paint",
|
|
4022
4065
|
(r) => {
|
|
4023
|
-
const
|
|
4066
|
+
const n = r.getEntries(), i = n[n.length - 1];
|
|
4024
4067
|
i && this.sendVital({ type: "LCP", value: Number(i.startTime.toFixed(2)) });
|
|
4025
4068
|
},
|
|
4026
4069
|
{ type: "largest-contentful-paint", buffered: !0 },
|
|
@@ -4030,8 +4073,8 @@ class Kt extends p {
|
|
|
4030
4073
|
this.safeObserve(
|
|
4031
4074
|
"layout-shift",
|
|
4032
4075
|
(r) => {
|
|
4033
|
-
const
|
|
4034
|
-
|
|
4076
|
+
const n = this.getNavigationId();
|
|
4077
|
+
n !== t && (e = 0, t = n);
|
|
4035
4078
|
const i = r.getEntries();
|
|
4036
4079
|
for (const o of i) {
|
|
4037
4080
|
if (o.hadRecentInput === !0)
|
|
@@ -4045,34 +4088,34 @@ class Kt extends p {
|
|
|
4045
4088
|
), this.safeObserve(
|
|
4046
4089
|
"paint",
|
|
4047
4090
|
(r) => {
|
|
4048
|
-
for (const
|
|
4049
|
-
|
|
4091
|
+
for (const n of r.getEntries())
|
|
4092
|
+
n.name === "first-contentful-paint" && this.sendVital({ type: "FCP", value: Number(n.startTime.toFixed(2)) });
|
|
4050
4093
|
},
|
|
4051
4094
|
{ type: "paint", buffered: !0 },
|
|
4052
4095
|
!0
|
|
4053
4096
|
), this.safeObserve(
|
|
4054
4097
|
"event",
|
|
4055
4098
|
(r) => {
|
|
4056
|
-
let
|
|
4099
|
+
let n = 0;
|
|
4057
4100
|
const i = r.getEntries();
|
|
4058
4101
|
for (const o of i) {
|
|
4059
4102
|
const l = (o.processingEnd ?? 0) - (o.startTime ?? 0);
|
|
4060
|
-
|
|
4103
|
+
n = Math.max(n, l);
|
|
4061
4104
|
}
|
|
4062
|
-
|
|
4105
|
+
n > 0 && this.sendVital({ type: "INP", value: Number(n.toFixed(2)) });
|
|
4063
4106
|
},
|
|
4064
4107
|
{ type: "event", buffered: !0 }
|
|
4065
4108
|
);
|
|
4066
4109
|
}
|
|
4067
4110
|
async initWebVitals() {
|
|
4068
4111
|
try {
|
|
4069
|
-
const { onLCP: e, onCLS: t, onFCP: r, onTTFB:
|
|
4070
|
-
const
|
|
4071
|
-
this.sendVital({ type: l, value:
|
|
4112
|
+
const { onLCP: e, onCLS: t, onFCP: r, onTTFB: n, onINP: i } = await Promise.resolve().then(() => Rr), o = (l) => (c) => {
|
|
4113
|
+
const u = Number(c.value.toFixed(2));
|
|
4114
|
+
this.sendVital({ type: l, value: u });
|
|
4072
4115
|
};
|
|
4073
|
-
e(o("LCP"), { reportAllChanges: !1 }), t(o("CLS"), { reportAllChanges: !1 }), r(o("FCP"), { reportAllChanges: !1 }),
|
|
4116
|
+
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 });
|
|
4074
4117
|
} catch (e) {
|
|
4075
|
-
a("
|
|
4118
|
+
a("debug", "Failed to load web-vitals library, using fallback", { error: e }), this.observeWebVitalsFallback();
|
|
4076
4119
|
}
|
|
4077
4120
|
}
|
|
4078
4121
|
reportTTFB() {
|
|
@@ -4083,7 +4126,7 @@ class Kt extends p {
|
|
|
4083
4126
|
const t = e.responseStart;
|
|
4084
4127
|
typeof t == "number" && Number.isFinite(t) && this.sendVital({ type: "TTFB", value: Number(t.toFixed(2)) });
|
|
4085
4128
|
} catch (e) {
|
|
4086
|
-
a("
|
|
4129
|
+
a("debug", "Failed to report TTFB", { error: e });
|
|
4087
4130
|
}
|
|
4088
4131
|
}
|
|
4089
4132
|
observeLongTasks() {
|
|
@@ -4092,8 +4135,8 @@ class Kt extends p {
|
|
|
4092
4135
|
(e) => {
|
|
4093
4136
|
const t = e.getEntries();
|
|
4094
4137
|
for (const r of t) {
|
|
4095
|
-
const
|
|
4096
|
-
i - this.lastLongTaskSentAt >=
|
|
4138
|
+
const n = Number(r.duration.toFixed(2)), i = Date.now();
|
|
4139
|
+
i - this.lastLongTaskSentAt >= Lt && (this.shouldSendVital("LONG_TASK", n) && this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = i);
|
|
4097
4140
|
}
|
|
4098
4141
|
},
|
|
4099
4142
|
{ type: "longtask", buffered: !0 }
|
|
@@ -4109,7 +4152,7 @@ class Kt extends p {
|
|
|
4109
4152
|
return;
|
|
4110
4153
|
if (r)
|
|
4111
4154
|
r.add(e.type);
|
|
4112
|
-
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length >
|
|
4155
|
+
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length > Mt) {
|
|
4113
4156
|
const i = this.navigationHistory.shift();
|
|
4114
4157
|
i && this.reportedByNav.delete(i);
|
|
4115
4158
|
}
|
|
@@ -4118,11 +4161,11 @@ class Kt extends p {
|
|
|
4118
4161
|
}
|
|
4119
4162
|
trackWebVital(e, t) {
|
|
4120
4163
|
if (!Number.isFinite(t)) {
|
|
4121
|
-
a("
|
|
4164
|
+
a("debug", "Invalid web vital value", { data: { type: e, value: t } });
|
|
4122
4165
|
return;
|
|
4123
4166
|
}
|
|
4124
4167
|
this.eventManager.track({
|
|
4125
|
-
type:
|
|
4168
|
+
type: d.WEB_VITALS,
|
|
4126
4169
|
web_vitals: {
|
|
4127
4170
|
type: e,
|
|
4128
4171
|
value: t
|
|
@@ -4155,10 +4198,10 @@ class Kt extends p {
|
|
|
4155
4198
|
const e = performance.getEntriesByType("navigation")[0];
|
|
4156
4199
|
if (!e)
|
|
4157
4200
|
return null;
|
|
4158
|
-
const t = e.startTime || performance.now(), r = ++this.navigationCounter,
|
|
4159
|
-
return r > 1 ? `${
|
|
4201
|
+
const t = e.startTime || performance.now(), r = ++this.navigationCounter, n = `${t.toFixed(2)}_${window.location.pathname}`;
|
|
4202
|
+
return r > 1 ? `${n}_${r}` : n;
|
|
4160
4203
|
} catch (e) {
|
|
4161
|
-
return a("
|
|
4204
|
+
return a("debug", "Failed to get navigation ID", { error: e }), null;
|
|
4162
4205
|
}
|
|
4163
4206
|
}
|
|
4164
4207
|
isObserverSupported(e) {
|
|
@@ -4166,7 +4209,7 @@ class Kt extends p {
|
|
|
4166
4209
|
const t = PerformanceObserver.supportedEntryTypes;
|
|
4167
4210
|
return !t || t.includes(e);
|
|
4168
4211
|
}
|
|
4169
|
-
safeObserve(e, t, r,
|
|
4212
|
+
safeObserve(e, t, r, n = !1) {
|
|
4170
4213
|
try {
|
|
4171
4214
|
if (!this.isObserverSupported(e))
|
|
4172
4215
|
return !1;
|
|
@@ -4174,20 +4217,20 @@ class Kt extends p {
|
|
|
4174
4217
|
try {
|
|
4175
4218
|
t(o, l);
|
|
4176
4219
|
} catch (c) {
|
|
4177
|
-
a("
|
|
4220
|
+
a("debug", "Observer callback failed", {
|
|
4178
4221
|
error: c,
|
|
4179
4222
|
data: { type: e }
|
|
4180
4223
|
});
|
|
4181
4224
|
}
|
|
4182
|
-
if (
|
|
4225
|
+
if (n)
|
|
4183
4226
|
try {
|
|
4184
4227
|
l.disconnect();
|
|
4185
4228
|
} catch {
|
|
4186
4229
|
}
|
|
4187
4230
|
});
|
|
4188
|
-
return i.observe(r ?? { type: e, buffered: !0 }),
|
|
4231
|
+
return i.observe(r ?? { type: e, buffered: !0 }), n || this.observers.push(i), !0;
|
|
4189
4232
|
} catch (i) {
|
|
4190
|
-
return a("
|
|
4233
|
+
return a("debug", "Failed to create performance observer", {
|
|
4191
4234
|
error: i,
|
|
4192
4235
|
data: { type: e }
|
|
4193
4236
|
}), !1;
|
|
@@ -4195,12 +4238,12 @@ class Kt extends p {
|
|
|
4195
4238
|
}
|
|
4196
4239
|
shouldSendVital(e, t) {
|
|
4197
4240
|
if (typeof t != "number" || !Number.isFinite(t))
|
|
4198
|
-
return a("
|
|
4241
|
+
return a("debug", "Invalid web vital value", { data: { type: e, value: t } }), !1;
|
|
4199
4242
|
const r = this.vitalThresholds[e];
|
|
4200
4243
|
return !(typeof r == "number" && t <= r);
|
|
4201
4244
|
}
|
|
4202
4245
|
}
|
|
4203
|
-
class
|
|
4246
|
+
class or extends T {
|
|
4204
4247
|
eventManager;
|
|
4205
4248
|
recentErrors = /* @__PURE__ */ new Map();
|
|
4206
4249
|
errorBurstCounter = 0;
|
|
@@ -4236,11 +4279,11 @@ class Yt extends p {
|
|
|
4236
4279
|
const e = Date.now();
|
|
4237
4280
|
if (e < this.burstBackoffUntil)
|
|
4238
4281
|
return !1;
|
|
4239
|
-
if (e - this.burstWindowStart >
|
|
4240
|
-
return this.burstBackoffUntil = e +
|
|
4282
|
+
if (e - this.burstWindowStart > wt && (this.errorBurstCounter = 0, this.burstWindowStart = e), this.errorBurstCounter++, this.errorBurstCounter > yt)
|
|
4283
|
+
return this.burstBackoffUntil = e + Ce, a("debug", "Error burst detected - entering cooldown", {
|
|
4241
4284
|
data: {
|
|
4242
4285
|
errorsInWindow: this.errorBurstCounter,
|
|
4243
|
-
cooldownMs:
|
|
4286
|
+
cooldownMs: Ce
|
|
4244
4287
|
}
|
|
4245
4288
|
}), !1;
|
|
4246
4289
|
const r = this.get("config")?.errorSampling ?? We;
|
|
@@ -4250,10 +4293,10 @@ class Yt extends p {
|
|
|
4250
4293
|
if (!this.shouldSample())
|
|
4251
4294
|
return;
|
|
4252
4295
|
const t = this.sanitize(e.message || "Unknown error");
|
|
4253
|
-
this.shouldSuppressError(
|
|
4254
|
-
type:
|
|
4296
|
+
this.shouldSuppressError(k.JS_ERROR, t) || this.eventManager.track({
|
|
4297
|
+
type: d.ERROR,
|
|
4255
4298
|
error_data: {
|
|
4256
|
-
type:
|
|
4299
|
+
type: k.JS_ERROR,
|
|
4257
4300
|
message: t,
|
|
4258
4301
|
...e.filename && { filename: e.filename },
|
|
4259
4302
|
...e.lineno && { line: e.lineno },
|
|
@@ -4265,10 +4308,10 @@ class Yt extends p {
|
|
|
4265
4308
|
if (!this.shouldSample())
|
|
4266
4309
|
return;
|
|
4267
4310
|
const t = this.extractRejectionMessage(e.reason), r = this.sanitize(t);
|
|
4268
|
-
this.shouldSuppressError(
|
|
4269
|
-
type:
|
|
4311
|
+
this.shouldSuppressError(k.PROMISE_REJECTION, r) || this.eventManager.track({
|
|
4312
|
+
type: d.ERROR,
|
|
4270
4313
|
error_data: {
|
|
4271
|
-
type:
|
|
4314
|
+
type: k.PROMISE_REJECTION,
|
|
4272
4315
|
message: r
|
|
4273
4316
|
}
|
|
4274
4317
|
});
|
|
@@ -4289,32 +4332,32 @@ class Yt extends p {
|
|
|
4289
4332
|
sanitize(e) {
|
|
4290
4333
|
let t = e.length > Le ? e.slice(0, Le) + "..." : e;
|
|
4291
4334
|
for (const r of Be) {
|
|
4292
|
-
const
|
|
4293
|
-
t = t.replace(
|
|
4335
|
+
const n = new RegExp(r.source, r.flags);
|
|
4336
|
+
t = t.replace(n, "[REDACTED]");
|
|
4294
4337
|
}
|
|
4295
4338
|
return t;
|
|
4296
4339
|
}
|
|
4297
4340
|
shouldSuppressError(e, t) {
|
|
4298
|
-
const r = Date.now(),
|
|
4299
|
-
return i && r - i <
|
|
4341
|
+
const r = Date.now(), n = `${e}:${t}`, i = this.recentErrors.get(n);
|
|
4342
|
+
return i && r - i < Me ? (this.recentErrors.set(n, r), !0) : (this.recentErrors.set(n, r), this.recentErrors.size > vt ? (this.recentErrors.clear(), this.recentErrors.set(n, r), !1) : (this.recentErrors.size > Q && this.pruneOldErrors(), !1));
|
|
4300
4343
|
}
|
|
4301
4344
|
pruneOldErrors() {
|
|
4302
4345
|
const e = Date.now();
|
|
4303
|
-
for (const [
|
|
4304
|
-
e - i >
|
|
4346
|
+
for (const [n, i] of this.recentErrors.entries())
|
|
4347
|
+
e - i > Me && this.recentErrors.delete(n);
|
|
4305
4348
|
if (this.recentErrors.size <= Q)
|
|
4306
4349
|
return;
|
|
4307
|
-
const t = Array.from(this.recentErrors.entries()).sort((
|
|
4308
|
-
for (let
|
|
4309
|
-
const i = t[
|
|
4350
|
+
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), r = this.recentErrors.size - Q;
|
|
4351
|
+
for (let n = 0; n < r; n += 1) {
|
|
4352
|
+
const i = t[n];
|
|
4310
4353
|
i && this.recentErrors.delete(i[0]);
|
|
4311
4354
|
}
|
|
4312
4355
|
}
|
|
4313
4356
|
}
|
|
4314
|
-
class
|
|
4357
|
+
class ar extends T {
|
|
4315
4358
|
isInitialized = !1;
|
|
4316
4359
|
suppressNextScrollTimer = null;
|
|
4317
|
-
emitter = new
|
|
4360
|
+
emitter = new Qt();
|
|
4318
4361
|
transformers = {};
|
|
4319
4362
|
managers = {};
|
|
4320
4363
|
handlers = {};
|
|
@@ -4330,9 +4373,9 @@ class qt extends p {
|
|
|
4330
4373
|
*/
|
|
4331
4374
|
async init(e = {}) {
|
|
4332
4375
|
if (!this.isInitialized) {
|
|
4333
|
-
this.managers.storage = new
|
|
4376
|
+
this.managers.storage = new nr();
|
|
4334
4377
|
try {
|
|
4335
|
-
this.setupState(e), this.managers.event = new
|
|
4378
|
+
this.setupState(e), this.managers.event = new Kt(this.managers.storage, this.emitter, this.transformers), this.initializeHandlers(), await this.managers.event.recoverPersistedEvents().catch((t) => {
|
|
4336
4379
|
a("warn", "Failed to recover persisted events", { error: t });
|
|
4337
4380
|
}), this.isInitialized = !0;
|
|
4338
4381
|
} catch (t) {
|
|
@@ -4356,14 +4399,14 @@ class qt extends p {
|
|
|
4356
4399
|
}
|
|
4357
4400
|
let r = t;
|
|
4358
4401
|
t && typeof t == "object" && !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && (r = Object.assign({}, t));
|
|
4359
|
-
const { valid:
|
|
4360
|
-
if (!
|
|
4361
|
-
if (this.get("mode") ===
|
|
4402
|
+
const { valid: n, error: i, sanitizedMetadata: o } = Xt(e, r);
|
|
4403
|
+
if (!n) {
|
|
4404
|
+
if (this.get("mode") === j.QA)
|
|
4362
4405
|
throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${i}`);
|
|
4363
4406
|
return;
|
|
4364
4407
|
}
|
|
4365
4408
|
this.managers.event.track({
|
|
4366
|
-
type:
|
|
4409
|
+
type: d.CUSTOM,
|
|
4367
4410
|
custom_event: {
|
|
4368
4411
|
name: e,
|
|
4369
4412
|
...o && { metadata: o }
|
|
@@ -4404,16 +4447,14 @@ class qt extends p {
|
|
|
4404
4447
|
}
|
|
4405
4448
|
setupState(e = {}) {
|
|
4406
4449
|
this.set("config", e);
|
|
4407
|
-
const t =
|
|
4450
|
+
const t = Yt.getId(this.managers.storage);
|
|
4408
4451
|
this.set("userId", t);
|
|
4409
|
-
const r =
|
|
4452
|
+
const r = Ut(e);
|
|
4410
4453
|
this.set("collectApiUrls", r);
|
|
4411
|
-
const
|
|
4412
|
-
this.set("device",
|
|
4413
|
-
const i =
|
|
4414
|
-
this.set("pageUrl", i);
|
|
4415
|
-
const o = It() ? z.QA : void 0;
|
|
4416
|
-
o && this.set("mode", o);
|
|
4454
|
+
const n = It();
|
|
4455
|
+
this.set("device", n);
|
|
4456
|
+
const i = le(window.location.href, e.sensitiveQueryParams);
|
|
4457
|
+
this.set("pageUrl", i), Ot() && this.set("mode", j.QA);
|
|
4417
4458
|
}
|
|
4418
4459
|
/**
|
|
4419
4460
|
* Returns the current configuration object.
|
|
@@ -4455,7 +4496,7 @@ class qt extends p {
|
|
|
4455
4496
|
valid: !1,
|
|
4456
4497
|
error: "Global metadata must be a plain object"
|
|
4457
4498
|
};
|
|
4458
|
-
const t =
|
|
4499
|
+
const t = ze("Global", e, "globalMetadata");
|
|
4459
4500
|
return t.valid ? { valid: !0 } : {
|
|
4460
4501
|
valid: !1,
|
|
4461
4502
|
error: t.error
|
|
@@ -4472,11 +4513,11 @@ class qt extends p {
|
|
|
4472
4513
|
const t = this.validateGlobalMetadata(e);
|
|
4473
4514
|
if (!t.valid)
|
|
4474
4515
|
throw new Error(`[TraceLog] Invalid global metadata: ${t.error}`);
|
|
4475
|
-
const
|
|
4516
|
+
const n = {
|
|
4476
4517
|
...this.get("config"),
|
|
4477
4518
|
globalMetadata: e
|
|
4478
4519
|
};
|
|
4479
|
-
this.set("config",
|
|
4520
|
+
this.set("config", n), a("debug", "Global metadata updated (replaced)", { data: { keys: Object.keys(e) } });
|
|
4480
4521
|
}
|
|
4481
4522
|
/**
|
|
4482
4523
|
* Merges new metadata with existing global metadata.
|
|
@@ -4499,106 +4540,106 @@ class qt extends p {
|
|
|
4499
4540
|
this.set("config", o), a("debug", "Global metadata updated (merged)", { data: { keys: Object.keys(e) } });
|
|
4500
4541
|
}
|
|
4501
4542
|
initializeHandlers() {
|
|
4502
|
-
const e = this.get("config")
|
|
4503
|
-
this.handlers.session = new
|
|
4543
|
+
const e = this.get("config");
|
|
4544
|
+
this.handlers.session = new Zt(
|
|
4504
4545
|
this.managers.storage,
|
|
4505
4546
|
this.managers.event
|
|
4506
4547
|
), this.handlers.session.startTracking();
|
|
4507
|
-
const
|
|
4548
|
+
const t = () => {
|
|
4508
4549
|
this.set("suppressNextScroll", !0), this.suppressNextScrollTimer && clearTimeout(this.suppressNextScrollTimer), this.suppressNextScrollTimer = window.setTimeout(() => {
|
|
4509
4550
|
this.set("suppressNextScroll", !1);
|
|
4510
4551
|
}, 500);
|
|
4511
4552
|
};
|
|
4512
|
-
this.handlers.pageView = new
|
|
4513
|
-
a("warn", "Failed to start performance tracking", { error:
|
|
4514
|
-
})
|
|
4553
|
+
this.handlers.pageView = new er(this.managers.event, t), this.handlers.pageView.startTracking(), this.handlers.click = new tr(this.managers.event), this.handlers.click.startTracking(), this.handlers.scroll = new rr(this.managers.event), this.handlers.scroll.startTracking(), this.handlers.performance = new ir(this.managers.event), this.handlers.performance.startTracking().catch((r) => {
|
|
4554
|
+
a("warn", "Failed to start performance tracking", { error: r });
|
|
4555
|
+
}), this.handlers.error = new or(this.managers.event), this.handlers.error.startTracking(), e.viewport && (this.handlers.viewport = new sr(this.managers.event), this.handlers.viewport.startTracking());
|
|
4515
4556
|
}
|
|
4516
4557
|
}
|
|
4517
|
-
const C = [],
|
|
4518
|
-
let f = null,
|
|
4519
|
-
const
|
|
4520
|
-
if (!(typeof window > "u" || typeof document > "u") && (_ = !1, window.__traceLogDisabled !== !0 && !f && !
|
|
4521
|
-
|
|
4558
|
+
const C = [], L = [];
|
|
4559
|
+
let f = null, M = !1, _ = !1;
|
|
4560
|
+
const lr = async (s) => {
|
|
4561
|
+
if (!(typeof window > "u" || typeof document > "u") && (_ = !1, window.__traceLogDisabled !== !0 && !f && !M)) {
|
|
4562
|
+
M = !0;
|
|
4522
4563
|
try {
|
|
4523
|
-
const e =
|
|
4564
|
+
const e = Bt(s ?? {}), t = new ar();
|
|
4524
4565
|
try {
|
|
4525
4566
|
C.forEach(({ event: i, callback: o }) => {
|
|
4526
4567
|
t.on(i, o);
|
|
4527
|
-
}), C.length = 0,
|
|
4568
|
+
}), C.length = 0, L.forEach(({ hook: i, fn: o }) => {
|
|
4528
4569
|
i === "beforeSend" ? t.setTransformer("beforeSend", o) : t.setTransformer("beforeBatch", o);
|
|
4529
|
-
}),
|
|
4530
|
-
const r = t.init(e),
|
|
4570
|
+
}), L.length = 0;
|
|
4571
|
+
const r = t.init(e), n = new Promise((i, o) => {
|
|
4531
4572
|
setTimeout(() => {
|
|
4532
4573
|
o(new Error("[TraceLog] Initialization timeout after 10000ms"));
|
|
4533
4574
|
}, 1e4);
|
|
4534
4575
|
});
|
|
4535
|
-
await Promise.race([r,
|
|
4576
|
+
await Promise.race([r, n]), f = t;
|
|
4536
4577
|
} catch (r) {
|
|
4537
4578
|
try {
|
|
4538
4579
|
t.destroy(!0);
|
|
4539
|
-
} catch (
|
|
4540
|
-
a("error", "Failed to cleanup partially initialized app", { error:
|
|
4580
|
+
} catch (n) {
|
|
4581
|
+
a("error", "Failed to cleanup partially initialized app", { error: n });
|
|
4541
4582
|
}
|
|
4542
4583
|
throw r;
|
|
4543
4584
|
}
|
|
4544
4585
|
} catch (e) {
|
|
4545
4586
|
throw f = null, e;
|
|
4546
4587
|
} finally {
|
|
4547
|
-
|
|
4588
|
+
M = !1;
|
|
4548
4589
|
}
|
|
4549
4590
|
}
|
|
4550
|
-
},
|
|
4591
|
+
}, cr = (s, e) => {
|
|
4551
4592
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4552
4593
|
if (!f)
|
|
4553
4594
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4554
4595
|
if (_)
|
|
4555
4596
|
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
4556
|
-
f.sendCustomEvent(
|
|
4597
|
+
f.sendCustomEvent(s, e);
|
|
4557
4598
|
}
|
|
4558
|
-
},
|
|
4599
|
+
}, ur = (s, e) => {
|
|
4559
4600
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4560
|
-
if (!f ||
|
|
4561
|
-
C.push({ event:
|
|
4601
|
+
if (!f || M) {
|
|
4602
|
+
C.push({ event: s, callback: e });
|
|
4562
4603
|
return;
|
|
4563
4604
|
}
|
|
4564
|
-
f.on(
|
|
4605
|
+
f.on(s, e);
|
|
4565
4606
|
}
|
|
4566
|
-
},
|
|
4607
|
+
}, dr = (s, e) => {
|
|
4567
4608
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4568
4609
|
if (!f) {
|
|
4569
|
-
const t = C.findIndex((r) => r.event ===
|
|
4610
|
+
const t = C.findIndex((r) => r.event === s && r.callback === e);
|
|
4570
4611
|
t !== -1 && C.splice(t, 1);
|
|
4571
4612
|
return;
|
|
4572
4613
|
}
|
|
4573
|
-
f.off(
|
|
4614
|
+
f.off(s, e);
|
|
4574
4615
|
}
|
|
4575
4616
|
};
|
|
4576
|
-
function
|
|
4617
|
+
function hr(s, e) {
|
|
4577
4618
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4578
4619
|
if (typeof e != "function")
|
|
4579
4620
|
throw new Error(`[TraceLog] Transformer must be a function, received: ${typeof e}`);
|
|
4580
|
-
if (!f ||
|
|
4581
|
-
const t =
|
|
4582
|
-
t !== -1 &&
|
|
4621
|
+
if (!f || M) {
|
|
4622
|
+
const t = L.findIndex((r) => r.hook === s);
|
|
4623
|
+
t !== -1 && L.splice(t, 1), L.push({ hook: s, fn: e });
|
|
4583
4624
|
return;
|
|
4584
4625
|
}
|
|
4585
4626
|
if (_)
|
|
4586
4627
|
throw new Error("[TraceLog] Cannot set transformers while TraceLog is being destroyed");
|
|
4587
|
-
|
|
4628
|
+
s === "beforeSend" ? f.setTransformer("beforeSend", e) : f.setTransformer("beforeBatch", e);
|
|
4588
4629
|
}
|
|
4589
4630
|
}
|
|
4590
|
-
const
|
|
4631
|
+
const fr = (s) => {
|
|
4591
4632
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4592
4633
|
if (!f) {
|
|
4593
|
-
const e =
|
|
4594
|
-
e !== -1 &&
|
|
4634
|
+
const e = L.findIndex((t) => t.hook === s);
|
|
4635
|
+
e !== -1 && L.splice(e, 1);
|
|
4595
4636
|
return;
|
|
4596
4637
|
}
|
|
4597
4638
|
if (_)
|
|
4598
4639
|
throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
|
|
4599
|
-
f.removeTransformer(
|
|
4640
|
+
f.removeTransformer(s);
|
|
4600
4641
|
}
|
|
4601
|
-
},
|
|
4642
|
+
}, mr = () => typeof window > "u" || typeof document > "u" ? !1 : f !== null, gr = () => {
|
|
4602
4643
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4603
4644
|
if (_)
|
|
4604
4645
|
throw new Error("[TraceLog] Destroy operation already in progress");
|
|
@@ -4608,273 +4649,273 @@ const nr = (n) => {
|
|
|
4608
4649
|
}
|
|
4609
4650
|
_ = !0;
|
|
4610
4651
|
try {
|
|
4611
|
-
f.destroy(), f = null,
|
|
4612
|
-
} catch (
|
|
4613
|
-
f = null,
|
|
4652
|
+
f.destroy(), f = null, M = !1, C.length = 0, L.length = 0, _ = !1;
|
|
4653
|
+
} catch (s) {
|
|
4654
|
+
f = null, M = !1, C.length = 0, L.length = 0, _ = !1, a("warn", "Error during destroy, forced cleanup completed", { error: s });
|
|
4614
4655
|
}
|
|
4615
4656
|
}
|
|
4616
|
-
},
|
|
4617
|
-
typeof window > "u" || typeof document > "u" ||
|
|
4618
|
-
},
|
|
4657
|
+
}, Er = (s) => {
|
|
4658
|
+
typeof window > "u" || typeof document > "u" || Pt(s);
|
|
4659
|
+
}, Sr = (s) => {
|
|
4619
4660
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4620
4661
|
if (!f)
|
|
4621
4662
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4622
4663
|
if (_)
|
|
4623
4664
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
4624
|
-
f.updateGlobalMetadata(
|
|
4665
|
+
f.updateGlobalMetadata(s);
|
|
4625
4666
|
}
|
|
4626
|
-
},
|
|
4667
|
+
}, pr = (s) => {
|
|
4627
4668
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4628
4669
|
if (!f)
|
|
4629
4670
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4630
4671
|
if (_)
|
|
4631
4672
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
4632
|
-
f.mergeGlobalMetadata(
|
|
4633
|
-
}
|
|
4634
|
-
},
|
|
4635
|
-
init:
|
|
4636
|
-
event:
|
|
4637
|
-
on:
|
|
4638
|
-
off:
|
|
4639
|
-
setTransformer:
|
|
4640
|
-
removeTransformer:
|
|
4641
|
-
isInitialized:
|
|
4642
|
-
destroy:
|
|
4643
|
-
setQaMode:
|
|
4644
|
-
updateGlobalMetadata:
|
|
4645
|
-
mergeGlobalMetadata:
|
|
4673
|
+
f.mergeGlobalMetadata(s);
|
|
4674
|
+
}
|
|
4675
|
+
}, Xr = {
|
|
4676
|
+
init: lr,
|
|
4677
|
+
event: cr,
|
|
4678
|
+
on: ur,
|
|
4679
|
+
off: dr,
|
|
4680
|
+
setTransformer: hr,
|
|
4681
|
+
removeTransformer: fr,
|
|
4682
|
+
isInitialized: mr,
|
|
4683
|
+
destroy: gr,
|
|
4684
|
+
setQaMode: Er,
|
|
4685
|
+
updateGlobalMetadata: Sr,
|
|
4686
|
+
mergeGlobalMetadata: pr
|
|
4646
4687
|
};
|
|
4647
|
-
var
|
|
4688
|
+
var ue, Ye = -1, O = function(s) {
|
|
4648
4689
|
addEventListener("pageshow", (function(e) {
|
|
4649
|
-
e.persisted && (
|
|
4690
|
+
e.persisted && (Ye = e.timeStamp, s(e));
|
|
4650
4691
|
}), !0);
|
|
4651
|
-
},
|
|
4652
|
-
var
|
|
4653
|
-
if (
|
|
4654
|
-
},
|
|
4655
|
-
var
|
|
4656
|
-
return
|
|
4657
|
-
}, y = function(
|
|
4658
|
-
var t =
|
|
4659
|
-
return
|
|
4660
|
-
},
|
|
4692
|
+
}, Ee = function() {
|
|
4693
|
+
var s = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
|
|
4694
|
+
if (s && s.responseStart > 0 && s.responseStart < performance.now()) return s;
|
|
4695
|
+
}, q = function() {
|
|
4696
|
+
var s = Ee();
|
|
4697
|
+
return s && s.activationStart || 0;
|
|
4698
|
+
}, y = function(s, e) {
|
|
4699
|
+
var t = Ee(), r = "navigate";
|
|
4700
|
+
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 };
|
|
4701
|
+
}, H = function(s, e, t) {
|
|
4661
4702
|
try {
|
|
4662
|
-
if (PerformanceObserver.supportedEntryTypes.includes(
|
|
4663
|
-
var r = new PerformanceObserver((function(
|
|
4703
|
+
if (PerformanceObserver.supportedEntryTypes.includes(s)) {
|
|
4704
|
+
var r = new PerformanceObserver((function(n) {
|
|
4664
4705
|
Promise.resolve().then((function() {
|
|
4665
|
-
e(
|
|
4706
|
+
e(n.getEntries());
|
|
4666
4707
|
}));
|
|
4667
4708
|
}));
|
|
4668
|
-
return r.observe(Object.assign({ type:
|
|
4709
|
+
return r.observe(Object.assign({ type: s, buffered: !0 }, t || {})), r;
|
|
4669
4710
|
}
|
|
4670
4711
|
} catch {
|
|
4671
4712
|
}
|
|
4672
|
-
}, b = function(
|
|
4673
|
-
var
|
|
4713
|
+
}, b = function(s, e, t, r) {
|
|
4714
|
+
var n, i;
|
|
4674
4715
|
return function(o) {
|
|
4675
|
-
e.value >= 0 && (o || r) && ((i = e.value - (
|
|
4716
|
+
e.value >= 0 && (o || r) && ((i = e.value - (n || 0)) || n === void 0) && (n = e.value, e.delta = i, e.rating = (function(l, c) {
|
|
4676
4717
|
return l > c[1] ? "poor" : l > c[0] ? "needs-improvement" : "good";
|
|
4677
|
-
})(e.value, t),
|
|
4718
|
+
})(e.value, t), s(e));
|
|
4678
4719
|
};
|
|
4679
|
-
},
|
|
4720
|
+
}, Se = function(s) {
|
|
4680
4721
|
requestAnimationFrame((function() {
|
|
4681
4722
|
return requestAnimationFrame((function() {
|
|
4682
|
-
return
|
|
4723
|
+
return s();
|
|
4683
4724
|
}));
|
|
4684
4725
|
}));
|
|
4685
|
-
},
|
|
4726
|
+
}, J = function(s) {
|
|
4686
4727
|
document.addEventListener("visibilitychange", (function() {
|
|
4687
|
-
document.visibilityState === "hidden" &&
|
|
4728
|
+
document.visibilityState === "hidden" && s();
|
|
4688
4729
|
}));
|
|
4689
|
-
},
|
|
4730
|
+
}, pe = function(s) {
|
|
4690
4731
|
var e = !1;
|
|
4691
4732
|
return function() {
|
|
4692
|
-
e || (
|
|
4733
|
+
e || (s(), e = !0);
|
|
4693
4734
|
};
|
|
4694
|
-
}, N = -1,
|
|
4735
|
+
}, N = -1, ke = function() {
|
|
4695
4736
|
return document.visibilityState !== "hidden" || document.prerendering ? 1 / 0 : 0;
|
|
4696
|
-
},
|
|
4697
|
-
document.visibilityState === "hidden" && N > -1 && (N =
|
|
4698
|
-
},
|
|
4699
|
-
addEventListener("visibilitychange",
|
|
4700
|
-
},
|
|
4701
|
-
removeEventListener("visibilitychange",
|
|
4702
|
-
},
|
|
4703
|
-
return N < 0 && (N =
|
|
4737
|
+
}, Y = function(s) {
|
|
4738
|
+
document.visibilityState === "hidden" && N > -1 && (N = s.type === "visibilitychange" ? s.timeStamp : 0, Tr());
|
|
4739
|
+
}, Ue = function() {
|
|
4740
|
+
addEventListener("visibilitychange", Y, !0), addEventListener("prerenderingchange", Y, !0);
|
|
4741
|
+
}, Tr = function() {
|
|
4742
|
+
removeEventListener("visibilitychange", Y, !0), removeEventListener("prerenderingchange", Y, !0);
|
|
4743
|
+
}, qe = function() {
|
|
4744
|
+
return N < 0 && (N = ke(), Ue(), O((function() {
|
|
4704
4745
|
setTimeout((function() {
|
|
4705
|
-
N =
|
|
4746
|
+
N = ke(), Ue();
|
|
4706
4747
|
}), 0);
|
|
4707
4748
|
}))), { get firstHiddenTime() {
|
|
4708
4749
|
return N;
|
|
4709
4750
|
} };
|
|
4710
|
-
},
|
|
4751
|
+
}, Z = function(s) {
|
|
4711
4752
|
document.prerendering ? addEventListener("prerenderingchange", (function() {
|
|
4712
|
-
return
|
|
4713
|
-
}), !0) :
|
|
4714
|
-
},
|
|
4715
|
-
e = e || {},
|
|
4716
|
-
var t, r =
|
|
4753
|
+
return s();
|
|
4754
|
+
}), !0) : s();
|
|
4755
|
+
}, de = [1800, 3e3], Je = function(s, e) {
|
|
4756
|
+
e = e || {}, Z((function() {
|
|
4757
|
+
var t, r = qe(), n = y("FCP"), i = H("paint", (function(o) {
|
|
4717
4758
|
o.forEach((function(l) {
|
|
4718
|
-
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime < r.firstHiddenTime && (
|
|
4759
|
+
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)));
|
|
4719
4760
|
}));
|
|
4720
4761
|
}));
|
|
4721
|
-
i && (t = b(
|
|
4722
|
-
|
|
4723
|
-
|
|
4762
|
+
i && (t = b(s, n, de, e.reportAllChanges), O((function(o) {
|
|
4763
|
+
n = y("FCP"), t = b(s, n, de, e.reportAllChanges), Se((function() {
|
|
4764
|
+
n.value = performance.now() - o.timeStamp, t(!0);
|
|
4724
4765
|
}));
|
|
4725
4766
|
})));
|
|
4726
4767
|
}));
|
|
4727
|
-
},
|
|
4728
|
-
e = e || {},
|
|
4729
|
-
var t, r = y("CLS", 0),
|
|
4730
|
-
c.forEach((function(
|
|
4731
|
-
if (!
|
|
4732
|
-
var
|
|
4733
|
-
|
|
4768
|
+
}, he = [0.1, 0.25], _r = function(s, e) {
|
|
4769
|
+
e = e || {}, Je(pe((function() {
|
|
4770
|
+
var t, r = y("CLS", 0), n = 0, i = [], o = function(c) {
|
|
4771
|
+
c.forEach((function(u) {
|
|
4772
|
+
if (!u.hadRecentInput) {
|
|
4773
|
+
var S = i[0], E = i[i.length - 1];
|
|
4774
|
+
n && u.startTime - E.startTime < 1e3 && u.startTime - S.startTime < 5e3 ? (n += u.value, i.push(u)) : (n = u.value, i = [u]);
|
|
4734
4775
|
}
|
|
4735
|
-
})),
|
|
4736
|
-
}, l =
|
|
4737
|
-
l && (t = b(
|
|
4776
|
+
})), n > r.value && (r.value = n, r.entries = i, t());
|
|
4777
|
+
}, l = H("layout-shift", o);
|
|
4778
|
+
l && (t = b(s, r, he, e.reportAllChanges), J((function() {
|
|
4738
4779
|
o(l.takeRecords()), t(!0);
|
|
4739
4780
|
})), O((function() {
|
|
4740
|
-
|
|
4781
|
+
n = 0, r = y("CLS", 0), t = b(s, r, he, e.reportAllChanges), Se((function() {
|
|
4741
4782
|
return t();
|
|
4742
4783
|
}));
|
|
4743
4784
|
})), setTimeout(t, 0));
|
|
4744
4785
|
})));
|
|
4745
|
-
},
|
|
4746
|
-
|
|
4747
|
-
e.interactionId && (
|
|
4786
|
+
}, Ze = 0, re = 1 / 0, G = 0, Ir = function(s) {
|
|
4787
|
+
s.forEach((function(e) {
|
|
4788
|
+
e.interactionId && (re = Math.min(re, e.interactionId), G = Math.max(G, e.interactionId), Ze = G ? (G - re) / 7 + 1 : 0);
|
|
4748
4789
|
}));
|
|
4749
|
-
},
|
|
4750
|
-
return
|
|
4751
|
-
},
|
|
4752
|
-
"interactionCount" in performance ||
|
|
4753
|
-
}, w = [],
|
|
4754
|
-
var
|
|
4755
|
-
return w[
|
|
4756
|
-
},
|
|
4757
|
-
if (
|
|
4758
|
-
return s
|
|
4759
|
-
})),
|
|
4760
|
-
var e = w[w.length - 1], t =
|
|
4761
|
-
if (t || w.length < 10 ||
|
|
4762
|
-
if (t)
|
|
4790
|
+
}, et = function() {
|
|
4791
|
+
return ue ? Ze : performance.interactionCount || 0;
|
|
4792
|
+
}, vr = function() {
|
|
4793
|
+
"interactionCount" in performance || ue || (ue = H("event", Ir, { type: "event", buffered: !0, durationThreshold: 0 }));
|
|
4794
|
+
}, w = [], z = /* @__PURE__ */ new Map(), tt = 0, wr = function() {
|
|
4795
|
+
var s = Math.min(w.length - 1, Math.floor((et() - tt) / 50));
|
|
4796
|
+
return w[s];
|
|
4797
|
+
}, yr = [], br = function(s) {
|
|
4798
|
+
if (yr.forEach((function(n) {
|
|
4799
|
+
return n(s);
|
|
4800
|
+
})), s.interactionId || s.entryType === "first-input") {
|
|
4801
|
+
var e = w[w.length - 1], t = z.get(s.interactionId);
|
|
4802
|
+
if (t || w.length < 10 || s.duration > e.latency) {
|
|
4803
|
+
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);
|
|
4763
4804
|
else {
|
|
4764
|
-
var r = { id:
|
|
4765
|
-
|
|
4805
|
+
var r = { id: s.interactionId, latency: s.duration, entries: [s] };
|
|
4806
|
+
z.set(r.id, r), w.push(r);
|
|
4766
4807
|
}
|
|
4767
|
-
w.sort((function(
|
|
4768
|
-
return i.latency -
|
|
4769
|
-
})), w.length > 10 && w.splice(10).forEach((function(
|
|
4770
|
-
return
|
|
4808
|
+
w.sort((function(n, i) {
|
|
4809
|
+
return i.latency - n.latency;
|
|
4810
|
+
})), w.length > 10 && w.splice(10).forEach((function(n) {
|
|
4811
|
+
return z.delete(n.id);
|
|
4771
4812
|
}));
|
|
4772
4813
|
}
|
|
4773
4814
|
}
|
|
4774
|
-
},
|
|
4815
|
+
}, rt = function(s) {
|
|
4775
4816
|
var e = self.requestIdleCallback || self.setTimeout, t = -1;
|
|
4776
|
-
return
|
|
4777
|
-
},
|
|
4778
|
-
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {},
|
|
4817
|
+
return s = pe(s), document.visibilityState === "hidden" ? s() : (t = e(s), J(s)), t;
|
|
4818
|
+
}, fe = [200, 500], Ar = function(s, e) {
|
|
4819
|
+
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, Z((function() {
|
|
4779
4820
|
var t;
|
|
4780
|
-
|
|
4781
|
-
var r,
|
|
4782
|
-
|
|
4783
|
-
l.forEach(
|
|
4784
|
-
var c =
|
|
4785
|
-
c && c.latency !==
|
|
4821
|
+
vr();
|
|
4822
|
+
var r, n = y("INP"), i = function(l) {
|
|
4823
|
+
rt((function() {
|
|
4824
|
+
l.forEach(br);
|
|
4825
|
+
var c = wr();
|
|
4826
|
+
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, r());
|
|
4786
4827
|
}));
|
|
4787
|
-
}, o =
|
|
4788
|
-
r = b(
|
|
4828
|
+
}, o = H("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
|
|
4829
|
+
r = b(s, n, fe, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), J((function() {
|
|
4789
4830
|
i(o.takeRecords()), r(!0);
|
|
4790
4831
|
})), O((function() {
|
|
4791
|
-
|
|
4832
|
+
tt = et(), w.length = 0, z.clear(), n = y("INP"), r = b(s, n, fe, e.reportAllChanges);
|
|
4792
4833
|
})));
|
|
4793
4834
|
})));
|
|
4794
|
-
},
|
|
4795
|
-
e = e || {},
|
|
4796
|
-
var t, r =
|
|
4797
|
-
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(
|
|
4798
|
-
|
|
4835
|
+
}, me = [2500, 4e3], se = {}, Lr = function(s, e) {
|
|
4836
|
+
e = e || {}, Z((function() {
|
|
4837
|
+
var t, r = qe(), n = y("LCP"), i = function(c) {
|
|
4838
|
+
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(u) {
|
|
4839
|
+
u.startTime < r.firstHiddenTime && (n.value = Math.max(u.startTime - q(), 0), n.entries = [u], t());
|
|
4799
4840
|
}));
|
|
4800
|
-
}, o =
|
|
4841
|
+
}, o = H("largest-contentful-paint", i);
|
|
4801
4842
|
if (o) {
|
|
4802
|
-
t = b(
|
|
4803
|
-
var l =
|
|
4804
|
-
|
|
4843
|
+
t = b(s, n, me, e.reportAllChanges);
|
|
4844
|
+
var l = pe((function() {
|
|
4845
|
+
se[n.id] || (i(o.takeRecords()), o.disconnect(), se[n.id] = !0, t(!0));
|
|
4805
4846
|
}));
|
|
4806
4847
|
["keydown", "click"].forEach((function(c) {
|
|
4807
4848
|
addEventListener(c, (function() {
|
|
4808
|
-
return
|
|
4849
|
+
return rt(l);
|
|
4809
4850
|
}), { once: !0, capture: !0 });
|
|
4810
|
-
})),
|
|
4811
|
-
|
|
4812
|
-
|
|
4851
|
+
})), J(l), O((function(c) {
|
|
4852
|
+
n = y("LCP"), t = b(s, n, me, e.reportAllChanges), Se((function() {
|
|
4853
|
+
n.value = performance.now() - c.timeStamp, se[n.id] = !0, t(!0);
|
|
4813
4854
|
}));
|
|
4814
4855
|
}));
|
|
4815
4856
|
}
|
|
4816
4857
|
}));
|
|
4817
|
-
},
|
|
4818
|
-
document.prerendering ?
|
|
4819
|
-
return
|
|
4858
|
+
}, ge = [800, 1800], Mr = function s(e) {
|
|
4859
|
+
document.prerendering ? Z((function() {
|
|
4860
|
+
return s(e);
|
|
4820
4861
|
})) : document.readyState !== "complete" ? addEventListener("load", (function() {
|
|
4821
|
-
return
|
|
4862
|
+
return s(e);
|
|
4822
4863
|
}), !0) : setTimeout(e, 0);
|
|
4823
|
-
},
|
|
4864
|
+
}, Cr = function(s, e) {
|
|
4824
4865
|
e = e || {};
|
|
4825
|
-
var t = y("TTFB"), r = b(
|
|
4826
|
-
|
|
4827
|
-
var
|
|
4828
|
-
|
|
4829
|
-
t = y("TTFB", 0), (r = b(
|
|
4866
|
+
var t = y("TTFB"), r = b(s, t, ge, e.reportAllChanges);
|
|
4867
|
+
Mr((function() {
|
|
4868
|
+
var n = Ee();
|
|
4869
|
+
n && (t.value = Math.max(n.responseStart - q(), 0), t.entries = [n], r(!0), O((function() {
|
|
4870
|
+
t = y("TTFB", 0), (r = b(s, t, ge, e.reportAllChanges))(!0);
|
|
4830
4871
|
})));
|
|
4831
4872
|
}));
|
|
4832
4873
|
};
|
|
4833
|
-
const
|
|
4874
|
+
const Rr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4834
4875
|
__proto__: null,
|
|
4835
|
-
CLSThresholds:
|
|
4836
|
-
FCPThresholds:
|
|
4837
|
-
INPThresholds:
|
|
4838
|
-
LCPThresholds:
|
|
4839
|
-
TTFBThresholds:
|
|
4840
|
-
onCLS:
|
|
4841
|
-
onFCP:
|
|
4842
|
-
onINP:
|
|
4843
|
-
onLCP:
|
|
4844
|
-
onTTFB:
|
|
4876
|
+
CLSThresholds: he,
|
|
4877
|
+
FCPThresholds: de,
|
|
4878
|
+
INPThresholds: fe,
|
|
4879
|
+
LCPThresholds: me,
|
|
4880
|
+
TTFBThresholds: ge,
|
|
4881
|
+
onCLS: _r,
|
|
4882
|
+
onFCP: Je,
|
|
4883
|
+
onINP: Ar,
|
|
4884
|
+
onLCP: Lr,
|
|
4885
|
+
onTTFB: Cr
|
|
4845
4886
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
4846
4887
|
export {
|
|
4847
4888
|
h as AppConfigValidationError,
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4889
|
+
Nr as DEFAULT_SESSION_TIMEOUT,
|
|
4890
|
+
ae as DEFAULT_WEB_VITALS_MODE,
|
|
4891
|
+
A as DeviceType,
|
|
4851
4892
|
ne as EmitterEvent,
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4893
|
+
k as ErrorType,
|
|
4894
|
+
d as EventType,
|
|
4895
|
+
Wr as InitializationTimeoutError,
|
|
4896
|
+
D as IntegrationValidationError,
|
|
4897
|
+
Fr as MAX_ARRAY_LENGTH,
|
|
4898
|
+
Vr as MAX_CUSTOM_EVENT_ARRAY_SIZE,
|
|
4899
|
+
Dr as MAX_CUSTOM_EVENT_KEYS,
|
|
4900
|
+
Or as MAX_CUSTOM_EVENT_NAME_LENGTH,
|
|
4901
|
+
Pr as MAX_CUSTOM_EVENT_STRING_SIZE,
|
|
4902
|
+
Ur as MAX_METADATA_NESTING_DEPTH,
|
|
4903
|
+
kr as MAX_NESTED_OBJECT_KEYS,
|
|
4904
|
+
xr as MAX_STRING_LENGTH,
|
|
4905
|
+
Hr as MAX_STRING_LENGTH_IN_ARRAY,
|
|
4906
|
+
j as Mode,
|
|
4866
4907
|
Be as PII_PATTERNS,
|
|
4867
4908
|
R as PermanentError,
|
|
4868
4909
|
Ae as SamplingRateValidationError,
|
|
4869
4910
|
X as ScrollDirection,
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4911
|
+
ut as SessionTimeoutValidationError,
|
|
4912
|
+
V as SpecialApiUrl,
|
|
4913
|
+
x as TraceLogValidationError,
|
|
4914
|
+
Gr as WEB_VITALS_GOOD_THRESHOLDS,
|
|
4915
|
+
Re as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
|
|
4916
|
+
At as WEB_VITALS_POOR_THRESHOLDS,
|
|
4917
|
+
Ne as getWebVitalsThresholds,
|
|
4918
|
+
$r as isPrimaryScrollEvent,
|
|
4919
|
+
Br as isSecondaryScrollEvent,
|
|
4920
|
+
Xr as tracelog
|
|
4880
4921
|
};
|