@tracelog/lib 2.8.0 → 2.8.1-rc.101.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/tracelog.esm.js +577 -543
- package/dist/browser/tracelog.esm.js.map +1 -1
- package/dist/browser/tracelog.js +2 -2
- package/dist/browser/tracelog.js.map +1 -1
- package/dist/public-api.cjs +2 -2
- package/dist/public-api.cjs.map +1 -1
- package/dist/public-api.d.mts +9 -1
- package/dist/public-api.d.ts +9 -1
- package/dist/public-api.js +2 -2
- package/dist/public-api.js.map +1 -1
- package/package.json +3 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const Er = 1e3,
|
|
4
|
-
const b = "data-tlog",
|
|
1
|
+
const dr = 9e5;
|
|
2
|
+
const ur = 120, hr = 49152, fr = 100, mr = 500, gr = 200;
|
|
3
|
+
const Er = 1e3, pr = 500, Sr = 1e3;
|
|
4
|
+
const b = "data-tlog", At = [
|
|
5
5
|
"button",
|
|
6
6
|
"a",
|
|
7
7
|
'input[type="button"]',
|
|
@@ -33,7 +33,7 @@ const b = "data-tlog", bt = [
|
|
|
33
33
|
".menu-item",
|
|
34
34
|
"[data-testid]",
|
|
35
35
|
'[tabindex="0"]'
|
|
36
|
-
],
|
|
36
|
+
], Lt = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"], Mt = [
|
|
37
37
|
"token",
|
|
38
38
|
"auth",
|
|
39
39
|
"key",
|
|
@@ -49,7 +49,7 @@ const b = "data-tlog", bt = [
|
|
|
49
49
|
"code",
|
|
50
50
|
"otp"
|
|
51
51
|
];
|
|
52
|
-
const
|
|
52
|
+
const E = {
|
|
53
53
|
INVALID_SESSION_TIMEOUT: "Session timeout must be between 30000ms (30 seconds) and 86400000ms (24 hours)",
|
|
54
54
|
INVALID_SAMPLING_RATE: "Sampling rate must be between 0 and 1",
|
|
55
55
|
INVALID_ERROR_SAMPLING_RATE: "Error sampling must be between 0 and 1",
|
|
@@ -72,63 +72,67 @@ const m = {
|
|
|
72
72
|
INVALID_VIEWPORT_COOLDOWN_PERIOD: "Viewport cooldownPeriod must be a non-negative number",
|
|
73
73
|
INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS: "Viewport maxTrackedElements must be a positive number",
|
|
74
74
|
INVALID_SEND_INTERVAL: "Send interval must be between 1000ms (1 second) and 60000ms (60 seconds)"
|
|
75
|
-
},
|
|
75
|
+
}, Ct = [
|
|
76
76
|
/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
|
77
77
|
/javascript:/gi,
|
|
78
78
|
/on\w+\s*=/gi,
|
|
79
79
|
/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
|
|
80
80
|
/<embed\b[^>]*>/gi,
|
|
81
81
|
/<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi
|
|
82
|
-
], I = "tlog",
|
|
83
|
-
var
|
|
82
|
+
], I = "tlog", X = `${I}:qa_mode`, Te = `${I}:uid`, nt = "tlog_mode", He = "qa", Fe = "qa_off", Rt = (r) => r ? `${I}:${r}:queue` : `${I}:queue`, Nt = (r) => r ? `${I}:${r}:session` : `${I}:session`, Ot = (r) => r ? `${I}:${r}:broadcast` : `${I}:broadcast`, xe = (r, e) => `${I}:${r}:session_counts:${e}`, $e = 10080 * 60 * 1e3, Be = `${I}:session_counts_last_cleanup`, We = 3600 * 1e3, fe = (r) => r ? `${I}:${r}:identity` : `${I}:identity`, U = `${I}:pending_identity`;
|
|
83
|
+
var $ = /* @__PURE__ */ ((r) => (r.Localhost = "localhost:8080", r.Fail = "localhost:9999", r))($ || {}), L = /* @__PURE__ */ ((r) => (r.Mobile = "mobile", r.Tablet = "tablet", r.Desktop = "desktop", r.Unknown = "unknown", r))(L || {}), se = /* @__PURE__ */ ((r) => (r.EVENT = "event", r.QUEUE = "queue", r))(se || {});
|
|
84
84
|
class O extends Error {
|
|
85
85
|
constructor(e, t) {
|
|
86
86
|
super(e), this.statusCode = t, this.name = "PermanentError", Error.captureStackTrace && Error.captureStackTrace(this, O);
|
|
87
87
|
}
|
|
88
|
+
statusCode;
|
|
88
89
|
}
|
|
89
|
-
class
|
|
90
|
+
class re extends Error {
|
|
90
91
|
constructor(e) {
|
|
91
|
-
super(e), this.name = "RateLimitError", Error.captureStackTrace && Error.captureStackTrace(this,
|
|
92
|
+
super(e), this.name = "RateLimitError", Error.captureStackTrace && Error.captureStackTrace(this, re);
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
|
-
class
|
|
95
|
+
class ne extends Error {
|
|
95
96
|
constructor(e) {
|
|
96
|
-
super(e), this.name = "TimeoutError", Error.captureStackTrace && Error.captureStackTrace(this,
|
|
97
|
+
super(e), this.name = "TimeoutError", Error.captureStackTrace && Error.captureStackTrace(this, ne);
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
|
-
var
|
|
100
|
-
const Tr = (r) => r.type ===
|
|
101
|
-
class
|
|
100
|
+
var u = /* @__PURE__ */ ((r) => (r.PAGE_VIEW = "page_view", r.CLICK = "click", r.SCROLL = "scroll", r.SESSION_START = "session_start", r.CUSTOM = "custom", r.WEB_VITALS = "web_vitals", r.ERROR = "error", r.VIEWPORT_VISIBLE = "viewport_visible", r))(u || {}), Z = /* @__PURE__ */ ((r) => (r.UP = "up", r.DOWN = "down", r))(Z || {}), B = /* @__PURE__ */ ((r) => (r.JS_ERROR = "js_error", r.PROMISE_REJECTION = "promise_rejection", r))(B || {}), ie = /* @__PURE__ */ ((r) => (r.QA = "qa", r))(ie || {});
|
|
101
|
+
const Tr = (r) => r.type === u.SCROLL && "scroll_data" in r && r.scroll_data.is_primary === !0, Ir = (r) => r.type === u.SCROLL && "scroll_data" in r && r.scroll_data.is_primary === !1;
|
|
102
|
+
class j extends Error {
|
|
102
103
|
constructor(e, t, s) {
|
|
103
104
|
super(e), this.errorCode = t, this.layer = s, this.name = this.constructor.name, Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
|
|
104
105
|
}
|
|
106
|
+
errorCode;
|
|
107
|
+
layer;
|
|
105
108
|
}
|
|
106
|
-
class
|
|
109
|
+
class m extends j {
|
|
107
110
|
constructor(e, t = "config") {
|
|
108
111
|
super(e, "APP_CONFIG_INVALID", t);
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
|
-
class
|
|
114
|
+
class Pt extends j {
|
|
112
115
|
constructor(e, t = "config") {
|
|
113
116
|
super(e, "SESSION_TIMEOUT_INVALID", t);
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
|
-
class
|
|
119
|
+
class Xe extends j {
|
|
117
120
|
constructor(e, t = "config") {
|
|
118
121
|
super(e, "SAMPLING_RATE_INVALID", t);
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
|
-
class N extends
|
|
124
|
+
class N extends j {
|
|
122
125
|
constructor(e, t = "config") {
|
|
123
126
|
super(e, "INTEGRATION_INVALID", t);
|
|
124
127
|
}
|
|
125
128
|
}
|
|
126
|
-
class vr extends
|
|
129
|
+
class vr extends j {
|
|
127
130
|
constructor(e, t, s = "runtime") {
|
|
128
131
|
super(e, "INITIALIZATION_TIMEOUT", s), this.timeoutMs = t;
|
|
129
132
|
}
|
|
133
|
+
timeoutMs;
|
|
130
134
|
}
|
|
131
|
-
const
|
|
135
|
+
const it = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", ot = "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;", kt = (r, e) => {
|
|
132
136
|
if (e) {
|
|
133
137
|
if (e instanceof Error) {
|
|
134
138
|
const t = e.message.replace(/\s+at\s+.*$/gm, "").replace(/\s*\([^()]+:\d+:\d+\)/g, "");
|
|
@@ -147,21 +151,21 @@ const nt = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8
|
|
|
147
151
|
return `[TraceLog] ${r}: ${String(e)}`;
|
|
148
152
|
}
|
|
149
153
|
return `[TraceLog] ${r}`;
|
|
150
|
-
},
|
|
154
|
+
}, Vt = () => {
|
|
151
155
|
if (typeof window > "u" || typeof sessionStorage > "u")
|
|
152
156
|
return !1;
|
|
153
157
|
try {
|
|
154
|
-
return sessionStorage.getItem(
|
|
158
|
+
return sessionStorage.getItem(X) === "true";
|
|
155
159
|
} catch {
|
|
156
160
|
return !1;
|
|
157
161
|
}
|
|
158
162
|
}, a = (r, e, t) => {
|
|
159
|
-
const { error: s, data: n, showToClient: i = !1, style: o, visibility: l } = t ?? {}, c = s ?
|
|
160
|
-
if (!
|
|
163
|
+
const { error: s, data: n, showToClient: i = !1, style: o, visibility: l } = t ?? {}, c = s ? kt(e, s) : `[TraceLog] ${e}`, d = r === "error" ? "error" : r === "warn" ? "warn" : "log";
|
|
164
|
+
if (!Ut(l, i))
|
|
161
165
|
return;
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
},
|
|
166
|
+
const g = Ht(l, o), T = n !== void 0 ? Ie(n) : void 0;
|
|
167
|
+
Ft(d, c, g, T);
|
|
168
|
+
}, Ut = (r, e) => r === "critical" ? !0 : r === "qa" || e ? Vt() : !1, Ht = (r, e) => e !== void 0 && e !== "" ? e : r === "critical" ? Dt : "", Ft = (r, e, t, s) => {
|
|
165
169
|
const n = t !== void 0 && t !== "", i = n ? `%c${e}` : e;
|
|
166
170
|
s !== void 0 ? n ? console[r](i, t, s) : console[r](i, s) : n ? console[r](i, t) : console[r](i);
|
|
167
171
|
}, Ie = (r) => {
|
|
@@ -178,10 +182,10 @@ const nt = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8
|
|
|
178
182
|
}
|
|
179
183
|
return e;
|
|
180
184
|
};
|
|
181
|
-
let ve,
|
|
182
|
-
const
|
|
183
|
-
typeof window < "u" && !ve && (ve = window.matchMedia("(pointer: coarse)"),
|
|
184
|
-
}, oe = "Unknown",
|
|
185
|
+
let ve, at;
|
|
186
|
+
const xt = () => {
|
|
187
|
+
typeof window < "u" && !ve && (ve = window.matchMedia("(pointer: coarse)"), at = window.matchMedia("(hover: none)"));
|
|
188
|
+
}, oe = "Unknown", $t = (r) => {
|
|
185
189
|
const e = r.userAgentData?.platform;
|
|
186
190
|
if (e != null && e !== "") {
|
|
187
191
|
if (/windows/i.test(e)) return "Windows";
|
|
@@ -193,7 +197,7 @@ const Ft = () => {
|
|
|
193
197
|
}
|
|
194
198
|
const t = navigator.userAgent;
|
|
195
199
|
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" : oe;
|
|
196
|
-
},
|
|
200
|
+
}, Bt = (r) => {
|
|
197
201
|
const e = r.userAgentData?.brands;
|
|
198
202
|
if (e != null && e.length > 0) {
|
|
199
203
|
const n = e.filter((i) => !/not.?a.?brand|chromium/i.test(i.brand))[0];
|
|
@@ -204,26 +208,26 @@ const Ft = () => {
|
|
|
204
208
|
}
|
|
205
209
|
const t = navigator.userAgent;
|
|
206
210
|
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" : oe;
|
|
207
|
-
},
|
|
211
|
+
}, Wt = () => {
|
|
208
212
|
try {
|
|
209
213
|
const r = navigator;
|
|
210
214
|
if (r.userAgentData != null && typeof r.userAgentData.mobile == "boolean") {
|
|
211
215
|
const c = r.userAgentData.platform;
|
|
212
216
|
return c != null && c !== "" && /ipad|tablet/i.test(c) ? L.Tablet : r.userAgentData.mobile ? L.Mobile : L.Desktop;
|
|
213
217
|
}
|
|
214
|
-
|
|
215
|
-
const e = window.innerWidth, t = ve?.matches ?? !1, s =
|
|
218
|
+
xt();
|
|
219
|
+
const e = window.innerWidth, t = ve?.matches ?? !1, s = at?.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);
|
|
216
220
|
return e <= 767 || o && n ? L.Mobile : e >= 768 && e <= 1024 || l || t && s && n ? L.Tablet : L.Desktop;
|
|
217
221
|
} catch (r) {
|
|
218
222
|
return a("debug", "Device detection failed, defaulting to desktop", { error: r }), L.Desktop;
|
|
219
223
|
}
|
|
220
|
-
},
|
|
224
|
+
}, Xt = () => {
|
|
221
225
|
try {
|
|
222
226
|
const r = navigator;
|
|
223
227
|
return {
|
|
224
|
-
type:
|
|
225
|
-
os:
|
|
226
|
-
browser:
|
|
228
|
+
type: Wt(),
|
|
229
|
+
os: $t(r),
|
|
230
|
+
browser: Bt(r)
|
|
227
231
|
};
|
|
228
232
|
} catch (r) {
|
|
229
233
|
return a("debug", "Device info detection failed, using defaults", { error: r }), {
|
|
@@ -232,7 +236,7 @@ const Ft = () => {
|
|
|
232
236
|
browser: oe
|
|
233
237
|
};
|
|
234
238
|
}
|
|
235
|
-
},
|
|
239
|
+
}, lt = [
|
|
236
240
|
// Email addresses
|
|
237
241
|
/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/gi,
|
|
238
242
|
// US Phone numbers (various formats)
|
|
@@ -249,7 +253,7 @@ const Ft = () => {
|
|
|
249
253
|
/:\/\/[^:/]+:([^@]+)@/gi,
|
|
250
254
|
// Sensitive URL query parameters (token=, password=, auth=, secret=, api_key=, etc.)
|
|
251
255
|
/[?&](token|password|passwd|auth|secret|secret_key|private_key|auth_key|api_key|apikey|access_token)=[^&\s]+/gi
|
|
252
|
-
],
|
|
256
|
+
], Ge = 500, je = 2e3, ze = 5e3, ee = 50, Gt = ee * 2, ct = 1, jt = 1e3, zt = 10, Qe = 5e3, Qt = 6e4, _r = {
|
|
253
257
|
LCP: 2500,
|
|
254
258
|
// Good: ≤ 2.5s
|
|
255
259
|
FCP: 1800,
|
|
@@ -261,7 +265,7 @@ const Ft = () => {
|
|
|
261
265
|
TTFB: 800,
|
|
262
266
|
// Good: ≤ 800ms
|
|
263
267
|
LONG_TASK: 50
|
|
264
|
-
},
|
|
268
|
+
}, Ke = {
|
|
265
269
|
LCP: 2500,
|
|
266
270
|
// Needs improvement: > 2.5s (same as good boundary)
|
|
267
271
|
FCP: 1800,
|
|
@@ -273,7 +277,7 @@ const Ft = () => {
|
|
|
273
277
|
TTFB: 800,
|
|
274
278
|
// Needs improvement: > 800ms
|
|
275
279
|
LONG_TASK: 50
|
|
276
|
-
},
|
|
280
|
+
}, Kt = {
|
|
277
281
|
LCP: 4e3,
|
|
278
282
|
// Poor: > 4s
|
|
279
283
|
FCP: 3e3,
|
|
@@ -285,53 +289,53 @@ const Ft = () => {
|
|
|
285
289
|
TTFB: 1800,
|
|
286
290
|
// Poor: > 1800ms
|
|
287
291
|
LONG_TASK: 50
|
|
288
|
-
}, _e = "needs-improvement",
|
|
292
|
+
}, _e = "needs-improvement", Ye = (r = _e) => {
|
|
289
293
|
switch (r) {
|
|
290
294
|
case "all":
|
|
291
295
|
return { LCP: 0, FCP: 0, CLS: 0, INP: 0, TTFB: 0, LONG_TASK: 0 };
|
|
292
296
|
// Track everything
|
|
293
297
|
case "needs-improvement":
|
|
294
|
-
return
|
|
298
|
+
return Ke;
|
|
295
299
|
case "poor":
|
|
296
|
-
return
|
|
300
|
+
return Kt;
|
|
297
301
|
default:
|
|
298
|
-
return
|
|
302
|
+
return Ke;
|
|
299
303
|
}
|
|
300
|
-
},
|
|
304
|
+
}, Yt = 1e3, qt = 50, Jt = "2.8.1", Zt = Jt, dt = () => typeof window < "u" && typeof sessionStorage < "u", es = () => {
|
|
301
305
|
try {
|
|
302
306
|
const r = new URLSearchParams(window.location.search);
|
|
303
|
-
r.delete(
|
|
307
|
+
r.delete(nt);
|
|
304
308
|
const e = r.toString(), t = window.location.pathname + (e ? "?" + e : "") + window.location.hash;
|
|
305
309
|
window.history.replaceState({}, "", t);
|
|
306
310
|
} catch {
|
|
307
311
|
}
|
|
308
|
-
},
|
|
309
|
-
if (!
|
|
312
|
+
}, ts = () => {
|
|
313
|
+
if (!dt())
|
|
310
314
|
return !1;
|
|
311
315
|
try {
|
|
312
|
-
const e = new URLSearchParams(window.location.search).get(
|
|
316
|
+
const e = new URLSearchParams(window.location.search).get(nt), t = sessionStorage.getItem(X);
|
|
313
317
|
let s = null;
|
|
314
|
-
return e ===
|
|
315
|
-
visibility: "qa",
|
|
316
|
-
style: nt
|
|
317
|
-
})) : e === He && (s = !1, sessionStorage.setItem(G, "false"), a("info", "QA Mode DISABLED", {
|
|
318
|
+
return e === He ? (s = !0, sessionStorage.setItem(X, "true"), a("info", "QA Mode ACTIVE", {
|
|
318
319
|
visibility: "qa",
|
|
319
320
|
style: it
|
|
320
|
-
}))
|
|
321
|
+
})) : e === Fe && (s = !1, sessionStorage.setItem(X, "false"), a("info", "QA Mode DISABLED", {
|
|
322
|
+
visibility: "qa",
|
|
323
|
+
style: ot
|
|
324
|
+
})), (e === He || e === Fe) && es(), s ?? t === "true";
|
|
321
325
|
} catch {
|
|
322
326
|
return !1;
|
|
323
327
|
}
|
|
324
|
-
},
|
|
325
|
-
if (
|
|
328
|
+
}, ss = (r) => {
|
|
329
|
+
if (dt())
|
|
326
330
|
try {
|
|
327
|
-
sessionStorage.setItem(
|
|
331
|
+
sessionStorage.setItem(X, r ? "true" : "false"), a("info", r ? "QA Mode ACTIVE" : "QA Mode DISABLED", {
|
|
328
332
|
visibility: "qa",
|
|
329
|
-
style: r ?
|
|
333
|
+
style: r ? it : ot
|
|
330
334
|
});
|
|
331
335
|
} catch {
|
|
332
336
|
a("debug", "Cannot set QA mode: sessionStorage unavailable");
|
|
333
337
|
}
|
|
334
|
-
},
|
|
338
|
+
}, rs = [
|
|
335
339
|
"co.uk",
|
|
336
340
|
"org.uk",
|
|
337
341
|
"com.au",
|
|
@@ -343,25 +347,25 @@ const Ft = () => {
|
|
|
343
347
|
"co.in",
|
|
344
348
|
"com.cn",
|
|
345
349
|
"co.za"
|
|
346
|
-
],
|
|
350
|
+
], qe = (r) => {
|
|
347
351
|
const e = r.toLowerCase().split(".");
|
|
348
352
|
if (e.length <= 2)
|
|
349
353
|
return r.toLowerCase();
|
|
350
354
|
const t = e.slice(-2).join(".");
|
|
351
|
-
return
|
|
352
|
-
},
|
|
355
|
+
return rs.includes(t) ? e.slice(-3).join(".") : e.slice(-2).join(".");
|
|
356
|
+
}, ns = (r, e) => r === e ? !0 : qe(r) === qe(e), me = () => {
|
|
353
357
|
const r = document.referrer;
|
|
354
358
|
if (!r)
|
|
355
359
|
return "Direct";
|
|
356
360
|
try {
|
|
357
361
|
const e = new URL(r).hostname.toLowerCase(), t = window.location.hostname.toLowerCase();
|
|
358
|
-
return
|
|
362
|
+
return ns(e, t) ? "Direct" : r;
|
|
359
363
|
} catch (e) {
|
|
360
364
|
return a("debug", "Failed to parse referrer URL, using raw value", { error: e, data: { referrer: r } }), r;
|
|
361
365
|
}
|
|
362
366
|
}, ge = () => {
|
|
363
367
|
const r = new URLSearchParams(window.location.search), e = {};
|
|
364
|
-
return
|
|
368
|
+
return Lt.forEach((s) => {
|
|
365
369
|
const n = r.get(s);
|
|
366
370
|
if (n) {
|
|
367
371
|
const i = s.split("utm_")[1];
|
|
@@ -372,11 +376,11 @@ const Ft = () => {
|
|
|
372
376
|
const e = Math.random() * 16 | 0;
|
|
373
377
|
return (r === "x" ? e : e & 3 | 8).toString(16);
|
|
374
378
|
});
|
|
375
|
-
let
|
|
376
|
-
const
|
|
379
|
+
let Y = 0, q = 0;
|
|
380
|
+
const ye = () => {
|
|
377
381
|
let r = Date.now();
|
|
378
|
-
r <
|
|
379
|
-
const e =
|
|
382
|
+
r < q && (r = q), r === q ? Y = (Y + 1) % 1e3 : Y = 0, q = r;
|
|
383
|
+
const e = Y.toString().padStart(3, "0");
|
|
380
384
|
let t = "";
|
|
381
385
|
try {
|
|
382
386
|
if (typeof crypto < "u" && crypto.getRandomValues) {
|
|
@@ -386,7 +390,7 @@ const ns = () => {
|
|
|
386
390
|
} catch {
|
|
387
391
|
}
|
|
388
392
|
return t || (t = Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")), `${r}-${e}-${t}`;
|
|
389
|
-
},
|
|
393
|
+
}, ht = (r, e = !1) => {
|
|
390
394
|
try {
|
|
391
395
|
const t = new URL(r), s = t.protocol === "https:", n = t.protocol === "http:";
|
|
392
396
|
return s || e && n;
|
|
@@ -411,7 +415,7 @@ const ns = () => {
|
|
|
411
415
|
if (s.length === 2 ? n = s.join(".") : n = s.slice(-2).join("."), !n || n.split(".").length < 2)
|
|
412
416
|
throw new Error("Invalid domain structure for SaaS");
|
|
413
417
|
const i = `https://${r}.${n}/collect`;
|
|
414
|
-
if (!
|
|
418
|
+
if (!ht(i))
|
|
415
419
|
throw new Error("Generated URL failed validation");
|
|
416
420
|
return i;
|
|
417
421
|
} catch (e) {
|
|
@@ -423,16 +427,16 @@ const ns = () => {
|
|
|
423
427
|
const t = r.integrations?.custom?.collectApiUrl;
|
|
424
428
|
if (t) {
|
|
425
429
|
const s = r.integrations?.custom?.allowHttp ?? !1;
|
|
426
|
-
if (!
|
|
430
|
+
if (!ht(t, s))
|
|
427
431
|
throw new Error("Invalid custom API URL");
|
|
428
432
|
e.custom = t;
|
|
429
433
|
}
|
|
430
434
|
return e;
|
|
431
|
-
},
|
|
435
|
+
}, we = (r, e = []) => {
|
|
432
436
|
if (!r || typeof r != "string")
|
|
433
437
|
return a("warn", "Invalid URL provided to normalizeUrl", { data: { type: typeof r } }), r || "";
|
|
434
438
|
try {
|
|
435
|
-
const t = new URL(r), s = t.searchParams, n = [.../* @__PURE__ */ new Set([...
|
|
439
|
+
const t = new URL(r), s = t.searchParams, n = [.../* @__PURE__ */ new Set([...Mt, ...e])];
|
|
436
440
|
let i = !1;
|
|
437
441
|
const o = [];
|
|
438
442
|
return n.forEach((c) => {
|
|
@@ -441,13 +445,13 @@ const ns = () => {
|
|
|
441
445
|
} catch (t) {
|
|
442
446
|
return a("warn", "URL normalization failed, returning original", { error: t, data: { urlLength: r?.length } }), r;
|
|
443
447
|
}
|
|
444
|
-
},
|
|
448
|
+
}, Je = (r) => {
|
|
445
449
|
if (!r || typeof r != "string" || r.trim().length === 0)
|
|
446
450
|
return "";
|
|
447
451
|
let e = r;
|
|
448
452
|
r.length > 1e3 && (e = r.slice(0, Math.max(0, 1e3)));
|
|
449
453
|
let t = 0;
|
|
450
|
-
for (const n of
|
|
454
|
+
for (const n of Ct) {
|
|
451
455
|
const i = e;
|
|
452
456
|
e = e.replace(n, ""), i !== e && t++;
|
|
453
457
|
}
|
|
@@ -457,11 +461,11 @@ const ns = () => {
|
|
|
457
461
|
valueLength: r.length
|
|
458
462
|
}
|
|
459
463
|
}), e.trim();
|
|
460
|
-
},
|
|
464
|
+
}, be = (r, e = 0) => {
|
|
461
465
|
if (r == null)
|
|
462
466
|
return null;
|
|
463
467
|
if (typeof r == "string")
|
|
464
|
-
return
|
|
468
|
+
return Je(r);
|
|
465
469
|
if (typeof r == "number")
|
|
466
470
|
return !Number.isFinite(r) || r < -Number.MAX_SAFE_INTEGER || r > Number.MAX_SAFE_INTEGER ? 0 : r;
|
|
467
471
|
if (typeof r == "boolean")
|
|
@@ -469,13 +473,13 @@ const ns = () => {
|
|
|
469
473
|
if (e > 10)
|
|
470
474
|
return null;
|
|
471
475
|
if (Array.isArray(r))
|
|
472
|
-
return r.slice(0, 1e3).map((n) =>
|
|
476
|
+
return r.slice(0, 1e3).map((n) => be(n, e + 1)).filter((n) => n !== null);
|
|
473
477
|
if (typeof r == "object") {
|
|
474
478
|
const t = {}, n = Object.entries(r).slice(0, 200);
|
|
475
479
|
for (const [i, o] of n) {
|
|
476
|
-
const l =
|
|
480
|
+
const l = Je(i);
|
|
477
481
|
if (l) {
|
|
478
|
-
const c =
|
|
482
|
+
const c = be(o, e + 1);
|
|
479
483
|
c !== null && (t[l] = c);
|
|
480
484
|
}
|
|
481
485
|
}
|
|
@@ -486,7 +490,7 @@ const ns = () => {
|
|
|
486
490
|
if (typeof r != "object" || r === null)
|
|
487
491
|
return {};
|
|
488
492
|
try {
|
|
489
|
-
const e =
|
|
493
|
+
const e = be(r);
|
|
490
494
|
return typeof e == "object" && e !== null ? e : {};
|
|
491
495
|
} catch (e) {
|
|
492
496
|
const t = e instanceof Error ? e.message : String(e);
|
|
@@ -494,69 +498,69 @@ const ns = () => {
|
|
|
494
498
|
}
|
|
495
499
|
}, ls = (r) => {
|
|
496
500
|
if (r !== void 0 && (r === null || typeof r != "object"))
|
|
497
|
-
throw new
|
|
501
|
+
throw new m("Configuration must be an object", "config");
|
|
498
502
|
if (r) {
|
|
499
503
|
if (r.sessionTimeout !== void 0 && (typeof r.sessionTimeout != "number" || r.sessionTimeout < 3e4 || r.sessionTimeout > 864e5))
|
|
500
|
-
throw new
|
|
504
|
+
throw new Pt(E.INVALID_SESSION_TIMEOUT, "config");
|
|
501
505
|
if (r.globalMetadata !== void 0 && (typeof r.globalMetadata != "object" || r.globalMetadata === null))
|
|
502
|
-
throw new
|
|
503
|
-
if (r.integrations &&
|
|
506
|
+
throw new m(E.INVALID_GLOBAL_METADATA, "config");
|
|
507
|
+
if (r.integrations && ds(r.integrations), r.sensitiveQueryParams !== void 0) {
|
|
504
508
|
if (!Array.isArray(r.sensitiveQueryParams))
|
|
505
|
-
throw new
|
|
509
|
+
throw new m(E.INVALID_SENSITIVE_QUERY_PARAMS, "config");
|
|
506
510
|
for (const e of r.sensitiveQueryParams)
|
|
507
511
|
if (typeof e != "string")
|
|
508
|
-
throw new
|
|
512
|
+
throw new m("All sensitive query params must be strings", "config");
|
|
509
513
|
}
|
|
510
514
|
if (r.errorSampling !== void 0 && (typeof r.errorSampling != "number" || r.errorSampling < 0 || r.errorSampling > 1))
|
|
511
|
-
throw new
|
|
515
|
+
throw new Xe(E.INVALID_ERROR_SAMPLING_RATE, "config");
|
|
512
516
|
if (r.samplingRate !== void 0 && (typeof r.samplingRate != "number" || r.samplingRate < 0 || r.samplingRate > 1))
|
|
513
|
-
throw new
|
|
517
|
+
throw new Xe(E.INVALID_SAMPLING_RATE, "config");
|
|
514
518
|
if (r.primaryScrollSelector !== void 0) {
|
|
515
519
|
if (typeof r.primaryScrollSelector != "string" || !r.primaryScrollSelector.trim())
|
|
516
|
-
throw new
|
|
520
|
+
throw new m(E.INVALID_PRIMARY_SCROLL_SELECTOR, "config");
|
|
517
521
|
if (r.primaryScrollSelector !== "window")
|
|
518
522
|
try {
|
|
519
523
|
document.querySelector(r.primaryScrollSelector);
|
|
520
524
|
} catch {
|
|
521
|
-
throw new
|
|
522
|
-
`${
|
|
525
|
+
throw new m(
|
|
526
|
+
`${E.INVALID_PRIMARY_SCROLL_SELECTOR_SYNTAX}: "${r.primaryScrollSelector}"`,
|
|
523
527
|
"config"
|
|
524
528
|
);
|
|
525
529
|
}
|
|
526
530
|
}
|
|
527
531
|
if (r.pageViewThrottleMs !== void 0 && (typeof r.pageViewThrottleMs != "number" || r.pageViewThrottleMs < 0))
|
|
528
|
-
throw new
|
|
532
|
+
throw new m(E.INVALID_PAGE_VIEW_THROTTLE, "config");
|
|
529
533
|
if (r.clickThrottleMs !== void 0 && (typeof r.clickThrottleMs != "number" || r.clickThrottleMs < 0))
|
|
530
|
-
throw new
|
|
534
|
+
throw new m(E.INVALID_CLICK_THROTTLE, "config");
|
|
531
535
|
if (r.maxSameEventPerMinute !== void 0 && (typeof r.maxSameEventPerMinute != "number" || r.maxSameEventPerMinute <= 0))
|
|
532
|
-
throw new
|
|
536
|
+
throw new m(E.INVALID_MAX_SAME_EVENT_PER_MINUTE, "config");
|
|
533
537
|
if (r.sendIntervalMs !== void 0 && (!Number.isFinite(r.sendIntervalMs) || r.sendIntervalMs < 1e3 || r.sendIntervalMs > 6e4))
|
|
534
|
-
throw new
|
|
538
|
+
throw new m(E.INVALID_SEND_INTERVAL, "config");
|
|
535
539
|
if (r.viewport !== void 0 && cs(r.viewport), r.webVitalsMode !== void 0) {
|
|
536
540
|
if (typeof r.webVitalsMode != "string")
|
|
537
|
-
throw new
|
|
541
|
+
throw new m(
|
|
538
542
|
`Invalid webVitalsMode type: ${typeof r.webVitalsMode}. Must be a string`,
|
|
539
543
|
"config"
|
|
540
544
|
);
|
|
541
545
|
const e = ["all", "needs-improvement", "poor"];
|
|
542
546
|
if (!e.includes(r.webVitalsMode))
|
|
543
|
-
throw new
|
|
547
|
+
throw new m(
|
|
544
548
|
`Invalid webVitalsMode: "${r.webVitalsMode}". Must be one of: ${e.join(", ")}`,
|
|
545
549
|
"config"
|
|
546
550
|
);
|
|
547
551
|
}
|
|
548
552
|
if (r.webVitalsThresholds !== void 0) {
|
|
549
553
|
if (typeof r.webVitalsThresholds != "object" || r.webVitalsThresholds === null || Array.isArray(r.webVitalsThresholds))
|
|
550
|
-
throw new
|
|
554
|
+
throw new m("webVitalsThresholds must be an object", "config");
|
|
551
555
|
const e = ["LCP", "FCP", "CLS", "INP", "TTFB", "LONG_TASK"];
|
|
552
556
|
for (const [t, s] of Object.entries(r.webVitalsThresholds)) {
|
|
553
557
|
if (!e.includes(t))
|
|
554
|
-
throw new
|
|
558
|
+
throw new m(
|
|
555
559
|
`Invalid Web Vitals threshold key: "${t}". Must be one of: ${e.join(", ")}`,
|
|
556
560
|
"config"
|
|
557
561
|
);
|
|
558
562
|
if (typeof s != "number" || !Number.isFinite(s) || s < 0)
|
|
559
|
-
throw new
|
|
563
|
+
throw new m(
|
|
560
564
|
`Invalid Web Vitals threshold value for ${t}: ${s}. Must be a non-negative finite number`,
|
|
561
565
|
"config"
|
|
562
566
|
);
|
|
@@ -565,41 +569,41 @@ const ns = () => {
|
|
|
565
569
|
}
|
|
566
570
|
}, cs = (r) => {
|
|
567
571
|
if (typeof r != "object" || r === null)
|
|
568
|
-
throw new
|
|
572
|
+
throw new m(E.INVALID_VIEWPORT_CONFIG, "config");
|
|
569
573
|
if (!r.elements || !Array.isArray(r.elements))
|
|
570
|
-
throw new
|
|
574
|
+
throw new m(E.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
571
575
|
if (r.elements.length === 0)
|
|
572
|
-
throw new
|
|
576
|
+
throw new m(E.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
573
577
|
const e = /* @__PURE__ */ new Set();
|
|
574
578
|
for (const t of r.elements) {
|
|
575
579
|
if (!t.selector || typeof t.selector != "string" || !t.selector.trim())
|
|
576
|
-
throw new
|
|
580
|
+
throw new m(E.INVALID_VIEWPORT_ELEMENT, "config");
|
|
577
581
|
const s = t.selector.trim();
|
|
578
582
|
if (e.has(s))
|
|
579
|
-
throw new
|
|
583
|
+
throw new m(
|
|
580
584
|
`Duplicate viewport selector found: "${s}". Each selector should appear only once.`,
|
|
581
585
|
"config"
|
|
582
586
|
);
|
|
583
587
|
if (e.add(s), t.id !== void 0 && (typeof t.id != "string" || !t.id.trim()))
|
|
584
|
-
throw new
|
|
588
|
+
throw new m(E.INVALID_VIEWPORT_ELEMENT_ID, "config");
|
|
585
589
|
if (t.name !== void 0 && (typeof t.name != "string" || !t.name.trim()))
|
|
586
|
-
throw new
|
|
590
|
+
throw new m(E.INVALID_VIEWPORT_ELEMENT_NAME, "config");
|
|
587
591
|
}
|
|
588
592
|
if (r.threshold !== void 0 && (typeof r.threshold != "number" || r.threshold < 0 || r.threshold > 1))
|
|
589
|
-
throw new
|
|
593
|
+
throw new m(E.INVALID_VIEWPORT_THRESHOLD, "config");
|
|
590
594
|
if (r.minDwellTime !== void 0 && (typeof r.minDwellTime != "number" || r.minDwellTime < 0))
|
|
591
|
-
throw new
|
|
595
|
+
throw new m(E.INVALID_VIEWPORT_MIN_DWELL_TIME, "config");
|
|
592
596
|
if (r.cooldownPeriod !== void 0 && (typeof r.cooldownPeriod != "number" || r.cooldownPeriod < 0))
|
|
593
|
-
throw new
|
|
597
|
+
throw new m(E.INVALID_VIEWPORT_COOLDOWN_PERIOD, "config");
|
|
594
598
|
if (r.maxTrackedElements !== void 0 && (typeof r.maxTrackedElements != "number" || r.maxTrackedElements <= 0))
|
|
595
|
-
throw new
|
|
596
|
-
},
|
|
599
|
+
throw new m(E.INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS, "config");
|
|
600
|
+
}, ds = (r) => {
|
|
597
601
|
if (r) {
|
|
598
602
|
if (r.tracelog && (!r.tracelog.projectId || typeof r.tracelog.projectId != "string" || r.tracelog.projectId.trim() === ""))
|
|
599
|
-
throw new N(
|
|
603
|
+
throw new N(E.INVALID_TRACELOG_PROJECT_ID, "config");
|
|
600
604
|
if (r.custom) {
|
|
601
605
|
if (!r.custom.collectApiUrl || typeof r.custom.collectApiUrl != "string" || r.custom.collectApiUrl.trim() === "")
|
|
602
|
-
throw new N(
|
|
606
|
+
throw new N(E.INVALID_CUSTOM_API_URL, "config");
|
|
603
607
|
if (r.custom.allowHttp !== void 0 && typeof r.custom.allowHttp != "boolean")
|
|
604
608
|
throw new N("allowHttp must be a boolean", "config");
|
|
605
609
|
const e = r.custom.collectApiUrl.trim();
|
|
@@ -616,14 +620,14 @@ const ns = () => {
|
|
|
616
620
|
if (r.tracelog?.shopify !== void 0 && typeof r.tracelog.shopify != "boolean")
|
|
617
621
|
throw new N("tracelog.shopify must be a boolean", "config");
|
|
618
622
|
}
|
|
619
|
-
},
|
|
623
|
+
}, us = (r) => {
|
|
620
624
|
ls(r);
|
|
621
625
|
const e = {
|
|
622
626
|
...r ?? {},
|
|
623
627
|
sessionTimeout: r?.sessionTimeout ?? 9e5,
|
|
624
628
|
globalMetadata: r?.globalMetadata ?? {},
|
|
625
629
|
sensitiveQueryParams: r?.sensitiveQueryParams ?? [],
|
|
626
|
-
errorSampling: r?.errorSampling ??
|
|
630
|
+
errorSampling: r?.errorSampling ?? ct,
|
|
627
631
|
samplingRate: r?.samplingRate ?? 1,
|
|
628
632
|
pageViewThrottleMs: r?.pageViewThrottleMs ?? 1e3,
|
|
629
633
|
clickThrottleMs: r?.clickThrottleMs ?? 300,
|
|
@@ -640,12 +644,12 @@ const ns = () => {
|
|
|
640
644
|
cooldownPeriod: e.viewport.cooldownPeriod ?? 6e4,
|
|
641
645
|
maxTrackedElements: e.viewport.maxTrackedElements ?? 100
|
|
642
646
|
}), e;
|
|
643
|
-
},
|
|
647
|
+
}, Ae = (r, e = /* @__PURE__ */ new Set()) => {
|
|
644
648
|
if (r == null)
|
|
645
649
|
return !0;
|
|
646
650
|
const t = typeof r;
|
|
647
|
-
return t === "string" || t === "number" || t === "boolean" ? !0 : t === "function" || t === "symbol" || t === "bigint" || e.has(r) ? !1 : (e.add(r), Array.isArray(r) ? r.every((s) =>
|
|
648
|
-
}, hs = (r) => typeof r != "object" || r === null ? !1 :
|
|
651
|
+
return t === "string" || t === "number" || t === "boolean" ? !0 : t === "function" || t === "symbol" || t === "bigint" || e.has(r) ? !1 : (e.add(r), Array.isArray(r) ? r.every((s) => Ae(s, e)) : t === "object" ? Object.values(r).every((s) => Ae(s, e)) : !1);
|
|
652
|
+
}, hs = (r) => typeof r != "object" || r === null ? !1 : Ae(r), ft = (r) => {
|
|
649
653
|
if (typeof r != "object" || r === null || Array.isArray(r)) return;
|
|
650
654
|
const e = {};
|
|
651
655
|
for (const [t, s] of Object.entries(r))
|
|
@@ -666,7 +670,7 @@ const ns = () => {
|
|
|
666
670
|
} : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(r.toLowerCase()) ? {
|
|
667
671
|
valid: !1,
|
|
668
672
|
error: "Event name cannot be a reserved word"
|
|
669
|
-
} : { valid: !0 },
|
|
673
|
+
} : { valid: !0 }, Ze = (r, e, t) => {
|
|
670
674
|
const s = as(e), n = t && t === "customEvent" ? `${t} "${r}" metadata error` : `${r} metadata error`;
|
|
671
675
|
if (!hs(s))
|
|
672
676
|
return {
|
|
@@ -692,21 +696,21 @@ const ns = () => {
|
|
|
692
696
|
valid: !1,
|
|
693
697
|
error: `${n}: object has too many keys (max 100 keys).`
|
|
694
698
|
};
|
|
695
|
-
for (const [c,
|
|
696
|
-
if (Array.isArray(
|
|
697
|
-
if (
|
|
699
|
+
for (const [c, d] of Object.entries(s)) {
|
|
700
|
+
if (Array.isArray(d)) {
|
|
701
|
+
if (d.length > 500)
|
|
698
702
|
return {
|
|
699
703
|
valid: !1,
|
|
700
704
|
error: `${n}: array property "${c}" is too large (max 500 items).`
|
|
701
705
|
};
|
|
702
|
-
for (const
|
|
703
|
-
if (typeof
|
|
706
|
+
for (const f of d)
|
|
707
|
+
if (typeof f == "string" && f.length > 500)
|
|
704
708
|
return {
|
|
705
709
|
valid: !1,
|
|
706
710
|
error: `${n}: array property "${c}" contains strings that are too long (max 500 characters).`
|
|
707
711
|
};
|
|
708
712
|
}
|
|
709
|
-
if (typeof
|
|
713
|
+
if (typeof d == "string" && d.length > 1e3)
|
|
710
714
|
return {
|
|
711
715
|
valid: !1,
|
|
712
716
|
error: `${n}: property "${c}" is too long (max 1000 characters).`
|
|
@@ -716,7 +720,7 @@ const ns = () => {
|
|
|
716
720
|
valid: !0,
|
|
717
721
|
sanitizedMetadata: s
|
|
718
722
|
};
|
|
719
|
-
},
|
|
723
|
+
}, mt = (r, e, t) => {
|
|
720
724
|
if (Array.isArray(e)) {
|
|
721
725
|
const s = [], n = t && t === "customEvent" ? `${t} "${r}" metadata error` : `${r} metadata error`;
|
|
722
726
|
for (let i = 0; i < e.length; i++) {
|
|
@@ -726,7 +730,7 @@ const ns = () => {
|
|
|
726
730
|
valid: !1,
|
|
727
731
|
error: `${n}: array item at index ${i} must be an object.`
|
|
728
732
|
};
|
|
729
|
-
const l =
|
|
733
|
+
const l = Ze(r, o, t);
|
|
730
734
|
if (!l.valid)
|
|
731
735
|
return {
|
|
732
736
|
valid: !1,
|
|
@@ -739,7 +743,7 @@ const ns = () => {
|
|
|
739
743
|
sanitizedMetadata: s
|
|
740
744
|
};
|
|
741
745
|
}
|
|
742
|
-
return
|
|
746
|
+
return Ze(r, e, t);
|
|
743
747
|
}, ms = (r, e) => {
|
|
744
748
|
const t = fs(r);
|
|
745
749
|
if (!t.valid)
|
|
@@ -748,7 +752,7 @@ const ns = () => {
|
|
|
748
752
|
}), t;
|
|
749
753
|
if (!e)
|
|
750
754
|
return { valid: !0 };
|
|
751
|
-
const s =
|
|
755
|
+
const s = mt(r, e, "customEvent");
|
|
752
756
|
return s.valid || a("error", "Event metadata validation failed", {
|
|
753
757
|
data: {
|
|
754
758
|
eventName: r,
|
|
@@ -873,7 +877,7 @@ class gs {
|
|
|
873
877
|
this.listeners.clear();
|
|
874
878
|
}
|
|
875
879
|
}
|
|
876
|
-
function
|
|
880
|
+
function gt(r, e, t) {
|
|
877
881
|
try {
|
|
878
882
|
const s = e(r);
|
|
879
883
|
return s === null ? null : typeof s == "object" && s !== null && "type" in s ? s : (a("warn", `beforeSend transformer returned invalid data, using original [${t}]`), r);
|
|
@@ -885,9 +889,9 @@ function mt(r, e, t) {
|
|
|
885
889
|
}
|
|
886
890
|
}
|
|
887
891
|
function Es(r, e, t) {
|
|
888
|
-
return r.map((s) =>
|
|
892
|
+
return r.map((s) => gt(s, e, t)).filter((s) => s !== null);
|
|
889
893
|
}
|
|
890
|
-
function
|
|
894
|
+
function Et(r, e, t) {
|
|
891
895
|
try {
|
|
892
896
|
const s = e(r);
|
|
893
897
|
return s === null ? (a("debug", `Batch filtered by beforeBatch transformer [${t}]`, {
|
|
@@ -962,7 +966,7 @@ class _ {
|
|
|
962
966
|
return { ...Ee };
|
|
963
967
|
}
|
|
964
968
|
}
|
|
965
|
-
class
|
|
969
|
+
class et extends _ {
|
|
966
970
|
storeManager;
|
|
967
971
|
integrationId;
|
|
968
972
|
apiUrl;
|
|
@@ -1047,7 +1051,7 @@ class Ze extends _ {
|
|
|
1047
1051
|
return { ...this.staticHeaders, ...e };
|
|
1048
1052
|
}
|
|
1049
1053
|
getQueueStorageKey() {
|
|
1050
|
-
const e = this.get("userId") || "anonymous", t =
|
|
1054
|
+
const e = this.get("userId") || "anonymous", t = Rt(e);
|
|
1051
1055
|
return this.integrationId ? `${t}:${this.integrationId}` : t;
|
|
1052
1056
|
}
|
|
1053
1057
|
/**
|
|
@@ -1064,13 +1068,14 @@ class Ze extends _ {
|
|
|
1064
1068
|
* - Uses `navigator.sendBeacon()` (browser-queued, synchronous API)
|
|
1065
1069
|
* - Payload size limited to 64KB (enforced by browser)
|
|
1066
1070
|
* - Browser guarantees delivery attempt (survives page close)
|
|
1067
|
-
* -
|
|
1071
|
+
* - Persists to localStorage on beacon failure/size overflow for later recovery
|
|
1068
1072
|
*
|
|
1069
1073
|
* **Return Values**:
|
|
1070
1074
|
* - `true`: Send succeeded OR skipped (standalone mode)
|
|
1071
1075
|
* - `false`: Send failed (network error, browser rejected beacon)
|
|
1072
1076
|
*
|
|
1073
|
-
* **Important**: No retry mechanism
|
|
1077
|
+
* **Important**: No retry mechanism. Failed events are persisted to localStorage for
|
|
1078
|
+
* recovery on next page load via `recoverPersistedEvents()`.
|
|
1074
1079
|
*
|
|
1075
1080
|
* **Custom Headers Limitation**: Custom headers set via `setCustomHeaders()` are NOT applied
|
|
1076
1081
|
* to sendBeacon requests due to browser API limitations. The sendBeacon API only supports
|
|
@@ -1089,13 +1094,13 @@ class Ze extends _ {
|
|
|
1089
1094
|
* @see src/managers/README.md (lines 82-139) for send details
|
|
1090
1095
|
*/
|
|
1091
1096
|
sendEventsQueueSync(e) {
|
|
1092
|
-
return this.shouldSkipSend() ? !0 : this.apiUrl?.includes(
|
|
1097
|
+
return this.shouldSkipSend() ? !0 : this.apiUrl?.includes($.Fail) ? (a(
|
|
1093
1098
|
"warn",
|
|
1094
1099
|
`Fail mode: simulating network failure (sync)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1095
1100
|
{
|
|
1096
1101
|
data: { events: e.events.length }
|
|
1097
1102
|
}
|
|
1098
|
-
), !1) : this.apiUrl?.includes(
|
|
1103
|
+
), !1) : this.apiUrl?.includes($.Localhost) ? (a(
|
|
1099
1104
|
"debug",
|
|
1100
1105
|
`Success mode: simulating successful send (sync)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1101
1106
|
{
|
|
@@ -1103,6 +1108,20 @@ class Ze extends _ {
|
|
|
1103
1108
|
}
|
|
1104
1109
|
), !0) : this.sendQueueSyncInternal(e);
|
|
1105
1110
|
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Persists events to localStorage for recovery without sending.
|
|
1113
|
+
*
|
|
1114
|
+
* Used when an async send is already in-flight to avoid generating
|
|
1115
|
+
* a second idempotency token for the same events via sendBeacon.
|
|
1116
|
+
* On next page load, `recoverPersistedEvents()` sends with the persisted token.
|
|
1117
|
+
*
|
|
1118
|
+
* @param body - Event queue to persist
|
|
1119
|
+
*/
|
|
1120
|
+
persistForRecovery(e) {
|
|
1121
|
+
if (this.shouldSkipSend()) return;
|
|
1122
|
+
const t = this.ensureBatchMetadata(e);
|
|
1123
|
+
this.persistEventsWithFailureCount(t, 0, !0);
|
|
1124
|
+
}
|
|
1106
1125
|
/**
|
|
1107
1126
|
* Sends events asynchronously using `fetch()` API with automatic persistence on failure.
|
|
1108
1127
|
*
|
|
@@ -1120,7 +1139,7 @@ class Ze extends _ {
|
|
|
1120
1139
|
*
|
|
1121
1140
|
* **Error Handling**:
|
|
1122
1141
|
* - **Permanent errors** (4xx except 408, 429): Events discarded, not persisted
|
|
1123
|
-
* - **Timeout errors
|
|
1142
|
+
* - **Timeout errors**: Events persisted for retry with the same batch idempotency token
|
|
1124
1143
|
* - **Transient errors** (5xx, network, mixed): Events persisted for recovery
|
|
1125
1144
|
*
|
|
1126
1145
|
* **Important**: Events are NOT retried in-session. Persistence is for
|
|
@@ -1134,14 +1153,12 @@ class Ze extends _ {
|
|
|
1134
1153
|
* @see src/managers/README.md (lines 82-139) for send details
|
|
1135
1154
|
*/
|
|
1136
1155
|
async sendEventsQueue(e, t) {
|
|
1156
|
+
const s = this.ensureBatchMetadata(e);
|
|
1137
1157
|
try {
|
|
1138
|
-
const
|
|
1139
|
-
return
|
|
1140
|
-
} catch (
|
|
1141
|
-
return
|
|
1142
|
-
"debug",
|
|
1143
|
-
`All attempts timed out, skipping persistence (server likely received events)${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1144
|
-
), this.clearPersistedEvents(), t?.onFailure?.(), !1) : (this.persistEvents(e), t?.onFailure?.(), !1);
|
|
1158
|
+
const n = await this.send(s);
|
|
1159
|
+
return n ? (this.clearPersistedEvents(), t?.onSuccess?.(s.events.length, s.events, s)) : (this.persistEvents(s), t?.onFailure?.()), n;
|
|
1160
|
+
} catch (n) {
|
|
1161
|
+
return n instanceof O ? (this.logPermanentError("Permanent error, not retrying", n), this.clearPersistedEvents(), t?.onFailure?.(), !1) : (this.persistEvents(s), t?.onFailure?.(), !1);
|
|
1145
1162
|
}
|
|
1146
1163
|
}
|
|
1147
1164
|
/**
|
|
@@ -1199,35 +1216,28 @@ class Ze extends _ {
|
|
|
1199
1216
|
return;
|
|
1200
1217
|
}
|
|
1201
1218
|
this.recoveryInProgress = !0;
|
|
1219
|
+
let t = null, s = 0;
|
|
1202
1220
|
try {
|
|
1203
|
-
const
|
|
1204
|
-
if (!
|
|
1221
|
+
const n = this.getPersistedData();
|
|
1222
|
+
if (!n || !this.isDataRecent(n) || n.events.length === 0) {
|
|
1205
1223
|
this.clearPersistedEvents();
|
|
1206
1224
|
return;
|
|
1207
1225
|
}
|
|
1208
|
-
const
|
|
1209
|
-
if (
|
|
1226
|
+
const i = n.recoveryFailures;
|
|
1227
|
+
if (s = typeof i == "number" && Number.isFinite(i) && i >= 0 ? i : 0, s >= 3) {
|
|
1210
1228
|
a(
|
|
1211
1229
|
"debug",
|
|
1212
|
-
`Discarding persisted events after ${
|
|
1230
|
+
`Discarding persisted events after ${s} failed recovery attempts${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1213
1231
|
), this.clearPersistedEvents(), e?.onFailure?.();
|
|
1214
1232
|
return;
|
|
1215
1233
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
this.logPermanentError("Permanent error during recovery, clearing persisted events", t), this.clearPersistedEvents(), e?.onFailure?.();
|
|
1221
|
-
return;
|
|
1222
|
-
}
|
|
1223
|
-
if (t instanceof P) {
|
|
1224
|
-
a(
|
|
1225
|
-
"debug",
|
|
1226
|
-
`Recovery timed out, clearing persisted events (server likely received them)${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1227
|
-
), this.clearPersistedEvents(), e?.onFailure?.();
|
|
1234
|
+
t = this.ensureBatchMetadata(this.createRecoveryBody(n)), await this.send(t) ? (this.clearPersistedEvents(), e?.onSuccess?.(n.events.length, n.events, t)) : (this.persistEventsWithFailureCount(t, s + 1, !0), e?.onFailure?.());
|
|
1235
|
+
} catch (n) {
|
|
1236
|
+
if (n instanceof O) {
|
|
1237
|
+
this.logPermanentError("Permanent error during recovery, clearing persisted events", n), this.clearPersistedEvents(), e?.onFailure?.();
|
|
1228
1238
|
return;
|
|
1229
1239
|
}
|
|
1230
|
-
a("error", "Failed to recover persisted events", { error:
|
|
1240
|
+
a("error", "Failed to recover persisted events", { error: n }), t && this.persistEventsWithFailureCount(t, s + 1, !0), e?.onFailure?.();
|
|
1231
1241
|
} finally {
|
|
1232
1242
|
this.recoveryInProgress = !1;
|
|
1233
1243
|
}
|
|
@@ -1322,7 +1332,7 @@ class Ze extends _ {
|
|
|
1322
1332
|
if (this.integrationId === "saas")
|
|
1323
1333
|
return e;
|
|
1324
1334
|
const t = this.transformers.beforeBatch;
|
|
1325
|
-
return t ?
|
|
1335
|
+
return t ? Et(e, t, this.integrationId || "SenderManager") : e;
|
|
1326
1336
|
}
|
|
1327
1337
|
/**
|
|
1328
1338
|
* Calculates exponential backoff delay with jitter for retry attempts.
|
|
@@ -1380,7 +1390,6 @@ class Ze extends _ {
|
|
|
1380
1390
|
* @param body - Event queue to send
|
|
1381
1391
|
* @returns Promise resolving to true if send succeeded, false if all retries exhausted
|
|
1382
1392
|
* @throws PermanentError for 4xx errors (caller should not retry)
|
|
1383
|
-
* @throws TimeoutError when all retry attempts timed out (caller should not persist)
|
|
1384
1393
|
*/
|
|
1385
1394
|
async send(e) {
|
|
1386
1395
|
if (this.shouldSkipSend())
|
|
@@ -1391,67 +1400,72 @@ class Ze extends _ {
|
|
|
1391
1400
|
const s = this.applyBeforeBatchTransformer(t);
|
|
1392
1401
|
if (!s)
|
|
1393
1402
|
return !0;
|
|
1394
|
-
|
|
1403
|
+
const n = this.ensureBatchMetadata(s, e._metadata?.idempotency_token);
|
|
1404
|
+
if (this.apiUrl?.includes($.Fail))
|
|
1395
1405
|
return a("debug", `Fail mode: simulating network failure${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1396
|
-
data: { events:
|
|
1406
|
+
data: { events: n.events.length }
|
|
1397
1407
|
}), !1;
|
|
1398
|
-
if (this.apiUrl?.includes(
|
|
1408
|
+
if (this.apiUrl?.includes($.Localhost))
|
|
1399
1409
|
return a("debug", `Success mode: simulating successful send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1400
|
-
data: { events:
|
|
1410
|
+
data: { events: n.events.length }
|
|
1401
1411
|
}), !0;
|
|
1402
1412
|
if (this.consecutiveNetworkFailures >= 3) {
|
|
1403
|
-
const
|
|
1404
|
-
if (
|
|
1413
|
+
const d = Date.now() - this.circuitOpenedAt;
|
|
1414
|
+
if (d < 12e4)
|
|
1405
1415
|
return a("debug", `Network circuit open, skipping send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1406
1416
|
data: {
|
|
1407
1417
|
consecutiveNetworkFailures: this.consecutiveNetworkFailures,
|
|
1408
|
-
cooldownRemainingMs: 12e4 -
|
|
1418
|
+
cooldownRemainingMs: 12e4 - d
|
|
1409
1419
|
}
|
|
1410
1420
|
}), !1;
|
|
1411
1421
|
}
|
|
1412
|
-
const { url:
|
|
1413
|
-
let
|
|
1414
|
-
for (let
|
|
1422
|
+
const { url: i, payload: o } = this.prepareRequest(n);
|
|
1423
|
+
let l = !0, c = !1;
|
|
1424
|
+
for (let d = 1; d <= 3; d++)
|
|
1415
1425
|
try {
|
|
1416
|
-
return (await this.sendWithTimeout(
|
|
1426
|
+
return (await this.sendWithTimeout(i, o)).ok ? (d > 1 && a(
|
|
1417
1427
|
"info",
|
|
1418
|
-
`Send succeeded after ${
|
|
1428
|
+
`Send succeeded after ${d - 1} retry attempt(s)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1419
1429
|
{
|
|
1420
|
-
data: { events:
|
|
1430
|
+
data: { events: n.events.length, attempt: d }
|
|
1421
1431
|
}
|
|
1422
1432
|
), this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, !0) : !1;
|
|
1423
|
-
} catch (
|
|
1424
|
-
const g =
|
|
1425
|
-
if (
|
|
1426
|
-
throw this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0,
|
|
1427
|
-
if (
|
|
1428
|
-
this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0,
|
|
1429
|
-
data: { events: e.events.length, attempt:
|
|
1433
|
+
} catch (f) {
|
|
1434
|
+
const g = d === 3;
|
|
1435
|
+
if (f instanceof O)
|
|
1436
|
+
throw this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, f;
|
|
1437
|
+
if (f instanceof re) {
|
|
1438
|
+
this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, l = !1, c = !0, a("warn", `Rate limited, skipping retries${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1439
|
+
data: { events: e.events.length, attempt: d }
|
|
1430
1440
|
});
|
|
1431
1441
|
break;
|
|
1432
1442
|
}
|
|
1433
|
-
if (
|
|
1443
|
+
if (f instanceof ne || (l = !1), f instanceof TypeError || (c = !0), a(
|
|
1434
1444
|
g ? "error" : "warn",
|
|
1435
|
-
`Send attempt ${
|
|
1445
|
+
`Send attempt ${d} failed${this.integrationId ? ` [${this.integrationId}]` : ""}${g ? " (all retries exhausted)" : ", will retry"}`,
|
|
1436
1446
|
{
|
|
1437
|
-
error:
|
|
1447
|
+
error: f,
|
|
1438
1448
|
data: {
|
|
1439
1449
|
events: e.events.length,
|
|
1440
|
-
url:
|
|
1441
|
-
attempt:
|
|
1450
|
+
url: i.replace(/\/\/[^/]+/, "//[DOMAIN]"),
|
|
1451
|
+
attempt: d,
|
|
1442
1452
|
maxAttempts: 3
|
|
1443
1453
|
}
|
|
1444
1454
|
}
|
|
1445
1455
|
), !g) {
|
|
1446
|
-
await this.backoffDelay(
|
|
1456
|
+
await this.backoffDelay(d);
|
|
1447
1457
|
continue;
|
|
1448
1458
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1459
|
+
return l ? (a(
|
|
1460
|
+
"debug",
|
|
1461
|
+
`All retry attempts timed out, preserving batch for retry${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1462
|
+
{
|
|
1463
|
+
data: { events: n.events.length }
|
|
1464
|
+
}
|
|
1465
|
+
), !1) : (c ? (this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0) : (this.consecutiveNetworkFailures = Math.min(
|
|
1452
1466
|
this.consecutiveNetworkFailures + 1,
|
|
1453
1467
|
3
|
|
1454
|
-
), this.consecutiveNetworkFailures >= 3 && (this.circuitOpenedAt = Date.now())), !1;
|
|
1468
|
+
), this.consecutiveNetworkFailures >= 3 && (this.circuitOpenedAt = Date.now())), !1);
|
|
1455
1469
|
}
|
|
1456
1470
|
return !1;
|
|
1457
1471
|
}
|
|
@@ -1463,18 +1477,18 @@ class Ze extends _ {
|
|
|
1463
1477
|
*
|
|
1464
1478
|
* **Timeout Behavior**:
|
|
1465
1479
|
* - 10-second timeout via AbortController (REQUEST_TIMEOUT_MS constant)
|
|
1466
|
-
* - Aborted requests throw TimeoutError
|
|
1480
|
+
* - Aborted requests throw TimeoutError
|
|
1467
1481
|
*
|
|
1468
1482
|
* **Error Classification**:
|
|
1469
1483
|
* - 4xx (except 408, 429): PermanentError thrown → no retries
|
|
1470
|
-
* - Timeout: TimeoutError thrown → caller
|
|
1484
|
+
* - Timeout: TimeoutError thrown → caller treats it as a retryable failure
|
|
1471
1485
|
* - 408, 429, 5xx, network: Standard Error thrown → triggers retry
|
|
1472
1486
|
*
|
|
1473
1487
|
* @param url - API endpoint URL
|
|
1474
1488
|
* @param payload - JSON-stringified EventsQueue body
|
|
1475
1489
|
* @returns Response object if successful
|
|
1476
1490
|
* @throws PermanentError for unrecoverable 4xx errors
|
|
1477
|
-
* @throws TimeoutError when request times out
|
|
1491
|
+
* @throws TimeoutError when request times out
|
|
1478
1492
|
* @throws Error for transient errors (5xx, network)
|
|
1479
1493
|
* @private
|
|
1480
1494
|
*/
|
|
@@ -1498,10 +1512,10 @@ class Ze extends _ {
|
|
|
1498
1512
|
}
|
|
1499
1513
|
});
|
|
1500
1514
|
if (!l.ok)
|
|
1501
|
-
throw l.status >= 400 && l.status < 500 && l.status !== 408 && l.status !== 429 ? new O(`HTTP ${l.status}: ${l.statusText}`, l.status) : l.status === 429 ? new
|
|
1515
|
+
throw l.status >= 400 && l.status < 500 && l.status !== 408 && l.status !== 429 ? new O(`HTTP ${l.status}: ${l.statusText}`, l.status) : l.status === 429 ? new re(`HTTP 429: ${l.statusText}`) : new Error(`HTTP ${l.status}: ${l.statusText}`);
|
|
1502
1516
|
return l;
|
|
1503
1517
|
} catch (o) {
|
|
1504
|
-
throw o instanceof O ? o : n ? new
|
|
1518
|
+
throw o instanceof O ? o : n ? new ne("Request timed out") : o;
|
|
1505
1519
|
} finally {
|
|
1506
1520
|
clearTimeout(i), this.pendingControllers.delete(s);
|
|
1507
1521
|
}
|
|
@@ -1523,40 +1537,40 @@ class Ze extends _ {
|
|
|
1523
1537
|
* - Oversized payloads persisted instead of silently failing
|
|
1524
1538
|
*
|
|
1525
1539
|
* @param body - EventsQueue to send
|
|
1526
|
-
* @returns `true` on success
|
|
1540
|
+
* @returns `true` on success, `false` on failure (events persisted for recovery)
|
|
1527
1541
|
* @private
|
|
1528
1542
|
*/
|
|
1529
1543
|
sendQueueSyncInternal(e) {
|
|
1530
|
-
const t = this.
|
|
1531
|
-
if (!t)
|
|
1532
|
-
return !0;
|
|
1533
|
-
const s = this.applyBeforeBatchTransformer(t);
|
|
1544
|
+
const t = this.ensureBatchMetadata(e), s = this.applyBeforeSendTransformer(t);
|
|
1534
1545
|
if (!s)
|
|
1535
1546
|
return !0;
|
|
1536
|
-
const
|
|
1537
|
-
if (
|
|
1547
|
+
const n = this.applyBeforeBatchTransformer(s);
|
|
1548
|
+
if (!n)
|
|
1549
|
+
return !0;
|
|
1550
|
+
const i = this.ensureBatchMetadata(n, t._metadata?.idempotency_token), { url: o, payload: l } = this.prepareRequest(i);
|
|
1551
|
+
if (l.length > 65536)
|
|
1538
1552
|
return a(
|
|
1539
1553
|
"warn",
|
|
1540
1554
|
`Payload exceeds sendBeacon limit, persisting for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1541
1555
|
{
|
|
1542
1556
|
data: {
|
|
1543
|
-
size:
|
|
1557
|
+
size: l.length,
|
|
1544
1558
|
limit: 65536,
|
|
1545
|
-
events:
|
|
1559
|
+
events: i.events.length
|
|
1546
1560
|
}
|
|
1547
1561
|
}
|
|
1548
|
-
), this.persistEvents(
|
|
1549
|
-
const
|
|
1562
|
+
), this.persistEvents(t), !1;
|
|
1563
|
+
const c = new Blob([l], { type: "application/json" });
|
|
1550
1564
|
if (!this.isSendBeaconAvailable())
|
|
1551
1565
|
return a(
|
|
1552
1566
|
"warn",
|
|
1553
1567
|
`sendBeacon not available, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1554
|
-
), this.persistEvents(
|
|
1555
|
-
const
|
|
1556
|
-
return
|
|
1568
|
+
), this.persistEvents(t), !1;
|
|
1569
|
+
const d = navigator.sendBeacon(o, c);
|
|
1570
|
+
return d || (a(
|
|
1557
1571
|
"warn",
|
|
1558
1572
|
`sendBeacon rejected request, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1559
|
-
), this.persistEvents(
|
|
1573
|
+
), this.persistEvents(t)), d;
|
|
1560
1574
|
}
|
|
1561
1575
|
/**
|
|
1562
1576
|
* Prepares request by enriching payload with metadata and serializing to JSON.
|
|
@@ -1568,9 +1582,10 @@ class Ze extends _ {
|
|
|
1568
1582
|
* - `timestamp`: Request generation time in milliseconds
|
|
1569
1583
|
*
|
|
1570
1584
|
* **Idempotency Token**:
|
|
1571
|
-
* -
|
|
1572
|
-
* -
|
|
1573
|
-
* -
|
|
1585
|
+
* - Set upstream by ensureBatchMetadata() before this method is called
|
|
1586
|
+
* - Fallback generateEventId() is defensive only (should not trigger in normal flow)
|
|
1587
|
+
* - Same token persists across all retry attempts of the same batch
|
|
1588
|
+
* - Backend uses this to deduplicate retries
|
|
1574
1589
|
*
|
|
1575
1590
|
* @param body - EventsQueue to send
|
|
1576
1591
|
* @returns Object with `url` (API endpoint) and `payload` (JSON string)
|
|
@@ -1582,9 +1597,11 @@ class Ze extends _ {
|
|
|
1582
1597
|
const s = {
|
|
1583
1598
|
...e,
|
|
1584
1599
|
_metadata: {
|
|
1600
|
+
...e._metadata,
|
|
1601
|
+
idempotency_token: e._metadata?.idempotency_token ?? ye(),
|
|
1585
1602
|
referer: typeof window < "u" ? window.location.href : void 0,
|
|
1586
1603
|
timestamp: t,
|
|
1587
|
-
client_version:
|
|
1604
|
+
client_version: Zt
|
|
1588
1605
|
}
|
|
1589
1606
|
};
|
|
1590
1607
|
return {
|
|
@@ -1592,6 +1609,16 @@ class Ze extends _ {
|
|
|
1592
1609
|
payload: JSON.stringify(s)
|
|
1593
1610
|
};
|
|
1594
1611
|
}
|
|
1612
|
+
ensureBatchMetadata(e, t) {
|
|
1613
|
+
const s = e._metadata?.idempotency_token ?? t ?? ye();
|
|
1614
|
+
return e._metadata?.idempotency_token === s ? e : {
|
|
1615
|
+
...e,
|
|
1616
|
+
_metadata: {
|
|
1617
|
+
...e._metadata,
|
|
1618
|
+
idempotency_token: s
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1595
1622
|
/**
|
|
1596
1623
|
* Retrieves persisted events from localStorage with error recovery.
|
|
1597
1624
|
*
|
|
@@ -1723,12 +1750,12 @@ class Ze extends _ {
|
|
|
1723
1750
|
}
|
|
1724
1751
|
logPermanentError(e, t) {
|
|
1725
1752
|
const s = Date.now();
|
|
1726
|
-
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || s - this.lastPermanentErrorLog.timestamp >=
|
|
1753
|
+
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || s - this.lastPermanentErrorLog.timestamp >= Qt) && (a("error", `${e}${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1727
1754
|
data: { status: t.statusCode, message: t.message }
|
|
1728
1755
|
}), this.lastPermanentErrorLog = { statusCode: t.statusCode, timestamp: s });
|
|
1729
1756
|
}
|
|
1730
1757
|
}
|
|
1731
|
-
class
|
|
1758
|
+
class ps extends _ {
|
|
1732
1759
|
bootTime;
|
|
1733
1760
|
bootTimestamp;
|
|
1734
1761
|
hasPerformanceNow;
|
|
@@ -1877,7 +1904,7 @@ class Ss extends _ {
|
|
|
1877
1904
|
};
|
|
1878
1905
|
}
|
|
1879
1906
|
}
|
|
1880
|
-
const
|
|
1907
|
+
const Ss = new Set(Object.values(u));
|
|
1881
1908
|
class Ts extends _ {
|
|
1882
1909
|
dataSenders;
|
|
1883
1910
|
emitter;
|
|
@@ -1895,11 +1922,11 @@ class Ts extends _ {
|
|
|
1895
1922
|
lastSessionId = null;
|
|
1896
1923
|
sessionEventCounts = {
|
|
1897
1924
|
total: 0,
|
|
1898
|
-
[
|
|
1899
|
-
[
|
|
1900
|
-
[
|
|
1901
|
-
[
|
|
1902
|
-
[
|
|
1925
|
+
[u.CLICK]: 0,
|
|
1926
|
+
[u.PAGE_VIEW]: 0,
|
|
1927
|
+
[u.CUSTOM]: 0,
|
|
1928
|
+
[u.VIEWPORT_VISIBLE]: 0,
|
|
1929
|
+
[u.SCROLL]: 0
|
|
1903
1930
|
};
|
|
1904
1931
|
saveSessionCountsDebounced = null;
|
|
1905
1932
|
/**
|
|
@@ -1917,10 +1944,10 @@ class Ts extends _ {
|
|
|
1917
1944
|
* @param fetchCredentials - Fetch credentials mode for custom backend. @default 'include'
|
|
1918
1945
|
*/
|
|
1919
1946
|
constructor(e, t = null, s = {}, n = {}, i, o = "include") {
|
|
1920
|
-
super(), this.emitter = t, this.transformers = s, this.timeManager = new
|
|
1947
|
+
super(), this.emitter = t, this.transformers = s, this.timeManager = new ps(), this.dataSenders = [];
|
|
1921
1948
|
const l = this.get("collectApiUrls");
|
|
1922
|
-
l?.saas && this.dataSenders.push(new
|
|
1923
|
-
new
|
|
1949
|
+
l?.saas && this.dataSenders.push(new et(e, "saas", l.saas, s)), l?.custom && this.dataSenders.push(
|
|
1950
|
+
new et(
|
|
1924
1951
|
e,
|
|
1925
1952
|
"custom",
|
|
1926
1953
|
l.custom,
|
|
@@ -2041,21 +2068,21 @@ class Ts extends _ {
|
|
|
2041
2068
|
custom_event: o,
|
|
2042
2069
|
web_vitals: l,
|
|
2043
2070
|
error_data: c,
|
|
2044
|
-
viewport_data:
|
|
2045
|
-
page_view:
|
|
2071
|
+
viewport_data: d,
|
|
2072
|
+
page_view: f
|
|
2046
2073
|
}) {
|
|
2047
2074
|
if (!e) {
|
|
2048
2075
|
a("error", "Event type is required - event will be ignored");
|
|
2049
2076
|
return;
|
|
2050
2077
|
}
|
|
2051
|
-
if (!
|
|
2078
|
+
if (!Ss.has(e)) {
|
|
2052
2079
|
a("error", "Invalid event type - event will be ignored", {
|
|
2053
2080
|
data: { type: e }
|
|
2054
2081
|
});
|
|
2055
2082
|
return;
|
|
2056
2083
|
}
|
|
2057
|
-
const
|
|
2058
|
-
if (!
|
|
2084
|
+
const g = this.get("sessionId");
|
|
2085
|
+
if (!g) {
|
|
2059
2086
|
this.pendingEventsBuffer.length >= 100 && (this.pendingEventsBuffer.shift(), a("debug", "Pending events buffer full - dropping oldest event", {
|
|
2060
2087
|
data: { maxBufferSize: 100 }
|
|
2061
2088
|
})), this.pendingEventsBuffer.push({
|
|
@@ -2067,36 +2094,36 @@ class Ts extends _ {
|
|
|
2067
2094
|
custom_event: o,
|
|
2068
2095
|
web_vitals: l,
|
|
2069
2096
|
error_data: c,
|
|
2070
|
-
viewport_data:
|
|
2071
|
-
page_view:
|
|
2097
|
+
viewport_data: d,
|
|
2098
|
+
page_view: f
|
|
2072
2099
|
});
|
|
2073
2100
|
return;
|
|
2074
2101
|
}
|
|
2075
|
-
this.lastSessionId !==
|
|
2076
|
-
const T = e ===
|
|
2102
|
+
this.lastSessionId !== g && (this.lastSessionId = g, this.sessionEventCounts = this.loadSessionCounts(g));
|
|
2103
|
+
const T = e === u.SESSION_START;
|
|
2077
2104
|
if (T && a("debug", "Processing SESSION_START event", {
|
|
2078
|
-
data: { sessionId:
|
|
2105
|
+
data: { sessionId: g }
|
|
2079
2106
|
}), !T && !this.checkRateLimit())
|
|
2080
2107
|
return;
|
|
2081
|
-
const
|
|
2108
|
+
const p = e;
|
|
2082
2109
|
if (!T) {
|
|
2083
2110
|
if (this.sessionEventCounts.total >= 1e3) {
|
|
2084
2111
|
a("warn", "Session event limit reached", {
|
|
2085
2112
|
data: {
|
|
2086
|
-
type:
|
|
2113
|
+
type: p,
|
|
2087
2114
|
total: this.sessionEventCounts.total,
|
|
2088
2115
|
limit: 1e3
|
|
2089
2116
|
}
|
|
2090
2117
|
});
|
|
2091
2118
|
return;
|
|
2092
2119
|
}
|
|
2093
|
-
const v = this.getTypeLimitForEvent(
|
|
2120
|
+
const v = this.getTypeLimitForEvent(p);
|
|
2094
2121
|
if (v) {
|
|
2095
|
-
const he = this.sessionEventCounts[
|
|
2122
|
+
const he = this.sessionEventCounts[p];
|
|
2096
2123
|
if (he !== void 0 && he >= v) {
|
|
2097
2124
|
a("warn", "Session event type limit reached", {
|
|
2098
2125
|
data: {
|
|
2099
|
-
type:
|
|
2126
|
+
type: p,
|
|
2100
2127
|
count: he,
|
|
2101
2128
|
limit: v
|
|
2102
2129
|
}
|
|
@@ -2105,25 +2132,25 @@ class Ts extends _ {
|
|
|
2105
2132
|
}
|
|
2106
2133
|
}
|
|
2107
2134
|
}
|
|
2108
|
-
if (
|
|
2135
|
+
if (p === u.CUSTOM && o?.name) {
|
|
2109
2136
|
const v = this.get("config")?.maxSameEventPerMinute ?? 60;
|
|
2110
2137
|
if (!this.checkPerEventRateLimit(o.name, v))
|
|
2111
2138
|
return;
|
|
2112
2139
|
}
|
|
2113
|
-
const
|
|
2114
|
-
type:
|
|
2115
|
-
page_url:
|
|
2140
|
+
const Ue = p === u.SESSION_START, K = t || this.get("pageUrl"), x = this.buildEventPayload({
|
|
2141
|
+
type: p,
|
|
2142
|
+
page_url: K,
|
|
2116
2143
|
from_page_url: s,
|
|
2117
2144
|
scroll_data: n,
|
|
2118
2145
|
click_data: i,
|
|
2119
2146
|
custom_event: o,
|
|
2120
2147
|
web_vitals: l,
|
|
2121
2148
|
error_data: c,
|
|
2122
|
-
viewport_data:
|
|
2123
|
-
page_view:
|
|
2149
|
+
viewport_data: d,
|
|
2150
|
+
page_view: f
|
|
2124
2151
|
});
|
|
2125
|
-
if (
|
|
2126
|
-
if (
|
|
2152
|
+
if (x && !(!T && !this.shouldSample())) {
|
|
2153
|
+
if (Ue) {
|
|
2127
2154
|
const v = this.get("sessionId");
|
|
2128
2155
|
if (!v) {
|
|
2129
2156
|
a("error", "Session start event requires sessionId - event will be ignored");
|
|
@@ -2137,35 +2164,35 @@ class Ts extends _ {
|
|
|
2137
2164
|
}
|
|
2138
2165
|
this.set("hasStartSession", !0);
|
|
2139
2166
|
}
|
|
2140
|
-
if (!this.isDuplicateEvent(
|
|
2167
|
+
if (!this.isDuplicateEvent(x)) {
|
|
2141
2168
|
if (this.get("mode") === ie.QA) {
|
|
2142
|
-
if (
|
|
2169
|
+
if (p === u.CUSTOM && o) {
|
|
2143
2170
|
a("info", `Custom Event: ${o.name}`, {
|
|
2144
2171
|
visibility: "qa",
|
|
2145
2172
|
data: {
|
|
2146
2173
|
name: o.name,
|
|
2147
2174
|
...o.metadata && { metadata: o.metadata }
|
|
2148
2175
|
}
|
|
2149
|
-
}), this.emitEvent(
|
|
2176
|
+
}), this.emitEvent(x);
|
|
2150
2177
|
return;
|
|
2151
2178
|
}
|
|
2152
|
-
if (
|
|
2153
|
-
const v =
|
|
2179
|
+
if (p === u.VIEWPORT_VISIBLE && d) {
|
|
2180
|
+
const v = d.name || d.id || d.selector;
|
|
2154
2181
|
a("info", `Viewport Visible: ${v}`, {
|
|
2155
2182
|
visibility: "qa",
|
|
2156
2183
|
data: {
|
|
2157
|
-
selector:
|
|
2158
|
-
...
|
|
2159
|
-
...
|
|
2160
|
-
visibilityRatio:
|
|
2161
|
-
dwellTime:
|
|
2184
|
+
selector: d.selector,
|
|
2185
|
+
...d.name && { name: d.name },
|
|
2186
|
+
...d.id && { id: d.id },
|
|
2187
|
+
visibilityRatio: d.visibilityRatio,
|
|
2188
|
+
dwellTime: d.dwellTime
|
|
2162
2189
|
}
|
|
2163
|
-
}), this.emitEvent(
|
|
2190
|
+
}), this.emitEvent(x);
|
|
2164
2191
|
return;
|
|
2165
2192
|
}
|
|
2166
2193
|
}
|
|
2167
|
-
if (this.addToQueue(
|
|
2168
|
-
this.sessionEventCounts.total++, this.sessionEventCounts[
|
|
2194
|
+
if (this.addToQueue(x), !T) {
|
|
2195
|
+
this.sessionEventCounts.total++, this.sessionEventCounts[p] !== void 0 && this.sessionEventCounts[p]++;
|
|
2169
2196
|
const v = this.get("sessionId");
|
|
2170
2197
|
v && this.saveSessionCountsDebounced && this.saveSessionCountsDebounced(v);
|
|
2171
2198
|
}
|
|
@@ -2211,11 +2238,11 @@ class Ts extends _ {
|
|
|
2211
2238
|
const e = this.get("sessionId");
|
|
2212
2239
|
e && this.saveSessionCounts(e), this.eventsQueue = [], this.pendingEventsBuffer = [], this.recentEventFingerprints.clear(), this.rateLimitCounter = 0, this.rateLimitWindowStart = 0, this.perEventRateLimits.clear(), this.sessionEventCounts = {
|
|
2213
2240
|
total: 0,
|
|
2214
|
-
[
|
|
2215
|
-
[
|
|
2216
|
-
[
|
|
2217
|
-
[
|
|
2218
|
-
[
|
|
2241
|
+
[u.CLICK]: 0,
|
|
2242
|
+
[u.PAGE_VIEW]: 0,
|
|
2243
|
+
[u.CUSTOM]: 0,
|
|
2244
|
+
[u.VIEWPORT_VISIBLE]: 0,
|
|
2245
|
+
[u.SCROLL]: 0
|
|
2219
2246
|
}, this.lastSessionId = null, this.set("hasStartSession", !1), this.dataSenders.forEach((t) => {
|
|
2220
2247
|
t.stop();
|
|
2221
2248
|
});
|
|
@@ -2434,6 +2461,13 @@ class Ts extends _ {
|
|
|
2434
2461
|
const t = this.buildEventsPayload(), s = [...this.eventsQueue], n = s.map((i) => i.id);
|
|
2435
2462
|
if (this.dataSenders.length === 0)
|
|
2436
2463
|
return this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t), e ? !0 : Promise.resolve(!0);
|
|
2464
|
+
if (e && this.sendInProgress) {
|
|
2465
|
+
for (const i of this.dataSenders)
|
|
2466
|
+
i.persistForRecovery(t);
|
|
2467
|
+
return a("debug", "Sync flush deferred: async send in progress, events persisted for recovery", {
|
|
2468
|
+
data: { eventCount: n.length }
|
|
2469
|
+
}), !0;
|
|
2470
|
+
}
|
|
2437
2471
|
if (e) {
|
|
2438
2472
|
const o = this.dataSenders.map((l) => l.sendEventsQueueSync(t)).some((l) => l);
|
|
2439
2473
|
return o ? (this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t)) : (this.clearSendTimeout(), a("debug", "Sync flush complete failure, events kept in queue for retry", {
|
|
@@ -2492,10 +2526,10 @@ class Ts extends _ {
|
|
|
2492
2526
|
buildEventsPayload() {
|
|
2493
2527
|
const e = /* @__PURE__ */ new Map(), t = [];
|
|
2494
2528
|
for (const c of this.eventsQueue) {
|
|
2495
|
-
const
|
|
2496
|
-
e.has(
|
|
2529
|
+
const d = this.createEventSignature(c);
|
|
2530
|
+
e.has(d) || t.push(d), e.set(d, c);
|
|
2497
2531
|
}
|
|
2498
|
-
const s = t.map((c) => e.get(c)).filter((c) => !!c).sort((c,
|
|
2532
|
+
const s = t.map((c) => e.get(c)).filter((c) => !!c).sort((c, d) => c.type === u.SESSION_START && d.type !== u.SESSION_START ? -1 : d.type === u.SESSION_START && c.type !== u.SESSION_START ? 1 : c.timestamp - d.timestamp);
|
|
2499
2533
|
let n = {
|
|
2500
2534
|
user_id: this.get("userId"),
|
|
2501
2535
|
session_id: this.get("sessionId"),
|
|
@@ -2506,7 +2540,7 @@ class Ts extends _ {
|
|
|
2506
2540
|
};
|
|
2507
2541
|
const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas), l = this.transformers.beforeBatch;
|
|
2508
2542
|
if (!o && l) {
|
|
2509
|
-
const c =
|
|
2543
|
+
const c = Et(n, l, "EventManager");
|
|
2510
2544
|
c !== null && (n = c);
|
|
2511
2545
|
}
|
|
2512
2546
|
return n;
|
|
@@ -2518,7 +2552,7 @@ class Ts extends _ {
|
|
|
2518
2552
|
});
|
|
2519
2553
|
const i = this.get("sessionReferrer"), o = this.get("sessionUtm");
|
|
2520
2554
|
let l = {
|
|
2521
|
-
id:
|
|
2555
|
+
id: ye(),
|
|
2522
2556
|
type: e.type,
|
|
2523
2557
|
page_url: t,
|
|
2524
2558
|
timestamp: s,
|
|
@@ -2533,12 +2567,12 @@ class Ts extends _ {
|
|
|
2533
2567
|
...e.page_view && { page_view: e.page_view },
|
|
2534
2568
|
...o && { utm: o }
|
|
2535
2569
|
};
|
|
2536
|
-
const c = this.get("collectApiUrls"),
|
|
2537
|
-
if (
|
|
2538
|
-
const
|
|
2539
|
-
if (
|
|
2570
|
+
const c = this.get("collectApiUrls"), d = !!c?.custom, f = !!c?.saas, g = d || f, T = d && f, p = this.transformers.beforeSend;
|
|
2571
|
+
if (p && (!g || d && !T)) {
|
|
2572
|
+
const K = gt(l, p, "EventManager");
|
|
2573
|
+
if (K === null)
|
|
2540
2574
|
return null;
|
|
2541
|
-
l =
|
|
2575
|
+
l = K;
|
|
2542
2576
|
}
|
|
2543
2577
|
return l;
|
|
2544
2578
|
}
|
|
@@ -2576,13 +2610,13 @@ class Ts extends _ {
|
|
|
2576
2610
|
}
|
|
2577
2611
|
addToQueue(e) {
|
|
2578
2612
|
if (this.emitEvent(e), this.eventsQueue.push(e), this.eventsQueue.length > 100) {
|
|
2579
|
-
const t = this.eventsQueue.findIndex((n) => n.type !==
|
|
2613
|
+
const t = this.eventsQueue.findIndex((n) => n.type !== u.SESSION_START), s = t >= 0 ? this.eventsQueue.splice(t, 1)[0] : this.eventsQueue.shift();
|
|
2580
2614
|
a("warn", "Event queue overflow, oldest non-critical event removed", {
|
|
2581
2615
|
data: {
|
|
2582
2616
|
maxLength: 100,
|
|
2583
2617
|
currentLength: this.eventsQueue.length,
|
|
2584
2618
|
removedEventType: s?.type,
|
|
2585
|
-
wasCritical: s?.type ===
|
|
2619
|
+
wasCritical: s?.type === u.SESSION_START
|
|
2586
2620
|
}
|
|
2587
2621
|
});
|
|
2588
2622
|
}
|
|
@@ -2621,11 +2655,11 @@ class Ts extends _ {
|
|
|
2621
2655
|
}
|
|
2622
2656
|
getTypeLimitForEvent(e) {
|
|
2623
2657
|
return {
|
|
2624
|
-
[
|
|
2625
|
-
[
|
|
2626
|
-
[
|
|
2627
|
-
[
|
|
2628
|
-
[
|
|
2658
|
+
[u.CLICK]: 500,
|
|
2659
|
+
[u.PAGE_VIEW]: 100,
|
|
2660
|
+
[u.CUSTOM]: 500,
|
|
2661
|
+
[u.VIEWPORT_VISIBLE]: 200,
|
|
2662
|
+
[u.SCROLL]: 120
|
|
2629
2663
|
}[e] ?? null;
|
|
2630
2664
|
}
|
|
2631
2665
|
removeProcessedEvents(e) {
|
|
@@ -2633,10 +2667,10 @@ class Ts extends _ {
|
|
|
2633
2667
|
this.eventsQueue = this.eventsQueue.filter((s) => !t.has(s.id));
|
|
2634
2668
|
}
|
|
2635
2669
|
emitEvent(e) {
|
|
2636
|
-
this.emitter && this.emitter.emit(
|
|
2670
|
+
this.emitter && this.emitter.emit(se.EVENT, e);
|
|
2637
2671
|
}
|
|
2638
2672
|
emitEventsQueue(e) {
|
|
2639
|
-
this.emitter && this.emitter.emit(
|
|
2673
|
+
this.emitter && this.emitter.emit(se.QUEUE, e);
|
|
2640
2674
|
}
|
|
2641
2675
|
/**
|
|
2642
2676
|
* Creates a debounced version of a function that delays execution until after
|
|
@@ -2679,11 +2713,11 @@ class Ts extends _ {
|
|
|
2679
2713
|
getInitialCounts() {
|
|
2680
2714
|
return {
|
|
2681
2715
|
total: 0,
|
|
2682
|
-
[
|
|
2683
|
-
[
|
|
2684
|
-
[
|
|
2685
|
-
[
|
|
2686
|
-
[
|
|
2716
|
+
[u.CLICK]: 0,
|
|
2717
|
+
[u.PAGE_VIEW]: 0,
|
|
2718
|
+
[u.CUSTOM]: 0,
|
|
2719
|
+
[u.VIEWPORT_VISIBLE]: 0,
|
|
2720
|
+
[u.SCROLL]: 0
|
|
2687
2721
|
};
|
|
2688
2722
|
}
|
|
2689
2723
|
/**
|
|
@@ -2712,21 +2746,21 @@ class Ts extends _ {
|
|
|
2712
2746
|
loadSessionCounts(e) {
|
|
2713
2747
|
if (typeof window > "u" || typeof localStorage > "u")
|
|
2714
2748
|
return this.getInitialCounts();
|
|
2715
|
-
const t = this.get("userId") || "anonymous", s =
|
|
2749
|
+
const t = this.get("userId") || "anonymous", s = xe(t, e);
|
|
2716
2750
|
try {
|
|
2717
2751
|
const n = localStorage.getItem(s);
|
|
2718
2752
|
if (!n)
|
|
2719
2753
|
return this.getInitialCounts();
|
|
2720
2754
|
const i = JSON.parse(n);
|
|
2721
|
-
return i._timestamp && Date.now() - i._timestamp >
|
|
2755
|
+
return i._timestamp && Date.now() - i._timestamp > $e ? (a("debug", "Session counts expired, clearing", {
|
|
2722
2756
|
data: { sessionId: e, age: Date.now() - i._timestamp }
|
|
2723
|
-
}), localStorage.removeItem(s), this.getInitialCounts()) : typeof i.total == "number" && typeof i[
|
|
2757
|
+
}), localStorage.removeItem(s), this.getInitialCounts()) : typeof i.total == "number" && typeof i[u.CLICK] == "number" && typeof i[u.PAGE_VIEW] == "number" && typeof i[u.CUSTOM] == "number" && typeof i[u.VIEWPORT_VISIBLE] == "number" && typeof i[u.SCROLL] == "number" ? {
|
|
2724
2758
|
total: i.total,
|
|
2725
|
-
[
|
|
2726
|
-
[
|
|
2727
|
-
[
|
|
2728
|
-
[
|
|
2729
|
-
[
|
|
2759
|
+
[u.CLICK]: i[u.CLICK],
|
|
2760
|
+
[u.PAGE_VIEW]: i[u.PAGE_VIEW],
|
|
2761
|
+
[u.CUSTOM]: i[u.CUSTOM],
|
|
2762
|
+
[u.VIEWPORT_VISIBLE]: i[u.VIEWPORT_VISIBLE],
|
|
2763
|
+
[u.SCROLL]: i[u.SCROLL]
|
|
2730
2764
|
} : (a("warn", "Invalid session counts structure in localStorage, resetting", {
|
|
2731
2765
|
data: { sessionId: e, parsed: i }
|
|
2732
2766
|
}), localStorage.removeItem(s), a("debug", "Session counts removed due to invalid/corrupted data", {
|
|
@@ -2763,12 +2797,12 @@ class Ts extends _ {
|
|
|
2763
2797
|
cleanupExpiredSessionCounts() {
|
|
2764
2798
|
if (!(typeof window > "u" || typeof localStorage > "u"))
|
|
2765
2799
|
try {
|
|
2766
|
-
const e = localStorage.getItem(
|
|
2800
|
+
const e = localStorage.getItem(Be);
|
|
2767
2801
|
if (e) {
|
|
2768
2802
|
const i = Date.now() - parseInt(e, 10);
|
|
2769
|
-
if (i <
|
|
2803
|
+
if (i < We) {
|
|
2770
2804
|
a("debug", "Skipping session counts cleanup (throttled)", {
|
|
2771
|
-
data: { timeSinceLastCleanup: i, throttleMs:
|
|
2805
|
+
data: { timeSinceLastCleanup: i, throttleMs: We }
|
|
2772
2806
|
});
|
|
2773
2807
|
return;
|
|
2774
2808
|
}
|
|
@@ -2781,14 +2815,14 @@ class Ts extends _ {
|
|
|
2781
2815
|
const l = localStorage.getItem(o);
|
|
2782
2816
|
if (l) {
|
|
2783
2817
|
const c = JSON.parse(l);
|
|
2784
|
-
c._timestamp && Date.now() - c._timestamp >
|
|
2818
|
+
c._timestamp && Date.now() - c._timestamp > $e && n.push(o);
|
|
2785
2819
|
}
|
|
2786
2820
|
} catch {
|
|
2787
2821
|
}
|
|
2788
2822
|
}
|
|
2789
2823
|
n.forEach((i) => {
|
|
2790
2824
|
localStorage.removeItem(i), a("debug", "Cleaned up expired session counts", { data: { key: i } });
|
|
2791
|
-
}), n.length > 0 && a("info", `Cleaned up ${n.length} expired session counts entries`), localStorage.setItem(
|
|
2825
|
+
}), n.length > 0 && a("info", `Cleaned up ${n.length} expired session counts entries`), localStorage.setItem(Be, Date.now().toString());
|
|
2792
2826
|
} catch (e) {
|
|
2793
2827
|
a("warn", "Failed to cleanup expired session counts", { error: e });
|
|
2794
2828
|
}
|
|
@@ -2822,7 +2856,7 @@ class Ts extends _ {
|
|
|
2822
2856
|
* @internal
|
|
2823
2857
|
*/
|
|
2824
2858
|
saveSessionCounts(e) {
|
|
2825
|
-
const t = this.get("userId") || "anonymous", s =
|
|
2859
|
+
const t = this.get("userId") || "anonymous", s = xe(t, e);
|
|
2826
2860
|
try {
|
|
2827
2861
|
const n = {
|
|
2828
2862
|
...this.sessionEventCounts,
|
|
@@ -2890,7 +2924,7 @@ class _s extends _ {
|
|
|
2890
2924
|
return;
|
|
2891
2925
|
}
|
|
2892
2926
|
const e = this.getProjectId();
|
|
2893
|
-
this.broadcastChannel = new BroadcastChannel(
|
|
2927
|
+
this.broadcastChannel = new BroadcastChannel(Ot(e)), this.broadcastChannel.onmessage = (t) => {
|
|
2894
2928
|
const { action: s, sessionId: n, timestamp: i, projectId: o } = t.data ?? {};
|
|
2895
2929
|
o === e && (s === "session_start" && n && typeof i == "number" && i > Date.now() - 5e3 ? (this.set("sessionId", n), this.persistSession(n, i), this.isTracking && this.setupSessionTimeout()) : s && s !== "session_start" && a("debug", "Ignored BroadcastChannel message with unknown action", { data: { action: s } }));
|
|
2896
2930
|
};
|
|
@@ -2955,7 +2989,7 @@ class _s extends _ {
|
|
|
2955
2989
|
this.storageManager.setItem(t, s), this.storageManager.setSessionItem(t, s);
|
|
2956
2990
|
}
|
|
2957
2991
|
getSessionStorageKey() {
|
|
2958
|
-
return
|
|
2992
|
+
return Nt(this.getProjectId());
|
|
2959
2993
|
}
|
|
2960
2994
|
getProjectId() {
|
|
2961
2995
|
return this.projectId;
|
|
@@ -3039,7 +3073,7 @@ class _s extends _ {
|
|
|
3039
3073
|
}) : (a("debug", "Emitting SESSION_START event", {
|
|
3040
3074
|
data: { sessionId: t }
|
|
3041
3075
|
}), this.eventManager.track({
|
|
3042
|
-
type:
|
|
3076
|
+
type: u.SESSION_START
|
|
3043
3077
|
})), this.setupSessionTimeout(), this.setupActivityListeners(), this.setupLifecycleListeners();
|
|
3044
3078
|
} catch (i) {
|
|
3045
3079
|
throw this.isTracking = !1, this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupLifecycleListeners(), this.cleanupCrossTabSync(), this.set("sessionId", null), i;
|
|
@@ -3078,7 +3112,7 @@ class _s extends _ {
|
|
|
3078
3112
|
a("debug", "Renewing session after timeout", {
|
|
3079
3113
|
data: { newSessionId: e }
|
|
3080
3114
|
}), this.set("sessionId", e), this.set("sessionReferrer", t), this.set("sessionUtm", s), this.persistSession(e, Date.now(), t, s), this.cleanupCrossTabSync(), this.initCrossTabSync(), this.shareSession(e), this.eventManager.track({
|
|
3081
|
-
type:
|
|
3115
|
+
type: u.SESSION_START
|
|
3082
3116
|
}), this.eventManager.flushPendingEvents(), this.setupSessionTimeout();
|
|
3083
3117
|
}
|
|
3084
3118
|
cleanupActivityListeners() {
|
|
@@ -3323,7 +3357,7 @@ class ws extends _ {
|
|
|
3323
3357
|
};
|
|
3324
3358
|
}
|
|
3325
3359
|
trackCurrentPage = () => {
|
|
3326
|
-
const e = window.location.href, t =
|
|
3360
|
+
const e = window.location.href, t = we(e, this.get("config").sensitiveQueryParams);
|
|
3327
3361
|
if (this.get("pageUrl") === t)
|
|
3328
3362
|
return;
|
|
3329
3363
|
const s = Date.now(), n = this.get("config").pageViewThrottleMs ?? 1e3;
|
|
@@ -3334,16 +3368,16 @@ class ws extends _ {
|
|
|
3334
3368
|
this.set("pageUrl", t);
|
|
3335
3369
|
const o = this.extractPageViewData();
|
|
3336
3370
|
this.eventManager.track({
|
|
3337
|
-
type:
|
|
3371
|
+
type: u.PAGE_VIEW,
|
|
3338
3372
|
page_url: this.get("pageUrl"),
|
|
3339
3373
|
from_page_url: i,
|
|
3340
3374
|
...o && { page_view: o }
|
|
3341
3375
|
});
|
|
3342
3376
|
};
|
|
3343
3377
|
trackInitialPageView() {
|
|
3344
|
-
const e =
|
|
3378
|
+
const e = we(window.location.href, this.get("config").sensitiveQueryParams), t = this.extractPageViewData();
|
|
3345
3379
|
this.lastPageViewTime = Date.now(), this.eventManager.track({
|
|
3346
|
-
type:
|
|
3380
|
+
type: u.PAGE_VIEW,
|
|
3347
3381
|
page_url: e,
|
|
3348
3382
|
...t && { page_view: t }
|
|
3349
3383
|
}), this.onTrack();
|
|
@@ -3394,22 +3428,22 @@ class bs extends _ {
|
|
|
3394
3428
|
return;
|
|
3395
3429
|
const o = this.findTrackingElement(n), l = this.getRelevantClickElement(n), c = this.calculateClickCoordinates(t, n);
|
|
3396
3430
|
if (o) {
|
|
3397
|
-
const
|
|
3398
|
-
if (
|
|
3399
|
-
const
|
|
3431
|
+
const f = this.extractTrackingData(o);
|
|
3432
|
+
if (f) {
|
|
3433
|
+
const g = this.createCustomEventData(f);
|
|
3400
3434
|
this.eventManager.track({
|
|
3401
|
-
type:
|
|
3435
|
+
type: u.CUSTOM,
|
|
3402
3436
|
custom_event: {
|
|
3403
|
-
name:
|
|
3404
|
-
...
|
|
3437
|
+
name: g.name,
|
|
3438
|
+
...g.value && { metadata: { value: g.value } }
|
|
3405
3439
|
}
|
|
3406
3440
|
});
|
|
3407
3441
|
}
|
|
3408
3442
|
}
|
|
3409
|
-
const
|
|
3443
|
+
const d = this.generateClickData(n, l, c);
|
|
3410
3444
|
this.eventManager.track({
|
|
3411
|
-
type:
|
|
3412
|
-
click_data:
|
|
3445
|
+
type: u.CLICK,
|
|
3446
|
+
click_data: d
|
|
3413
3447
|
});
|
|
3414
3448
|
}, window.addEventListener("click", this.clickHandler, !0));
|
|
3415
3449
|
}
|
|
@@ -3497,7 +3531,7 @@ class bs extends _ {
|
|
|
3497
3531
|
return e.hasAttribute(`${b}-name`) ? e : e.closest(`[${b}-name]`);
|
|
3498
3532
|
}
|
|
3499
3533
|
getRelevantClickElement(e) {
|
|
3500
|
-
for (const t of
|
|
3534
|
+
for (const t of At)
|
|
3501
3535
|
try {
|
|
3502
3536
|
if (e.matches(t))
|
|
3503
3537
|
return e;
|
|
@@ -3538,7 +3572,7 @@ class bs extends _ {
|
|
|
3538
3572
|
};
|
|
3539
3573
|
}
|
|
3540
3574
|
generateClickData(e, t, s) {
|
|
3541
|
-
const { x: n, y: i, relativeX: o, relativeY: l } = s, c = this.getRelevantText(e, t),
|
|
3575
|
+
const { x: n, y: i, relativeX: o, relativeY: l } = s, c = this.getRelevantText(e, t), d = this.extractElementAttributes(t);
|
|
3542
3576
|
return {
|
|
3543
3577
|
x: n,
|
|
3544
3578
|
y: i,
|
|
@@ -3548,12 +3582,12 @@ class bs extends _ {
|
|
|
3548
3582
|
...t.id && { id: t.id },
|
|
3549
3583
|
...t.className && { class: t.className },
|
|
3550
3584
|
...c && { text: c },
|
|
3551
|
-
...
|
|
3552
|
-
...
|
|
3553
|
-
...
|
|
3554
|
-
...
|
|
3555
|
-
...
|
|
3556
|
-
...Object.keys(
|
|
3585
|
+
...d.href && { href: d.href },
|
|
3586
|
+
...d.title && { title: d.title },
|
|
3587
|
+
...d.alt && { alt: d.alt },
|
|
3588
|
+
...d.role && { role: d.role },
|
|
3589
|
+
...d["aria-label"] && { ariaLabel: d["aria-label"] },
|
|
3590
|
+
...Object.keys(d).length > 0 && { dataAttributes: d }
|
|
3557
3591
|
};
|
|
3558
3592
|
}
|
|
3559
3593
|
/**
|
|
@@ -3577,7 +3611,7 @@ class bs extends _ {
|
|
|
3577
3611
|
*/
|
|
3578
3612
|
sanitizeText(e) {
|
|
3579
3613
|
let t = e;
|
|
3580
|
-
for (const s of
|
|
3614
|
+
for (const s of lt) {
|
|
3581
3615
|
const n = new RegExp(s.source, s.flags);
|
|
3582
3616
|
t = t.replace(n, "[REDACTED]");
|
|
3583
3617
|
}
|
|
@@ -3717,7 +3751,7 @@ class As extends _ {
|
|
|
3717
3751
|
return this.isWindowScrollable() ? e === window : this.containers.length === 0;
|
|
3718
3752
|
}
|
|
3719
3753
|
setupScrollContainer(e, t) {
|
|
3720
|
-
if (this.containers.some((
|
|
3754
|
+
if (this.containers.some((d) => d.element === e) || e !== window && !this.isElementScrollable(e))
|
|
3721
3755
|
return;
|
|
3722
3756
|
const n = this.getScrollTop(e), i = this.calculateScrollDepth(
|
|
3723
3757
|
n,
|
|
@@ -3729,7 +3763,7 @@ class As extends _ {
|
|
|
3729
3763
|
isPrimary: o,
|
|
3730
3764
|
lastScrollPos: n,
|
|
3731
3765
|
lastDepth: i,
|
|
3732
|
-
lastDirection:
|
|
3766
|
+
lastDirection: Z.DOWN,
|
|
3733
3767
|
lastEventTime: 0,
|
|
3734
3768
|
firstScrollEventTime: null,
|
|
3735
3769
|
maxDepthReached: i,
|
|
@@ -3737,10 +3771,10 @@ class As extends _ {
|
|
|
3737
3771
|
listener: null
|
|
3738
3772
|
}, c = () => {
|
|
3739
3773
|
this.get("suppressNextScroll") || (l.firstScrollEventTime === null && (l.firstScrollEventTime = Date.now()), this.clearContainerTimer(l), l.debounceTimer = window.setTimeout(() => {
|
|
3740
|
-
const
|
|
3741
|
-
if (
|
|
3742
|
-
const
|
|
3743
|
-
this.processScrollEvent(l,
|
|
3774
|
+
const d = this.calculateScrollData(l);
|
|
3775
|
+
if (d) {
|
|
3776
|
+
const f = Date.now();
|
|
3777
|
+
this.processScrollEvent(l, d, f);
|
|
3744
3778
|
}
|
|
3745
3779
|
l.debounceTimer = null;
|
|
3746
3780
|
}, 250));
|
|
@@ -3753,7 +3787,7 @@ class As extends _ {
|
|
|
3753
3787
|
e.lastEventTime = s, e.lastDepth = t.depth, e.lastDirection = t.direction;
|
|
3754
3788
|
const n = this.get("scrollEventCount") ?? 0;
|
|
3755
3789
|
this.set("scrollEventCount", n + 1), this.eventManager.track({
|
|
3756
|
-
type:
|
|
3790
|
+
type: u.SCROLL,
|
|
3757
3791
|
scroll_data: {
|
|
3758
3792
|
...t,
|
|
3759
3793
|
container_selector: e.selector,
|
|
@@ -3788,7 +3822,7 @@ class As extends _ {
|
|
|
3788
3822
|
e.debounceTimer !== null && (clearTimeout(e.debounceTimer), e.debounceTimer = null);
|
|
3789
3823
|
}
|
|
3790
3824
|
getScrollDirection(e, t) {
|
|
3791
|
-
return e > t ?
|
|
3825
|
+
return e > t ? Z.DOWN : Z.UP;
|
|
3792
3826
|
}
|
|
3793
3827
|
calculateScrollDepth(e, t, s) {
|
|
3794
3828
|
if (t <= s)
|
|
@@ -3800,14 +3834,14 @@ class As extends _ {
|
|
|
3800
3834
|
const { element: t, lastScrollPos: s, lastEventTime: n } = e, i = this.getScrollTop(t), o = Date.now(), l = Math.abs(i - s);
|
|
3801
3835
|
if (l < 10 || t === window && !this.isWindowScrollable())
|
|
3802
3836
|
return null;
|
|
3803
|
-
const c = this.getViewportHeight(t),
|
|
3837
|
+
const c = this.getViewportHeight(t), d = this.getScrollHeight(t), f = this.getScrollDirection(i, s), g = this.calculateScrollDepth(i, d, c);
|
|
3804
3838
|
let T;
|
|
3805
3839
|
n > 0 ? T = o - n : e.firstScrollEventTime !== null ? T = o - e.firstScrollEventTime : T = 250;
|
|
3806
|
-
const
|
|
3807
|
-
return
|
|
3808
|
-
depth:
|
|
3809
|
-
direction:
|
|
3810
|
-
velocity:
|
|
3840
|
+
const p = Math.round(l / T * 1e3);
|
|
3841
|
+
return g > e.maxDepthReached && (e.maxDepthReached = g), e.lastScrollPos = i, {
|
|
3842
|
+
depth: g,
|
|
3843
|
+
direction: f,
|
|
3844
|
+
velocity: p,
|
|
3811
3845
|
max_depth_reached: e.maxDepthReached
|
|
3812
3846
|
};
|
|
3813
3847
|
}
|
|
@@ -3965,7 +3999,7 @@ class Ls extends _ {
|
|
|
3965
3999
|
...e.name !== void 0 && { name: e.name }
|
|
3966
4000
|
};
|
|
3967
4001
|
this.eventManager.track({
|
|
3968
|
-
type:
|
|
4002
|
+
type: u.VIEWPORT_VISIBLE,
|
|
3969
4003
|
viewport_data: o
|
|
3970
4004
|
}), e.startTime = null, e.timeoutId = null, e.lastFiredTime = i;
|
|
3971
4005
|
}
|
|
@@ -4342,7 +4376,7 @@ class Ns extends _ {
|
|
|
4342
4376
|
navigationCounter = 0;
|
|
4343
4377
|
// Counter for handling simultaneous navigations edge case
|
|
4344
4378
|
constructor(e) {
|
|
4345
|
-
super(), this.eventManager = e, this.vitalThresholds =
|
|
4379
|
+
super(), this.eventManager = e, this.vitalThresholds = Ye(_e);
|
|
4346
4380
|
}
|
|
4347
4381
|
/**
|
|
4348
4382
|
* Starts tracking Web Vitals and performance metrics.
|
|
@@ -4360,7 +4394,7 @@ class Ns extends _ {
|
|
|
4360
4394
|
*/
|
|
4361
4395
|
async startTracking() {
|
|
4362
4396
|
const e = this.get("config"), t = e?.webVitalsMode ?? _e;
|
|
4363
|
-
this.vitalThresholds =
|
|
4397
|
+
this.vitalThresholds = Ye(t), e?.webVitalsThresholds && (this.vitalThresholds = { ...this.vitalThresholds, ...e.webVitalsThresholds }), await this.initWebVitals(), this.observeLongTasks();
|
|
4364
4398
|
}
|
|
4365
4399
|
/**
|
|
4366
4400
|
* Stops tracking Web Vitals and cleans up resources.
|
|
@@ -4431,8 +4465,8 @@ class Ns extends _ {
|
|
|
4431
4465
|
async initWebVitals() {
|
|
4432
4466
|
try {
|
|
4433
4467
|
const { onLCP: e, onCLS: t, onFCP: s, onTTFB: n, onINP: i } = await Promise.resolve().then(() => cr), o = (l) => (c) => {
|
|
4434
|
-
const
|
|
4435
|
-
this.sendVital({ type: l, value:
|
|
4468
|
+
const d = Number(c.value.toFixed(2));
|
|
4469
|
+
this.sendVital({ type: l, value: d });
|
|
4436
4470
|
};
|
|
4437
4471
|
e(o("LCP"), { reportAllChanges: !1 }), t(o("CLS"), { reportAllChanges: !1 }), s(o("FCP"), { reportAllChanges: !1 }), n(o("TTFB"), { reportAllChanges: !1 }), i(o("INP"), { reportAllChanges: !1 });
|
|
4438
4472
|
} catch (e) {
|
|
@@ -4457,7 +4491,7 @@ class Ns extends _ {
|
|
|
4457
4491
|
const t = e.getEntries();
|
|
4458
4492
|
for (const s of t) {
|
|
4459
4493
|
const n = Number(s.duration.toFixed(2)), i = Date.now();
|
|
4460
|
-
i - this.lastLongTaskSentAt >=
|
|
4494
|
+
i - this.lastLongTaskSentAt >= Yt && (this.shouldSendVital("LONG_TASK", n) && this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = i);
|
|
4461
4495
|
}
|
|
4462
4496
|
},
|
|
4463
4497
|
{ type: "longtask", buffered: !0 }
|
|
@@ -4473,7 +4507,7 @@ class Ns extends _ {
|
|
|
4473
4507
|
return;
|
|
4474
4508
|
if (s)
|
|
4475
4509
|
s.add(e.type);
|
|
4476
|
-
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length >
|
|
4510
|
+
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length > qt) {
|
|
4477
4511
|
const i = this.navigationHistory.shift();
|
|
4478
4512
|
i && this.reportedByNav.delete(i);
|
|
4479
4513
|
}
|
|
@@ -4486,7 +4520,7 @@ class Ns extends _ {
|
|
|
4486
4520
|
return;
|
|
4487
4521
|
}
|
|
4488
4522
|
this.eventManager.track({
|
|
4489
|
-
type:
|
|
4523
|
+
type: u.WEB_VITALS,
|
|
4490
4524
|
web_vitals: {
|
|
4491
4525
|
type: e,
|
|
4492
4526
|
value: t
|
|
@@ -4600,27 +4634,27 @@ class ae extends _ {
|
|
|
4600
4634
|
const e = Date.now();
|
|
4601
4635
|
if (e < this.burstBackoffUntil)
|
|
4602
4636
|
return !1;
|
|
4603
|
-
if (e - this.burstWindowStart >
|
|
4604
|
-
return this.burstBackoffUntil = e +
|
|
4637
|
+
if (e - this.burstWindowStart > jt && (this.errorBurstCounter = 0, this.burstWindowStart = e), this.errorBurstCounter++, this.errorBurstCounter > zt)
|
|
4638
|
+
return this.burstBackoffUntil = e + Qe, a("debug", "Error burst detected - entering cooldown", {
|
|
4605
4639
|
data: {
|
|
4606
4640
|
errorsInWindow: this.errorBurstCounter,
|
|
4607
|
-
cooldownMs:
|
|
4641
|
+
cooldownMs: Qe
|
|
4608
4642
|
}
|
|
4609
4643
|
}), !1;
|
|
4610
|
-
const s = this.get("config").errorSampling ??
|
|
4644
|
+
const s = this.get("config").errorSampling ?? ct;
|
|
4611
4645
|
return Math.random() < s;
|
|
4612
4646
|
}
|
|
4613
4647
|
handleError = (e) => {
|
|
4614
4648
|
if (!this.shouldSample())
|
|
4615
4649
|
return;
|
|
4616
4650
|
const t = this.sanitize(e.message || "Unknown error");
|
|
4617
|
-
if (this.shouldSuppressError(
|
|
4651
|
+
if (this.shouldSuppressError(B.JS_ERROR, t))
|
|
4618
4652
|
return;
|
|
4619
4653
|
const s = typeof e.error?.stack == "string" ? this.truncateStack(e.error.stack) : void 0;
|
|
4620
4654
|
this.eventManager.track({
|
|
4621
|
-
type:
|
|
4655
|
+
type: u.ERROR,
|
|
4622
4656
|
error_data: {
|
|
4623
|
-
type:
|
|
4657
|
+
type: B.JS_ERROR,
|
|
4624
4658
|
message: t,
|
|
4625
4659
|
...e.filename !== "" && { filename: e.filename },
|
|
4626
4660
|
...e.lineno !== 0 && { line: e.lineno },
|
|
@@ -4633,13 +4667,13 @@ class ae extends _ {
|
|
|
4633
4667
|
if (!this.shouldSample())
|
|
4634
4668
|
return;
|
|
4635
4669
|
const t = this.extractRejectionMessage(e.reason), s = this.sanitize(t);
|
|
4636
|
-
if (this.shouldSuppressError(
|
|
4670
|
+
if (this.shouldSuppressError(B.PROMISE_REJECTION, s))
|
|
4637
4671
|
return;
|
|
4638
4672
|
const n = e.reason instanceof Error && typeof e.reason.stack == "string" ? this.truncateStack(e.reason.stack) : void 0;
|
|
4639
4673
|
this.eventManager.track({
|
|
4640
|
-
type:
|
|
4674
|
+
type: u.ERROR,
|
|
4641
4675
|
error_data: {
|
|
4642
|
-
type:
|
|
4676
|
+
type: B.PROMISE_REJECTION,
|
|
4643
4677
|
message: s,
|
|
4644
4678
|
...n !== void 0 && { stack: n }
|
|
4645
4679
|
}
|
|
@@ -4659,12 +4693,12 @@ class ae extends _ {
|
|
|
4659
4693
|
}
|
|
4660
4694
|
}
|
|
4661
4695
|
sanitize(e) {
|
|
4662
|
-
const t = e.length >
|
|
4696
|
+
const t = e.length > Ge ? e.slice(0, Ge) + "..." : e;
|
|
4663
4697
|
return this.sanitizePii(t);
|
|
4664
4698
|
}
|
|
4665
4699
|
sanitizePii(e) {
|
|
4666
4700
|
let t = e;
|
|
4667
|
-
for (const s of
|
|
4701
|
+
for (const s of lt) {
|
|
4668
4702
|
const n = new RegExp(s.source, s.flags);
|
|
4669
4703
|
t = t.replace(n, "[REDACTED]");
|
|
4670
4704
|
}
|
|
@@ -4672,22 +4706,22 @@ class ae extends _ {
|
|
|
4672
4706
|
}
|
|
4673
4707
|
shouldSuppressError(e, t) {
|
|
4674
4708
|
const s = Date.now(), n = `${e}:${t}`, i = this.recentErrors.get(n);
|
|
4675
|
-
return i !== void 0 && s - i <
|
|
4709
|
+
return i !== void 0 && s - i < ze ? (this.recentErrors.set(n, s), !0) : (this.recentErrors.set(n, s), this.recentErrors.size > Gt ? (this.recentErrors.clear(), this.recentErrors.set(n, s), !1) : (this.recentErrors.size > ee && this.pruneOldErrors(), !1));
|
|
4676
4710
|
}
|
|
4677
4711
|
static TRUNCATION_SUFFIX = `
|
|
4678
4712
|
...truncated`;
|
|
4679
4713
|
truncateStack(e) {
|
|
4680
|
-
if (e.length <=
|
|
4681
|
-
const t =
|
|
4714
|
+
if (e.length <= je) return this.sanitizePii(e);
|
|
4715
|
+
const t = je - ae.TRUNCATION_SUFFIX.length, s = e.slice(0, t) + ae.TRUNCATION_SUFFIX;
|
|
4682
4716
|
return this.sanitizePii(s);
|
|
4683
4717
|
}
|
|
4684
4718
|
pruneOldErrors() {
|
|
4685
4719
|
const e = Date.now();
|
|
4686
4720
|
for (const [n, i] of this.recentErrors.entries())
|
|
4687
|
-
e - i >
|
|
4688
|
-
if (this.recentErrors.size <=
|
|
4721
|
+
e - i > ze && this.recentErrors.delete(n);
|
|
4722
|
+
if (this.recentErrors.size <= ee)
|
|
4689
4723
|
return;
|
|
4690
|
-
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), s = this.recentErrors.size -
|
|
4724
|
+
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), s = this.recentErrors.size - ee;
|
|
4691
4725
|
for (let n = 0; n < s; n += 1) {
|
|
4692
4726
|
const i = t[n];
|
|
4693
4727
|
i && this.recentErrors.delete(i[0]);
|
|
@@ -4759,7 +4793,7 @@ class Os extends _ {
|
|
|
4759
4793
|
return;
|
|
4760
4794
|
}
|
|
4761
4795
|
this.managers.event.track({
|
|
4762
|
-
type:
|
|
4796
|
+
type: u.CUSTOM,
|
|
4763
4797
|
custom_event: {
|
|
4764
4798
|
name: e,
|
|
4765
4799
|
...o && { metadata: o }
|
|
@@ -4825,10 +4859,10 @@ class Os extends _ {
|
|
|
4825
4859
|
this.set("userId", t);
|
|
4826
4860
|
const s = os(e);
|
|
4827
4861
|
this.set("collectApiUrls", s);
|
|
4828
|
-
const n =
|
|
4862
|
+
const n = Xt();
|
|
4829
4863
|
this.set("device", n);
|
|
4830
|
-
const i =
|
|
4831
|
-
this.set("pageUrl", i),
|
|
4864
|
+
const i = we(window.location.href, e.sensitiveQueryParams);
|
|
4865
|
+
this.set("pageUrl", i), ts() && this.set("mode", ie.QA);
|
|
4832
4866
|
}
|
|
4833
4867
|
/**
|
|
4834
4868
|
* Returns the current configuration object.
|
|
@@ -4879,7 +4913,7 @@ class Os extends _ {
|
|
|
4879
4913
|
valid: !1,
|
|
4880
4914
|
error: "Global metadata must be a plain object"
|
|
4881
4915
|
};
|
|
4882
|
-
const t =
|
|
4916
|
+
const t = mt("Global", e, "globalMetadata");
|
|
4883
4917
|
return t.valid ? { valid: !0 } : {
|
|
4884
4918
|
valid: !1,
|
|
4885
4919
|
error: t.error
|
|
@@ -4946,7 +4980,7 @@ class Os extends _ {
|
|
|
4946
4980
|
a("warn", "identify() userId exceeds 256 characters", { data: { length: e.trim().length } });
|
|
4947
4981
|
return;
|
|
4948
4982
|
}
|
|
4949
|
-
const s = e.trim(), n =
|
|
4983
|
+
const s = e.trim(), n = ft(t), i = {
|
|
4950
4984
|
userId: s,
|
|
4951
4985
|
...n ? { traits: n } : {}
|
|
4952
4986
|
};
|
|
@@ -4993,10 +5027,10 @@ class Os extends _ {
|
|
|
4993
5027
|
loadPersistedIdentity() {
|
|
4994
5028
|
const e = this.managers.storage, t = this.getProjectId(), s = fe(t);
|
|
4995
5029
|
try {
|
|
4996
|
-
const n = e.getItem(
|
|
5030
|
+
const n = e.getItem(U);
|
|
4997
5031
|
if (n) {
|
|
4998
5032
|
const i = JSON.parse(n);
|
|
4999
|
-
if (e.removeItem(
|
|
5033
|
+
if (e.removeItem(U), !this.isValidIdentityData(i)) {
|
|
5000
5034
|
a("debug", "Invalid pending identity in localStorage, discarded");
|
|
5001
5035
|
return;
|
|
5002
5036
|
}
|
|
@@ -5005,7 +5039,7 @@ class Os extends _ {
|
|
|
5005
5039
|
return;
|
|
5006
5040
|
}
|
|
5007
5041
|
} catch {
|
|
5008
|
-
e.removeItem(
|
|
5042
|
+
e.removeItem(U);
|
|
5009
5043
|
}
|
|
5010
5044
|
try {
|
|
5011
5045
|
const n = e.getItem(s);
|
|
@@ -5043,7 +5077,7 @@ class Os extends _ {
|
|
|
5043
5077
|
clearPersistedIdentity() {
|
|
5044
5078
|
try {
|
|
5045
5079
|
const e = this.managers.storage, t = this.getProjectId();
|
|
5046
|
-
e.removeItem(fe(t)), e.removeItem(
|
|
5080
|
+
e.removeItem(fe(t)), e.removeItem(U);
|
|
5047
5081
|
} catch {
|
|
5048
5082
|
a("debug", "Failed to clear persisted identity");
|
|
5049
5083
|
}
|
|
@@ -5068,23 +5102,23 @@ class Os extends _ {
|
|
|
5068
5102
|
a("warn", "Failed to start performance tracking", { error: s });
|
|
5069
5103
|
}), this.handlers.error = new ae(this.managers.event), this.handlers.error.startTracking(), e.viewport && (this.handlers.viewport = new Ls(this.managers.event), this.handlers.viewport.startTracking()), e.integrations?.tracelog?.shopify) {
|
|
5070
5104
|
const s = new Cs();
|
|
5071
|
-
s.activate(), this.integrationInstances.shopifyCartLinker = s, this.emitter.on(
|
|
5072
|
-
n.type ===
|
|
5105
|
+
s.activate(), this.integrationInstances.shopifyCartLinker = s, this.emitter.on(se.EVENT, (n) => {
|
|
5106
|
+
n.type === u.SESSION_START && s.onSessionChange();
|
|
5073
5107
|
});
|
|
5074
5108
|
}
|
|
5075
5109
|
}
|
|
5076
5110
|
}
|
|
5077
|
-
const
|
|
5078
|
-
let
|
|
5079
|
-
const Ps = async (r) => typeof window > "u" || typeof document > "u" ? { sessionId: "" } : (
|
|
5111
|
+
const k = [], M = [];
|
|
5112
|
+
let D = null, h = null, R = !1, S = !1, P = null;
|
|
5113
|
+
const Ps = async (r) => typeof window > "u" || typeof document > "u" ? { sessionId: "" } : (S = !1, window.__traceLogDisabled === !0 ? { sessionId: "" } : h ? { sessionId: h.getSessionId() ?? "" } : (R && P || (R = !0, P = (async () => {
|
|
5080
5114
|
try {
|
|
5081
|
-
const e =
|
|
5115
|
+
const e = us(r ?? {}), t = new Os();
|
|
5082
5116
|
try {
|
|
5083
|
-
|
|
5117
|
+
k.forEach(({ event: o, callback: l }) => {
|
|
5084
5118
|
t.on(o, l);
|
|
5085
|
-
}),
|
|
5119
|
+
}), k.length = 0, M.forEach(({ hook: o, fn: l }) => {
|
|
5086
5120
|
o === "beforeSend" ? t.setTransformer("beforeSend", l) : t.setTransformer("beforeBatch", l);
|
|
5087
|
-
}), M.length = 0,
|
|
5121
|
+
}), M.length = 0, D && (t.setCustomHeaders(D), D = null);
|
|
5088
5122
|
const s = t.init(e), n = new Promise((o, l) => {
|
|
5089
5123
|
setTimeout(() => {
|
|
5090
5124
|
l(new Error("[TraceLog] Initialization timeout after 10000ms"));
|
|
@@ -5102,20 +5136,20 @@ const Ps = async (r) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
5102
5136
|
} catch (e) {
|
|
5103
5137
|
throw h = null, e;
|
|
5104
5138
|
} finally {
|
|
5105
|
-
R = !1,
|
|
5139
|
+
R = !1, P = null;
|
|
5106
5140
|
}
|
|
5107
|
-
})()),
|
|
5141
|
+
})()), P)), Ds = (r, e) => {
|
|
5108
5142
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5109
5143
|
if (!h)
|
|
5110
5144
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
5111
|
-
if (
|
|
5145
|
+
if (S)
|
|
5112
5146
|
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
5113
5147
|
h.sendCustomEvent(r, e);
|
|
5114
5148
|
}
|
|
5115
5149
|
}, ks = (r, e) => {
|
|
5116
5150
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5117
5151
|
if (!h || R) {
|
|
5118
|
-
|
|
5152
|
+
k.push({ event: r, callback: e });
|
|
5119
5153
|
return;
|
|
5120
5154
|
}
|
|
5121
5155
|
h.on(r, e);
|
|
@@ -5123,8 +5157,8 @@ const Ps = async (r) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
5123
5157
|
}, Vs = (r, e) => {
|
|
5124
5158
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5125
5159
|
if (!h) {
|
|
5126
|
-
const t =
|
|
5127
|
-
t !== -1 &&
|
|
5160
|
+
const t = k.findIndex((s) => s.event === r && s.callback === e);
|
|
5161
|
+
t !== -1 && k.splice(t, 1);
|
|
5128
5162
|
return;
|
|
5129
5163
|
}
|
|
5130
5164
|
h.off(r, e);
|
|
@@ -5139,7 +5173,7 @@ function Us(r, e) {
|
|
|
5139
5173
|
t !== -1 && M.splice(t, 1), M.push({ hook: r, fn: e });
|
|
5140
5174
|
return;
|
|
5141
5175
|
}
|
|
5142
|
-
if (
|
|
5176
|
+
if (S)
|
|
5143
5177
|
throw new Error("[TraceLog] Cannot set transformers while TraceLog is being destroyed");
|
|
5144
5178
|
r === "beforeSend" ? h.setTransformer("beforeSend", e) : h.setTransformer("beforeBatch", e);
|
|
5145
5179
|
}
|
|
@@ -5151,7 +5185,7 @@ const Hs = (r) => {
|
|
|
5151
5185
|
e !== -1 && M.splice(e, 1);
|
|
5152
5186
|
return;
|
|
5153
5187
|
}
|
|
5154
|
-
if (
|
|
5188
|
+
if (S)
|
|
5155
5189
|
throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
|
|
5156
5190
|
h.removeTransformer(r);
|
|
5157
5191
|
}
|
|
@@ -5160,45 +5194,45 @@ const Hs = (r) => {
|
|
|
5160
5194
|
if (typeof r != "function")
|
|
5161
5195
|
throw new Error(`[TraceLog] Custom headers provider must be a function, received: ${typeof r}`);
|
|
5162
5196
|
if (!h || R) {
|
|
5163
|
-
|
|
5197
|
+
D = r;
|
|
5164
5198
|
return;
|
|
5165
5199
|
}
|
|
5166
|
-
if (
|
|
5200
|
+
if (S)
|
|
5167
5201
|
throw new Error("[TraceLog] Cannot set custom headers while TraceLog is being destroyed");
|
|
5168
5202
|
h.setCustomHeaders(r);
|
|
5169
5203
|
}
|
|
5170
5204
|
}, xs = () => {
|
|
5171
5205
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5172
5206
|
if (!h) {
|
|
5173
|
-
|
|
5207
|
+
D = null;
|
|
5174
5208
|
return;
|
|
5175
5209
|
}
|
|
5176
|
-
if (
|
|
5210
|
+
if (S)
|
|
5177
5211
|
throw new Error("[TraceLog] Cannot remove custom headers while TraceLog is being destroyed");
|
|
5178
5212
|
h.removeCustomHeaders();
|
|
5179
5213
|
}
|
|
5180
5214
|
}, $s = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, Bs = () => typeof window > "u" || typeof document > "u" || !h ? null : h.getSessionId(), Ws = () => {
|
|
5181
5215
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5182
|
-
if (
|
|
5216
|
+
if (S)
|
|
5183
5217
|
throw new Error("[TraceLog] Destroy operation already in progress");
|
|
5184
5218
|
if (!h) {
|
|
5185
|
-
|
|
5219
|
+
S = !1;
|
|
5186
5220
|
return;
|
|
5187
5221
|
}
|
|
5188
|
-
|
|
5222
|
+
S = !0;
|
|
5189
5223
|
try {
|
|
5190
|
-
h.destroy(), h = null, R = !1,
|
|
5224
|
+
h.destroy(), h = null, R = !1, P = null, k.length = 0, M.length = 0, D = null, S = !1;
|
|
5191
5225
|
} catch (r) {
|
|
5192
|
-
h = null, R = !1,
|
|
5226
|
+
h = null, R = !1, P = null, k.length = 0, M.length = 0, D = null, S = !1, a("warn", "Error during destroy, forced cleanup completed", { error: r });
|
|
5193
5227
|
}
|
|
5194
5228
|
}
|
|
5195
5229
|
}, Xs = (r) => {
|
|
5196
|
-
typeof window > "u" || typeof document > "u" ||
|
|
5230
|
+
typeof window > "u" || typeof document > "u" || ss(r);
|
|
5197
5231
|
}, Gs = (r) => {
|
|
5198
5232
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5199
5233
|
if (!h)
|
|
5200
5234
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
5201
|
-
if (
|
|
5235
|
+
if (S)
|
|
5202
5236
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
5203
5237
|
h.updateGlobalMetadata(r);
|
|
5204
5238
|
}
|
|
@@ -5206,7 +5240,7 @@ const Hs = (r) => {
|
|
|
5206
5240
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5207
5241
|
if (!h)
|
|
5208
5242
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
5209
|
-
if (
|
|
5243
|
+
if (S)
|
|
5210
5244
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
5211
5245
|
h.mergeGlobalMetadata(r);
|
|
5212
5246
|
}
|
|
@@ -5220,7 +5254,7 @@ const Hs = (r) => {
|
|
|
5220
5254
|
a("warn", "identify() userId exceeds 256 characters");
|
|
5221
5255
|
return;
|
|
5222
5256
|
}
|
|
5223
|
-
if (
|
|
5257
|
+
if (S) {
|
|
5224
5258
|
a("warn", "Cannot identify while TraceLog is being destroyed");
|
|
5225
5259
|
return;
|
|
5226
5260
|
}
|
|
@@ -5229,11 +5263,11 @@ const Hs = (r) => {
|
|
|
5229
5263
|
return;
|
|
5230
5264
|
}
|
|
5231
5265
|
try {
|
|
5232
|
-
const t =
|
|
5266
|
+
const t = ft(e), s = {
|
|
5233
5267
|
userId: r.trim(),
|
|
5234
5268
|
...t ? { traits: t } : {}
|
|
5235
5269
|
};
|
|
5236
|
-
localStorage.setItem(
|
|
5270
|
+
localStorage.setItem(U, JSON.stringify(s)), a("debug", "Identity persisted pre-init (will be applied on init)");
|
|
5237
5271
|
} catch {
|
|
5238
5272
|
a("debug", "Failed to persist pre-init identity");
|
|
5239
5273
|
}
|
|
@@ -5242,12 +5276,12 @@ const Hs = (r) => {
|
|
|
5242
5276
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5243
5277
|
if (!h) {
|
|
5244
5278
|
try {
|
|
5245
|
-
localStorage.removeItem(
|
|
5279
|
+
localStorage.removeItem(U);
|
|
5246
5280
|
} catch {
|
|
5247
5281
|
}
|
|
5248
5282
|
return;
|
|
5249
5283
|
}
|
|
5250
|
-
if (
|
|
5284
|
+
if (S)
|
|
5251
5285
|
throw new Error("[TraceLog] Cannot reset identity while TraceLog is being destroyed");
|
|
5252
5286
|
await h.resetIdentity();
|
|
5253
5287
|
}
|
|
@@ -5269,20 +5303,20 @@ const Hs = (r) => {
|
|
|
5269
5303
|
identify: zs,
|
|
5270
5304
|
resetIdentity: Qs
|
|
5271
5305
|
};
|
|
5272
|
-
var
|
|
5306
|
+
var Le, C, G, pt, le, St = -1, V = function(r) {
|
|
5273
5307
|
addEventListener("pageshow", (function(e) {
|
|
5274
5308
|
e.persisted && (St = e.timeStamp, r(e));
|
|
5275
5309
|
}), !0);
|
|
5276
|
-
},
|
|
5310
|
+
}, De = function() {
|
|
5277
5311
|
var r = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
|
|
5278
5312
|
if (r && r.responseStart > 0 && r.responseStart < performance.now()) return r;
|
|
5279
|
-
},
|
|
5280
|
-
var r =
|
|
5313
|
+
}, de = function() {
|
|
5314
|
+
var r = De();
|
|
5281
5315
|
return r && r.activationStart || 0;
|
|
5282
5316
|
}, y = function(r, e) {
|
|
5283
|
-
var t =
|
|
5284
|
-
return St >= 0 ? s = "back-forward-cache" : t && (document.prerendering ||
|
|
5285
|
-
},
|
|
5317
|
+
var t = De(), s = "navigate";
|
|
5318
|
+
return St >= 0 ? s = "back-forward-cache" : t && (document.prerendering || de() > 0 ? s = "prerender" : document.wasDiscarded ? s = "restore" : t.type && (s = t.type.replace(/_/g, "-"))), { name: r, value: e === void 0 ? -1 : e, rating: "good", delta: 0, entries: [], id: "v4-".concat(Date.now(), "-").concat(Math.floor(8999999999999 * Math.random()) + 1e12), navigationType: s };
|
|
5319
|
+
}, F = function(r, e, t) {
|
|
5286
5320
|
try {
|
|
5287
5321
|
if (PerformanceObserver.supportedEntryTypes.includes(r)) {
|
|
5288
5322
|
var s = new PerformanceObserver((function(n) {
|
|
@@ -5301,164 +5335,164 @@ var Ae, C, j, Et, le, St = -1, U = function(r) {
|
|
|
5301
5335
|
return l > c[1] ? "poor" : l > c[0] ? "needs-improvement" : "good";
|
|
5302
5336
|
})(e.value, t), r(e));
|
|
5303
5337
|
};
|
|
5304
|
-
},
|
|
5338
|
+
}, ke = function(r) {
|
|
5305
5339
|
requestAnimationFrame((function() {
|
|
5306
5340
|
return requestAnimationFrame((function() {
|
|
5307
5341
|
return r();
|
|
5308
5342
|
}));
|
|
5309
5343
|
}));
|
|
5310
|
-
},
|
|
5344
|
+
}, z = function(r) {
|
|
5311
5345
|
document.addEventListener("visibilitychange", (function() {
|
|
5312
5346
|
document.visibilityState === "hidden" && r();
|
|
5313
5347
|
}));
|
|
5314
|
-
},
|
|
5348
|
+
}, ue = function(r) {
|
|
5315
5349
|
var e = !1;
|
|
5316
5350
|
return function() {
|
|
5317
5351
|
e || (r(), e = !0);
|
|
5318
5352
|
};
|
|
5319
|
-
},
|
|
5353
|
+
}, H = -1, tt = function() {
|
|
5320
5354
|
return document.visibilityState !== "hidden" || document.prerendering ? 1 / 0 : 0;
|
|
5321
5355
|
}, ce = function(r) {
|
|
5322
|
-
document.visibilityState === "hidden" &&
|
|
5323
|
-
},
|
|
5356
|
+
document.visibilityState === "hidden" && H > -1 && (H = r.type === "visibilitychange" ? r.timeStamp : 0, Ks());
|
|
5357
|
+
}, st = function() {
|
|
5324
5358
|
addEventListener("visibilitychange", ce, !0), addEventListener("prerenderingchange", ce, !0);
|
|
5325
5359
|
}, Ks = function() {
|
|
5326
5360
|
removeEventListener("visibilitychange", ce, !0), removeEventListener("prerenderingchange", ce, !0);
|
|
5327
|
-
},
|
|
5328
|
-
return
|
|
5361
|
+
}, Ve = function() {
|
|
5362
|
+
return H < 0 && (H = tt(), st(), V((function() {
|
|
5329
5363
|
setTimeout((function() {
|
|
5330
|
-
|
|
5364
|
+
H = tt(), st();
|
|
5331
5365
|
}), 0);
|
|
5332
5366
|
}))), { get firstHiddenTime() {
|
|
5333
|
-
return
|
|
5367
|
+
return H;
|
|
5334
5368
|
} };
|
|
5335
|
-
},
|
|
5369
|
+
}, Q = function(r) {
|
|
5336
5370
|
document.prerendering ? addEventListener("prerenderingchange", (function() {
|
|
5337
5371
|
return r();
|
|
5338
5372
|
}), !0) : r();
|
|
5339
|
-
},
|
|
5340
|
-
e = e || {},
|
|
5341
|
-
var t, s =
|
|
5373
|
+
}, Me = [1800, 3e3], Tt = function(r, e) {
|
|
5374
|
+
e = e || {}, Q((function() {
|
|
5375
|
+
var t, s = Ve(), n = y("FCP"), i = F("paint", (function(o) {
|
|
5342
5376
|
o.forEach((function(l) {
|
|
5343
|
-
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime < s.firstHiddenTime && (n.value = Math.max(l.startTime -
|
|
5377
|
+
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime < s.firstHiddenTime && (n.value = Math.max(l.startTime - de(), 0), n.entries.push(l), t(!0)));
|
|
5344
5378
|
}));
|
|
5345
5379
|
}));
|
|
5346
|
-
i && (t = w(r, n,
|
|
5347
|
-
n = y("FCP"), t = w(r, n,
|
|
5380
|
+
i && (t = w(r, n, Me, e.reportAllChanges), V((function(o) {
|
|
5381
|
+
n = y("FCP"), t = w(r, n, Me, e.reportAllChanges), ke((function() {
|
|
5348
5382
|
n.value = performance.now() - o.timeStamp, t(!0);
|
|
5349
5383
|
}));
|
|
5350
5384
|
})));
|
|
5351
5385
|
}));
|
|
5352
|
-
},
|
|
5353
|
-
e = e || {},
|
|
5386
|
+
}, Ce = [0.1, 0.25], Ys = function(r, e) {
|
|
5387
|
+
e = e || {}, Tt(ue((function() {
|
|
5354
5388
|
var t, s = y("CLS", 0), n = 0, i = [], o = function(c) {
|
|
5355
|
-
c.forEach((function(
|
|
5356
|
-
if (!
|
|
5357
|
-
var
|
|
5358
|
-
n &&
|
|
5389
|
+
c.forEach((function(d) {
|
|
5390
|
+
if (!d.hadRecentInput) {
|
|
5391
|
+
var f = i[0], g = i[i.length - 1];
|
|
5392
|
+
n && d.startTime - g.startTime < 1e3 && d.startTime - f.startTime < 5e3 ? (n += d.value, i.push(d)) : (n = d.value, i = [d]);
|
|
5359
5393
|
}
|
|
5360
5394
|
})), n > s.value && (s.value = n, s.entries = i, t());
|
|
5361
|
-
}, l =
|
|
5362
|
-
l && (t = w(r, s,
|
|
5395
|
+
}, l = F("layout-shift", o);
|
|
5396
|
+
l && (t = w(r, s, Ce, e.reportAllChanges), z((function() {
|
|
5363
5397
|
o(l.takeRecords()), t(!0);
|
|
5364
|
-
})),
|
|
5365
|
-
n = 0, s = y("CLS", 0), t = w(r, s,
|
|
5398
|
+
})), V((function() {
|
|
5399
|
+
n = 0, s = y("CLS", 0), t = w(r, s, Ce, e.reportAllChanges), ke((function() {
|
|
5366
5400
|
return t();
|
|
5367
5401
|
}));
|
|
5368
5402
|
})), setTimeout(t, 0));
|
|
5369
5403
|
})));
|
|
5370
|
-
},
|
|
5404
|
+
}, It = 0, pe = 1 / 0, J = 0, qs = function(r) {
|
|
5371
5405
|
r.forEach((function(e) {
|
|
5372
|
-
e.interactionId && (
|
|
5406
|
+
e.interactionId && (pe = Math.min(pe, e.interactionId), J = Math.max(J, e.interactionId), It = J ? (J - pe) / 7 + 1 : 0);
|
|
5373
5407
|
}));
|
|
5374
|
-
},
|
|
5375
|
-
return
|
|
5408
|
+
}, vt = function() {
|
|
5409
|
+
return Le ? It : performance.interactionCount || 0;
|
|
5376
5410
|
}, Js = function() {
|
|
5377
|
-
"interactionCount" in performance ||
|
|
5378
|
-
}, A = [],
|
|
5379
|
-
var r = Math.min(A.length - 1, Math.floor((
|
|
5411
|
+
"interactionCount" in performance || Le || (Le = F("event", qs, { type: "event", buffered: !0, durationThreshold: 0 }));
|
|
5412
|
+
}, A = [], te = /* @__PURE__ */ new Map(), _t = 0, Zs = function() {
|
|
5413
|
+
var r = Math.min(A.length - 1, Math.floor((vt() - _t) / 50));
|
|
5380
5414
|
return A[r];
|
|
5381
5415
|
}, er = [], tr = function(r) {
|
|
5382
5416
|
if (er.forEach((function(n) {
|
|
5383
5417
|
return n(r);
|
|
5384
5418
|
})), r.interactionId || r.entryType === "first-input") {
|
|
5385
|
-
var e = A[A.length - 1], t =
|
|
5419
|
+
var e = A[A.length - 1], t = te.get(r.interactionId);
|
|
5386
5420
|
if (t || A.length < 10 || r.duration > e.latency) {
|
|
5387
5421
|
if (t) r.duration > t.latency ? (t.entries = [r], t.latency = r.duration) : r.duration === t.latency && r.startTime === t.entries[0].startTime && t.entries.push(r);
|
|
5388
5422
|
else {
|
|
5389
5423
|
var s = { id: r.interactionId, latency: r.duration, entries: [r] };
|
|
5390
|
-
|
|
5424
|
+
te.set(s.id, s), A.push(s);
|
|
5391
5425
|
}
|
|
5392
5426
|
A.sort((function(n, i) {
|
|
5393
5427
|
return i.latency - n.latency;
|
|
5394
5428
|
})), A.length > 10 && A.splice(10).forEach((function(n) {
|
|
5395
|
-
return
|
|
5429
|
+
return te.delete(n.id);
|
|
5396
5430
|
}));
|
|
5397
5431
|
}
|
|
5398
5432
|
}
|
|
5399
|
-
},
|
|
5433
|
+
}, yt = function(r) {
|
|
5400
5434
|
var e = self.requestIdleCallback || self.setTimeout, t = -1;
|
|
5401
|
-
return r =
|
|
5402
|
-
},
|
|
5403
|
-
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {},
|
|
5435
|
+
return r = ue(r), document.visibilityState === "hidden" ? r() : (t = e(r), z(r)), t;
|
|
5436
|
+
}, Re = [200, 500], sr = function(r, e) {
|
|
5437
|
+
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, Q((function() {
|
|
5404
5438
|
var t;
|
|
5405
5439
|
Js();
|
|
5406
5440
|
var s, n = y("INP"), i = function(l) {
|
|
5407
|
-
|
|
5441
|
+
yt((function() {
|
|
5408
5442
|
l.forEach(tr);
|
|
5409
5443
|
var c = Zs();
|
|
5410
5444
|
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, s());
|
|
5411
5445
|
}));
|
|
5412
|
-
}, o =
|
|
5413
|
-
s = w(r, n,
|
|
5446
|
+
}, o = F("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
|
|
5447
|
+
s = w(r, n, Re, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), z((function() {
|
|
5414
5448
|
i(o.takeRecords()), s(!0);
|
|
5415
|
-
})),
|
|
5416
|
-
|
|
5449
|
+
})), V((function() {
|
|
5450
|
+
_t = vt(), A.length = 0, te.clear(), n = y("INP"), s = w(r, n, Re, e.reportAllChanges);
|
|
5417
5451
|
})));
|
|
5418
5452
|
})));
|
|
5419
|
-
},
|
|
5420
|
-
e = e || {},
|
|
5421
|
-
var t, s =
|
|
5422
|
-
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(
|
|
5423
|
-
|
|
5453
|
+
}, Ne = [2500, 4e3], Se = {}, rr = function(r, e) {
|
|
5454
|
+
e = e || {}, Q((function() {
|
|
5455
|
+
var t, s = Ve(), n = y("LCP"), i = function(c) {
|
|
5456
|
+
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(d) {
|
|
5457
|
+
d.startTime < s.firstHiddenTime && (n.value = Math.max(d.startTime - de(), 0), n.entries = [d], t());
|
|
5424
5458
|
}));
|
|
5425
|
-
}, o =
|
|
5459
|
+
}, o = F("largest-contentful-paint", i);
|
|
5426
5460
|
if (o) {
|
|
5427
|
-
t = w(r, n,
|
|
5428
|
-
var l =
|
|
5429
|
-
|
|
5461
|
+
t = w(r, n, Ne, e.reportAllChanges);
|
|
5462
|
+
var l = ue((function() {
|
|
5463
|
+
Se[n.id] || (i(o.takeRecords()), o.disconnect(), Se[n.id] = !0, t(!0));
|
|
5430
5464
|
}));
|
|
5431
5465
|
["keydown", "click"].forEach((function(c) {
|
|
5432
5466
|
addEventListener(c, (function() {
|
|
5433
|
-
return
|
|
5467
|
+
return yt(l);
|
|
5434
5468
|
}), { once: !0, capture: !0 });
|
|
5435
|
-
})),
|
|
5436
|
-
n = y("LCP"), t = w(r, n,
|
|
5437
|
-
n.value = performance.now() - c.timeStamp,
|
|
5469
|
+
})), z(l), V((function(c) {
|
|
5470
|
+
n = y("LCP"), t = w(r, n, Ne, e.reportAllChanges), ke((function() {
|
|
5471
|
+
n.value = performance.now() - c.timeStamp, Se[n.id] = !0, t(!0);
|
|
5438
5472
|
}));
|
|
5439
5473
|
}));
|
|
5440
5474
|
}
|
|
5441
5475
|
}));
|
|
5442
|
-
},
|
|
5443
|
-
document.prerendering ?
|
|
5476
|
+
}, Oe = [800, 1800], nr = function r(e) {
|
|
5477
|
+
document.prerendering ? Q((function() {
|
|
5444
5478
|
return r(e);
|
|
5445
5479
|
})) : document.readyState !== "complete" ? addEventListener("load", (function() {
|
|
5446
5480
|
return r(e);
|
|
5447
5481
|
}), !0) : setTimeout(e, 0);
|
|
5448
5482
|
}, ir = function(r, e) {
|
|
5449
5483
|
e = e || {};
|
|
5450
|
-
var t = y("TTFB"), s = w(r, t,
|
|
5484
|
+
var t = y("TTFB"), s = w(r, t, Oe, e.reportAllChanges);
|
|
5451
5485
|
nr((function() {
|
|
5452
|
-
var n =
|
|
5453
|
-
n && (t.value = Math.max(n.responseStart -
|
|
5454
|
-
t = y("TTFB", 0), (s = w(r, t,
|
|
5486
|
+
var n = De();
|
|
5487
|
+
n && (t.value = Math.max(n.responseStart - de(), 0), t.entries = [n], s(!0), V((function() {
|
|
5488
|
+
t = y("TTFB", 0), (s = w(r, t, Oe, e.reportAllChanges))(!0);
|
|
5455
5489
|
})));
|
|
5456
5490
|
}));
|
|
5457
|
-
},
|
|
5458
|
-
C || (C = e,
|
|
5459
|
-
},
|
|
5460
|
-
if (
|
|
5461
|
-
var r = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp +
|
|
5491
|
+
}, W = { passive: !0, capture: !0 }, or = /* @__PURE__ */ new Date(), rt = function(r, e) {
|
|
5492
|
+
C || (C = e, G = r, pt = /* @__PURE__ */ new Date(), bt(removeEventListener), wt());
|
|
5493
|
+
}, wt = function() {
|
|
5494
|
+
if (G >= 0 && G < pt - or) {
|
|
5495
|
+
var r = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp + G };
|
|
5462
5496
|
le.forEach((function(e) {
|
|
5463
5497
|
e(r);
|
|
5464
5498
|
})), le = [];
|
|
@@ -5468,81 +5502,81 @@ var Ae, C, j, Et, le, St = -1, U = function(r) {
|
|
|
5468
5502
|
var e = (r.timeStamp > 1e12 ? /* @__PURE__ */ new Date() : performance.now()) - r.timeStamp;
|
|
5469
5503
|
r.type == "pointerdown" ? (function(t, s) {
|
|
5470
5504
|
var n = function() {
|
|
5471
|
-
|
|
5505
|
+
rt(t, s), o();
|
|
5472
5506
|
}, i = function() {
|
|
5473
5507
|
o();
|
|
5474
5508
|
}, o = function() {
|
|
5475
|
-
removeEventListener("pointerup", n,
|
|
5509
|
+
removeEventListener("pointerup", n, W), removeEventListener("pointercancel", i, W);
|
|
5476
5510
|
};
|
|
5477
|
-
addEventListener("pointerup", n,
|
|
5478
|
-
})(e, r) :
|
|
5511
|
+
addEventListener("pointerup", n, W), addEventListener("pointercancel", i, W);
|
|
5512
|
+
})(e, r) : rt(e, r);
|
|
5479
5513
|
}
|
|
5480
|
-
},
|
|
5514
|
+
}, bt = function(r) {
|
|
5481
5515
|
["mousedown", "keydown", "touchstart", "pointerdown"].forEach((function(e) {
|
|
5482
|
-
return r(e, ar,
|
|
5516
|
+
return r(e, ar, W);
|
|
5483
5517
|
}));
|
|
5484
|
-
},
|
|
5485
|
-
e = e || {},
|
|
5486
|
-
var t, s =
|
|
5518
|
+
}, Pe = [100, 300], lr = function(r, e) {
|
|
5519
|
+
e = e || {}, Q((function() {
|
|
5520
|
+
var t, s = Ve(), n = y("FID"), i = function(c) {
|
|
5487
5521
|
c.startTime < s.firstHiddenTime && (n.value = c.processingStart - c.startTime, n.entries.push(c), t(!0));
|
|
5488
5522
|
}, o = function(c) {
|
|
5489
5523
|
c.forEach(i);
|
|
5490
|
-
}, l =
|
|
5491
|
-
t = w(r, n,
|
|
5524
|
+
}, l = F("first-input", o);
|
|
5525
|
+
t = w(r, n, Pe, e.reportAllChanges), l && (z(ue((function() {
|
|
5492
5526
|
o(l.takeRecords()), l.disconnect();
|
|
5493
|
-
}))),
|
|
5527
|
+
}))), V((function() {
|
|
5494
5528
|
var c;
|
|
5495
|
-
n = y("FID"), t = w(r, n,
|
|
5529
|
+
n = y("FID"), t = w(r, n, Pe, e.reportAllChanges), le = [], G = -1, C = null, bt(addEventListener), c = i, le.push(c), wt();
|
|
5496
5530
|
})));
|
|
5497
5531
|
}));
|
|
5498
5532
|
};
|
|
5499
5533
|
const cr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5500
5534
|
__proto__: null,
|
|
5501
|
-
CLSThresholds:
|
|
5502
|
-
FCPThresholds:
|
|
5503
|
-
FIDThresholds:
|
|
5504
|
-
INPThresholds:
|
|
5505
|
-
LCPThresholds:
|
|
5506
|
-
TTFBThresholds:
|
|
5535
|
+
CLSThresholds: Ce,
|
|
5536
|
+
FCPThresholds: Me,
|
|
5537
|
+
FIDThresholds: Pe,
|
|
5538
|
+
INPThresholds: Re,
|
|
5539
|
+
LCPThresholds: Ne,
|
|
5540
|
+
TTFBThresholds: Oe,
|
|
5507
5541
|
onCLS: Ys,
|
|
5508
|
-
onFCP:
|
|
5542
|
+
onFCP: Tt,
|
|
5509
5543
|
onFID: lr,
|
|
5510
5544
|
onINP: sr,
|
|
5511
5545
|
onLCP: rr,
|
|
5512
5546
|
onTTFB: ir
|
|
5513
5547
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
5514
5548
|
export {
|
|
5515
|
-
|
|
5516
|
-
|
|
5549
|
+
m as AppConfigValidationError,
|
|
5550
|
+
dr as DEFAULT_SESSION_TIMEOUT,
|
|
5517
5551
|
_e as DEFAULT_WEB_VITALS_MODE,
|
|
5518
5552
|
L as DeviceType,
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5553
|
+
se as EmitterEvent,
|
|
5554
|
+
B as ErrorType,
|
|
5555
|
+
u as EventType,
|
|
5522
5556
|
vr as InitializationTimeoutError,
|
|
5523
5557
|
N as IntegrationValidationError,
|
|
5524
|
-
|
|
5558
|
+
Sr as MAX_ARRAY_LENGTH,
|
|
5525
5559
|
mr as MAX_CUSTOM_EVENT_ARRAY_SIZE,
|
|
5526
5560
|
fr as MAX_CUSTOM_EVENT_KEYS,
|
|
5527
|
-
|
|
5561
|
+
ur as MAX_CUSTOM_EVENT_NAME_LENGTH,
|
|
5528
5562
|
hr as MAX_CUSTOM_EVENT_STRING_SIZE,
|
|
5529
5563
|
gr as MAX_NESTED_OBJECT_KEYS,
|
|
5530
5564
|
Er as MAX_STRING_LENGTH,
|
|
5531
|
-
|
|
5565
|
+
pr as MAX_STRING_LENGTH_IN_ARRAY,
|
|
5532
5566
|
ie as Mode,
|
|
5533
|
-
|
|
5567
|
+
lt as PII_PATTERNS,
|
|
5534
5568
|
O as PermanentError,
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5569
|
+
re as RateLimitError,
|
|
5570
|
+
Xe as SamplingRateValidationError,
|
|
5571
|
+
Z as ScrollDirection,
|
|
5572
|
+
Pt as SessionTimeoutValidationError,
|
|
5573
|
+
$ as SpecialApiUrl,
|
|
5574
|
+
ne as TimeoutError,
|
|
5575
|
+
j as TraceLogValidationError,
|
|
5542
5576
|
_r as WEB_VITALS_GOOD_THRESHOLDS,
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5577
|
+
Ke as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
|
|
5578
|
+
Kt as WEB_VITALS_POOR_THRESHOLDS,
|
|
5579
|
+
Ye as getWebVitalsThresholds,
|
|
5546
5580
|
Tr as isPrimaryScrollEvent,
|
|
5547
5581
|
Ir as isSecondaryScrollEvent,
|
|
5548
5582
|
yr as tracelog
|