@tracelog/lib 2.8.0 → 2.8.1-rc.101.3
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 +578 -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,21 @@ 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 sending the same
|
|
1115
|
+
* events through two paths (fetch + sendBeacon) with different idempotency tokens.
|
|
1116
|
+
* `ensureBatchMetadata()` assigns a stable token before persisting.
|
|
1117
|
+
* On next page load, `recoverPersistedEvents()` sends with the persisted token.
|
|
1118
|
+
*
|
|
1119
|
+
* @param body - Event queue to persist
|
|
1120
|
+
*/
|
|
1121
|
+
persistForRecovery(e) {
|
|
1122
|
+
if (this.shouldSkipSend()) return;
|
|
1123
|
+
const t = this.ensureBatchMetadata(e);
|
|
1124
|
+
this.persistEventsWithFailureCount(t, 0, !0);
|
|
1125
|
+
}
|
|
1106
1126
|
/**
|
|
1107
1127
|
* Sends events asynchronously using `fetch()` API with automatic persistence on failure.
|
|
1108
1128
|
*
|
|
@@ -1120,7 +1140,7 @@ class Ze extends _ {
|
|
|
1120
1140
|
*
|
|
1121
1141
|
* **Error Handling**:
|
|
1122
1142
|
* - **Permanent errors** (4xx except 408, 429): Events discarded, not persisted
|
|
1123
|
-
* - **Timeout errors
|
|
1143
|
+
* - **Timeout errors**: Events persisted for retry with the same batch idempotency token
|
|
1124
1144
|
* - **Transient errors** (5xx, network, mixed): Events persisted for recovery
|
|
1125
1145
|
*
|
|
1126
1146
|
* **Important**: Events are NOT retried in-session. Persistence is for
|
|
@@ -1134,14 +1154,12 @@ class Ze extends _ {
|
|
|
1134
1154
|
* @see src/managers/README.md (lines 82-139) for send details
|
|
1135
1155
|
*/
|
|
1136
1156
|
async sendEventsQueue(e, t) {
|
|
1157
|
+
const s = this.ensureBatchMetadata(e);
|
|
1137
1158
|
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);
|
|
1159
|
+
const n = await this.send(s);
|
|
1160
|
+
return n ? (this.clearPersistedEvents(), t?.onSuccess?.(s.events.length, s.events, s)) : (this.persistEvents(s), t?.onFailure?.()), n;
|
|
1161
|
+
} catch (n) {
|
|
1162
|
+
return n instanceof O ? (this.logPermanentError("Permanent error, not retrying", n), this.clearPersistedEvents(), t?.onFailure?.(), !1) : (this.persistEvents(s), t?.onFailure?.(), !1);
|
|
1145
1163
|
}
|
|
1146
1164
|
}
|
|
1147
1165
|
/**
|
|
@@ -1199,35 +1217,28 @@ class Ze extends _ {
|
|
|
1199
1217
|
return;
|
|
1200
1218
|
}
|
|
1201
1219
|
this.recoveryInProgress = !0;
|
|
1220
|
+
let t = null, s = 0;
|
|
1202
1221
|
try {
|
|
1203
|
-
const
|
|
1204
|
-
if (!
|
|
1222
|
+
const n = this.getPersistedData();
|
|
1223
|
+
if (!n || !this.isDataRecent(n) || n.events.length === 0) {
|
|
1205
1224
|
this.clearPersistedEvents();
|
|
1206
1225
|
return;
|
|
1207
1226
|
}
|
|
1208
|
-
const
|
|
1209
|
-
if (
|
|
1227
|
+
const i = n.recoveryFailures;
|
|
1228
|
+
if (s = typeof i == "number" && Number.isFinite(i) && i >= 0 ? i : 0, s >= 3) {
|
|
1210
1229
|
a(
|
|
1211
1230
|
"debug",
|
|
1212
|
-
`Discarding persisted events after ${
|
|
1231
|
+
`Discarding persisted events after ${s} failed recovery attempts${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1213
1232
|
), this.clearPersistedEvents(), e?.onFailure?.();
|
|
1214
1233
|
return;
|
|
1215
1234
|
}
|
|
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?.();
|
|
1235
|
+
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?.());
|
|
1236
|
+
} catch (n) {
|
|
1237
|
+
if (n instanceof O) {
|
|
1238
|
+
this.logPermanentError("Permanent error during recovery, clearing persisted events", n), this.clearPersistedEvents(), e?.onFailure?.();
|
|
1228
1239
|
return;
|
|
1229
1240
|
}
|
|
1230
|
-
a("error", "Failed to recover persisted events", { error:
|
|
1241
|
+
a("error", "Failed to recover persisted events", { error: n }), t && this.persistEventsWithFailureCount(t, s + 1, !0), e?.onFailure?.();
|
|
1231
1242
|
} finally {
|
|
1232
1243
|
this.recoveryInProgress = !1;
|
|
1233
1244
|
}
|
|
@@ -1322,7 +1333,7 @@ class Ze extends _ {
|
|
|
1322
1333
|
if (this.integrationId === "saas")
|
|
1323
1334
|
return e;
|
|
1324
1335
|
const t = this.transformers.beforeBatch;
|
|
1325
|
-
return t ?
|
|
1336
|
+
return t ? Et(e, t, this.integrationId || "SenderManager") : e;
|
|
1326
1337
|
}
|
|
1327
1338
|
/**
|
|
1328
1339
|
* Calculates exponential backoff delay with jitter for retry attempts.
|
|
@@ -1380,7 +1391,6 @@ class Ze extends _ {
|
|
|
1380
1391
|
* @param body - Event queue to send
|
|
1381
1392
|
* @returns Promise resolving to true if send succeeded, false if all retries exhausted
|
|
1382
1393
|
* @throws PermanentError for 4xx errors (caller should not retry)
|
|
1383
|
-
* @throws TimeoutError when all retry attempts timed out (caller should not persist)
|
|
1384
1394
|
*/
|
|
1385
1395
|
async send(e) {
|
|
1386
1396
|
if (this.shouldSkipSend())
|
|
@@ -1391,67 +1401,72 @@ class Ze extends _ {
|
|
|
1391
1401
|
const s = this.applyBeforeBatchTransformer(t);
|
|
1392
1402
|
if (!s)
|
|
1393
1403
|
return !0;
|
|
1394
|
-
|
|
1404
|
+
const n = this.ensureBatchMetadata(s, e._metadata?.idempotency_token);
|
|
1405
|
+
if (this.apiUrl?.includes($.Fail))
|
|
1395
1406
|
return a("debug", `Fail mode: simulating network failure${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1396
|
-
data: { events:
|
|
1407
|
+
data: { events: n.events.length }
|
|
1397
1408
|
}), !1;
|
|
1398
|
-
if (this.apiUrl?.includes(
|
|
1409
|
+
if (this.apiUrl?.includes($.Localhost))
|
|
1399
1410
|
return a("debug", `Success mode: simulating successful send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1400
|
-
data: { events:
|
|
1411
|
+
data: { events: n.events.length }
|
|
1401
1412
|
}), !0;
|
|
1402
1413
|
if (this.consecutiveNetworkFailures >= 3) {
|
|
1403
|
-
const
|
|
1404
|
-
if (
|
|
1414
|
+
const d = Date.now() - this.circuitOpenedAt;
|
|
1415
|
+
if (d < 12e4)
|
|
1405
1416
|
return a("debug", `Network circuit open, skipping send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1406
1417
|
data: {
|
|
1407
1418
|
consecutiveNetworkFailures: this.consecutiveNetworkFailures,
|
|
1408
|
-
cooldownRemainingMs: 12e4 -
|
|
1419
|
+
cooldownRemainingMs: 12e4 - d
|
|
1409
1420
|
}
|
|
1410
1421
|
}), !1;
|
|
1411
1422
|
}
|
|
1412
|
-
const { url:
|
|
1413
|
-
let
|
|
1414
|
-
for (let
|
|
1423
|
+
const { url: i, payload: o } = this.prepareRequest(n);
|
|
1424
|
+
let l = !0, c = !1;
|
|
1425
|
+
for (let d = 1; d <= 3; d++)
|
|
1415
1426
|
try {
|
|
1416
|
-
return (await this.sendWithTimeout(
|
|
1427
|
+
return (await this.sendWithTimeout(i, o)).ok ? (d > 1 && a(
|
|
1417
1428
|
"info",
|
|
1418
|
-
`Send succeeded after ${
|
|
1429
|
+
`Send succeeded after ${d - 1} retry attempt(s)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1419
1430
|
{
|
|
1420
|
-
data: { events:
|
|
1431
|
+
data: { events: n.events.length, attempt: d }
|
|
1421
1432
|
}
|
|
1422
1433
|
), 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:
|
|
1434
|
+
} catch (f) {
|
|
1435
|
+
const g = d === 3;
|
|
1436
|
+
if (f instanceof O)
|
|
1437
|
+
throw this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, f;
|
|
1438
|
+
if (f instanceof re) {
|
|
1439
|
+
this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, l = !1, c = !0, a("warn", `Rate limited, skipping retries${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1440
|
+
data: { events: e.events.length, attempt: d }
|
|
1430
1441
|
});
|
|
1431
1442
|
break;
|
|
1432
1443
|
}
|
|
1433
|
-
if (
|
|
1444
|
+
if (f instanceof ne || (l = !1), f instanceof TypeError || (c = !0), a(
|
|
1434
1445
|
g ? "error" : "warn",
|
|
1435
|
-
`Send attempt ${
|
|
1446
|
+
`Send attempt ${d} failed${this.integrationId ? ` [${this.integrationId}]` : ""}${g ? " (all retries exhausted)" : ", will retry"}`,
|
|
1436
1447
|
{
|
|
1437
|
-
error:
|
|
1448
|
+
error: f,
|
|
1438
1449
|
data: {
|
|
1439
1450
|
events: e.events.length,
|
|
1440
|
-
url:
|
|
1441
|
-
attempt:
|
|
1451
|
+
url: i.replace(/\/\/[^/]+/, "//[DOMAIN]"),
|
|
1452
|
+
attempt: d,
|
|
1442
1453
|
maxAttempts: 3
|
|
1443
1454
|
}
|
|
1444
1455
|
}
|
|
1445
1456
|
), !g) {
|
|
1446
|
-
await this.backoffDelay(
|
|
1457
|
+
await this.backoffDelay(d);
|
|
1447
1458
|
continue;
|
|
1448
1459
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1460
|
+
return l ? (a(
|
|
1461
|
+
"debug",
|
|
1462
|
+
`All retry attempts timed out, preserving batch for retry${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1463
|
+
{
|
|
1464
|
+
data: { events: n.events.length }
|
|
1465
|
+
}
|
|
1466
|
+
), !1) : (c ? (this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0) : (this.consecutiveNetworkFailures = Math.min(
|
|
1452
1467
|
this.consecutiveNetworkFailures + 1,
|
|
1453
1468
|
3
|
|
1454
|
-
), this.consecutiveNetworkFailures >= 3 && (this.circuitOpenedAt = Date.now())), !1;
|
|
1469
|
+
), this.consecutiveNetworkFailures >= 3 && (this.circuitOpenedAt = Date.now())), !1);
|
|
1455
1470
|
}
|
|
1456
1471
|
return !1;
|
|
1457
1472
|
}
|
|
@@ -1463,18 +1478,18 @@ class Ze extends _ {
|
|
|
1463
1478
|
*
|
|
1464
1479
|
* **Timeout Behavior**:
|
|
1465
1480
|
* - 10-second timeout via AbortController (REQUEST_TIMEOUT_MS constant)
|
|
1466
|
-
* - Aborted requests throw TimeoutError
|
|
1481
|
+
* - Aborted requests throw TimeoutError
|
|
1467
1482
|
*
|
|
1468
1483
|
* **Error Classification**:
|
|
1469
1484
|
* - 4xx (except 408, 429): PermanentError thrown → no retries
|
|
1470
|
-
* - Timeout: TimeoutError thrown → caller
|
|
1485
|
+
* - Timeout: TimeoutError thrown → caller treats it as a retryable failure
|
|
1471
1486
|
* - 408, 429, 5xx, network: Standard Error thrown → triggers retry
|
|
1472
1487
|
*
|
|
1473
1488
|
* @param url - API endpoint URL
|
|
1474
1489
|
* @param payload - JSON-stringified EventsQueue body
|
|
1475
1490
|
* @returns Response object if successful
|
|
1476
1491
|
* @throws PermanentError for unrecoverable 4xx errors
|
|
1477
|
-
* @throws TimeoutError when request times out
|
|
1492
|
+
* @throws TimeoutError when request times out
|
|
1478
1493
|
* @throws Error for transient errors (5xx, network)
|
|
1479
1494
|
* @private
|
|
1480
1495
|
*/
|
|
@@ -1498,10 +1513,10 @@ class Ze extends _ {
|
|
|
1498
1513
|
}
|
|
1499
1514
|
});
|
|
1500
1515
|
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
|
|
1516
|
+
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
1517
|
return l;
|
|
1503
1518
|
} catch (o) {
|
|
1504
|
-
throw o instanceof O ? o : n ? new
|
|
1519
|
+
throw o instanceof O ? o : n ? new ne("Request timed out") : o;
|
|
1505
1520
|
} finally {
|
|
1506
1521
|
clearTimeout(i), this.pendingControllers.delete(s);
|
|
1507
1522
|
}
|
|
@@ -1523,40 +1538,40 @@ class Ze extends _ {
|
|
|
1523
1538
|
* - Oversized payloads persisted instead of silently failing
|
|
1524
1539
|
*
|
|
1525
1540
|
* @param body - EventsQueue to send
|
|
1526
|
-
* @returns `true` on success
|
|
1541
|
+
* @returns `true` on success, `false` on failure (events persisted for recovery)
|
|
1527
1542
|
* @private
|
|
1528
1543
|
*/
|
|
1529
1544
|
sendQueueSyncInternal(e) {
|
|
1530
|
-
const t = this.
|
|
1531
|
-
if (!t)
|
|
1532
|
-
return !0;
|
|
1533
|
-
const s = this.applyBeforeBatchTransformer(t);
|
|
1545
|
+
const t = this.ensureBatchMetadata(e), s = this.applyBeforeSendTransformer(t);
|
|
1534
1546
|
if (!s)
|
|
1535
1547
|
return !0;
|
|
1536
|
-
const
|
|
1537
|
-
if (
|
|
1548
|
+
const n = this.applyBeforeBatchTransformer(s);
|
|
1549
|
+
if (!n)
|
|
1550
|
+
return !0;
|
|
1551
|
+
const i = this.ensureBatchMetadata(n, t._metadata?.idempotency_token), { url: o, payload: l } = this.prepareRequest(i);
|
|
1552
|
+
if (l.length > 65536)
|
|
1538
1553
|
return a(
|
|
1539
1554
|
"warn",
|
|
1540
1555
|
`Payload exceeds sendBeacon limit, persisting for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1541
1556
|
{
|
|
1542
1557
|
data: {
|
|
1543
|
-
size:
|
|
1558
|
+
size: l.length,
|
|
1544
1559
|
limit: 65536,
|
|
1545
|
-
events:
|
|
1560
|
+
events: i.events.length
|
|
1546
1561
|
}
|
|
1547
1562
|
}
|
|
1548
|
-
), this.persistEvents(
|
|
1549
|
-
const
|
|
1563
|
+
), this.persistEvents(t), !1;
|
|
1564
|
+
const c = new Blob([l], { type: "application/json" });
|
|
1550
1565
|
if (!this.isSendBeaconAvailable())
|
|
1551
1566
|
return a(
|
|
1552
1567
|
"warn",
|
|
1553
1568
|
`sendBeacon not available, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1554
|
-
), this.persistEvents(
|
|
1555
|
-
const
|
|
1556
|
-
return
|
|
1569
|
+
), this.persistEvents(t), !1;
|
|
1570
|
+
const d = navigator.sendBeacon(o, c);
|
|
1571
|
+
return d || (a(
|
|
1557
1572
|
"warn",
|
|
1558
1573
|
`sendBeacon rejected request, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1559
|
-
), this.persistEvents(
|
|
1574
|
+
), this.persistEvents(t)), d;
|
|
1560
1575
|
}
|
|
1561
1576
|
/**
|
|
1562
1577
|
* Prepares request by enriching payload with metadata and serializing to JSON.
|
|
@@ -1568,9 +1583,10 @@ class Ze extends _ {
|
|
|
1568
1583
|
* - `timestamp`: Request generation time in milliseconds
|
|
1569
1584
|
*
|
|
1570
1585
|
* **Idempotency Token**:
|
|
1571
|
-
* -
|
|
1572
|
-
* -
|
|
1573
|
-
* -
|
|
1586
|
+
* - Set upstream by ensureBatchMetadata() before this method is called
|
|
1587
|
+
* - Fallback generateEventId() is defensive only (should not trigger in normal flow)
|
|
1588
|
+
* - Same token persists across all retry attempts of the same batch
|
|
1589
|
+
* - Backend uses this to deduplicate retries
|
|
1574
1590
|
*
|
|
1575
1591
|
* @param body - EventsQueue to send
|
|
1576
1592
|
* @returns Object with `url` (API endpoint) and `payload` (JSON string)
|
|
@@ -1582,9 +1598,11 @@ class Ze extends _ {
|
|
|
1582
1598
|
const s = {
|
|
1583
1599
|
...e,
|
|
1584
1600
|
_metadata: {
|
|
1601
|
+
...e._metadata,
|
|
1602
|
+
idempotency_token: e._metadata?.idempotency_token ?? ye(),
|
|
1585
1603
|
referer: typeof window < "u" ? window.location.href : void 0,
|
|
1586
1604
|
timestamp: t,
|
|
1587
|
-
client_version:
|
|
1605
|
+
client_version: Zt
|
|
1588
1606
|
}
|
|
1589
1607
|
};
|
|
1590
1608
|
return {
|
|
@@ -1592,6 +1610,16 @@ class Ze extends _ {
|
|
|
1592
1610
|
payload: JSON.stringify(s)
|
|
1593
1611
|
};
|
|
1594
1612
|
}
|
|
1613
|
+
ensureBatchMetadata(e, t) {
|
|
1614
|
+
const s = e._metadata?.idempotency_token ?? t ?? ye();
|
|
1615
|
+
return e._metadata?.idempotency_token === s ? e : {
|
|
1616
|
+
...e,
|
|
1617
|
+
_metadata: {
|
|
1618
|
+
...e._metadata,
|
|
1619
|
+
idempotency_token: s
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1595
1623
|
/**
|
|
1596
1624
|
* Retrieves persisted events from localStorage with error recovery.
|
|
1597
1625
|
*
|
|
@@ -1723,12 +1751,12 @@ class Ze extends _ {
|
|
|
1723
1751
|
}
|
|
1724
1752
|
logPermanentError(e, t) {
|
|
1725
1753
|
const s = Date.now();
|
|
1726
|
-
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || s - this.lastPermanentErrorLog.timestamp >=
|
|
1754
|
+
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || s - this.lastPermanentErrorLog.timestamp >= Qt) && (a("error", `${e}${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1727
1755
|
data: { status: t.statusCode, message: t.message }
|
|
1728
1756
|
}), this.lastPermanentErrorLog = { statusCode: t.statusCode, timestamp: s });
|
|
1729
1757
|
}
|
|
1730
1758
|
}
|
|
1731
|
-
class
|
|
1759
|
+
class ps extends _ {
|
|
1732
1760
|
bootTime;
|
|
1733
1761
|
bootTimestamp;
|
|
1734
1762
|
hasPerformanceNow;
|
|
@@ -1877,7 +1905,7 @@ class Ss extends _ {
|
|
|
1877
1905
|
};
|
|
1878
1906
|
}
|
|
1879
1907
|
}
|
|
1880
|
-
const
|
|
1908
|
+
const Ss = new Set(Object.values(u));
|
|
1881
1909
|
class Ts extends _ {
|
|
1882
1910
|
dataSenders;
|
|
1883
1911
|
emitter;
|
|
@@ -1895,11 +1923,11 @@ class Ts extends _ {
|
|
|
1895
1923
|
lastSessionId = null;
|
|
1896
1924
|
sessionEventCounts = {
|
|
1897
1925
|
total: 0,
|
|
1898
|
-
[
|
|
1899
|
-
[
|
|
1900
|
-
[
|
|
1901
|
-
[
|
|
1902
|
-
[
|
|
1926
|
+
[u.CLICK]: 0,
|
|
1927
|
+
[u.PAGE_VIEW]: 0,
|
|
1928
|
+
[u.CUSTOM]: 0,
|
|
1929
|
+
[u.VIEWPORT_VISIBLE]: 0,
|
|
1930
|
+
[u.SCROLL]: 0
|
|
1903
1931
|
};
|
|
1904
1932
|
saveSessionCountsDebounced = null;
|
|
1905
1933
|
/**
|
|
@@ -1917,10 +1945,10 @@ class Ts extends _ {
|
|
|
1917
1945
|
* @param fetchCredentials - Fetch credentials mode for custom backend. @default 'include'
|
|
1918
1946
|
*/
|
|
1919
1947
|
constructor(e, t = null, s = {}, n = {}, i, o = "include") {
|
|
1920
|
-
super(), this.emitter = t, this.transformers = s, this.timeManager = new
|
|
1948
|
+
super(), this.emitter = t, this.transformers = s, this.timeManager = new ps(), this.dataSenders = [];
|
|
1921
1949
|
const l = this.get("collectApiUrls");
|
|
1922
|
-
l?.saas && this.dataSenders.push(new
|
|
1923
|
-
new
|
|
1950
|
+
l?.saas && this.dataSenders.push(new et(e, "saas", l.saas, s)), l?.custom && this.dataSenders.push(
|
|
1951
|
+
new et(
|
|
1924
1952
|
e,
|
|
1925
1953
|
"custom",
|
|
1926
1954
|
l.custom,
|
|
@@ -2041,21 +2069,21 @@ class Ts extends _ {
|
|
|
2041
2069
|
custom_event: o,
|
|
2042
2070
|
web_vitals: l,
|
|
2043
2071
|
error_data: c,
|
|
2044
|
-
viewport_data:
|
|
2045
|
-
page_view:
|
|
2072
|
+
viewport_data: d,
|
|
2073
|
+
page_view: f
|
|
2046
2074
|
}) {
|
|
2047
2075
|
if (!e) {
|
|
2048
2076
|
a("error", "Event type is required - event will be ignored");
|
|
2049
2077
|
return;
|
|
2050
2078
|
}
|
|
2051
|
-
if (!
|
|
2079
|
+
if (!Ss.has(e)) {
|
|
2052
2080
|
a("error", "Invalid event type - event will be ignored", {
|
|
2053
2081
|
data: { type: e }
|
|
2054
2082
|
});
|
|
2055
2083
|
return;
|
|
2056
2084
|
}
|
|
2057
|
-
const
|
|
2058
|
-
if (!
|
|
2085
|
+
const g = this.get("sessionId");
|
|
2086
|
+
if (!g) {
|
|
2059
2087
|
this.pendingEventsBuffer.length >= 100 && (this.pendingEventsBuffer.shift(), a("debug", "Pending events buffer full - dropping oldest event", {
|
|
2060
2088
|
data: { maxBufferSize: 100 }
|
|
2061
2089
|
})), this.pendingEventsBuffer.push({
|
|
@@ -2067,36 +2095,36 @@ class Ts extends _ {
|
|
|
2067
2095
|
custom_event: o,
|
|
2068
2096
|
web_vitals: l,
|
|
2069
2097
|
error_data: c,
|
|
2070
|
-
viewport_data:
|
|
2071
|
-
page_view:
|
|
2098
|
+
viewport_data: d,
|
|
2099
|
+
page_view: f
|
|
2072
2100
|
});
|
|
2073
2101
|
return;
|
|
2074
2102
|
}
|
|
2075
|
-
this.lastSessionId !==
|
|
2076
|
-
const T = e ===
|
|
2103
|
+
this.lastSessionId !== g && (this.lastSessionId = g, this.sessionEventCounts = this.loadSessionCounts(g));
|
|
2104
|
+
const T = e === u.SESSION_START;
|
|
2077
2105
|
if (T && a("debug", "Processing SESSION_START event", {
|
|
2078
|
-
data: { sessionId:
|
|
2106
|
+
data: { sessionId: g }
|
|
2079
2107
|
}), !T && !this.checkRateLimit())
|
|
2080
2108
|
return;
|
|
2081
|
-
const
|
|
2109
|
+
const p = e;
|
|
2082
2110
|
if (!T) {
|
|
2083
2111
|
if (this.sessionEventCounts.total >= 1e3) {
|
|
2084
2112
|
a("warn", "Session event limit reached", {
|
|
2085
2113
|
data: {
|
|
2086
|
-
type:
|
|
2114
|
+
type: p,
|
|
2087
2115
|
total: this.sessionEventCounts.total,
|
|
2088
2116
|
limit: 1e3
|
|
2089
2117
|
}
|
|
2090
2118
|
});
|
|
2091
2119
|
return;
|
|
2092
2120
|
}
|
|
2093
|
-
const v = this.getTypeLimitForEvent(
|
|
2121
|
+
const v = this.getTypeLimitForEvent(p);
|
|
2094
2122
|
if (v) {
|
|
2095
|
-
const he = this.sessionEventCounts[
|
|
2123
|
+
const he = this.sessionEventCounts[p];
|
|
2096
2124
|
if (he !== void 0 && he >= v) {
|
|
2097
2125
|
a("warn", "Session event type limit reached", {
|
|
2098
2126
|
data: {
|
|
2099
|
-
type:
|
|
2127
|
+
type: p,
|
|
2100
2128
|
count: he,
|
|
2101
2129
|
limit: v
|
|
2102
2130
|
}
|
|
@@ -2105,25 +2133,25 @@ class Ts extends _ {
|
|
|
2105
2133
|
}
|
|
2106
2134
|
}
|
|
2107
2135
|
}
|
|
2108
|
-
if (
|
|
2136
|
+
if (p === u.CUSTOM && o?.name) {
|
|
2109
2137
|
const v = this.get("config")?.maxSameEventPerMinute ?? 60;
|
|
2110
2138
|
if (!this.checkPerEventRateLimit(o.name, v))
|
|
2111
2139
|
return;
|
|
2112
2140
|
}
|
|
2113
|
-
const
|
|
2114
|
-
type:
|
|
2115
|
-
page_url:
|
|
2141
|
+
const Ue = p === u.SESSION_START, K = t || this.get("pageUrl"), x = this.buildEventPayload({
|
|
2142
|
+
type: p,
|
|
2143
|
+
page_url: K,
|
|
2116
2144
|
from_page_url: s,
|
|
2117
2145
|
scroll_data: n,
|
|
2118
2146
|
click_data: i,
|
|
2119
2147
|
custom_event: o,
|
|
2120
2148
|
web_vitals: l,
|
|
2121
2149
|
error_data: c,
|
|
2122
|
-
viewport_data:
|
|
2123
|
-
page_view:
|
|
2150
|
+
viewport_data: d,
|
|
2151
|
+
page_view: f
|
|
2124
2152
|
});
|
|
2125
|
-
if (
|
|
2126
|
-
if (
|
|
2153
|
+
if (x && !(!T && !this.shouldSample())) {
|
|
2154
|
+
if (Ue) {
|
|
2127
2155
|
const v = this.get("sessionId");
|
|
2128
2156
|
if (!v) {
|
|
2129
2157
|
a("error", "Session start event requires sessionId - event will be ignored");
|
|
@@ -2137,35 +2165,35 @@ class Ts extends _ {
|
|
|
2137
2165
|
}
|
|
2138
2166
|
this.set("hasStartSession", !0);
|
|
2139
2167
|
}
|
|
2140
|
-
if (!this.isDuplicateEvent(
|
|
2168
|
+
if (!this.isDuplicateEvent(x)) {
|
|
2141
2169
|
if (this.get("mode") === ie.QA) {
|
|
2142
|
-
if (
|
|
2170
|
+
if (p === u.CUSTOM && o) {
|
|
2143
2171
|
a("info", `Custom Event: ${o.name}`, {
|
|
2144
2172
|
visibility: "qa",
|
|
2145
2173
|
data: {
|
|
2146
2174
|
name: o.name,
|
|
2147
2175
|
...o.metadata && { metadata: o.metadata }
|
|
2148
2176
|
}
|
|
2149
|
-
}), this.emitEvent(
|
|
2177
|
+
}), this.emitEvent(x);
|
|
2150
2178
|
return;
|
|
2151
2179
|
}
|
|
2152
|
-
if (
|
|
2153
|
-
const v =
|
|
2180
|
+
if (p === u.VIEWPORT_VISIBLE && d) {
|
|
2181
|
+
const v = d.name || d.id || d.selector;
|
|
2154
2182
|
a("info", `Viewport Visible: ${v}`, {
|
|
2155
2183
|
visibility: "qa",
|
|
2156
2184
|
data: {
|
|
2157
|
-
selector:
|
|
2158
|
-
...
|
|
2159
|
-
...
|
|
2160
|
-
visibilityRatio:
|
|
2161
|
-
dwellTime:
|
|
2185
|
+
selector: d.selector,
|
|
2186
|
+
...d.name && { name: d.name },
|
|
2187
|
+
...d.id && { id: d.id },
|
|
2188
|
+
visibilityRatio: d.visibilityRatio,
|
|
2189
|
+
dwellTime: d.dwellTime
|
|
2162
2190
|
}
|
|
2163
|
-
}), this.emitEvent(
|
|
2191
|
+
}), this.emitEvent(x);
|
|
2164
2192
|
return;
|
|
2165
2193
|
}
|
|
2166
2194
|
}
|
|
2167
|
-
if (this.addToQueue(
|
|
2168
|
-
this.sessionEventCounts.total++, this.sessionEventCounts[
|
|
2195
|
+
if (this.addToQueue(x), !T) {
|
|
2196
|
+
this.sessionEventCounts.total++, this.sessionEventCounts[p] !== void 0 && this.sessionEventCounts[p]++;
|
|
2169
2197
|
const v = this.get("sessionId");
|
|
2170
2198
|
v && this.saveSessionCountsDebounced && this.saveSessionCountsDebounced(v);
|
|
2171
2199
|
}
|
|
@@ -2211,11 +2239,11 @@ class Ts extends _ {
|
|
|
2211
2239
|
const e = this.get("sessionId");
|
|
2212
2240
|
e && this.saveSessionCounts(e), this.eventsQueue = [], this.pendingEventsBuffer = [], this.recentEventFingerprints.clear(), this.rateLimitCounter = 0, this.rateLimitWindowStart = 0, this.perEventRateLimits.clear(), this.sessionEventCounts = {
|
|
2213
2241
|
total: 0,
|
|
2214
|
-
[
|
|
2215
|
-
[
|
|
2216
|
-
[
|
|
2217
|
-
[
|
|
2218
|
-
[
|
|
2242
|
+
[u.CLICK]: 0,
|
|
2243
|
+
[u.PAGE_VIEW]: 0,
|
|
2244
|
+
[u.CUSTOM]: 0,
|
|
2245
|
+
[u.VIEWPORT_VISIBLE]: 0,
|
|
2246
|
+
[u.SCROLL]: 0
|
|
2219
2247
|
}, this.lastSessionId = null, this.set("hasStartSession", !1), this.dataSenders.forEach((t) => {
|
|
2220
2248
|
t.stop();
|
|
2221
2249
|
});
|
|
@@ -2434,6 +2462,13 @@ class Ts extends _ {
|
|
|
2434
2462
|
const t = this.buildEventsPayload(), s = [...this.eventsQueue], n = s.map((i) => i.id);
|
|
2435
2463
|
if (this.dataSenders.length === 0)
|
|
2436
2464
|
return this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t), e ? !0 : Promise.resolve(!0);
|
|
2465
|
+
if (e && this.sendInProgress) {
|
|
2466
|
+
for (const i of this.dataSenders)
|
|
2467
|
+
i.persistForRecovery(t);
|
|
2468
|
+
return a("debug", "Sync flush deferred: async send in progress, events persisted for recovery", {
|
|
2469
|
+
data: { eventCount: n.length }
|
|
2470
|
+
}), !0;
|
|
2471
|
+
}
|
|
2437
2472
|
if (e) {
|
|
2438
2473
|
const o = this.dataSenders.map((l) => l.sendEventsQueueSync(t)).some((l) => l);
|
|
2439
2474
|
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 +2527,10 @@ class Ts extends _ {
|
|
|
2492
2527
|
buildEventsPayload() {
|
|
2493
2528
|
const e = /* @__PURE__ */ new Map(), t = [];
|
|
2494
2529
|
for (const c of this.eventsQueue) {
|
|
2495
|
-
const
|
|
2496
|
-
e.has(
|
|
2530
|
+
const d = this.createEventSignature(c);
|
|
2531
|
+
e.has(d) || t.push(d), e.set(d, c);
|
|
2497
2532
|
}
|
|
2498
|
-
const s = t.map((c) => e.get(c)).filter((c) => !!c).sort((c,
|
|
2533
|
+
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
2534
|
let n = {
|
|
2500
2535
|
user_id: this.get("userId"),
|
|
2501
2536
|
session_id: this.get("sessionId"),
|
|
@@ -2506,7 +2541,7 @@ class Ts extends _ {
|
|
|
2506
2541
|
};
|
|
2507
2542
|
const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas), l = this.transformers.beforeBatch;
|
|
2508
2543
|
if (!o && l) {
|
|
2509
|
-
const c =
|
|
2544
|
+
const c = Et(n, l, "EventManager");
|
|
2510
2545
|
c !== null && (n = c);
|
|
2511
2546
|
}
|
|
2512
2547
|
return n;
|
|
@@ -2518,7 +2553,7 @@ class Ts extends _ {
|
|
|
2518
2553
|
});
|
|
2519
2554
|
const i = this.get("sessionReferrer"), o = this.get("sessionUtm");
|
|
2520
2555
|
let l = {
|
|
2521
|
-
id:
|
|
2556
|
+
id: ye(),
|
|
2522
2557
|
type: e.type,
|
|
2523
2558
|
page_url: t,
|
|
2524
2559
|
timestamp: s,
|
|
@@ -2533,12 +2568,12 @@ class Ts extends _ {
|
|
|
2533
2568
|
...e.page_view && { page_view: e.page_view },
|
|
2534
2569
|
...o && { utm: o }
|
|
2535
2570
|
};
|
|
2536
|
-
const c = this.get("collectApiUrls"),
|
|
2537
|
-
if (
|
|
2538
|
-
const
|
|
2539
|
-
if (
|
|
2571
|
+
const c = this.get("collectApiUrls"), d = !!c?.custom, f = !!c?.saas, g = d || f, T = d && f, p = this.transformers.beforeSend;
|
|
2572
|
+
if (p && (!g || d && !T)) {
|
|
2573
|
+
const K = gt(l, p, "EventManager");
|
|
2574
|
+
if (K === null)
|
|
2540
2575
|
return null;
|
|
2541
|
-
l =
|
|
2576
|
+
l = K;
|
|
2542
2577
|
}
|
|
2543
2578
|
return l;
|
|
2544
2579
|
}
|
|
@@ -2576,13 +2611,13 @@ class Ts extends _ {
|
|
|
2576
2611
|
}
|
|
2577
2612
|
addToQueue(e) {
|
|
2578
2613
|
if (this.emitEvent(e), this.eventsQueue.push(e), this.eventsQueue.length > 100) {
|
|
2579
|
-
const t = this.eventsQueue.findIndex((n) => n.type !==
|
|
2614
|
+
const t = this.eventsQueue.findIndex((n) => n.type !== u.SESSION_START), s = t >= 0 ? this.eventsQueue.splice(t, 1)[0] : this.eventsQueue.shift();
|
|
2580
2615
|
a("warn", "Event queue overflow, oldest non-critical event removed", {
|
|
2581
2616
|
data: {
|
|
2582
2617
|
maxLength: 100,
|
|
2583
2618
|
currentLength: this.eventsQueue.length,
|
|
2584
2619
|
removedEventType: s?.type,
|
|
2585
|
-
wasCritical: s?.type ===
|
|
2620
|
+
wasCritical: s?.type === u.SESSION_START
|
|
2586
2621
|
}
|
|
2587
2622
|
});
|
|
2588
2623
|
}
|
|
@@ -2621,11 +2656,11 @@ class Ts extends _ {
|
|
|
2621
2656
|
}
|
|
2622
2657
|
getTypeLimitForEvent(e) {
|
|
2623
2658
|
return {
|
|
2624
|
-
[
|
|
2625
|
-
[
|
|
2626
|
-
[
|
|
2627
|
-
[
|
|
2628
|
-
[
|
|
2659
|
+
[u.CLICK]: 500,
|
|
2660
|
+
[u.PAGE_VIEW]: 100,
|
|
2661
|
+
[u.CUSTOM]: 500,
|
|
2662
|
+
[u.VIEWPORT_VISIBLE]: 200,
|
|
2663
|
+
[u.SCROLL]: 120
|
|
2629
2664
|
}[e] ?? null;
|
|
2630
2665
|
}
|
|
2631
2666
|
removeProcessedEvents(e) {
|
|
@@ -2633,10 +2668,10 @@ class Ts extends _ {
|
|
|
2633
2668
|
this.eventsQueue = this.eventsQueue.filter((s) => !t.has(s.id));
|
|
2634
2669
|
}
|
|
2635
2670
|
emitEvent(e) {
|
|
2636
|
-
this.emitter && this.emitter.emit(
|
|
2671
|
+
this.emitter && this.emitter.emit(se.EVENT, e);
|
|
2637
2672
|
}
|
|
2638
2673
|
emitEventsQueue(e) {
|
|
2639
|
-
this.emitter && this.emitter.emit(
|
|
2674
|
+
this.emitter && this.emitter.emit(se.QUEUE, e);
|
|
2640
2675
|
}
|
|
2641
2676
|
/**
|
|
2642
2677
|
* Creates a debounced version of a function that delays execution until after
|
|
@@ -2679,11 +2714,11 @@ class Ts extends _ {
|
|
|
2679
2714
|
getInitialCounts() {
|
|
2680
2715
|
return {
|
|
2681
2716
|
total: 0,
|
|
2682
|
-
[
|
|
2683
|
-
[
|
|
2684
|
-
[
|
|
2685
|
-
[
|
|
2686
|
-
[
|
|
2717
|
+
[u.CLICK]: 0,
|
|
2718
|
+
[u.PAGE_VIEW]: 0,
|
|
2719
|
+
[u.CUSTOM]: 0,
|
|
2720
|
+
[u.VIEWPORT_VISIBLE]: 0,
|
|
2721
|
+
[u.SCROLL]: 0
|
|
2687
2722
|
};
|
|
2688
2723
|
}
|
|
2689
2724
|
/**
|
|
@@ -2712,21 +2747,21 @@ class Ts extends _ {
|
|
|
2712
2747
|
loadSessionCounts(e) {
|
|
2713
2748
|
if (typeof window > "u" || typeof localStorage > "u")
|
|
2714
2749
|
return this.getInitialCounts();
|
|
2715
|
-
const t = this.get("userId") || "anonymous", s =
|
|
2750
|
+
const t = this.get("userId") || "anonymous", s = xe(t, e);
|
|
2716
2751
|
try {
|
|
2717
2752
|
const n = localStorage.getItem(s);
|
|
2718
2753
|
if (!n)
|
|
2719
2754
|
return this.getInitialCounts();
|
|
2720
2755
|
const i = JSON.parse(n);
|
|
2721
|
-
return i._timestamp && Date.now() - i._timestamp >
|
|
2756
|
+
return i._timestamp && Date.now() - i._timestamp > $e ? (a("debug", "Session counts expired, clearing", {
|
|
2722
2757
|
data: { sessionId: e, age: Date.now() - i._timestamp }
|
|
2723
|
-
}), localStorage.removeItem(s), this.getInitialCounts()) : typeof i.total == "number" && typeof i[
|
|
2758
|
+
}), 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
2759
|
total: i.total,
|
|
2725
|
-
[
|
|
2726
|
-
[
|
|
2727
|
-
[
|
|
2728
|
-
[
|
|
2729
|
-
[
|
|
2760
|
+
[u.CLICK]: i[u.CLICK],
|
|
2761
|
+
[u.PAGE_VIEW]: i[u.PAGE_VIEW],
|
|
2762
|
+
[u.CUSTOM]: i[u.CUSTOM],
|
|
2763
|
+
[u.VIEWPORT_VISIBLE]: i[u.VIEWPORT_VISIBLE],
|
|
2764
|
+
[u.SCROLL]: i[u.SCROLL]
|
|
2730
2765
|
} : (a("warn", "Invalid session counts structure in localStorage, resetting", {
|
|
2731
2766
|
data: { sessionId: e, parsed: i }
|
|
2732
2767
|
}), localStorage.removeItem(s), a("debug", "Session counts removed due to invalid/corrupted data", {
|
|
@@ -2763,12 +2798,12 @@ class Ts extends _ {
|
|
|
2763
2798
|
cleanupExpiredSessionCounts() {
|
|
2764
2799
|
if (!(typeof window > "u" || typeof localStorage > "u"))
|
|
2765
2800
|
try {
|
|
2766
|
-
const e = localStorage.getItem(
|
|
2801
|
+
const e = localStorage.getItem(Be);
|
|
2767
2802
|
if (e) {
|
|
2768
2803
|
const i = Date.now() - parseInt(e, 10);
|
|
2769
|
-
if (i <
|
|
2804
|
+
if (i < We) {
|
|
2770
2805
|
a("debug", "Skipping session counts cleanup (throttled)", {
|
|
2771
|
-
data: { timeSinceLastCleanup: i, throttleMs:
|
|
2806
|
+
data: { timeSinceLastCleanup: i, throttleMs: We }
|
|
2772
2807
|
});
|
|
2773
2808
|
return;
|
|
2774
2809
|
}
|
|
@@ -2781,14 +2816,14 @@ class Ts extends _ {
|
|
|
2781
2816
|
const l = localStorage.getItem(o);
|
|
2782
2817
|
if (l) {
|
|
2783
2818
|
const c = JSON.parse(l);
|
|
2784
|
-
c._timestamp && Date.now() - c._timestamp >
|
|
2819
|
+
c._timestamp && Date.now() - c._timestamp > $e && n.push(o);
|
|
2785
2820
|
}
|
|
2786
2821
|
} catch {
|
|
2787
2822
|
}
|
|
2788
2823
|
}
|
|
2789
2824
|
n.forEach((i) => {
|
|
2790
2825
|
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(
|
|
2826
|
+
}), n.length > 0 && a("info", `Cleaned up ${n.length} expired session counts entries`), localStorage.setItem(Be, Date.now().toString());
|
|
2792
2827
|
} catch (e) {
|
|
2793
2828
|
a("warn", "Failed to cleanup expired session counts", { error: e });
|
|
2794
2829
|
}
|
|
@@ -2822,7 +2857,7 @@ class Ts extends _ {
|
|
|
2822
2857
|
* @internal
|
|
2823
2858
|
*/
|
|
2824
2859
|
saveSessionCounts(e) {
|
|
2825
|
-
const t = this.get("userId") || "anonymous", s =
|
|
2860
|
+
const t = this.get("userId") || "anonymous", s = xe(t, e);
|
|
2826
2861
|
try {
|
|
2827
2862
|
const n = {
|
|
2828
2863
|
...this.sessionEventCounts,
|
|
@@ -2890,7 +2925,7 @@ class _s extends _ {
|
|
|
2890
2925
|
return;
|
|
2891
2926
|
}
|
|
2892
2927
|
const e = this.getProjectId();
|
|
2893
|
-
this.broadcastChannel = new BroadcastChannel(
|
|
2928
|
+
this.broadcastChannel = new BroadcastChannel(Ot(e)), this.broadcastChannel.onmessage = (t) => {
|
|
2894
2929
|
const { action: s, sessionId: n, timestamp: i, projectId: o } = t.data ?? {};
|
|
2895
2930
|
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
2931
|
};
|
|
@@ -2955,7 +2990,7 @@ class _s extends _ {
|
|
|
2955
2990
|
this.storageManager.setItem(t, s), this.storageManager.setSessionItem(t, s);
|
|
2956
2991
|
}
|
|
2957
2992
|
getSessionStorageKey() {
|
|
2958
|
-
return
|
|
2993
|
+
return Nt(this.getProjectId());
|
|
2959
2994
|
}
|
|
2960
2995
|
getProjectId() {
|
|
2961
2996
|
return this.projectId;
|
|
@@ -3039,7 +3074,7 @@ class _s extends _ {
|
|
|
3039
3074
|
}) : (a("debug", "Emitting SESSION_START event", {
|
|
3040
3075
|
data: { sessionId: t }
|
|
3041
3076
|
}), this.eventManager.track({
|
|
3042
|
-
type:
|
|
3077
|
+
type: u.SESSION_START
|
|
3043
3078
|
})), this.setupSessionTimeout(), this.setupActivityListeners(), this.setupLifecycleListeners();
|
|
3044
3079
|
} catch (i) {
|
|
3045
3080
|
throw this.isTracking = !1, this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupLifecycleListeners(), this.cleanupCrossTabSync(), this.set("sessionId", null), i;
|
|
@@ -3078,7 +3113,7 @@ class _s extends _ {
|
|
|
3078
3113
|
a("debug", "Renewing session after timeout", {
|
|
3079
3114
|
data: { newSessionId: e }
|
|
3080
3115
|
}), 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:
|
|
3116
|
+
type: u.SESSION_START
|
|
3082
3117
|
}), this.eventManager.flushPendingEvents(), this.setupSessionTimeout();
|
|
3083
3118
|
}
|
|
3084
3119
|
cleanupActivityListeners() {
|
|
@@ -3323,7 +3358,7 @@ class ws extends _ {
|
|
|
3323
3358
|
};
|
|
3324
3359
|
}
|
|
3325
3360
|
trackCurrentPage = () => {
|
|
3326
|
-
const e = window.location.href, t =
|
|
3361
|
+
const e = window.location.href, t = we(e, this.get("config").sensitiveQueryParams);
|
|
3327
3362
|
if (this.get("pageUrl") === t)
|
|
3328
3363
|
return;
|
|
3329
3364
|
const s = Date.now(), n = this.get("config").pageViewThrottleMs ?? 1e3;
|
|
@@ -3334,16 +3369,16 @@ class ws extends _ {
|
|
|
3334
3369
|
this.set("pageUrl", t);
|
|
3335
3370
|
const o = this.extractPageViewData();
|
|
3336
3371
|
this.eventManager.track({
|
|
3337
|
-
type:
|
|
3372
|
+
type: u.PAGE_VIEW,
|
|
3338
3373
|
page_url: this.get("pageUrl"),
|
|
3339
3374
|
from_page_url: i,
|
|
3340
3375
|
...o && { page_view: o }
|
|
3341
3376
|
});
|
|
3342
3377
|
};
|
|
3343
3378
|
trackInitialPageView() {
|
|
3344
|
-
const e =
|
|
3379
|
+
const e = we(window.location.href, this.get("config").sensitiveQueryParams), t = this.extractPageViewData();
|
|
3345
3380
|
this.lastPageViewTime = Date.now(), this.eventManager.track({
|
|
3346
|
-
type:
|
|
3381
|
+
type: u.PAGE_VIEW,
|
|
3347
3382
|
page_url: e,
|
|
3348
3383
|
...t && { page_view: t }
|
|
3349
3384
|
}), this.onTrack();
|
|
@@ -3394,22 +3429,22 @@ class bs extends _ {
|
|
|
3394
3429
|
return;
|
|
3395
3430
|
const o = this.findTrackingElement(n), l = this.getRelevantClickElement(n), c = this.calculateClickCoordinates(t, n);
|
|
3396
3431
|
if (o) {
|
|
3397
|
-
const
|
|
3398
|
-
if (
|
|
3399
|
-
const
|
|
3432
|
+
const f = this.extractTrackingData(o);
|
|
3433
|
+
if (f) {
|
|
3434
|
+
const g = this.createCustomEventData(f);
|
|
3400
3435
|
this.eventManager.track({
|
|
3401
|
-
type:
|
|
3436
|
+
type: u.CUSTOM,
|
|
3402
3437
|
custom_event: {
|
|
3403
|
-
name:
|
|
3404
|
-
...
|
|
3438
|
+
name: g.name,
|
|
3439
|
+
...g.value && { metadata: { value: g.value } }
|
|
3405
3440
|
}
|
|
3406
3441
|
});
|
|
3407
3442
|
}
|
|
3408
3443
|
}
|
|
3409
|
-
const
|
|
3444
|
+
const d = this.generateClickData(n, l, c);
|
|
3410
3445
|
this.eventManager.track({
|
|
3411
|
-
type:
|
|
3412
|
-
click_data:
|
|
3446
|
+
type: u.CLICK,
|
|
3447
|
+
click_data: d
|
|
3413
3448
|
});
|
|
3414
3449
|
}, window.addEventListener("click", this.clickHandler, !0));
|
|
3415
3450
|
}
|
|
@@ -3497,7 +3532,7 @@ class bs extends _ {
|
|
|
3497
3532
|
return e.hasAttribute(`${b}-name`) ? e : e.closest(`[${b}-name]`);
|
|
3498
3533
|
}
|
|
3499
3534
|
getRelevantClickElement(e) {
|
|
3500
|
-
for (const t of
|
|
3535
|
+
for (const t of At)
|
|
3501
3536
|
try {
|
|
3502
3537
|
if (e.matches(t))
|
|
3503
3538
|
return e;
|
|
@@ -3538,7 +3573,7 @@ class bs extends _ {
|
|
|
3538
3573
|
};
|
|
3539
3574
|
}
|
|
3540
3575
|
generateClickData(e, t, s) {
|
|
3541
|
-
const { x: n, y: i, relativeX: o, relativeY: l } = s, c = this.getRelevantText(e, t),
|
|
3576
|
+
const { x: n, y: i, relativeX: o, relativeY: l } = s, c = this.getRelevantText(e, t), d = this.extractElementAttributes(t);
|
|
3542
3577
|
return {
|
|
3543
3578
|
x: n,
|
|
3544
3579
|
y: i,
|
|
@@ -3548,12 +3583,12 @@ class bs extends _ {
|
|
|
3548
3583
|
...t.id && { id: t.id },
|
|
3549
3584
|
...t.className && { class: t.className },
|
|
3550
3585
|
...c && { text: c },
|
|
3551
|
-
...
|
|
3552
|
-
...
|
|
3553
|
-
...
|
|
3554
|
-
...
|
|
3555
|
-
...
|
|
3556
|
-
...Object.keys(
|
|
3586
|
+
...d.href && { href: d.href },
|
|
3587
|
+
...d.title && { title: d.title },
|
|
3588
|
+
...d.alt && { alt: d.alt },
|
|
3589
|
+
...d.role && { role: d.role },
|
|
3590
|
+
...d["aria-label"] && { ariaLabel: d["aria-label"] },
|
|
3591
|
+
...Object.keys(d).length > 0 && { dataAttributes: d }
|
|
3557
3592
|
};
|
|
3558
3593
|
}
|
|
3559
3594
|
/**
|
|
@@ -3577,7 +3612,7 @@ class bs extends _ {
|
|
|
3577
3612
|
*/
|
|
3578
3613
|
sanitizeText(e) {
|
|
3579
3614
|
let t = e;
|
|
3580
|
-
for (const s of
|
|
3615
|
+
for (const s of lt) {
|
|
3581
3616
|
const n = new RegExp(s.source, s.flags);
|
|
3582
3617
|
t = t.replace(n, "[REDACTED]");
|
|
3583
3618
|
}
|
|
@@ -3717,7 +3752,7 @@ class As extends _ {
|
|
|
3717
3752
|
return this.isWindowScrollable() ? e === window : this.containers.length === 0;
|
|
3718
3753
|
}
|
|
3719
3754
|
setupScrollContainer(e, t) {
|
|
3720
|
-
if (this.containers.some((
|
|
3755
|
+
if (this.containers.some((d) => d.element === e) || e !== window && !this.isElementScrollable(e))
|
|
3721
3756
|
return;
|
|
3722
3757
|
const n = this.getScrollTop(e), i = this.calculateScrollDepth(
|
|
3723
3758
|
n,
|
|
@@ -3729,7 +3764,7 @@ class As extends _ {
|
|
|
3729
3764
|
isPrimary: o,
|
|
3730
3765
|
lastScrollPos: n,
|
|
3731
3766
|
lastDepth: i,
|
|
3732
|
-
lastDirection:
|
|
3767
|
+
lastDirection: Z.DOWN,
|
|
3733
3768
|
lastEventTime: 0,
|
|
3734
3769
|
firstScrollEventTime: null,
|
|
3735
3770
|
maxDepthReached: i,
|
|
@@ -3737,10 +3772,10 @@ class As extends _ {
|
|
|
3737
3772
|
listener: null
|
|
3738
3773
|
}, c = () => {
|
|
3739
3774
|
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,
|
|
3775
|
+
const d = this.calculateScrollData(l);
|
|
3776
|
+
if (d) {
|
|
3777
|
+
const f = Date.now();
|
|
3778
|
+
this.processScrollEvent(l, d, f);
|
|
3744
3779
|
}
|
|
3745
3780
|
l.debounceTimer = null;
|
|
3746
3781
|
}, 250));
|
|
@@ -3753,7 +3788,7 @@ class As extends _ {
|
|
|
3753
3788
|
e.lastEventTime = s, e.lastDepth = t.depth, e.lastDirection = t.direction;
|
|
3754
3789
|
const n = this.get("scrollEventCount") ?? 0;
|
|
3755
3790
|
this.set("scrollEventCount", n + 1), this.eventManager.track({
|
|
3756
|
-
type:
|
|
3791
|
+
type: u.SCROLL,
|
|
3757
3792
|
scroll_data: {
|
|
3758
3793
|
...t,
|
|
3759
3794
|
container_selector: e.selector,
|
|
@@ -3788,7 +3823,7 @@ class As extends _ {
|
|
|
3788
3823
|
e.debounceTimer !== null && (clearTimeout(e.debounceTimer), e.debounceTimer = null);
|
|
3789
3824
|
}
|
|
3790
3825
|
getScrollDirection(e, t) {
|
|
3791
|
-
return e > t ?
|
|
3826
|
+
return e > t ? Z.DOWN : Z.UP;
|
|
3792
3827
|
}
|
|
3793
3828
|
calculateScrollDepth(e, t, s) {
|
|
3794
3829
|
if (t <= s)
|
|
@@ -3800,14 +3835,14 @@ class As extends _ {
|
|
|
3800
3835
|
const { element: t, lastScrollPos: s, lastEventTime: n } = e, i = this.getScrollTop(t), o = Date.now(), l = Math.abs(i - s);
|
|
3801
3836
|
if (l < 10 || t === window && !this.isWindowScrollable())
|
|
3802
3837
|
return null;
|
|
3803
|
-
const c = this.getViewportHeight(t),
|
|
3838
|
+
const c = this.getViewportHeight(t), d = this.getScrollHeight(t), f = this.getScrollDirection(i, s), g = this.calculateScrollDepth(i, d, c);
|
|
3804
3839
|
let T;
|
|
3805
3840
|
n > 0 ? T = o - n : e.firstScrollEventTime !== null ? T = o - e.firstScrollEventTime : T = 250;
|
|
3806
|
-
const
|
|
3807
|
-
return
|
|
3808
|
-
depth:
|
|
3809
|
-
direction:
|
|
3810
|
-
velocity:
|
|
3841
|
+
const p = Math.round(l / T * 1e3);
|
|
3842
|
+
return g > e.maxDepthReached && (e.maxDepthReached = g), e.lastScrollPos = i, {
|
|
3843
|
+
depth: g,
|
|
3844
|
+
direction: f,
|
|
3845
|
+
velocity: p,
|
|
3811
3846
|
max_depth_reached: e.maxDepthReached
|
|
3812
3847
|
};
|
|
3813
3848
|
}
|
|
@@ -3965,7 +4000,7 @@ class Ls extends _ {
|
|
|
3965
4000
|
...e.name !== void 0 && { name: e.name }
|
|
3966
4001
|
};
|
|
3967
4002
|
this.eventManager.track({
|
|
3968
|
-
type:
|
|
4003
|
+
type: u.VIEWPORT_VISIBLE,
|
|
3969
4004
|
viewport_data: o
|
|
3970
4005
|
}), e.startTime = null, e.timeoutId = null, e.lastFiredTime = i;
|
|
3971
4006
|
}
|
|
@@ -4342,7 +4377,7 @@ class Ns extends _ {
|
|
|
4342
4377
|
navigationCounter = 0;
|
|
4343
4378
|
// Counter for handling simultaneous navigations edge case
|
|
4344
4379
|
constructor(e) {
|
|
4345
|
-
super(), this.eventManager = e, this.vitalThresholds =
|
|
4380
|
+
super(), this.eventManager = e, this.vitalThresholds = Ye(_e);
|
|
4346
4381
|
}
|
|
4347
4382
|
/**
|
|
4348
4383
|
* Starts tracking Web Vitals and performance metrics.
|
|
@@ -4360,7 +4395,7 @@ class Ns extends _ {
|
|
|
4360
4395
|
*/
|
|
4361
4396
|
async startTracking() {
|
|
4362
4397
|
const e = this.get("config"), t = e?.webVitalsMode ?? _e;
|
|
4363
|
-
this.vitalThresholds =
|
|
4398
|
+
this.vitalThresholds = Ye(t), e?.webVitalsThresholds && (this.vitalThresholds = { ...this.vitalThresholds, ...e.webVitalsThresholds }), await this.initWebVitals(), this.observeLongTasks();
|
|
4364
4399
|
}
|
|
4365
4400
|
/**
|
|
4366
4401
|
* Stops tracking Web Vitals and cleans up resources.
|
|
@@ -4431,8 +4466,8 @@ class Ns extends _ {
|
|
|
4431
4466
|
async initWebVitals() {
|
|
4432
4467
|
try {
|
|
4433
4468
|
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:
|
|
4469
|
+
const d = Number(c.value.toFixed(2));
|
|
4470
|
+
this.sendVital({ type: l, value: d });
|
|
4436
4471
|
};
|
|
4437
4472
|
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
4473
|
} catch (e) {
|
|
@@ -4457,7 +4492,7 @@ class Ns extends _ {
|
|
|
4457
4492
|
const t = e.getEntries();
|
|
4458
4493
|
for (const s of t) {
|
|
4459
4494
|
const n = Number(s.duration.toFixed(2)), i = Date.now();
|
|
4460
|
-
i - this.lastLongTaskSentAt >=
|
|
4495
|
+
i - this.lastLongTaskSentAt >= Yt && (this.shouldSendVital("LONG_TASK", n) && this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = i);
|
|
4461
4496
|
}
|
|
4462
4497
|
},
|
|
4463
4498
|
{ type: "longtask", buffered: !0 }
|
|
@@ -4473,7 +4508,7 @@ class Ns extends _ {
|
|
|
4473
4508
|
return;
|
|
4474
4509
|
if (s)
|
|
4475
4510
|
s.add(e.type);
|
|
4476
|
-
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length >
|
|
4511
|
+
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length > qt) {
|
|
4477
4512
|
const i = this.navigationHistory.shift();
|
|
4478
4513
|
i && this.reportedByNav.delete(i);
|
|
4479
4514
|
}
|
|
@@ -4486,7 +4521,7 @@ class Ns extends _ {
|
|
|
4486
4521
|
return;
|
|
4487
4522
|
}
|
|
4488
4523
|
this.eventManager.track({
|
|
4489
|
-
type:
|
|
4524
|
+
type: u.WEB_VITALS,
|
|
4490
4525
|
web_vitals: {
|
|
4491
4526
|
type: e,
|
|
4492
4527
|
value: t
|
|
@@ -4600,27 +4635,27 @@ class ae extends _ {
|
|
|
4600
4635
|
const e = Date.now();
|
|
4601
4636
|
if (e < this.burstBackoffUntil)
|
|
4602
4637
|
return !1;
|
|
4603
|
-
if (e - this.burstWindowStart >
|
|
4604
|
-
return this.burstBackoffUntil = e +
|
|
4638
|
+
if (e - this.burstWindowStart > jt && (this.errorBurstCounter = 0, this.burstWindowStart = e), this.errorBurstCounter++, this.errorBurstCounter > zt)
|
|
4639
|
+
return this.burstBackoffUntil = e + Qe, a("debug", "Error burst detected - entering cooldown", {
|
|
4605
4640
|
data: {
|
|
4606
4641
|
errorsInWindow: this.errorBurstCounter,
|
|
4607
|
-
cooldownMs:
|
|
4642
|
+
cooldownMs: Qe
|
|
4608
4643
|
}
|
|
4609
4644
|
}), !1;
|
|
4610
|
-
const s = this.get("config").errorSampling ??
|
|
4645
|
+
const s = this.get("config").errorSampling ?? ct;
|
|
4611
4646
|
return Math.random() < s;
|
|
4612
4647
|
}
|
|
4613
4648
|
handleError = (e) => {
|
|
4614
4649
|
if (!this.shouldSample())
|
|
4615
4650
|
return;
|
|
4616
4651
|
const t = this.sanitize(e.message || "Unknown error");
|
|
4617
|
-
if (this.shouldSuppressError(
|
|
4652
|
+
if (this.shouldSuppressError(B.JS_ERROR, t))
|
|
4618
4653
|
return;
|
|
4619
4654
|
const s = typeof e.error?.stack == "string" ? this.truncateStack(e.error.stack) : void 0;
|
|
4620
4655
|
this.eventManager.track({
|
|
4621
|
-
type:
|
|
4656
|
+
type: u.ERROR,
|
|
4622
4657
|
error_data: {
|
|
4623
|
-
type:
|
|
4658
|
+
type: B.JS_ERROR,
|
|
4624
4659
|
message: t,
|
|
4625
4660
|
...e.filename !== "" && { filename: e.filename },
|
|
4626
4661
|
...e.lineno !== 0 && { line: e.lineno },
|
|
@@ -4633,13 +4668,13 @@ class ae extends _ {
|
|
|
4633
4668
|
if (!this.shouldSample())
|
|
4634
4669
|
return;
|
|
4635
4670
|
const t = this.extractRejectionMessage(e.reason), s = this.sanitize(t);
|
|
4636
|
-
if (this.shouldSuppressError(
|
|
4671
|
+
if (this.shouldSuppressError(B.PROMISE_REJECTION, s))
|
|
4637
4672
|
return;
|
|
4638
4673
|
const n = e.reason instanceof Error && typeof e.reason.stack == "string" ? this.truncateStack(e.reason.stack) : void 0;
|
|
4639
4674
|
this.eventManager.track({
|
|
4640
|
-
type:
|
|
4675
|
+
type: u.ERROR,
|
|
4641
4676
|
error_data: {
|
|
4642
|
-
type:
|
|
4677
|
+
type: B.PROMISE_REJECTION,
|
|
4643
4678
|
message: s,
|
|
4644
4679
|
...n !== void 0 && { stack: n }
|
|
4645
4680
|
}
|
|
@@ -4659,12 +4694,12 @@ class ae extends _ {
|
|
|
4659
4694
|
}
|
|
4660
4695
|
}
|
|
4661
4696
|
sanitize(e) {
|
|
4662
|
-
const t = e.length >
|
|
4697
|
+
const t = e.length > Ge ? e.slice(0, Ge) + "..." : e;
|
|
4663
4698
|
return this.sanitizePii(t);
|
|
4664
4699
|
}
|
|
4665
4700
|
sanitizePii(e) {
|
|
4666
4701
|
let t = e;
|
|
4667
|
-
for (const s of
|
|
4702
|
+
for (const s of lt) {
|
|
4668
4703
|
const n = new RegExp(s.source, s.flags);
|
|
4669
4704
|
t = t.replace(n, "[REDACTED]");
|
|
4670
4705
|
}
|
|
@@ -4672,22 +4707,22 @@ class ae extends _ {
|
|
|
4672
4707
|
}
|
|
4673
4708
|
shouldSuppressError(e, t) {
|
|
4674
4709
|
const s = Date.now(), n = `${e}:${t}`, i = this.recentErrors.get(n);
|
|
4675
|
-
return i !== void 0 && s - i <
|
|
4710
|
+
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
4711
|
}
|
|
4677
4712
|
static TRUNCATION_SUFFIX = `
|
|
4678
4713
|
...truncated`;
|
|
4679
4714
|
truncateStack(e) {
|
|
4680
|
-
if (e.length <=
|
|
4681
|
-
const t =
|
|
4715
|
+
if (e.length <= je) return this.sanitizePii(e);
|
|
4716
|
+
const t = je - ae.TRUNCATION_SUFFIX.length, s = e.slice(0, t) + ae.TRUNCATION_SUFFIX;
|
|
4682
4717
|
return this.sanitizePii(s);
|
|
4683
4718
|
}
|
|
4684
4719
|
pruneOldErrors() {
|
|
4685
4720
|
const e = Date.now();
|
|
4686
4721
|
for (const [n, i] of this.recentErrors.entries())
|
|
4687
|
-
e - i >
|
|
4688
|
-
if (this.recentErrors.size <=
|
|
4722
|
+
e - i > ze && this.recentErrors.delete(n);
|
|
4723
|
+
if (this.recentErrors.size <= ee)
|
|
4689
4724
|
return;
|
|
4690
|
-
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), s = this.recentErrors.size -
|
|
4725
|
+
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), s = this.recentErrors.size - ee;
|
|
4691
4726
|
for (let n = 0; n < s; n += 1) {
|
|
4692
4727
|
const i = t[n];
|
|
4693
4728
|
i && this.recentErrors.delete(i[0]);
|
|
@@ -4759,7 +4794,7 @@ class Os extends _ {
|
|
|
4759
4794
|
return;
|
|
4760
4795
|
}
|
|
4761
4796
|
this.managers.event.track({
|
|
4762
|
-
type:
|
|
4797
|
+
type: u.CUSTOM,
|
|
4763
4798
|
custom_event: {
|
|
4764
4799
|
name: e,
|
|
4765
4800
|
...o && { metadata: o }
|
|
@@ -4825,10 +4860,10 @@ class Os extends _ {
|
|
|
4825
4860
|
this.set("userId", t);
|
|
4826
4861
|
const s = os(e);
|
|
4827
4862
|
this.set("collectApiUrls", s);
|
|
4828
|
-
const n =
|
|
4863
|
+
const n = Xt();
|
|
4829
4864
|
this.set("device", n);
|
|
4830
|
-
const i =
|
|
4831
|
-
this.set("pageUrl", i),
|
|
4865
|
+
const i = we(window.location.href, e.sensitiveQueryParams);
|
|
4866
|
+
this.set("pageUrl", i), ts() && this.set("mode", ie.QA);
|
|
4832
4867
|
}
|
|
4833
4868
|
/**
|
|
4834
4869
|
* Returns the current configuration object.
|
|
@@ -4879,7 +4914,7 @@ class Os extends _ {
|
|
|
4879
4914
|
valid: !1,
|
|
4880
4915
|
error: "Global metadata must be a plain object"
|
|
4881
4916
|
};
|
|
4882
|
-
const t =
|
|
4917
|
+
const t = mt("Global", e, "globalMetadata");
|
|
4883
4918
|
return t.valid ? { valid: !0 } : {
|
|
4884
4919
|
valid: !1,
|
|
4885
4920
|
error: t.error
|
|
@@ -4946,7 +4981,7 @@ class Os extends _ {
|
|
|
4946
4981
|
a("warn", "identify() userId exceeds 256 characters", { data: { length: e.trim().length } });
|
|
4947
4982
|
return;
|
|
4948
4983
|
}
|
|
4949
|
-
const s = e.trim(), n =
|
|
4984
|
+
const s = e.trim(), n = ft(t), i = {
|
|
4950
4985
|
userId: s,
|
|
4951
4986
|
...n ? { traits: n } : {}
|
|
4952
4987
|
};
|
|
@@ -4993,10 +5028,10 @@ class Os extends _ {
|
|
|
4993
5028
|
loadPersistedIdentity() {
|
|
4994
5029
|
const e = this.managers.storage, t = this.getProjectId(), s = fe(t);
|
|
4995
5030
|
try {
|
|
4996
|
-
const n = e.getItem(
|
|
5031
|
+
const n = e.getItem(U);
|
|
4997
5032
|
if (n) {
|
|
4998
5033
|
const i = JSON.parse(n);
|
|
4999
|
-
if (e.removeItem(
|
|
5034
|
+
if (e.removeItem(U), !this.isValidIdentityData(i)) {
|
|
5000
5035
|
a("debug", "Invalid pending identity in localStorage, discarded");
|
|
5001
5036
|
return;
|
|
5002
5037
|
}
|
|
@@ -5005,7 +5040,7 @@ class Os extends _ {
|
|
|
5005
5040
|
return;
|
|
5006
5041
|
}
|
|
5007
5042
|
} catch {
|
|
5008
|
-
e.removeItem(
|
|
5043
|
+
e.removeItem(U);
|
|
5009
5044
|
}
|
|
5010
5045
|
try {
|
|
5011
5046
|
const n = e.getItem(s);
|
|
@@ -5043,7 +5078,7 @@ class Os extends _ {
|
|
|
5043
5078
|
clearPersistedIdentity() {
|
|
5044
5079
|
try {
|
|
5045
5080
|
const e = this.managers.storage, t = this.getProjectId();
|
|
5046
|
-
e.removeItem(fe(t)), e.removeItem(
|
|
5081
|
+
e.removeItem(fe(t)), e.removeItem(U);
|
|
5047
5082
|
} catch {
|
|
5048
5083
|
a("debug", "Failed to clear persisted identity");
|
|
5049
5084
|
}
|
|
@@ -5068,23 +5103,23 @@ class Os extends _ {
|
|
|
5068
5103
|
a("warn", "Failed to start performance tracking", { error: s });
|
|
5069
5104
|
}), 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
5105
|
const s = new Cs();
|
|
5071
|
-
s.activate(), this.integrationInstances.shopifyCartLinker = s, this.emitter.on(
|
|
5072
|
-
n.type ===
|
|
5106
|
+
s.activate(), this.integrationInstances.shopifyCartLinker = s, this.emitter.on(se.EVENT, (n) => {
|
|
5107
|
+
n.type === u.SESSION_START && s.onSessionChange();
|
|
5073
5108
|
});
|
|
5074
5109
|
}
|
|
5075
5110
|
}
|
|
5076
5111
|
}
|
|
5077
|
-
const
|
|
5078
|
-
let
|
|
5079
|
-
const Ps = async (r) => typeof window > "u" || typeof document > "u" ? { sessionId: "" } : (
|
|
5112
|
+
const k = [], M = [];
|
|
5113
|
+
let D = null, h = null, R = !1, S = !1, P = null;
|
|
5114
|
+
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
5115
|
try {
|
|
5081
|
-
const e =
|
|
5116
|
+
const e = us(r ?? {}), t = new Os();
|
|
5082
5117
|
try {
|
|
5083
|
-
|
|
5118
|
+
k.forEach(({ event: o, callback: l }) => {
|
|
5084
5119
|
t.on(o, l);
|
|
5085
|
-
}),
|
|
5120
|
+
}), k.length = 0, M.forEach(({ hook: o, fn: l }) => {
|
|
5086
5121
|
o === "beforeSend" ? t.setTransformer("beforeSend", l) : t.setTransformer("beforeBatch", l);
|
|
5087
|
-
}), M.length = 0,
|
|
5122
|
+
}), M.length = 0, D && (t.setCustomHeaders(D), D = null);
|
|
5088
5123
|
const s = t.init(e), n = new Promise((o, l) => {
|
|
5089
5124
|
setTimeout(() => {
|
|
5090
5125
|
l(new Error("[TraceLog] Initialization timeout after 10000ms"));
|
|
@@ -5102,20 +5137,20 @@ const Ps = async (r) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
5102
5137
|
} catch (e) {
|
|
5103
5138
|
throw h = null, e;
|
|
5104
5139
|
} finally {
|
|
5105
|
-
R = !1,
|
|
5140
|
+
R = !1, P = null;
|
|
5106
5141
|
}
|
|
5107
|
-
})()),
|
|
5142
|
+
})()), P)), Ds = (r, e) => {
|
|
5108
5143
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5109
5144
|
if (!h)
|
|
5110
5145
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
5111
|
-
if (
|
|
5146
|
+
if (S)
|
|
5112
5147
|
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
5113
5148
|
h.sendCustomEvent(r, e);
|
|
5114
5149
|
}
|
|
5115
5150
|
}, ks = (r, e) => {
|
|
5116
5151
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5117
5152
|
if (!h || R) {
|
|
5118
|
-
|
|
5153
|
+
k.push({ event: r, callback: e });
|
|
5119
5154
|
return;
|
|
5120
5155
|
}
|
|
5121
5156
|
h.on(r, e);
|
|
@@ -5123,8 +5158,8 @@ const Ps = async (r) => typeof window > "u" || typeof document > "u" ? { session
|
|
|
5123
5158
|
}, Vs = (r, e) => {
|
|
5124
5159
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5125
5160
|
if (!h) {
|
|
5126
|
-
const t =
|
|
5127
|
-
t !== -1 &&
|
|
5161
|
+
const t = k.findIndex((s) => s.event === r && s.callback === e);
|
|
5162
|
+
t !== -1 && k.splice(t, 1);
|
|
5128
5163
|
return;
|
|
5129
5164
|
}
|
|
5130
5165
|
h.off(r, e);
|
|
@@ -5139,7 +5174,7 @@ function Us(r, e) {
|
|
|
5139
5174
|
t !== -1 && M.splice(t, 1), M.push({ hook: r, fn: e });
|
|
5140
5175
|
return;
|
|
5141
5176
|
}
|
|
5142
|
-
if (
|
|
5177
|
+
if (S)
|
|
5143
5178
|
throw new Error("[TraceLog] Cannot set transformers while TraceLog is being destroyed");
|
|
5144
5179
|
r === "beforeSend" ? h.setTransformer("beforeSend", e) : h.setTransformer("beforeBatch", e);
|
|
5145
5180
|
}
|
|
@@ -5151,7 +5186,7 @@ const Hs = (r) => {
|
|
|
5151
5186
|
e !== -1 && M.splice(e, 1);
|
|
5152
5187
|
return;
|
|
5153
5188
|
}
|
|
5154
|
-
if (
|
|
5189
|
+
if (S)
|
|
5155
5190
|
throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
|
|
5156
5191
|
h.removeTransformer(r);
|
|
5157
5192
|
}
|
|
@@ -5160,45 +5195,45 @@ const Hs = (r) => {
|
|
|
5160
5195
|
if (typeof r != "function")
|
|
5161
5196
|
throw new Error(`[TraceLog] Custom headers provider must be a function, received: ${typeof r}`);
|
|
5162
5197
|
if (!h || R) {
|
|
5163
|
-
|
|
5198
|
+
D = r;
|
|
5164
5199
|
return;
|
|
5165
5200
|
}
|
|
5166
|
-
if (
|
|
5201
|
+
if (S)
|
|
5167
5202
|
throw new Error("[TraceLog] Cannot set custom headers while TraceLog is being destroyed");
|
|
5168
5203
|
h.setCustomHeaders(r);
|
|
5169
5204
|
}
|
|
5170
5205
|
}, xs = () => {
|
|
5171
5206
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5172
5207
|
if (!h) {
|
|
5173
|
-
|
|
5208
|
+
D = null;
|
|
5174
5209
|
return;
|
|
5175
5210
|
}
|
|
5176
|
-
if (
|
|
5211
|
+
if (S)
|
|
5177
5212
|
throw new Error("[TraceLog] Cannot remove custom headers while TraceLog is being destroyed");
|
|
5178
5213
|
h.removeCustomHeaders();
|
|
5179
5214
|
}
|
|
5180
5215
|
}, $s = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, Bs = () => typeof window > "u" || typeof document > "u" || !h ? null : h.getSessionId(), Ws = () => {
|
|
5181
5216
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5182
|
-
if (
|
|
5217
|
+
if (S)
|
|
5183
5218
|
throw new Error("[TraceLog] Destroy operation already in progress");
|
|
5184
5219
|
if (!h) {
|
|
5185
|
-
|
|
5220
|
+
S = !1;
|
|
5186
5221
|
return;
|
|
5187
5222
|
}
|
|
5188
|
-
|
|
5223
|
+
S = !0;
|
|
5189
5224
|
try {
|
|
5190
|
-
h.destroy(), h = null, R = !1,
|
|
5225
|
+
h.destroy(), h = null, R = !1, P = null, k.length = 0, M.length = 0, D = null, S = !1;
|
|
5191
5226
|
} catch (r) {
|
|
5192
|
-
h = null, R = !1,
|
|
5227
|
+
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
5228
|
}
|
|
5194
5229
|
}
|
|
5195
5230
|
}, Xs = (r) => {
|
|
5196
|
-
typeof window > "u" || typeof document > "u" ||
|
|
5231
|
+
typeof window > "u" || typeof document > "u" || ss(r);
|
|
5197
5232
|
}, Gs = (r) => {
|
|
5198
5233
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5199
5234
|
if (!h)
|
|
5200
5235
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
5201
|
-
if (
|
|
5236
|
+
if (S)
|
|
5202
5237
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
5203
5238
|
h.updateGlobalMetadata(r);
|
|
5204
5239
|
}
|
|
@@ -5206,7 +5241,7 @@ const Hs = (r) => {
|
|
|
5206
5241
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5207
5242
|
if (!h)
|
|
5208
5243
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
5209
|
-
if (
|
|
5244
|
+
if (S)
|
|
5210
5245
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
5211
5246
|
h.mergeGlobalMetadata(r);
|
|
5212
5247
|
}
|
|
@@ -5220,7 +5255,7 @@ const Hs = (r) => {
|
|
|
5220
5255
|
a("warn", "identify() userId exceeds 256 characters");
|
|
5221
5256
|
return;
|
|
5222
5257
|
}
|
|
5223
|
-
if (
|
|
5258
|
+
if (S) {
|
|
5224
5259
|
a("warn", "Cannot identify while TraceLog is being destroyed");
|
|
5225
5260
|
return;
|
|
5226
5261
|
}
|
|
@@ -5229,11 +5264,11 @@ const Hs = (r) => {
|
|
|
5229
5264
|
return;
|
|
5230
5265
|
}
|
|
5231
5266
|
try {
|
|
5232
|
-
const t =
|
|
5267
|
+
const t = ft(e), s = {
|
|
5233
5268
|
userId: r.trim(),
|
|
5234
5269
|
...t ? { traits: t } : {}
|
|
5235
5270
|
};
|
|
5236
|
-
localStorage.setItem(
|
|
5271
|
+
localStorage.setItem(U, JSON.stringify(s)), a("debug", "Identity persisted pre-init (will be applied on init)");
|
|
5237
5272
|
} catch {
|
|
5238
5273
|
a("debug", "Failed to persist pre-init identity");
|
|
5239
5274
|
}
|
|
@@ -5242,12 +5277,12 @@ const Hs = (r) => {
|
|
|
5242
5277
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5243
5278
|
if (!h) {
|
|
5244
5279
|
try {
|
|
5245
|
-
localStorage.removeItem(
|
|
5280
|
+
localStorage.removeItem(U);
|
|
5246
5281
|
} catch {
|
|
5247
5282
|
}
|
|
5248
5283
|
return;
|
|
5249
5284
|
}
|
|
5250
|
-
if (
|
|
5285
|
+
if (S)
|
|
5251
5286
|
throw new Error("[TraceLog] Cannot reset identity while TraceLog is being destroyed");
|
|
5252
5287
|
await h.resetIdentity();
|
|
5253
5288
|
}
|
|
@@ -5269,20 +5304,20 @@ const Hs = (r) => {
|
|
|
5269
5304
|
identify: zs,
|
|
5270
5305
|
resetIdentity: Qs
|
|
5271
5306
|
};
|
|
5272
|
-
var
|
|
5307
|
+
var Le, C, G, pt, le, St = -1, V = function(r) {
|
|
5273
5308
|
addEventListener("pageshow", (function(e) {
|
|
5274
5309
|
e.persisted && (St = e.timeStamp, r(e));
|
|
5275
5310
|
}), !0);
|
|
5276
|
-
},
|
|
5311
|
+
}, De = function() {
|
|
5277
5312
|
var r = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
|
|
5278
5313
|
if (r && r.responseStart > 0 && r.responseStart < performance.now()) return r;
|
|
5279
|
-
},
|
|
5280
|
-
var r =
|
|
5314
|
+
}, de = function() {
|
|
5315
|
+
var r = De();
|
|
5281
5316
|
return r && r.activationStart || 0;
|
|
5282
5317
|
}, y = function(r, e) {
|
|
5283
|
-
var t =
|
|
5284
|
-
return St >= 0 ? s = "back-forward-cache" : t && (document.prerendering ||
|
|
5285
|
-
},
|
|
5318
|
+
var t = De(), s = "navigate";
|
|
5319
|
+
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 };
|
|
5320
|
+
}, F = function(r, e, t) {
|
|
5286
5321
|
try {
|
|
5287
5322
|
if (PerformanceObserver.supportedEntryTypes.includes(r)) {
|
|
5288
5323
|
var s = new PerformanceObserver((function(n) {
|
|
@@ -5301,164 +5336,164 @@ var Ae, C, j, Et, le, St = -1, U = function(r) {
|
|
|
5301
5336
|
return l > c[1] ? "poor" : l > c[0] ? "needs-improvement" : "good";
|
|
5302
5337
|
})(e.value, t), r(e));
|
|
5303
5338
|
};
|
|
5304
|
-
},
|
|
5339
|
+
}, ke = function(r) {
|
|
5305
5340
|
requestAnimationFrame((function() {
|
|
5306
5341
|
return requestAnimationFrame((function() {
|
|
5307
5342
|
return r();
|
|
5308
5343
|
}));
|
|
5309
5344
|
}));
|
|
5310
|
-
},
|
|
5345
|
+
}, z = function(r) {
|
|
5311
5346
|
document.addEventListener("visibilitychange", (function() {
|
|
5312
5347
|
document.visibilityState === "hidden" && r();
|
|
5313
5348
|
}));
|
|
5314
|
-
},
|
|
5349
|
+
}, ue = function(r) {
|
|
5315
5350
|
var e = !1;
|
|
5316
5351
|
return function() {
|
|
5317
5352
|
e || (r(), e = !0);
|
|
5318
5353
|
};
|
|
5319
|
-
},
|
|
5354
|
+
}, H = -1, tt = function() {
|
|
5320
5355
|
return document.visibilityState !== "hidden" || document.prerendering ? 1 / 0 : 0;
|
|
5321
5356
|
}, ce = function(r) {
|
|
5322
|
-
document.visibilityState === "hidden" &&
|
|
5323
|
-
},
|
|
5357
|
+
document.visibilityState === "hidden" && H > -1 && (H = r.type === "visibilitychange" ? r.timeStamp : 0, Ks());
|
|
5358
|
+
}, st = function() {
|
|
5324
5359
|
addEventListener("visibilitychange", ce, !0), addEventListener("prerenderingchange", ce, !0);
|
|
5325
5360
|
}, Ks = function() {
|
|
5326
5361
|
removeEventListener("visibilitychange", ce, !0), removeEventListener("prerenderingchange", ce, !0);
|
|
5327
|
-
},
|
|
5328
|
-
return
|
|
5362
|
+
}, Ve = function() {
|
|
5363
|
+
return H < 0 && (H = tt(), st(), V((function() {
|
|
5329
5364
|
setTimeout((function() {
|
|
5330
|
-
|
|
5365
|
+
H = tt(), st();
|
|
5331
5366
|
}), 0);
|
|
5332
5367
|
}))), { get firstHiddenTime() {
|
|
5333
|
-
return
|
|
5368
|
+
return H;
|
|
5334
5369
|
} };
|
|
5335
|
-
},
|
|
5370
|
+
}, Q = function(r) {
|
|
5336
5371
|
document.prerendering ? addEventListener("prerenderingchange", (function() {
|
|
5337
5372
|
return r();
|
|
5338
5373
|
}), !0) : r();
|
|
5339
|
-
},
|
|
5340
|
-
e = e || {},
|
|
5341
|
-
var t, s =
|
|
5374
|
+
}, Me = [1800, 3e3], Tt = function(r, e) {
|
|
5375
|
+
e = e || {}, Q((function() {
|
|
5376
|
+
var t, s = Ve(), n = y("FCP"), i = F("paint", (function(o) {
|
|
5342
5377
|
o.forEach((function(l) {
|
|
5343
|
-
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime < s.firstHiddenTime && (n.value = Math.max(l.startTime -
|
|
5378
|
+
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
5379
|
}));
|
|
5345
5380
|
}));
|
|
5346
|
-
i && (t = w(r, n,
|
|
5347
|
-
n = y("FCP"), t = w(r, n,
|
|
5381
|
+
i && (t = w(r, n, Me, e.reportAllChanges), V((function(o) {
|
|
5382
|
+
n = y("FCP"), t = w(r, n, Me, e.reportAllChanges), ke((function() {
|
|
5348
5383
|
n.value = performance.now() - o.timeStamp, t(!0);
|
|
5349
5384
|
}));
|
|
5350
5385
|
})));
|
|
5351
5386
|
}));
|
|
5352
|
-
},
|
|
5353
|
-
e = e || {},
|
|
5387
|
+
}, Ce = [0.1, 0.25], Ys = function(r, e) {
|
|
5388
|
+
e = e || {}, Tt(ue((function() {
|
|
5354
5389
|
var t, s = y("CLS", 0), n = 0, i = [], o = function(c) {
|
|
5355
|
-
c.forEach((function(
|
|
5356
|
-
if (!
|
|
5357
|
-
var
|
|
5358
|
-
n &&
|
|
5390
|
+
c.forEach((function(d) {
|
|
5391
|
+
if (!d.hadRecentInput) {
|
|
5392
|
+
var f = i[0], g = i[i.length - 1];
|
|
5393
|
+
n && d.startTime - g.startTime < 1e3 && d.startTime - f.startTime < 5e3 ? (n += d.value, i.push(d)) : (n = d.value, i = [d]);
|
|
5359
5394
|
}
|
|
5360
5395
|
})), n > s.value && (s.value = n, s.entries = i, t());
|
|
5361
|
-
}, l =
|
|
5362
|
-
l && (t = w(r, s,
|
|
5396
|
+
}, l = F("layout-shift", o);
|
|
5397
|
+
l && (t = w(r, s, Ce, e.reportAllChanges), z((function() {
|
|
5363
5398
|
o(l.takeRecords()), t(!0);
|
|
5364
|
-
})),
|
|
5365
|
-
n = 0, s = y("CLS", 0), t = w(r, s,
|
|
5399
|
+
})), V((function() {
|
|
5400
|
+
n = 0, s = y("CLS", 0), t = w(r, s, Ce, e.reportAllChanges), ke((function() {
|
|
5366
5401
|
return t();
|
|
5367
5402
|
}));
|
|
5368
5403
|
})), setTimeout(t, 0));
|
|
5369
5404
|
})));
|
|
5370
|
-
},
|
|
5405
|
+
}, It = 0, pe = 1 / 0, J = 0, qs = function(r) {
|
|
5371
5406
|
r.forEach((function(e) {
|
|
5372
|
-
e.interactionId && (
|
|
5407
|
+
e.interactionId && (pe = Math.min(pe, e.interactionId), J = Math.max(J, e.interactionId), It = J ? (J - pe) / 7 + 1 : 0);
|
|
5373
5408
|
}));
|
|
5374
|
-
},
|
|
5375
|
-
return
|
|
5409
|
+
}, vt = function() {
|
|
5410
|
+
return Le ? It : performance.interactionCount || 0;
|
|
5376
5411
|
}, Js = function() {
|
|
5377
|
-
"interactionCount" in performance ||
|
|
5378
|
-
}, A = [],
|
|
5379
|
-
var r = Math.min(A.length - 1, Math.floor((
|
|
5412
|
+
"interactionCount" in performance || Le || (Le = F("event", qs, { type: "event", buffered: !0, durationThreshold: 0 }));
|
|
5413
|
+
}, A = [], te = /* @__PURE__ */ new Map(), _t = 0, Zs = function() {
|
|
5414
|
+
var r = Math.min(A.length - 1, Math.floor((vt() - _t) / 50));
|
|
5380
5415
|
return A[r];
|
|
5381
5416
|
}, er = [], tr = function(r) {
|
|
5382
5417
|
if (er.forEach((function(n) {
|
|
5383
5418
|
return n(r);
|
|
5384
5419
|
})), r.interactionId || r.entryType === "first-input") {
|
|
5385
|
-
var e = A[A.length - 1], t =
|
|
5420
|
+
var e = A[A.length - 1], t = te.get(r.interactionId);
|
|
5386
5421
|
if (t || A.length < 10 || r.duration > e.latency) {
|
|
5387
5422
|
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
5423
|
else {
|
|
5389
5424
|
var s = { id: r.interactionId, latency: r.duration, entries: [r] };
|
|
5390
|
-
|
|
5425
|
+
te.set(s.id, s), A.push(s);
|
|
5391
5426
|
}
|
|
5392
5427
|
A.sort((function(n, i) {
|
|
5393
5428
|
return i.latency - n.latency;
|
|
5394
5429
|
})), A.length > 10 && A.splice(10).forEach((function(n) {
|
|
5395
|
-
return
|
|
5430
|
+
return te.delete(n.id);
|
|
5396
5431
|
}));
|
|
5397
5432
|
}
|
|
5398
5433
|
}
|
|
5399
|
-
},
|
|
5434
|
+
}, yt = function(r) {
|
|
5400
5435
|
var e = self.requestIdleCallback || self.setTimeout, t = -1;
|
|
5401
|
-
return r =
|
|
5402
|
-
},
|
|
5403
|
-
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {},
|
|
5436
|
+
return r = ue(r), document.visibilityState === "hidden" ? r() : (t = e(r), z(r)), t;
|
|
5437
|
+
}, Re = [200, 500], sr = function(r, e) {
|
|
5438
|
+
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, Q((function() {
|
|
5404
5439
|
var t;
|
|
5405
5440
|
Js();
|
|
5406
5441
|
var s, n = y("INP"), i = function(l) {
|
|
5407
|
-
|
|
5442
|
+
yt((function() {
|
|
5408
5443
|
l.forEach(tr);
|
|
5409
5444
|
var c = Zs();
|
|
5410
5445
|
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, s());
|
|
5411
5446
|
}));
|
|
5412
|
-
}, o =
|
|
5413
|
-
s = w(r, n,
|
|
5447
|
+
}, o = F("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
|
|
5448
|
+
s = w(r, n, Re, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), z((function() {
|
|
5414
5449
|
i(o.takeRecords()), s(!0);
|
|
5415
|
-
})),
|
|
5416
|
-
|
|
5450
|
+
})), V((function() {
|
|
5451
|
+
_t = vt(), A.length = 0, te.clear(), n = y("INP"), s = w(r, n, Re, e.reportAllChanges);
|
|
5417
5452
|
})));
|
|
5418
5453
|
})));
|
|
5419
|
-
},
|
|
5420
|
-
e = e || {},
|
|
5421
|
-
var t, s =
|
|
5422
|
-
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(
|
|
5423
|
-
|
|
5454
|
+
}, Ne = [2500, 4e3], Se = {}, rr = function(r, e) {
|
|
5455
|
+
e = e || {}, Q((function() {
|
|
5456
|
+
var t, s = Ve(), n = y("LCP"), i = function(c) {
|
|
5457
|
+
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(d) {
|
|
5458
|
+
d.startTime < s.firstHiddenTime && (n.value = Math.max(d.startTime - de(), 0), n.entries = [d], t());
|
|
5424
5459
|
}));
|
|
5425
|
-
}, o =
|
|
5460
|
+
}, o = F("largest-contentful-paint", i);
|
|
5426
5461
|
if (o) {
|
|
5427
|
-
t = w(r, n,
|
|
5428
|
-
var l =
|
|
5429
|
-
|
|
5462
|
+
t = w(r, n, Ne, e.reportAllChanges);
|
|
5463
|
+
var l = ue((function() {
|
|
5464
|
+
Se[n.id] || (i(o.takeRecords()), o.disconnect(), Se[n.id] = !0, t(!0));
|
|
5430
5465
|
}));
|
|
5431
5466
|
["keydown", "click"].forEach((function(c) {
|
|
5432
5467
|
addEventListener(c, (function() {
|
|
5433
|
-
return
|
|
5468
|
+
return yt(l);
|
|
5434
5469
|
}), { once: !0, capture: !0 });
|
|
5435
|
-
})),
|
|
5436
|
-
n = y("LCP"), t = w(r, n,
|
|
5437
|
-
n.value = performance.now() - c.timeStamp,
|
|
5470
|
+
})), z(l), V((function(c) {
|
|
5471
|
+
n = y("LCP"), t = w(r, n, Ne, e.reportAllChanges), ke((function() {
|
|
5472
|
+
n.value = performance.now() - c.timeStamp, Se[n.id] = !0, t(!0);
|
|
5438
5473
|
}));
|
|
5439
5474
|
}));
|
|
5440
5475
|
}
|
|
5441
5476
|
}));
|
|
5442
|
-
},
|
|
5443
|
-
document.prerendering ?
|
|
5477
|
+
}, Oe = [800, 1800], nr = function r(e) {
|
|
5478
|
+
document.prerendering ? Q((function() {
|
|
5444
5479
|
return r(e);
|
|
5445
5480
|
})) : document.readyState !== "complete" ? addEventListener("load", (function() {
|
|
5446
5481
|
return r(e);
|
|
5447
5482
|
}), !0) : setTimeout(e, 0);
|
|
5448
5483
|
}, ir = function(r, e) {
|
|
5449
5484
|
e = e || {};
|
|
5450
|
-
var t = y("TTFB"), s = w(r, t,
|
|
5485
|
+
var t = y("TTFB"), s = w(r, t, Oe, e.reportAllChanges);
|
|
5451
5486
|
nr((function() {
|
|
5452
|
-
var n =
|
|
5453
|
-
n && (t.value = Math.max(n.responseStart -
|
|
5454
|
-
t = y("TTFB", 0), (s = w(r, t,
|
|
5487
|
+
var n = De();
|
|
5488
|
+
n && (t.value = Math.max(n.responseStart - de(), 0), t.entries = [n], s(!0), V((function() {
|
|
5489
|
+
t = y("TTFB", 0), (s = w(r, t, Oe, e.reportAllChanges))(!0);
|
|
5455
5490
|
})));
|
|
5456
5491
|
}));
|
|
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 +
|
|
5492
|
+
}, W = { passive: !0, capture: !0 }, or = /* @__PURE__ */ new Date(), rt = function(r, e) {
|
|
5493
|
+
C || (C = e, G = r, pt = /* @__PURE__ */ new Date(), bt(removeEventListener), wt());
|
|
5494
|
+
}, wt = function() {
|
|
5495
|
+
if (G >= 0 && G < pt - or) {
|
|
5496
|
+
var r = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp + G };
|
|
5462
5497
|
le.forEach((function(e) {
|
|
5463
5498
|
e(r);
|
|
5464
5499
|
})), le = [];
|
|
@@ -5468,81 +5503,81 @@ var Ae, C, j, Et, le, St = -1, U = function(r) {
|
|
|
5468
5503
|
var e = (r.timeStamp > 1e12 ? /* @__PURE__ */ new Date() : performance.now()) - r.timeStamp;
|
|
5469
5504
|
r.type == "pointerdown" ? (function(t, s) {
|
|
5470
5505
|
var n = function() {
|
|
5471
|
-
|
|
5506
|
+
rt(t, s), o();
|
|
5472
5507
|
}, i = function() {
|
|
5473
5508
|
o();
|
|
5474
5509
|
}, o = function() {
|
|
5475
|
-
removeEventListener("pointerup", n,
|
|
5510
|
+
removeEventListener("pointerup", n, W), removeEventListener("pointercancel", i, W);
|
|
5476
5511
|
};
|
|
5477
|
-
addEventListener("pointerup", n,
|
|
5478
|
-
})(e, r) :
|
|
5512
|
+
addEventListener("pointerup", n, W), addEventListener("pointercancel", i, W);
|
|
5513
|
+
})(e, r) : rt(e, r);
|
|
5479
5514
|
}
|
|
5480
|
-
},
|
|
5515
|
+
}, bt = function(r) {
|
|
5481
5516
|
["mousedown", "keydown", "touchstart", "pointerdown"].forEach((function(e) {
|
|
5482
|
-
return r(e, ar,
|
|
5517
|
+
return r(e, ar, W);
|
|
5483
5518
|
}));
|
|
5484
|
-
},
|
|
5485
|
-
e = e || {},
|
|
5486
|
-
var t, s =
|
|
5519
|
+
}, Pe = [100, 300], lr = function(r, e) {
|
|
5520
|
+
e = e || {}, Q((function() {
|
|
5521
|
+
var t, s = Ve(), n = y("FID"), i = function(c) {
|
|
5487
5522
|
c.startTime < s.firstHiddenTime && (n.value = c.processingStart - c.startTime, n.entries.push(c), t(!0));
|
|
5488
5523
|
}, o = function(c) {
|
|
5489
5524
|
c.forEach(i);
|
|
5490
|
-
}, l =
|
|
5491
|
-
t = w(r, n,
|
|
5525
|
+
}, l = F("first-input", o);
|
|
5526
|
+
t = w(r, n, Pe, e.reportAllChanges), l && (z(ue((function() {
|
|
5492
5527
|
o(l.takeRecords()), l.disconnect();
|
|
5493
|
-
}))),
|
|
5528
|
+
}))), V((function() {
|
|
5494
5529
|
var c;
|
|
5495
|
-
n = y("FID"), t = w(r, n,
|
|
5530
|
+
n = y("FID"), t = w(r, n, Pe, e.reportAllChanges), le = [], G = -1, C = null, bt(addEventListener), c = i, le.push(c), wt();
|
|
5496
5531
|
})));
|
|
5497
5532
|
}));
|
|
5498
5533
|
};
|
|
5499
5534
|
const cr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5500
5535
|
__proto__: null,
|
|
5501
|
-
CLSThresholds:
|
|
5502
|
-
FCPThresholds:
|
|
5503
|
-
FIDThresholds:
|
|
5504
|
-
INPThresholds:
|
|
5505
|
-
LCPThresholds:
|
|
5506
|
-
TTFBThresholds:
|
|
5536
|
+
CLSThresholds: Ce,
|
|
5537
|
+
FCPThresholds: Me,
|
|
5538
|
+
FIDThresholds: Pe,
|
|
5539
|
+
INPThresholds: Re,
|
|
5540
|
+
LCPThresholds: Ne,
|
|
5541
|
+
TTFBThresholds: Oe,
|
|
5507
5542
|
onCLS: Ys,
|
|
5508
|
-
onFCP:
|
|
5543
|
+
onFCP: Tt,
|
|
5509
5544
|
onFID: lr,
|
|
5510
5545
|
onINP: sr,
|
|
5511
5546
|
onLCP: rr,
|
|
5512
5547
|
onTTFB: ir
|
|
5513
5548
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
5514
5549
|
export {
|
|
5515
|
-
|
|
5516
|
-
|
|
5550
|
+
m as AppConfigValidationError,
|
|
5551
|
+
dr as DEFAULT_SESSION_TIMEOUT,
|
|
5517
5552
|
_e as DEFAULT_WEB_VITALS_MODE,
|
|
5518
5553
|
L as DeviceType,
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5554
|
+
se as EmitterEvent,
|
|
5555
|
+
B as ErrorType,
|
|
5556
|
+
u as EventType,
|
|
5522
5557
|
vr as InitializationTimeoutError,
|
|
5523
5558
|
N as IntegrationValidationError,
|
|
5524
|
-
|
|
5559
|
+
Sr as MAX_ARRAY_LENGTH,
|
|
5525
5560
|
mr as MAX_CUSTOM_EVENT_ARRAY_SIZE,
|
|
5526
5561
|
fr as MAX_CUSTOM_EVENT_KEYS,
|
|
5527
|
-
|
|
5562
|
+
ur as MAX_CUSTOM_EVENT_NAME_LENGTH,
|
|
5528
5563
|
hr as MAX_CUSTOM_EVENT_STRING_SIZE,
|
|
5529
5564
|
gr as MAX_NESTED_OBJECT_KEYS,
|
|
5530
5565
|
Er as MAX_STRING_LENGTH,
|
|
5531
|
-
|
|
5566
|
+
pr as MAX_STRING_LENGTH_IN_ARRAY,
|
|
5532
5567
|
ie as Mode,
|
|
5533
|
-
|
|
5568
|
+
lt as PII_PATTERNS,
|
|
5534
5569
|
O as PermanentError,
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5570
|
+
re as RateLimitError,
|
|
5571
|
+
Xe as SamplingRateValidationError,
|
|
5572
|
+
Z as ScrollDirection,
|
|
5573
|
+
Pt as SessionTimeoutValidationError,
|
|
5574
|
+
$ as SpecialApiUrl,
|
|
5575
|
+
ne as TimeoutError,
|
|
5576
|
+
j as TraceLogValidationError,
|
|
5542
5577
|
_r as WEB_VITALS_GOOD_THRESHOLDS,
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5578
|
+
Ke as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
|
|
5579
|
+
Kt as WEB_VITALS_POOR_THRESHOLDS,
|
|
5580
|
+
Ye as getWebVitalsThresholds,
|
|
5546
5581
|
Tr as isPrimaryScrollEvent,
|
|
5547
5582
|
Ir as isSecondaryScrollEvent,
|
|
5548
5583
|
yr as tracelog
|