@tracelog/lib 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -4
- package/dist/browser/tracelog.esm.js +569 -440
- package/dist/browser/tracelog.esm.js.map +1 -1
- package/dist/browser/tracelog.js +1 -1
- package/dist/browser/tracelog.js.map +1 -1
- package/dist/public-api.cjs +170 -5
- package/dist/public-api.cjs.map +1 -1
- package/dist/public-api.d.mts +45 -2
- package/dist/public-api.d.ts +45 -2
- package/dist/public-api.js +170 -5
- package/dist/public-api.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const w = "data-tlog",
|
|
1
|
+
const xr = 9e5;
|
|
2
|
+
const Fr = 120, $r = 8192, Br = 10, Wr = 10, Gr = 20, Xr = 1;
|
|
3
|
+
const Qr = 1e3, jr = 500, zr = 100;
|
|
4
|
+
const w = "data-tlog", at = [
|
|
5
5
|
"button",
|
|
6
6
|
"a",
|
|
7
7
|
'input[type="button"]',
|
|
@@ -33,7 +33,7 @@ const w = "data-tlog", ot = [
|
|
|
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"], ct = [
|
|
37
37
|
"token",
|
|
38
38
|
"auth",
|
|
39
39
|
"key",
|
|
@@ -71,53 +71,53 @@ const m = {
|
|
|
71
71
|
INVALID_VIEWPORT_MIN_DWELL_TIME: "Viewport minDwellTime must be a non-negative number",
|
|
72
72
|
INVALID_VIEWPORT_COOLDOWN_PERIOD: "Viewport cooldownPeriod must be a non-negative number",
|
|
73
73
|
INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS: "Viewport maxTrackedElements must be a positive number"
|
|
74
|
-
},
|
|
74
|
+
}, ut = [
|
|
75
75
|
/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
|
76
76
|
/javascript:/gi,
|
|
77
77
|
/on\w+\s*=/gi,
|
|
78
78
|
/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
|
|
79
79
|
/<embed\b[^>]*>/gi,
|
|
80
80
|
/<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi
|
|
81
|
-
], I = "tlog", x = `${I}:qa_mode`,
|
|
82
|
-
var
|
|
83
|
-
class
|
|
81
|
+
], I = "tlog", x = `${I}:qa_mode`, we = `${I}:uid`, Be = "tlog_mode", ye = "qa", be = "qa_off", dt = (s) => s ? `${I}:${s}:queue` : `${I}:queue`, ht = (s) => s ? `${I}:${s}:session` : `${I}:session`, ft = (s) => s ? `${I}:${s}:broadcast` : `${I}:broadcast`, Ae = (s, e) => `${I}:${s}:session_counts:${e}`, Le = 10080 * 60 * 1e3, Me = `${I}:session_counts_last_cleanup`, Ce = 3600 * 1e3;
|
|
82
|
+
var U = /* @__PURE__ */ ((s) => (s.Localhost = "localhost:8080", s.Fail = "localhost:9999", s))(U || {}), L = /* @__PURE__ */ ((s) => (s.Mobile = "mobile", s.Tablet = "tablet", s.Desktop = "desktop", s.Unknown = "unknown", s))(L || {}), ae = /* @__PURE__ */ ((s) => (s.EVENT = "event", s.QUEUE = "queue", s))(ae || {});
|
|
83
|
+
class O extends Error {
|
|
84
84
|
constructor(e, t) {
|
|
85
|
-
super(e), this.statusCode = t, this.name = "PermanentError", Error.captureStackTrace && Error.captureStackTrace(this,
|
|
85
|
+
super(e), this.statusCode = t, this.name = "PermanentError", Error.captureStackTrace && Error.captureStackTrace(this, O);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
var d = /* @__PURE__ */ ((s) => (s.PAGE_VIEW = "page_view", s.CLICK = "click", s.SCROLL = "scroll", s.SESSION_START = "session_start", s.CUSTOM = "custom", s.WEB_VITALS = "web_vitals", s.ERROR = "error", s.VIEWPORT_VISIBLE = "viewport_visible", s))(d || {}),
|
|
89
|
-
const
|
|
90
|
-
class
|
|
88
|
+
var d = /* @__PURE__ */ ((s) => (s.PAGE_VIEW = "page_view", s.CLICK = "click", s.SCROLL = "scroll", s.SESSION_START = "session_start", s.CUSTOM = "custom", s.WEB_VITALS = "web_vitals", s.ERROR = "error", s.VIEWPORT_VISIBLE = "viewport_visible", s))(d || {}), Q = /* @__PURE__ */ ((s) => (s.UP = "up", s.DOWN = "down", s))(Q || {}), H = /* @__PURE__ */ ((s) => (s.JS_ERROR = "js_error", s.PROMISE_REJECTION = "promise_rejection", s))(H || {}), K = /* @__PURE__ */ ((s) => (s.QA = "qa", s))(K || {});
|
|
89
|
+
const Kr = (s) => s.type === d.SCROLL && "scroll_data" in s && s.scroll_data.is_primary === !0, Yr = (s) => s.type === d.SCROLL && "scroll_data" in s && s.scroll_data.is_primary === !1;
|
|
90
|
+
class F extends Error {
|
|
91
91
|
constructor(e, t, r) {
|
|
92
92
|
super(e), this.errorCode = t, this.layer = r, this.name = this.constructor.name, Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
class
|
|
95
|
+
class f extends F {
|
|
96
96
|
constructor(e, t = "config") {
|
|
97
97
|
super(e, "APP_CONFIG_INVALID", t);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
class
|
|
100
|
+
class mt extends F {
|
|
101
101
|
constructor(e, t = "config") {
|
|
102
102
|
super(e, "SESSION_TIMEOUT_INVALID", t);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
class Re extends
|
|
105
|
+
class Re extends F {
|
|
106
106
|
constructor(e, t = "config") {
|
|
107
107
|
super(e, "SAMPLING_RATE_INVALID", t);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
class
|
|
110
|
+
class V extends F {
|
|
111
111
|
constructor(e, t = "config") {
|
|
112
112
|
super(e, "INTEGRATION_INVALID", t);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
class
|
|
115
|
+
class qr extends F {
|
|
116
116
|
constructor(e, t, r = "runtime") {
|
|
117
117
|
super(e, "INITIALIZATION_TIMEOUT", r), this.timeoutMs = t;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
const
|
|
120
|
+
const We = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", Ge = "background: #9e9e9e; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", gt = "background: #d32f2f; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", Et = (s, e) => {
|
|
121
121
|
if (e) {
|
|
122
122
|
if (e instanceof Error) {
|
|
123
123
|
const t = e.message.replace(/\s+at\s+.*$/gm, "").replace(/\s*\([^()]+:\d+:\d+\)/g, "");
|
|
@@ -136,7 +136,7 @@ const Be = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8
|
|
|
136
136
|
return `[TraceLog] ${s}: ${String(e)}`;
|
|
137
137
|
}
|
|
138
138
|
return `[TraceLog] ${s}`;
|
|
139
|
-
},
|
|
139
|
+
}, St = () => {
|
|
140
140
|
if (typeof window > "u" || typeof sessionStorage > "u")
|
|
141
141
|
return !1;
|
|
142
142
|
try {
|
|
@@ -145,15 +145,15 @@ const Be = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8
|
|
|
145
145
|
return !1;
|
|
146
146
|
}
|
|
147
147
|
}, a = (s, e, t) => {
|
|
148
|
-
const { error: r, data: n, showToClient: i = !1, style: o, visibility: l } = t ?? {}, c = r ?
|
|
149
|
-
if (!
|
|
148
|
+
const { error: r, data: n, showToClient: i = !1, style: o, visibility: l } = t ?? {}, c = r ? Et(e, r) : `[TraceLog] ${e}`, u = s === "error" ? "error" : s === "warn" ? "warn" : "log";
|
|
149
|
+
if (!pt(l, i))
|
|
150
150
|
return;
|
|
151
|
-
const g =
|
|
152
|
-
|
|
153
|
-
},
|
|
151
|
+
const g = Tt(l, o), p = n !== void 0 ? le(n) : void 0;
|
|
152
|
+
vt(u, c, g, p);
|
|
153
|
+
}, pt = (s, e) => s === "critical" ? !0 : s === "qa" || e ? St() : !1, Tt = (s, e) => e !== void 0 && e !== "" ? e : s === "critical" ? gt : "", vt = (s, e, t, r) => {
|
|
154
154
|
const n = t !== void 0 && t !== "", i = n ? `%c${e}` : e;
|
|
155
155
|
r !== void 0 ? n ? console[s](i, t, r) : console[s](i, r) : n ? console[s](i, t) : console[s](i);
|
|
156
|
-
},
|
|
156
|
+
}, le = (s) => {
|
|
157
157
|
const e = {}, t = ["token", "password", "secret", "key", "apikey", "api_key", "sessionid", "session_id"];
|
|
158
158
|
for (const [r, n] of Object.entries(s)) {
|
|
159
159
|
const i = r.toLowerCase();
|
|
@@ -161,16 +161,16 @@ const Be = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8
|
|
|
161
161
|
e[r] = "[REDACTED]";
|
|
162
162
|
continue;
|
|
163
163
|
}
|
|
164
|
-
n !== null && typeof n == "object" && !Array.isArray(n) ? e[r] =
|
|
165
|
-
(o) => o !== null && typeof o == "object" && !Array.isArray(o) ?
|
|
164
|
+
n !== null && typeof n == "object" && !Array.isArray(n) ? e[r] = le(n) : Array.isArray(n) ? e[r] = n.map(
|
|
165
|
+
(o) => o !== null && typeof o == "object" && !Array.isArray(o) ? le(o) : o
|
|
166
166
|
) : e[r] = n;
|
|
167
167
|
}
|
|
168
168
|
return e;
|
|
169
169
|
};
|
|
170
|
-
let
|
|
170
|
+
let ce, Xe;
|
|
171
171
|
const _t = () => {
|
|
172
|
-
typeof window < "u" && !
|
|
173
|
-
},
|
|
172
|
+
typeof window < "u" && !ce && (ce = window.matchMedia("(pointer: coarse)"), Xe = window.matchMedia("(hover: none)"));
|
|
173
|
+
}, Y = "Unknown", It = (s) => {
|
|
174
174
|
const e = s.userAgentData?.platform;
|
|
175
175
|
if (e != null && e !== "") {
|
|
176
176
|
if (/windows/i.test(e)) return "Windows";
|
|
@@ -181,8 +181,8 @@ const _t = () => {
|
|
|
181
181
|
if (/ios/i.test(e)) return "iOS";
|
|
182
182
|
}
|
|
183
183
|
const t = navigator.userAgent;
|
|
184
|
-
return /Windows/i.test(t) ? "Windows" : /iPhone|iPad|iPod/i.test(t) ? "iOS" : /Mac OS X|Macintosh/i.test(t) ? "macOS" : /Android/i.test(t) ? "Android" : /CrOS/i.test(t) ? "ChromeOS" : /Linux/i.test(t) ? "Linux" :
|
|
185
|
-
},
|
|
184
|
+
return /Windows/i.test(t) ? "Windows" : /iPhone|iPad|iPod/i.test(t) ? "iOS" : /Mac OS X|Macintosh/i.test(t) ? "macOS" : /Android/i.test(t) ? "Android" : /CrOS/i.test(t) ? "ChromeOS" : /Linux/i.test(t) ? "Linux" : Y;
|
|
185
|
+
}, wt = (s) => {
|
|
186
186
|
const e = s.userAgentData?.brands;
|
|
187
187
|
if (e != null && e.length > 0) {
|
|
188
188
|
const n = e.filter((i) => !/not.?a.?brand|chromium/i.test(i.brand))[0];
|
|
@@ -192,8 +192,8 @@ const _t = () => {
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
const t = navigator.userAgent;
|
|
195
|
-
return /Edg\//i.test(t) ? "Edge" : /OPR\//i.test(t) ? "Opera" : /Chrome/i.test(t) ? "Chrome" : /Firefox/i.test(t) ? "Firefox" : /Safari/i.test(t) && !/Chrome/i.test(t) ? "Safari" :
|
|
196
|
-
},
|
|
195
|
+
return /Edg\//i.test(t) ? "Edge" : /OPR\//i.test(t) ? "Opera" : /Chrome/i.test(t) ? "Chrome" : /Firefox/i.test(t) ? "Firefox" : /Safari/i.test(t) && !/Chrome/i.test(t) ? "Safari" : Y;
|
|
196
|
+
}, yt = () => {
|
|
197
197
|
try {
|
|
198
198
|
const s = navigator;
|
|
199
199
|
if (s.userAgentData != null && typeof s.userAgentData.mobile == "boolean") {
|
|
@@ -201,27 +201,27 @@ const _t = () => {
|
|
|
201
201
|
return c != null && c !== "" && /ipad|tablet/i.test(c) ? L.Tablet : s.userAgentData.mobile ? L.Mobile : L.Desktop;
|
|
202
202
|
}
|
|
203
203
|
_t();
|
|
204
|
-
const e = window.innerWidth, t =
|
|
204
|
+
const e = window.innerWidth, t = ce?.matches ?? !1, r = Xe?.matches ?? !1, n = "ontouchstart" in window || navigator.maxTouchPoints > 0, i = navigator.userAgent.toLowerCase(), o = /mobile|android|iphone|ipod|blackberry|iemobile|opera mini/.test(i), l = /tablet|ipad|android(?!.*mobile)/.test(i);
|
|
205
205
|
return e <= 767 || o && n ? L.Mobile : e >= 768 && e <= 1024 || l || t && r && n ? L.Tablet : L.Desktop;
|
|
206
206
|
} catch (s) {
|
|
207
207
|
return a("debug", "Device detection failed, defaulting to desktop", { error: s }), L.Desktop;
|
|
208
208
|
}
|
|
209
|
-
},
|
|
209
|
+
}, bt = () => {
|
|
210
210
|
try {
|
|
211
211
|
const s = navigator;
|
|
212
212
|
return {
|
|
213
|
-
type:
|
|
214
|
-
os:
|
|
215
|
-
browser:
|
|
213
|
+
type: yt(),
|
|
214
|
+
os: It(s),
|
|
215
|
+
browser: wt(s)
|
|
216
216
|
};
|
|
217
217
|
} catch (s) {
|
|
218
218
|
return a("debug", "Device info detection failed, using defaults", { error: s }), {
|
|
219
219
|
type: L.Desktop,
|
|
220
|
-
os:
|
|
221
|
-
browser:
|
|
220
|
+
os: Y,
|
|
221
|
+
browser: Y
|
|
222
222
|
};
|
|
223
223
|
}
|
|
224
|
-
},
|
|
224
|
+
}, Qe = [
|
|
225
225
|
// Email addresses
|
|
226
226
|
/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/gi,
|
|
227
227
|
// US Phone numbers (various formats)
|
|
@@ -236,7 +236,7 @@ const _t = () => {
|
|
|
236
236
|
/Bearer\s+[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)?(?:\.[A-Za-z0-9_-]+)?/gi,
|
|
237
237
|
// Passwords in connection strings (protocol://user:password@host)
|
|
238
238
|
/:\/\/[^:/]+:([^@]+)@/gi
|
|
239
|
-
],
|
|
239
|
+
], Ne = 500, Oe = 5e3, j = 50, At = j * 2, je = 1, Lt = 1e3, Mt = 10, Pe = 5e3, Ct = 6e4, Jr = {
|
|
240
240
|
LCP: 2500,
|
|
241
241
|
// Good: ≤ 2.5s
|
|
242
242
|
FCP: 1800,
|
|
@@ -248,7 +248,7 @@ const _t = () => {
|
|
|
248
248
|
TTFB: 800,
|
|
249
249
|
// Good: ≤ 800ms
|
|
250
250
|
LONG_TASK: 50
|
|
251
|
-
},
|
|
251
|
+
}, De = {
|
|
252
252
|
LCP: 2500,
|
|
253
253
|
// Needs improvement: > 2.5s (same as good boundary)
|
|
254
254
|
FCP: 1800,
|
|
@@ -272,53 +272,53 @@ const _t = () => {
|
|
|
272
272
|
TTFB: 1800,
|
|
273
273
|
// Poor: > 1800ms
|
|
274
274
|
LONG_TASK: 50
|
|
275
|
-
},
|
|
275
|
+
}, ue = "needs-improvement", ke = (s = ue) => {
|
|
276
276
|
switch (s) {
|
|
277
277
|
case "all":
|
|
278
278
|
return { LCP: 0, FCP: 0, CLS: 0, INP: 0, TTFB: 0, LONG_TASK: 0 };
|
|
279
279
|
// Track everything
|
|
280
280
|
case "needs-improvement":
|
|
281
|
-
return
|
|
281
|
+
return De;
|
|
282
282
|
case "poor":
|
|
283
283
|
return Rt;
|
|
284
284
|
default:
|
|
285
|
-
return
|
|
285
|
+
return De;
|
|
286
286
|
}
|
|
287
|
-
},
|
|
287
|
+
}, Nt = 1e3, Ot = 50, Pt = "2.1.2", Dt = Pt, ze = () => typeof window < "u" && typeof sessionStorage < "u", kt = () => {
|
|
288
288
|
try {
|
|
289
289
|
const s = new URLSearchParams(window.location.search);
|
|
290
|
-
s.delete(
|
|
290
|
+
s.delete(Be);
|
|
291
291
|
const e = s.toString(), t = window.location.pathname + (e ? "?" + e : "") + window.location.hash;
|
|
292
292
|
window.history.replaceState({}, "", t);
|
|
293
293
|
} catch {
|
|
294
294
|
}
|
|
295
|
-
},
|
|
296
|
-
if (!
|
|
295
|
+
}, Vt = () => {
|
|
296
|
+
if (!ze())
|
|
297
297
|
return !1;
|
|
298
298
|
try {
|
|
299
|
-
const e = new URLSearchParams(window.location.search).get(
|
|
299
|
+
const e = new URLSearchParams(window.location.search).get(Be), t = sessionStorage.getItem(x);
|
|
300
300
|
let r = null;
|
|
301
|
-
return e ===
|
|
302
|
-
visibility: "qa",
|
|
303
|
-
style: Be
|
|
304
|
-
})) : e === ye && (r = !1, sessionStorage.setItem(x, "false"), a("info", "QA Mode DISABLED", {
|
|
301
|
+
return e === ye ? (r = !0, sessionStorage.setItem(x, "true"), a("info", "QA Mode ACTIVE", {
|
|
305
302
|
visibility: "qa",
|
|
306
303
|
style: We
|
|
307
|
-
}))
|
|
304
|
+
})) : e === be && (r = !1, sessionStorage.setItem(x, "false"), a("info", "QA Mode DISABLED", {
|
|
305
|
+
visibility: "qa",
|
|
306
|
+
style: Ge
|
|
307
|
+
})), (e === ye || e === be) && kt(), r ?? t === "true";
|
|
308
308
|
} catch {
|
|
309
309
|
return !1;
|
|
310
310
|
}
|
|
311
|
-
},
|
|
312
|
-
if (
|
|
311
|
+
}, Ut = (s) => {
|
|
312
|
+
if (ze())
|
|
313
313
|
try {
|
|
314
314
|
sessionStorage.setItem(x, s ? "true" : "false"), a("info", s ? "QA Mode ACTIVE" : "QA Mode DISABLED", {
|
|
315
315
|
visibility: "qa",
|
|
316
|
-
style: s ?
|
|
316
|
+
style: s ? We : Ge
|
|
317
317
|
});
|
|
318
318
|
} catch {
|
|
319
319
|
a("debug", "Cannot set QA mode: sessionStorage unavailable");
|
|
320
320
|
}
|
|
321
|
-
},
|
|
321
|
+
}, Ht = [
|
|
322
322
|
"co.uk",
|
|
323
323
|
"org.uk",
|
|
324
324
|
"com.au",
|
|
@@ -330,13 +330,13 @@ const _t = () => {
|
|
|
330
330
|
"co.in",
|
|
331
331
|
"com.cn",
|
|
332
332
|
"co.za"
|
|
333
|
-
],
|
|
333
|
+
], Ve = (s) => {
|
|
334
334
|
const e = s.toLowerCase().split(".");
|
|
335
335
|
if (e.length <= 2)
|
|
336
336
|
return s.toLowerCase();
|
|
337
337
|
const t = e.slice(-2).join(".");
|
|
338
|
-
return
|
|
339
|
-
}, xt = (s, e) => s === e ? !0 :
|
|
338
|
+
return Ht.includes(t) ? e.slice(-3).join(".") : e.slice(-2).join(".");
|
|
339
|
+
}, xt = (s, e) => s === e ? !0 : Ve(s) === Ve(e), re = () => {
|
|
340
340
|
const s = document.referrer;
|
|
341
341
|
if (!s)
|
|
342
342
|
return "Direct";
|
|
@@ -346,24 +346,24 @@ const _t = () => {
|
|
|
346
346
|
} catch (e) {
|
|
347
347
|
return a("debug", "Failed to parse referrer URL, using raw value", { error: e, data: { referrer: s } }), s;
|
|
348
348
|
}
|
|
349
|
-
},
|
|
349
|
+
}, se = () => {
|
|
350
350
|
const s = new URLSearchParams(window.location.search), e = {};
|
|
351
|
-
return
|
|
351
|
+
return lt.forEach((r) => {
|
|
352
352
|
const n = s.get(r);
|
|
353
353
|
if (n) {
|
|
354
354
|
const i = r.split("utm_")[1];
|
|
355
355
|
e[i] = n;
|
|
356
356
|
}
|
|
357
357
|
}), Object.keys(e).length ? e : void 0;
|
|
358
|
-
},
|
|
358
|
+
}, Ft = () => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (s) => {
|
|
359
359
|
const e = Math.random() * 16 | 0;
|
|
360
360
|
return (s === "x" ? e : e & 3 | 8).toString(16);
|
|
361
361
|
});
|
|
362
|
-
let
|
|
363
|
-
const
|
|
362
|
+
let W = 0, G = 0;
|
|
363
|
+
const $t = () => {
|
|
364
364
|
let s = Date.now();
|
|
365
|
-
s <
|
|
366
|
-
const e =
|
|
365
|
+
s < G && (s = G), s === G ? W = (W + 1) % 1e3 : W = 0, G = s;
|
|
366
|
+
const e = W.toString().padStart(3, "0");
|
|
367
367
|
let t = "";
|
|
368
368
|
try {
|
|
369
369
|
if (typeof crypto < "u" && crypto.getRandomValues) {
|
|
@@ -373,14 +373,14 @@ const Ft = () => {
|
|
|
373
373
|
} catch {
|
|
374
374
|
}
|
|
375
375
|
return t || (t = Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")), `${s}-${e}-${t}`;
|
|
376
|
-
},
|
|
376
|
+
}, Ke = (s, e = !1) => {
|
|
377
377
|
try {
|
|
378
378
|
const t = new URL(s), r = t.protocol === "https:", n = t.protocol === "http:";
|
|
379
379
|
return r || e && n;
|
|
380
380
|
} catch {
|
|
381
381
|
return !1;
|
|
382
382
|
}
|
|
383
|
-
},
|
|
383
|
+
}, Bt = (s) => {
|
|
384
384
|
try {
|
|
385
385
|
const t = new URL(window.location.href).hostname;
|
|
386
386
|
if (!t || typeof t != "string")
|
|
@@ -398,28 +398,28 @@ const Ft = () => {
|
|
|
398
398
|
if (r.length === 2 ? n = r.join(".") : n = r.slice(-2).join("."), !n || n.split(".").length < 2)
|
|
399
399
|
throw new Error("Invalid domain structure for SaaS");
|
|
400
400
|
const i = `https://${s}.${n}/collect`;
|
|
401
|
-
if (!
|
|
401
|
+
if (!Ke(i))
|
|
402
402
|
throw new Error("Generated URL failed validation");
|
|
403
403
|
return i;
|
|
404
404
|
} catch (e) {
|
|
405
405
|
throw new Error(`Invalid SaaS URL configuration: ${e instanceof Error ? e.message : String(e)}`);
|
|
406
406
|
}
|
|
407
|
-
},
|
|
407
|
+
}, Wt = (s) => {
|
|
408
408
|
const e = {};
|
|
409
|
-
s.integrations?.tracelog?.projectId && (e.saas =
|
|
409
|
+
s.integrations?.tracelog?.projectId && (e.saas = Bt(s.integrations.tracelog.projectId));
|
|
410
410
|
const t = s.integrations?.custom?.collectApiUrl;
|
|
411
411
|
if (t) {
|
|
412
412
|
const r = s.integrations?.custom?.allowHttp ?? !1;
|
|
413
|
-
if (!
|
|
413
|
+
if (!Ke(t, r))
|
|
414
414
|
throw new Error("Invalid custom API URL");
|
|
415
415
|
e.custom = t;
|
|
416
416
|
}
|
|
417
417
|
return e;
|
|
418
|
-
},
|
|
418
|
+
}, de = (s, e = []) => {
|
|
419
419
|
if (!s || typeof s != "string")
|
|
420
420
|
return a("warn", "Invalid URL provided to normalizeUrl", { data: { type: typeof s } }), s || "";
|
|
421
421
|
try {
|
|
422
|
-
const t = new URL(s), r = t.searchParams, n = [.../* @__PURE__ */ new Set([...
|
|
422
|
+
const t = new URL(s), r = t.searchParams, n = [.../* @__PURE__ */ new Set([...ct, ...e])];
|
|
423
423
|
let i = !1;
|
|
424
424
|
const o = [];
|
|
425
425
|
return n.forEach((c) => {
|
|
@@ -428,13 +428,13 @@ const Ft = () => {
|
|
|
428
428
|
} catch (t) {
|
|
429
429
|
return a("warn", "URL normalization failed, returning original", { error: t, data: { urlLength: s?.length } }), s;
|
|
430
430
|
}
|
|
431
|
-
},
|
|
431
|
+
}, Ue = (s) => {
|
|
432
432
|
if (!s || typeof s != "string" || s.trim().length === 0)
|
|
433
433
|
return "";
|
|
434
434
|
let e = s;
|
|
435
435
|
s.length > 1e3 && (e = s.slice(0, Math.max(0, 1e3)));
|
|
436
436
|
let t = 0;
|
|
437
|
-
for (const n of
|
|
437
|
+
for (const n of ut) {
|
|
438
438
|
const i = e;
|
|
439
439
|
e = e.replace(n, ""), i !== e && t++;
|
|
440
440
|
}
|
|
@@ -444,53 +444,53 @@ const Ft = () => {
|
|
|
444
444
|
valueLength: s.length
|
|
445
445
|
}
|
|
446
446
|
}), e = e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'").replaceAll("/", "/"), e.trim();
|
|
447
|
-
},
|
|
447
|
+
}, he = (s, e = 0) => {
|
|
448
448
|
if (e > 3 || s == null)
|
|
449
449
|
return null;
|
|
450
450
|
if (typeof s == "string")
|
|
451
|
-
return
|
|
451
|
+
return Ue(s);
|
|
452
452
|
if (typeof s == "number")
|
|
453
453
|
return !Number.isFinite(s) || s < -Number.MAX_SAFE_INTEGER || s > Number.MAX_SAFE_INTEGER ? 0 : s;
|
|
454
454
|
if (typeof s == "boolean")
|
|
455
455
|
return s;
|
|
456
456
|
if (Array.isArray(s))
|
|
457
|
-
return s.slice(0, 100).map((n) =>
|
|
457
|
+
return s.slice(0, 100).map((n) => he(n, e + 1)).filter((n) => n !== null);
|
|
458
458
|
if (typeof s == "object") {
|
|
459
459
|
const t = {}, n = Object.entries(s).slice(0, 20);
|
|
460
460
|
for (const [i, o] of n) {
|
|
461
|
-
const l =
|
|
461
|
+
const l = Ue(i);
|
|
462
462
|
if (l) {
|
|
463
|
-
const c =
|
|
463
|
+
const c = he(o, e + 1);
|
|
464
464
|
c !== null && (t[l] = c);
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
467
|
return t;
|
|
468
468
|
}
|
|
469
469
|
return null;
|
|
470
|
-
},
|
|
470
|
+
}, Gt = (s) => {
|
|
471
471
|
if (typeof s != "object" || s === null)
|
|
472
472
|
return {};
|
|
473
473
|
try {
|
|
474
|
-
const e =
|
|
474
|
+
const e = he(s);
|
|
475
475
|
return typeof e == "object" && e !== null ? e : {};
|
|
476
476
|
} catch (e) {
|
|
477
477
|
const t = e instanceof Error ? e.message : String(e);
|
|
478
478
|
throw new Error(`[TraceLog] Metadata sanitization failed: ${t}`);
|
|
479
479
|
}
|
|
480
|
-
},
|
|
480
|
+
}, Xt = (s) => {
|
|
481
481
|
if (s !== void 0 && (s === null || typeof s != "object"))
|
|
482
|
-
throw new
|
|
482
|
+
throw new f("Configuration must be an object", "config");
|
|
483
483
|
if (s) {
|
|
484
484
|
if (s.sessionTimeout !== void 0 && (typeof s.sessionTimeout != "number" || s.sessionTimeout < 3e4 || s.sessionTimeout > 864e5))
|
|
485
|
-
throw new
|
|
485
|
+
throw new mt(m.INVALID_SESSION_TIMEOUT, "config");
|
|
486
486
|
if (s.globalMetadata !== void 0 && (typeof s.globalMetadata != "object" || s.globalMetadata === null))
|
|
487
|
-
throw new
|
|
488
|
-
if (s.integrations &&
|
|
487
|
+
throw new f(m.INVALID_GLOBAL_METADATA, "config");
|
|
488
|
+
if (s.integrations && jt(s.integrations), s.sensitiveQueryParams !== void 0) {
|
|
489
489
|
if (!Array.isArray(s.sensitiveQueryParams))
|
|
490
|
-
throw new
|
|
490
|
+
throw new f(m.INVALID_SENSITIVE_QUERY_PARAMS, "config");
|
|
491
491
|
for (const e of s.sensitiveQueryParams)
|
|
492
492
|
if (typeof e != "string")
|
|
493
|
-
throw new
|
|
493
|
+
throw new f("All sensitive query params must be strings", "config");
|
|
494
494
|
}
|
|
495
495
|
if (s.errorSampling !== void 0 && (typeof s.errorSampling != "number" || s.errorSampling < 0 || s.errorSampling > 1))
|
|
496
496
|
throw new Re(m.INVALID_ERROR_SAMPLING_RATE, "config");
|
|
@@ -498,111 +498,111 @@ const Ft = () => {
|
|
|
498
498
|
throw new Re(m.INVALID_SAMPLING_RATE, "config");
|
|
499
499
|
if (s.primaryScrollSelector !== void 0) {
|
|
500
500
|
if (typeof s.primaryScrollSelector != "string" || !s.primaryScrollSelector.trim())
|
|
501
|
-
throw new
|
|
501
|
+
throw new f(m.INVALID_PRIMARY_SCROLL_SELECTOR, "config");
|
|
502
502
|
if (s.primaryScrollSelector !== "window")
|
|
503
503
|
try {
|
|
504
504
|
document.querySelector(s.primaryScrollSelector);
|
|
505
505
|
} catch {
|
|
506
|
-
throw new
|
|
506
|
+
throw new f(
|
|
507
507
|
`${m.INVALID_PRIMARY_SCROLL_SELECTOR_SYNTAX}: "${s.primaryScrollSelector}"`,
|
|
508
508
|
"config"
|
|
509
509
|
);
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
512
|
if (s.pageViewThrottleMs !== void 0 && (typeof s.pageViewThrottleMs != "number" || s.pageViewThrottleMs < 0))
|
|
513
|
-
throw new
|
|
513
|
+
throw new f(m.INVALID_PAGE_VIEW_THROTTLE, "config");
|
|
514
514
|
if (s.clickThrottleMs !== void 0 && (typeof s.clickThrottleMs != "number" || s.clickThrottleMs < 0))
|
|
515
|
-
throw new
|
|
515
|
+
throw new f(m.INVALID_CLICK_THROTTLE, "config");
|
|
516
516
|
if (s.maxSameEventPerMinute !== void 0 && (typeof s.maxSameEventPerMinute != "number" || s.maxSameEventPerMinute <= 0))
|
|
517
|
-
throw new
|
|
518
|
-
if (s.viewport !== void 0 &&
|
|
517
|
+
throw new f(m.INVALID_MAX_SAME_EVENT_PER_MINUTE, "config");
|
|
518
|
+
if (s.viewport !== void 0 && Qt(s.viewport), s.webVitalsMode !== void 0) {
|
|
519
519
|
if (typeof s.webVitalsMode != "string")
|
|
520
|
-
throw new
|
|
520
|
+
throw new f(
|
|
521
521
|
`Invalid webVitalsMode type: ${typeof s.webVitalsMode}. Must be a string`,
|
|
522
522
|
"config"
|
|
523
523
|
);
|
|
524
524
|
const e = ["all", "needs-improvement", "poor"];
|
|
525
525
|
if (!e.includes(s.webVitalsMode))
|
|
526
|
-
throw new
|
|
526
|
+
throw new f(
|
|
527
527
|
`Invalid webVitalsMode: "${s.webVitalsMode}". Must be one of: ${e.join(", ")}`,
|
|
528
528
|
"config"
|
|
529
529
|
);
|
|
530
530
|
}
|
|
531
531
|
if (s.webVitalsThresholds !== void 0) {
|
|
532
532
|
if (typeof s.webVitalsThresholds != "object" || s.webVitalsThresholds === null || Array.isArray(s.webVitalsThresholds))
|
|
533
|
-
throw new
|
|
533
|
+
throw new f("webVitalsThresholds must be an object", "config");
|
|
534
534
|
const e = ["LCP", "FCP", "CLS", "INP", "TTFB", "LONG_TASK"];
|
|
535
535
|
for (const [t, r] of Object.entries(s.webVitalsThresholds)) {
|
|
536
536
|
if (!e.includes(t))
|
|
537
|
-
throw new
|
|
537
|
+
throw new f(
|
|
538
538
|
`Invalid Web Vitals threshold key: "${t}". Must be one of: ${e.join(", ")}`,
|
|
539
539
|
"config"
|
|
540
540
|
);
|
|
541
541
|
if (typeof r != "number" || !Number.isFinite(r) || r < 0)
|
|
542
|
-
throw new
|
|
542
|
+
throw new f(
|
|
543
543
|
`Invalid Web Vitals threshold value for ${t}: ${r}. Must be a non-negative finite number`,
|
|
544
544
|
"config"
|
|
545
545
|
);
|
|
546
546
|
}
|
|
547
547
|
}
|
|
548
548
|
}
|
|
549
|
-
},
|
|
549
|
+
}, Qt = (s) => {
|
|
550
550
|
if (typeof s != "object" || s === null)
|
|
551
|
-
throw new
|
|
551
|
+
throw new f(m.INVALID_VIEWPORT_CONFIG, "config");
|
|
552
552
|
if (!s.elements || !Array.isArray(s.elements))
|
|
553
|
-
throw new
|
|
553
|
+
throw new f(m.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
554
554
|
if (s.elements.length === 0)
|
|
555
|
-
throw new
|
|
555
|
+
throw new f(m.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
556
556
|
const e = /* @__PURE__ */ new Set();
|
|
557
557
|
for (const t of s.elements) {
|
|
558
558
|
if (!t.selector || typeof t.selector != "string" || !t.selector.trim())
|
|
559
|
-
throw new
|
|
559
|
+
throw new f(m.INVALID_VIEWPORT_ELEMENT, "config");
|
|
560
560
|
const r = t.selector.trim();
|
|
561
561
|
if (e.has(r))
|
|
562
|
-
throw new
|
|
562
|
+
throw new f(
|
|
563
563
|
`Duplicate viewport selector found: "${r}". Each selector should appear only once.`,
|
|
564
564
|
"config"
|
|
565
565
|
);
|
|
566
566
|
if (e.add(r), t.id !== void 0 && (typeof t.id != "string" || !t.id.trim()))
|
|
567
|
-
throw new
|
|
567
|
+
throw new f(m.INVALID_VIEWPORT_ELEMENT_ID, "config");
|
|
568
568
|
if (t.name !== void 0 && (typeof t.name != "string" || !t.name.trim()))
|
|
569
|
-
throw new
|
|
569
|
+
throw new f(m.INVALID_VIEWPORT_ELEMENT_NAME, "config");
|
|
570
570
|
}
|
|
571
571
|
if (s.threshold !== void 0 && (typeof s.threshold != "number" || s.threshold < 0 || s.threshold > 1))
|
|
572
|
-
throw new
|
|
572
|
+
throw new f(m.INVALID_VIEWPORT_THRESHOLD, "config");
|
|
573
573
|
if (s.minDwellTime !== void 0 && (typeof s.minDwellTime != "number" || s.minDwellTime < 0))
|
|
574
|
-
throw new
|
|
574
|
+
throw new f(m.INVALID_VIEWPORT_MIN_DWELL_TIME, "config");
|
|
575
575
|
if (s.cooldownPeriod !== void 0 && (typeof s.cooldownPeriod != "number" || s.cooldownPeriod < 0))
|
|
576
|
-
throw new
|
|
576
|
+
throw new f(m.INVALID_VIEWPORT_COOLDOWN_PERIOD, "config");
|
|
577
577
|
if (s.maxTrackedElements !== void 0 && (typeof s.maxTrackedElements != "number" || s.maxTrackedElements <= 0))
|
|
578
|
-
throw new
|
|
579
|
-
},
|
|
578
|
+
throw new f(m.INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS, "config");
|
|
579
|
+
}, jt = (s) => {
|
|
580
580
|
if (s) {
|
|
581
581
|
if (s.tracelog && (!s.tracelog.projectId || typeof s.tracelog.projectId != "string" || s.tracelog.projectId.trim() === ""))
|
|
582
|
-
throw new
|
|
582
|
+
throw new V(m.INVALID_TRACELOG_PROJECT_ID, "config");
|
|
583
583
|
if (s.custom) {
|
|
584
584
|
if (!s.custom.collectApiUrl || typeof s.custom.collectApiUrl != "string" || s.custom.collectApiUrl.trim() === "")
|
|
585
|
-
throw new
|
|
585
|
+
throw new V(m.INVALID_CUSTOM_API_URL, "config");
|
|
586
586
|
if (s.custom.allowHttp !== void 0 && typeof s.custom.allowHttp != "boolean")
|
|
587
|
-
throw new
|
|
587
|
+
throw new V("allowHttp must be a boolean", "config");
|
|
588
588
|
const e = s.custom.collectApiUrl.trim();
|
|
589
589
|
if (!e.startsWith("http://") && !e.startsWith("https://"))
|
|
590
|
-
throw new
|
|
590
|
+
throw new V('Custom API URL must start with "http://" or "https://"', "config");
|
|
591
591
|
if (!(s.custom.allowHttp ?? !1) && e.startsWith("http://"))
|
|
592
|
-
throw new
|
|
592
|
+
throw new V(
|
|
593
593
|
"Custom API URL must use HTTPS in production. Set allowHttp: true in integration config to allow HTTP (not recommended)",
|
|
594
594
|
"config"
|
|
595
595
|
);
|
|
596
596
|
}
|
|
597
597
|
}
|
|
598
|
-
},
|
|
599
|
-
|
|
598
|
+
}, zt = (s) => {
|
|
599
|
+
Xt(s);
|
|
600
600
|
const e = {
|
|
601
601
|
...s ?? {},
|
|
602
602
|
sessionTimeout: s?.sessionTimeout ?? 9e5,
|
|
603
603
|
globalMetadata: s?.globalMetadata ?? {},
|
|
604
604
|
sensitiveQueryParams: s?.sensitiveQueryParams ?? [],
|
|
605
|
-
errorSampling: s?.errorSampling ??
|
|
605
|
+
errorSampling: s?.errorSampling ?? je,
|
|
606
606
|
samplingRate: s?.samplingRate ?? 1,
|
|
607
607
|
pageViewThrottleMs: s?.pageViewThrottleMs ?? 1e3,
|
|
608
608
|
clickThrottleMs: s?.clickThrottleMs ?? 300,
|
|
@@ -618,7 +618,7 @@ const Ft = () => {
|
|
|
618
618
|
cooldownPeriod: e.viewport.cooldownPeriod ?? 6e4,
|
|
619
619
|
maxTrackedElements: e.viewport.maxTrackedElements ?? 100
|
|
620
620
|
}), e;
|
|
621
|
-
},
|
|
621
|
+
}, Kt = (s) => {
|
|
622
622
|
if (typeof s == "string")
|
|
623
623
|
return !0;
|
|
624
624
|
if (typeof s == "object" && s !== null && !Array.isArray(s)) {
|
|
@@ -635,7 +635,7 @@ const Ft = () => {
|
|
|
635
635
|
return !0;
|
|
636
636
|
}
|
|
637
637
|
return !1;
|
|
638
|
-
},
|
|
638
|
+
}, Ye = (s, e = 0) => {
|
|
639
639
|
if (typeof s != "object" || s === null || e > 1)
|
|
640
640
|
return !1;
|
|
641
641
|
for (const t of Object.values(s)) {
|
|
@@ -649,12 +649,12 @@ const Ft = () => {
|
|
|
649
649
|
if (typeof t[0] == "string") {
|
|
650
650
|
if (!t.every((o) => typeof o == "string"))
|
|
651
651
|
return !1;
|
|
652
|
-
} else if (!t.every((o) =>
|
|
652
|
+
} else if (!t.every((o) => Kt(o)))
|
|
653
653
|
return !1;
|
|
654
654
|
continue;
|
|
655
655
|
}
|
|
656
656
|
if (r === "object" && e === 0) {
|
|
657
|
-
if (!
|
|
657
|
+
if (!Ye(t, e + 1))
|
|
658
658
|
return !1;
|
|
659
659
|
continue;
|
|
660
660
|
}
|
|
@@ -662,7 +662,7 @@ const Ft = () => {
|
|
|
662
662
|
}
|
|
663
663
|
}
|
|
664
664
|
return !0;
|
|
665
|
-
},
|
|
665
|
+
}, Yt = (s) => typeof s != "string" ? {
|
|
666
666
|
valid: !1,
|
|
667
667
|
error: "Event name must be a string"
|
|
668
668
|
} : s.length === 0 ? {
|
|
@@ -677,9 +677,9 @@ const Ft = () => {
|
|
|
677
677
|
} : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(s.toLowerCase()) ? {
|
|
678
678
|
valid: !1,
|
|
679
679
|
error: "Event name cannot be a reserved word"
|
|
680
|
-
} : { valid: !0 },
|
|
681
|
-
const r =
|
|
682
|
-
if (!
|
|
680
|
+
} : { valid: !0 }, He = (s, e, t) => {
|
|
681
|
+
const r = Gt(e), n = t && t === "customEvent" ? `${t} "${s}" metadata error` : `${s} metadata error`;
|
|
682
|
+
if (!Ye(r))
|
|
683
683
|
return {
|
|
684
684
|
valid: !1,
|
|
685
685
|
error: `${n}: object has invalid types. Valid types are string, number, boolean or string arrays.`
|
|
@@ -727,7 +727,7 @@ const Ft = () => {
|
|
|
727
727
|
valid: !0,
|
|
728
728
|
sanitizedMetadata: r
|
|
729
729
|
};
|
|
730
|
-
},
|
|
730
|
+
}, qe = (s, e, t) => {
|
|
731
731
|
if (Array.isArray(e)) {
|
|
732
732
|
const r = [], n = t && t === "customEvent" ? `${t} "${s}" metadata error` : `${s} metadata error`;
|
|
733
733
|
for (let i = 0; i < e.length; i++) {
|
|
@@ -737,7 +737,7 @@ const Ft = () => {
|
|
|
737
737
|
valid: !1,
|
|
738
738
|
error: `${n}: array item at index ${i} must be an object.`
|
|
739
739
|
};
|
|
740
|
-
const l =
|
|
740
|
+
const l = He(s, o, t);
|
|
741
741
|
if (!l.valid)
|
|
742
742
|
return {
|
|
743
743
|
valid: !1,
|
|
@@ -750,16 +750,16 @@ const Ft = () => {
|
|
|
750
750
|
sanitizedMetadata: r
|
|
751
751
|
};
|
|
752
752
|
}
|
|
753
|
-
return
|
|
754
|
-
},
|
|
755
|
-
const t =
|
|
753
|
+
return He(s, e, t);
|
|
754
|
+
}, qt = (s, e) => {
|
|
755
|
+
const t = Yt(s);
|
|
756
756
|
if (!t.valid)
|
|
757
757
|
return a("error", "Event name validation failed", {
|
|
758
758
|
data: { eventName: s, error: t.error }
|
|
759
759
|
}), t;
|
|
760
760
|
if (!e)
|
|
761
761
|
return { valid: !0 };
|
|
762
|
-
const r =
|
|
762
|
+
const r = qe(s, e, "customEvent");
|
|
763
763
|
return r.valid || a("error", "Event metadata validation failed", {
|
|
764
764
|
data: {
|
|
765
765
|
eventName: s,
|
|
@@ -767,7 +767,7 @@ const Ft = () => {
|
|
|
767
767
|
}
|
|
768
768
|
}), r;
|
|
769
769
|
};
|
|
770
|
-
class
|
|
770
|
+
class Jt {
|
|
771
771
|
listeners = /* @__PURE__ */ new Map();
|
|
772
772
|
/**
|
|
773
773
|
* Subscribes to an event channel
|
|
@@ -884,7 +884,7 @@ class qt {
|
|
|
884
884
|
this.listeners.clear();
|
|
885
885
|
}
|
|
886
886
|
}
|
|
887
|
-
function
|
|
887
|
+
function Je(s, e, t) {
|
|
888
888
|
try {
|
|
889
889
|
const r = e(s);
|
|
890
890
|
return r === null ? null : typeof r == "object" && r !== null && "type" in r ? r : (a("warn", `beforeSend transformer returned invalid data, using original [${t}]`), s);
|
|
@@ -895,10 +895,10 @@ function qe(s, e, t) {
|
|
|
895
895
|
}), s;
|
|
896
896
|
}
|
|
897
897
|
}
|
|
898
|
-
function
|
|
899
|
-
return s.map((r) =>
|
|
898
|
+
function Zt(s, e, t) {
|
|
899
|
+
return s.map((r) => Je(r, e, t)).filter((r) => r !== null);
|
|
900
900
|
}
|
|
901
|
-
function
|
|
901
|
+
function Ze(s, e, t) {
|
|
902
902
|
try {
|
|
903
903
|
const r = e(s);
|
|
904
904
|
return r === null ? (a("debug", `Batch filtered by beforeBatch transformer [${t}]`, {
|
|
@@ -914,7 +914,7 @@ function Je(s, e, t) {
|
|
|
914
914
|
}), s;
|
|
915
915
|
}
|
|
916
916
|
}
|
|
917
|
-
const
|
|
917
|
+
const ne = {};
|
|
918
918
|
class _ {
|
|
919
919
|
/**
|
|
920
920
|
* Retrieves a value from global state.
|
|
@@ -933,7 +933,7 @@ class _ {
|
|
|
933
933
|
* ```
|
|
934
934
|
*/
|
|
935
935
|
get(e) {
|
|
936
|
-
return
|
|
936
|
+
return ne[e];
|
|
937
937
|
}
|
|
938
938
|
/**
|
|
939
939
|
* Sets a value in global state.
|
|
@@ -953,7 +953,7 @@ class _ {
|
|
|
953
953
|
* ```
|
|
954
954
|
*/
|
|
955
955
|
set(e, t) {
|
|
956
|
-
|
|
956
|
+
ne[e] = t;
|
|
957
957
|
}
|
|
958
958
|
/**
|
|
959
959
|
* Returns an immutable snapshot of the entire global state.
|
|
@@ -970,7 +970,7 @@ class _ {
|
|
|
970
970
|
* ```
|
|
971
971
|
*/
|
|
972
972
|
getState() {
|
|
973
|
-
return { ...
|
|
973
|
+
return { ...ne };
|
|
974
974
|
}
|
|
975
975
|
}
|
|
976
976
|
class xe extends _ {
|
|
@@ -978,6 +978,8 @@ class xe extends _ {
|
|
|
978
978
|
integrationId;
|
|
979
979
|
apiUrl;
|
|
980
980
|
transformers;
|
|
981
|
+
staticHeaders;
|
|
982
|
+
customHeadersProvider;
|
|
981
983
|
lastPermanentErrorLog = null;
|
|
982
984
|
recoveryInProgress = !1;
|
|
983
985
|
lastMetadataTimestamp = 0;
|
|
@@ -992,12 +994,14 @@ class xe extends _ {
|
|
|
992
994
|
* @param integrationId - Optional integration identifier ('saas' or 'custom')
|
|
993
995
|
* @param apiUrl - Optional API endpoint URL
|
|
994
996
|
* @param transformers - Optional event transformation hooks
|
|
997
|
+
* @param staticHeaders - Optional static HTTP headers (from config)
|
|
998
|
+
* @param customHeadersProvider - Optional callback for dynamic headers
|
|
995
999
|
* @throws Error if integrationId and apiUrl are not both provided or both undefined
|
|
996
1000
|
*/
|
|
997
|
-
constructor(e, t, r, n = {}) {
|
|
1001
|
+
constructor(e, t, r, n = {}, i = {}, o) {
|
|
998
1002
|
if (super(), t && !r || !t && r)
|
|
999
1003
|
throw new Error("SenderManager: integrationId and apiUrl must either both be provided or both be undefined");
|
|
1000
|
-
this.storeManager = e, this.integrationId = t, this.apiUrl = r, this.transformers = n;
|
|
1004
|
+
this.storeManager = e, this.integrationId = t, this.apiUrl = r, this.transformers = n, this.staticHeaders = i, this.customHeadersProvider = o;
|
|
1001
1005
|
}
|
|
1002
1006
|
/**
|
|
1003
1007
|
* Get the integration ID for this sender
|
|
@@ -1006,8 +1010,45 @@ class xe extends _ {
|
|
|
1006
1010
|
getIntegrationId() {
|
|
1007
1011
|
return this.integrationId;
|
|
1008
1012
|
}
|
|
1013
|
+
/**
|
|
1014
|
+
* Sets the custom headers provider callback.
|
|
1015
|
+
* Only applies to 'custom' integration (ignored for 'saas').
|
|
1016
|
+
*
|
|
1017
|
+
* @param provider - Callback function that returns custom headers
|
|
1018
|
+
*/
|
|
1019
|
+
setCustomHeadersProvider(e) {
|
|
1020
|
+
this.customHeadersProvider = e;
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Removes the custom headers provider callback.
|
|
1024
|
+
*/
|
|
1025
|
+
removeCustomHeadersProvider() {
|
|
1026
|
+
this.customHeadersProvider = void 0;
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Builds custom headers by merging static headers with dynamic headers from provider.
|
|
1030
|
+
* Only applies to 'custom' integration (returns empty object for 'saas').
|
|
1031
|
+
*
|
|
1032
|
+
* @returns Merged custom headers object (dynamic headers override static)
|
|
1033
|
+
* @private
|
|
1034
|
+
*/
|
|
1035
|
+
getCustomHeaders() {
|
|
1036
|
+
if (this.integrationId !== "custom")
|
|
1037
|
+
return {};
|
|
1038
|
+
let e = {};
|
|
1039
|
+
if (this.customHeadersProvider)
|
|
1040
|
+
try {
|
|
1041
|
+
const t = this.customHeadersProvider();
|
|
1042
|
+
typeof t == "object" && t !== null && !Array.isArray(t) ? e = t : a("warn", "Custom headers provider returned invalid value, expected object", {
|
|
1043
|
+
data: { received: typeof t }
|
|
1044
|
+
});
|
|
1045
|
+
} catch (t) {
|
|
1046
|
+
a("warn", "Custom headers provider threw an error, using static headers only", { error: t });
|
|
1047
|
+
}
|
|
1048
|
+
return { ...this.staticHeaders, ...e };
|
|
1049
|
+
}
|
|
1009
1050
|
getQueueStorageKey() {
|
|
1010
|
-
const e = this.get("userId") || "anonymous", t =
|
|
1051
|
+
const e = this.get("userId") || "anonymous", t = dt(e);
|
|
1011
1052
|
return this.integrationId ? `${t}:${this.integrationId}` : t;
|
|
1012
1053
|
}
|
|
1013
1054
|
/**
|
|
@@ -1032,6 +1073,11 @@ class xe extends _ {
|
|
|
1032
1073
|
*
|
|
1033
1074
|
* **Important**: No retry mechanism for failures. Events are NOT persisted.
|
|
1034
1075
|
*
|
|
1076
|
+
* **Custom Headers Limitation**: Custom headers set via `setCustomHeaders()` are NOT applied
|
|
1077
|
+
* to sendBeacon requests due to browser API limitations. The sendBeacon API only supports
|
|
1078
|
+
* Content-Type header via Blob. For scenarios requiring custom headers, ensure async
|
|
1079
|
+
* sends complete before page unload.
|
|
1080
|
+
*
|
|
1035
1081
|
* @param body - Event queue to send
|
|
1036
1082
|
* @returns `true` if send succeeded or was skipped, `false` if failed
|
|
1037
1083
|
*
|
|
@@ -1039,13 +1085,13 @@ class xe extends _ {
|
|
|
1039
1085
|
* @see src/managers/README.md (lines 82-139) for send details
|
|
1040
1086
|
*/
|
|
1041
1087
|
sendEventsQueueSync(e) {
|
|
1042
|
-
return this.shouldSkipSend() ? !0 : this.apiUrl?.includes(
|
|
1088
|
+
return this.shouldSkipSend() ? !0 : this.apiUrl?.includes(U.Fail) ? (a(
|
|
1043
1089
|
"warn",
|
|
1044
1090
|
`Fail mode: simulating network failure (sync)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1045
1091
|
{
|
|
1046
1092
|
data: { events: e.events.length }
|
|
1047
1093
|
}
|
|
1048
|
-
), !1) : this.apiUrl?.includes(
|
|
1094
|
+
), !1) : this.apiUrl?.includes(U.Localhost) ? (a(
|
|
1049
1095
|
"debug",
|
|
1050
1096
|
`Success mode: simulating successful send (sync)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1051
1097
|
{
|
|
@@ -1087,7 +1133,7 @@ class xe extends _ {
|
|
|
1087
1133
|
const r = await this.send(e);
|
|
1088
1134
|
return r ? (this.clearPersistedEvents(), t?.onSuccess?.(e.events.length, e.events, e)) : (this.persistEvents(e), t?.onFailure?.()), r;
|
|
1089
1135
|
} catch (r) {
|
|
1090
|
-
return r instanceof
|
|
1136
|
+
return r instanceof O ? (this.logPermanentError("Permanent error, not retrying", r), this.clearPersistedEvents(), t?.onFailure?.(), !1) : (this.persistEvents(e), t?.onFailure?.(), !1);
|
|
1091
1137
|
}
|
|
1092
1138
|
}
|
|
1093
1139
|
/**
|
|
@@ -1154,7 +1200,7 @@ class xe extends _ {
|
|
|
1154
1200
|
const r = this.createRecoveryBody(t);
|
|
1155
1201
|
await this.send(r) ? (this.clearPersistedEvents(), e?.onSuccess?.(t.events.length, t.events, r)) : e?.onFailure?.();
|
|
1156
1202
|
} catch (t) {
|
|
1157
|
-
if (t instanceof
|
|
1203
|
+
if (t instanceof O) {
|
|
1158
1204
|
this.logPermanentError("Permanent error during recovery, clearing persisted events", t), this.clearPersistedEvents(), e?.onFailure?.();
|
|
1159
1205
|
return;
|
|
1160
1206
|
}
|
|
@@ -1208,7 +1254,7 @@ class xe extends _ {
|
|
|
1208
1254
|
const t = this.transformers.beforeSend;
|
|
1209
1255
|
if (!t)
|
|
1210
1256
|
return e;
|
|
1211
|
-
const r =
|
|
1257
|
+
const r = Zt(
|
|
1212
1258
|
e.events,
|
|
1213
1259
|
t,
|
|
1214
1260
|
this.integrationId || "SenderManager"
|
|
@@ -1253,7 +1299,7 @@ class xe extends _ {
|
|
|
1253
1299
|
if (this.integrationId === "saas")
|
|
1254
1300
|
return e;
|
|
1255
1301
|
const t = this.transformers.beforeBatch;
|
|
1256
|
-
return t ?
|
|
1302
|
+
return t ? Ze(e, t, this.integrationId || "SenderManager") : e;
|
|
1257
1303
|
}
|
|
1258
1304
|
/**
|
|
1259
1305
|
* Calculates exponential backoff delay with jitter for retry attempts.
|
|
@@ -1321,11 +1367,11 @@ class xe extends _ {
|
|
|
1321
1367
|
const r = this.applyBeforeBatchTransformer(t);
|
|
1322
1368
|
if (!r)
|
|
1323
1369
|
return !0;
|
|
1324
|
-
if (this.apiUrl?.includes(
|
|
1370
|
+
if (this.apiUrl?.includes(U.Fail))
|
|
1325
1371
|
return a("debug", `Fail mode: simulating network failure${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1326
1372
|
data: { events: r.events.length }
|
|
1327
1373
|
}), !1;
|
|
1328
|
-
if (this.apiUrl?.includes(
|
|
1374
|
+
if (this.apiUrl?.includes(U.Localhost))
|
|
1329
1375
|
return a("debug", `Success mode: simulating successful send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1330
1376
|
data: { events: r.events.length }
|
|
1331
1377
|
}), !0;
|
|
@@ -1341,7 +1387,7 @@ class xe extends _ {
|
|
|
1341
1387
|
), !0) : !1;
|
|
1342
1388
|
} catch (l) {
|
|
1343
1389
|
const c = o === 3;
|
|
1344
|
-
if (l instanceof
|
|
1390
|
+
if (l instanceof O)
|
|
1345
1391
|
throw l;
|
|
1346
1392
|
if (a(
|
|
1347
1393
|
c ? "error" : "warn",
|
|
@@ -1391,19 +1437,20 @@ class xe extends _ {
|
|
|
1391
1437
|
r.abort();
|
|
1392
1438
|
}, 15e3);
|
|
1393
1439
|
try {
|
|
1394
|
-
const i = await fetch(e, {
|
|
1440
|
+
const i = this.getCustomHeaders(), o = await fetch(e, {
|
|
1395
1441
|
method: "POST",
|
|
1396
1442
|
body: t,
|
|
1397
1443
|
keepalive: !0,
|
|
1398
1444
|
credentials: "include",
|
|
1399
1445
|
signal: r.signal,
|
|
1400
1446
|
headers: {
|
|
1447
|
+
...i,
|
|
1401
1448
|
"Content-Type": "application/json"
|
|
1402
1449
|
}
|
|
1403
1450
|
});
|
|
1404
|
-
if (!
|
|
1405
|
-
throw
|
|
1406
|
-
return
|
|
1451
|
+
if (!o.ok)
|
|
1452
|
+
throw o.status >= 400 && o.status < 500 && o.status !== 408 && o.status !== 429 ? new O(`HTTP ${o.status}: ${o.statusText}`, o.status) : new Error(`HTTP ${o.status}: ${o.statusText}`);
|
|
1453
|
+
return o;
|
|
1407
1454
|
} finally {
|
|
1408
1455
|
clearTimeout(n), this.pendingControllers.delete(r);
|
|
1409
1456
|
}
|
|
@@ -1486,7 +1533,7 @@ class xe extends _ {
|
|
|
1486
1533
|
_metadata: {
|
|
1487
1534
|
referer: typeof window < "u" ? window.location.href : void 0,
|
|
1488
1535
|
timestamp: t,
|
|
1489
|
-
client_version:
|
|
1536
|
+
client_version: Dt
|
|
1490
1537
|
}
|
|
1491
1538
|
};
|
|
1492
1539
|
return {
|
|
@@ -1607,12 +1654,12 @@ class xe extends _ {
|
|
|
1607
1654
|
}
|
|
1608
1655
|
logPermanentError(e, t) {
|
|
1609
1656
|
const r = Date.now();
|
|
1610
|
-
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || r - this.lastPermanentErrorLog.timestamp >=
|
|
1657
|
+
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || r - this.lastPermanentErrorLog.timestamp >= Ct) && (a("error", `${e}${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1611
1658
|
data: { status: t.statusCode, message: t.message }
|
|
1612
1659
|
}), this.lastPermanentErrorLog = { statusCode: t.statusCode, timestamp: r });
|
|
1613
1660
|
}
|
|
1614
1661
|
}
|
|
1615
|
-
class
|
|
1662
|
+
class er extends _ {
|
|
1616
1663
|
bootTime;
|
|
1617
1664
|
bootTimestamp;
|
|
1618
1665
|
hasPerformanceNow;
|
|
@@ -1761,7 +1808,7 @@ class Zt extends _ {
|
|
|
1761
1808
|
};
|
|
1762
1809
|
}
|
|
1763
1810
|
}
|
|
1764
|
-
class
|
|
1811
|
+
class tr extends _ {
|
|
1765
1812
|
dataSenders;
|
|
1766
1813
|
emitter;
|
|
1767
1814
|
transformers;
|
|
@@ -1793,12 +1840,23 @@ class er extends _ {
|
|
|
1793
1840
|
* @param storeManager - Storage manager for persistence
|
|
1794
1841
|
* @param emitter - Optional event emitter for local event consumption
|
|
1795
1842
|
* @param transformers - Optional event transformation hooks
|
|
1843
|
+
* @param staticHeaders - Optional static HTTP headers for custom backend (from config)
|
|
1844
|
+
* @param customHeadersProvider - Optional callback for dynamic headers
|
|
1796
1845
|
*/
|
|
1797
|
-
constructor(e, t = null, r = {}) {
|
|
1798
|
-
super(), this.emitter = t, this.transformers = r, this.timeManager = new
|
|
1799
|
-
const
|
|
1800
|
-
|
|
1801
|
-
|
|
1846
|
+
constructor(e, t = null, r = {}, n = {}, i) {
|
|
1847
|
+
super(), this.emitter = t, this.transformers = r, this.timeManager = new er(), this.dataSenders = [];
|
|
1848
|
+
const o = this.get("collectApiUrls");
|
|
1849
|
+
o?.saas && this.dataSenders.push(new xe(e, "saas", o.saas, r)), o?.custom && this.dataSenders.push(
|
|
1850
|
+
new xe(
|
|
1851
|
+
e,
|
|
1852
|
+
"custom",
|
|
1853
|
+
o.custom,
|
|
1854
|
+
r,
|
|
1855
|
+
n,
|
|
1856
|
+
i
|
|
1857
|
+
)
|
|
1858
|
+
), this.saveSessionCountsDebounced = this.debounce((l) => {
|
|
1859
|
+
this.saveSessionCounts(l);
|
|
1802
1860
|
}, 500), this.cleanupExpiredSessionCounts();
|
|
1803
1861
|
}
|
|
1804
1862
|
/**
|
|
@@ -1954,12 +2012,12 @@ class er extends _ {
|
|
|
1954
2012
|
}
|
|
1955
2013
|
const T = this.getTypeLimitForEvent(E);
|
|
1956
2014
|
if (T) {
|
|
1957
|
-
const
|
|
1958
|
-
if (
|
|
2015
|
+
const te = this.sessionEventCounts[E];
|
|
2016
|
+
if (te !== void 0 && te >= T) {
|
|
1959
2017
|
a("warn", "Session event type limit reached", {
|
|
1960
2018
|
data: {
|
|
1961
2019
|
type: E,
|
|
1962
|
-
count:
|
|
2020
|
+
count: te,
|
|
1963
2021
|
limit: T
|
|
1964
2022
|
}
|
|
1965
2023
|
});
|
|
@@ -1972,9 +2030,9 @@ class er extends _ {
|
|
|
1972
2030
|
if (!this.checkPerEventRateLimit(o.name, T))
|
|
1973
2031
|
return;
|
|
1974
2032
|
}
|
|
1975
|
-
const
|
|
2033
|
+
const Ie = E === d.SESSION_START, B = t || this.get("pageUrl"), k = this.buildEventPayload({
|
|
1976
2034
|
type: E,
|
|
1977
|
-
page_url:
|
|
2035
|
+
page_url: B,
|
|
1978
2036
|
from_page_url: r,
|
|
1979
2037
|
scroll_data: n,
|
|
1980
2038
|
click_data: i,
|
|
@@ -1984,8 +2042,8 @@ class er extends _ {
|
|
|
1984
2042
|
viewport_data: u,
|
|
1985
2043
|
page_view: S
|
|
1986
2044
|
});
|
|
1987
|
-
if (
|
|
1988
|
-
if (
|
|
2045
|
+
if (k && !(!p && !this.shouldSample())) {
|
|
2046
|
+
if (Ie) {
|
|
1989
2047
|
const T = this.get("sessionId");
|
|
1990
2048
|
if (!T) {
|
|
1991
2049
|
a("error", "Session start event requires sessionId - event will be ignored");
|
|
@@ -1999,8 +2057,8 @@ class er extends _ {
|
|
|
1999
2057
|
}
|
|
2000
2058
|
this.set("hasStartSession", !0);
|
|
2001
2059
|
}
|
|
2002
|
-
if (!this.isDuplicateEvent(
|
|
2003
|
-
if (this.get("mode") ===
|
|
2060
|
+
if (!this.isDuplicateEvent(k)) {
|
|
2061
|
+
if (this.get("mode") === K.QA) {
|
|
2004
2062
|
if (E === d.CUSTOM && o) {
|
|
2005
2063
|
a("info", `Custom Event: ${o.name}`, {
|
|
2006
2064
|
visibility: "qa",
|
|
@@ -2008,7 +2066,7 @@ class er extends _ {
|
|
|
2008
2066
|
name: o.name,
|
|
2009
2067
|
...o.metadata && { metadata: o.metadata }
|
|
2010
2068
|
}
|
|
2011
|
-
}), this.emitEvent(
|
|
2069
|
+
}), this.emitEvent(k);
|
|
2012
2070
|
return;
|
|
2013
2071
|
}
|
|
2014
2072
|
if (E === d.VIEWPORT_VISIBLE && u) {
|
|
@@ -2022,11 +2080,11 @@ class er extends _ {
|
|
|
2022
2080
|
visibilityRatio: u.visibilityRatio,
|
|
2023
2081
|
dwellTime: u.dwellTime
|
|
2024
2082
|
}
|
|
2025
|
-
}), this.emitEvent(
|
|
2083
|
+
}), this.emitEvent(k);
|
|
2026
2084
|
return;
|
|
2027
2085
|
}
|
|
2028
2086
|
}
|
|
2029
|
-
if (this.addToQueue(
|
|
2087
|
+
if (this.addToQueue(k), !p) {
|
|
2030
2088
|
this.sessionEventCounts.total++, this.sessionEventCounts[E] !== void 0 && this.sessionEventCounts[E]++;
|
|
2031
2089
|
const T = this.get("sessionId");
|
|
2032
2090
|
T && this.saveSessionCountsDebounced && this.saveSessionCountsDebounced(T);
|
|
@@ -2156,6 +2214,23 @@ class er extends _ {
|
|
|
2156
2214
|
flushImmediatelySync() {
|
|
2157
2215
|
return this.flushEvents(!0);
|
|
2158
2216
|
}
|
|
2217
|
+
/**
|
|
2218
|
+
* Sets the custom headers provider callback for the custom integration.
|
|
2219
|
+
* Only affects requests to custom backend (not TraceLog SaaS).
|
|
2220
|
+
*
|
|
2221
|
+
* @param provider - Callback function that returns custom headers
|
|
2222
|
+
*/
|
|
2223
|
+
setCustomHeadersProvider(e) {
|
|
2224
|
+
for (const t of this.dataSenders)
|
|
2225
|
+
t.getIntegrationId() === "custom" && t.setCustomHeadersProvider(e);
|
|
2226
|
+
}
|
|
2227
|
+
/**
|
|
2228
|
+
* Removes the custom headers provider callback from the custom integration.
|
|
2229
|
+
*/
|
|
2230
|
+
removeCustomHeadersProvider() {
|
|
2231
|
+
for (const e of this.dataSenders)
|
|
2232
|
+
e.getIntegrationId() === "custom" && e.removeCustomHeadersProvider();
|
|
2233
|
+
}
|
|
2159
2234
|
/**
|
|
2160
2235
|
* Returns the current number of events in the main queue.
|
|
2161
2236
|
*
|
|
@@ -2343,7 +2418,7 @@ class er extends _ {
|
|
|
2343
2418
|
};
|
|
2344
2419
|
const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas), l = this.transformers.beforeBatch;
|
|
2345
2420
|
if (!o && l) {
|
|
2346
|
-
const c =
|
|
2421
|
+
const c = Ze(n, l, "EventManager");
|
|
2347
2422
|
c !== null && (n = c);
|
|
2348
2423
|
}
|
|
2349
2424
|
return n;
|
|
@@ -2355,7 +2430,7 @@ class er extends _ {
|
|
|
2355
2430
|
});
|
|
2356
2431
|
const i = this.get("sessionReferrer"), o = this.get("sessionUtm");
|
|
2357
2432
|
let l = {
|
|
2358
|
-
id:
|
|
2433
|
+
id: $t(),
|
|
2359
2434
|
type: e.type,
|
|
2360
2435
|
page_url: t,
|
|
2361
2436
|
timestamp: r,
|
|
@@ -2372,10 +2447,10 @@ class er extends _ {
|
|
|
2372
2447
|
};
|
|
2373
2448
|
const c = this.get("collectApiUrls"), u = !!c?.custom, S = !!c?.saas, g = u || S, p = u && S, E = this.transformers.beforeSend;
|
|
2374
2449
|
if (E && (!g || u && !p)) {
|
|
2375
|
-
const
|
|
2376
|
-
if (
|
|
2450
|
+
const B = Je(l, E, "EventManager");
|
|
2451
|
+
if (B === null)
|
|
2377
2452
|
return null;
|
|
2378
|
-
l =
|
|
2453
|
+
l = B;
|
|
2379
2454
|
}
|
|
2380
2455
|
return l;
|
|
2381
2456
|
}
|
|
@@ -2458,10 +2533,10 @@ class er extends _ {
|
|
|
2458
2533
|
this.eventsQueue = this.eventsQueue.filter((r) => !t.has(r.id));
|
|
2459
2534
|
}
|
|
2460
2535
|
emitEvent(e) {
|
|
2461
|
-
this.emitter && this.emitter.emit(
|
|
2536
|
+
this.emitter && this.emitter.emit(ae.EVENT, e);
|
|
2462
2537
|
}
|
|
2463
2538
|
emitEventsQueue(e) {
|
|
2464
|
-
this.emitter && this.emitter.emit(
|
|
2539
|
+
this.emitter && this.emitter.emit(ae.QUEUE, e);
|
|
2465
2540
|
}
|
|
2466
2541
|
/**
|
|
2467
2542
|
* Creates a debounced version of a function that delays execution until after
|
|
@@ -2537,13 +2612,13 @@ class er extends _ {
|
|
|
2537
2612
|
loadSessionCounts(e) {
|
|
2538
2613
|
if (typeof window > "u" || typeof localStorage > "u")
|
|
2539
2614
|
return this.getInitialCounts();
|
|
2540
|
-
const t = this.get("userId") || "anonymous", r =
|
|
2615
|
+
const t = this.get("userId") || "anonymous", r = Ae(t, e);
|
|
2541
2616
|
try {
|
|
2542
2617
|
const n = localStorage.getItem(r);
|
|
2543
2618
|
if (!n)
|
|
2544
2619
|
return this.getInitialCounts();
|
|
2545
2620
|
const i = JSON.parse(n);
|
|
2546
|
-
return i._timestamp && Date.now() - i._timestamp >
|
|
2621
|
+
return i._timestamp && Date.now() - i._timestamp > Le ? (a("debug", "Session counts expired, clearing", {
|
|
2547
2622
|
data: { sessionId: e, age: Date.now() - i._timestamp }
|
|
2548
2623
|
}), localStorage.removeItem(r), this.getInitialCounts()) : typeof i.total == "number" && typeof i[d.CLICK] == "number" && typeof i[d.PAGE_VIEW] == "number" && typeof i[d.CUSTOM] == "number" && typeof i[d.VIEWPORT_VISIBLE] == "number" && typeof i[d.SCROLL] == "number" ? {
|
|
2549
2624
|
total: i.total,
|
|
@@ -2588,12 +2663,12 @@ class er extends _ {
|
|
|
2588
2663
|
cleanupExpiredSessionCounts() {
|
|
2589
2664
|
if (!(typeof window > "u" || typeof localStorage > "u"))
|
|
2590
2665
|
try {
|
|
2591
|
-
const e = localStorage.getItem(
|
|
2666
|
+
const e = localStorage.getItem(Me);
|
|
2592
2667
|
if (e) {
|
|
2593
2668
|
const i = Date.now() - parseInt(e, 10);
|
|
2594
|
-
if (i <
|
|
2669
|
+
if (i < Ce) {
|
|
2595
2670
|
a("debug", "Skipping session counts cleanup (throttled)", {
|
|
2596
|
-
data: { timeSinceLastCleanup: i, throttleMs:
|
|
2671
|
+
data: { timeSinceLastCleanup: i, throttleMs: Ce }
|
|
2597
2672
|
});
|
|
2598
2673
|
return;
|
|
2599
2674
|
}
|
|
@@ -2606,14 +2681,14 @@ class er extends _ {
|
|
|
2606
2681
|
const l = localStorage.getItem(o);
|
|
2607
2682
|
if (l) {
|
|
2608
2683
|
const c = JSON.parse(l);
|
|
2609
|
-
c._timestamp && Date.now() - c._timestamp >
|
|
2684
|
+
c._timestamp && Date.now() - c._timestamp > Le && n.push(o);
|
|
2610
2685
|
}
|
|
2611
2686
|
} catch {
|
|
2612
2687
|
}
|
|
2613
2688
|
}
|
|
2614
2689
|
n.forEach((i) => {
|
|
2615
2690
|
localStorage.removeItem(i), a("debug", "Cleaned up expired session counts", { data: { key: i } });
|
|
2616
|
-
}), n.length > 0 && a("info", `Cleaned up ${n.length} expired session counts entries`), localStorage.setItem(
|
|
2691
|
+
}), n.length > 0 && a("info", `Cleaned up ${n.length} expired session counts entries`), localStorage.setItem(Me, Date.now().toString());
|
|
2617
2692
|
} catch (e) {
|
|
2618
2693
|
a("warn", "Failed to cleanup expired session counts", { error: e });
|
|
2619
2694
|
}
|
|
@@ -2647,7 +2722,7 @@ class er extends _ {
|
|
|
2647
2722
|
* @internal
|
|
2648
2723
|
*/
|
|
2649
2724
|
saveSessionCounts(e) {
|
|
2650
|
-
const t = this.get("userId") || "anonymous", r =
|
|
2725
|
+
const t = this.get("userId") || "anonymous", r = Ae(t, e);
|
|
2651
2726
|
try {
|
|
2652
2727
|
const n = {
|
|
2653
2728
|
...this.sessionEventCounts,
|
|
@@ -2663,7 +2738,7 @@ class er extends _ {
|
|
|
2663
2738
|
}
|
|
2664
2739
|
}
|
|
2665
2740
|
}
|
|
2666
|
-
class
|
|
2741
|
+
class rr {
|
|
2667
2742
|
/**
|
|
2668
2743
|
* Gets or creates a unique user ID.
|
|
2669
2744
|
*
|
|
@@ -2681,15 +2756,15 @@ class tr {
|
|
|
2681
2756
|
* @returns Persistent unique user ID (UUID v4 format)
|
|
2682
2757
|
*/
|
|
2683
2758
|
static getId(e) {
|
|
2684
|
-
const t = e.getItem(
|
|
2759
|
+
const t = e.getItem(we);
|
|
2685
2760
|
if (t)
|
|
2686
2761
|
return t;
|
|
2687
|
-
const r =
|
|
2688
|
-
return e.setItem(
|
|
2762
|
+
const r = Ft();
|
|
2763
|
+
return e.setItem(we, r), r;
|
|
2689
2764
|
}
|
|
2690
2765
|
}
|
|
2691
|
-
const
|
|
2692
|
-
class
|
|
2766
|
+
const sr = /^\d{13}-[a-z0-9]{9}$/;
|
|
2767
|
+
class nr extends _ {
|
|
2693
2768
|
storageManager;
|
|
2694
2769
|
eventManager;
|
|
2695
2770
|
projectId;
|
|
@@ -2715,7 +2790,7 @@ class sr extends _ {
|
|
|
2715
2790
|
return;
|
|
2716
2791
|
}
|
|
2717
2792
|
const e = this.getProjectId();
|
|
2718
|
-
this.broadcastChannel = new BroadcastChannel(
|
|
2793
|
+
this.broadcastChannel = new BroadcastChannel(ft(e)), this.broadcastChannel.onmessage = (t) => {
|
|
2719
2794
|
const { action: r, sessionId: n, timestamp: i, projectId: o } = t.data ?? {};
|
|
2720
2795
|
o === e && (r === "session_start" && n && typeof i == "number" && i > Date.now() - 5e3 ? (this.set("sessionId", n), this.persistSession(n, i), this.isTracking && this.setupSessionTimeout()) : r && r !== "session_start" && a("debug", "Ignored BroadcastChannel message with unknown action", { data: { action: r } }));
|
|
2721
2796
|
};
|
|
@@ -2735,7 +2810,7 @@ class sr extends _ {
|
|
|
2735
2810
|
const e = this.loadStoredSession();
|
|
2736
2811
|
if (!e)
|
|
2737
2812
|
return null;
|
|
2738
|
-
if (!
|
|
2813
|
+
if (!sr.test(e.id))
|
|
2739
2814
|
return a("warn", "Invalid session ID format recovered from storage, clearing", {
|
|
2740
2815
|
data: { sessionId: e.id }
|
|
2741
2816
|
}), this.clearStoredSession(), null;
|
|
@@ -2770,7 +2845,7 @@ class sr extends _ {
|
|
|
2770
2845
|
this.storageManager.setItem(t, JSON.stringify(e));
|
|
2771
2846
|
}
|
|
2772
2847
|
getSessionStorageKey() {
|
|
2773
|
-
return
|
|
2848
|
+
return ht(this.getProjectId());
|
|
2774
2849
|
}
|
|
2775
2850
|
getProjectId() {
|
|
2776
2851
|
return this.projectId;
|
|
@@ -2835,9 +2910,9 @@ class sr extends _ {
|
|
|
2835
2910
|
let r, n;
|
|
2836
2911
|
if (e) {
|
|
2837
2912
|
const i = this.loadStoredSession();
|
|
2838
|
-
r = i?.referrer ??
|
|
2913
|
+
r = i?.referrer ?? re(), n = i?.utm ?? se();
|
|
2839
2914
|
} else
|
|
2840
|
-
r =
|
|
2915
|
+
r = re(), n = se();
|
|
2841
2916
|
a("debug", "Session tracking initialized", {
|
|
2842
2917
|
data: {
|
|
2843
2918
|
sessionId: t,
|
|
@@ -2888,7 +2963,7 @@ class sr extends _ {
|
|
|
2888
2963
|
*/
|
|
2889
2964
|
renewSession() {
|
|
2890
2965
|
this.needsRenewal = !1;
|
|
2891
|
-
const e = this.generateSessionId(), t =
|
|
2966
|
+
const e = this.generateSessionId(), t = re(), r = se();
|
|
2892
2967
|
a("debug", "Renewing session after timeout", {
|
|
2893
2968
|
data: { newSessionId: e }
|
|
2894
2969
|
}), this.set("sessionId", e), this.set("sessionReferrer", t), this.set("sessionUtm", r), this.persistSession(e, Date.now(), t, r), this.cleanupCrossTabSync(), this.initCrossTabSync(), this.shareSession(e), this.eventManager.track({
|
|
@@ -3009,7 +3084,7 @@ class sr extends _ {
|
|
|
3009
3084
|
this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupCrossTabSync(), this.cleanupLifecycleListeners(), this.isTracking = !1, this.needsRenewal = !1, this.set("hasStartSession", !1);
|
|
3010
3085
|
}
|
|
3011
3086
|
}
|
|
3012
|
-
class
|
|
3087
|
+
class ir extends _ {
|
|
3013
3088
|
eventManager;
|
|
3014
3089
|
storageManager;
|
|
3015
3090
|
sessionManager = null;
|
|
@@ -3044,7 +3119,7 @@ class nr extends _ {
|
|
|
3044
3119
|
}
|
|
3045
3120
|
const t = this.get("config")?.integrations?.tracelog?.projectId ?? "custom";
|
|
3046
3121
|
try {
|
|
3047
|
-
this.sessionManager = new
|
|
3122
|
+
this.sessionManager = new nr(this.storageManager, this.eventManager, t), this.sessionManager.startTracking(), this.eventManager.flushPendingEvents();
|
|
3048
3123
|
} catch (r) {
|
|
3049
3124
|
if (this.sessionManager) {
|
|
3050
3125
|
try {
|
|
@@ -3097,7 +3172,7 @@ class nr extends _ {
|
|
|
3097
3172
|
this.destroyed || (this.sessionManager && (this.sessionManager.destroy(), this.sessionManager = null), this.destroyed = !0);
|
|
3098
3173
|
}
|
|
3099
3174
|
}
|
|
3100
|
-
class
|
|
3175
|
+
class or extends _ {
|
|
3101
3176
|
eventManager;
|
|
3102
3177
|
onTrack;
|
|
3103
3178
|
originalPushState;
|
|
@@ -3137,7 +3212,7 @@ class ir extends _ {
|
|
|
3137
3212
|
};
|
|
3138
3213
|
}
|
|
3139
3214
|
trackCurrentPage = () => {
|
|
3140
|
-
const e = window.location.href, t =
|
|
3215
|
+
const e = window.location.href, t = de(e, this.get("config").sensitiveQueryParams);
|
|
3141
3216
|
if (this.get("pageUrl") === t)
|
|
3142
3217
|
return;
|
|
3143
3218
|
const r = Date.now(), n = this.get("config").pageViewThrottleMs ?? 1e3;
|
|
@@ -3155,7 +3230,7 @@ class ir extends _ {
|
|
|
3155
3230
|
});
|
|
3156
3231
|
};
|
|
3157
3232
|
trackInitialPageView() {
|
|
3158
|
-
const e =
|
|
3233
|
+
const e = de(window.location.href, this.get("config").sensitiveQueryParams), t = this.extractPageViewData();
|
|
3159
3234
|
this.lastPageViewTime = Date.now(), this.eventManager.track({
|
|
3160
3235
|
type: d.PAGE_VIEW,
|
|
3161
3236
|
page_url: e,
|
|
@@ -3173,7 +3248,7 @@ class ir extends _ {
|
|
|
3173
3248
|
};
|
|
3174
3249
|
}
|
|
3175
3250
|
}
|
|
3176
|
-
class
|
|
3251
|
+
class ar extends _ {
|
|
3177
3252
|
eventManager;
|
|
3178
3253
|
lastClickTimes = /* @__PURE__ */ new Map();
|
|
3179
3254
|
clickHandler;
|
|
@@ -3311,7 +3386,7 @@ class or extends _ {
|
|
|
3311
3386
|
return e.hasAttribute(`${w}-name`) ? e : e.closest(`[${w}-name]`);
|
|
3312
3387
|
}
|
|
3313
3388
|
getRelevantClickElement(e) {
|
|
3314
|
-
for (const t of
|
|
3389
|
+
for (const t of at)
|
|
3315
3390
|
try {
|
|
3316
3391
|
if (e.matches(t))
|
|
3317
3392
|
return e;
|
|
@@ -3391,7 +3466,7 @@ class or extends _ {
|
|
|
3391
3466
|
*/
|
|
3392
3467
|
sanitizeText(e) {
|
|
3393
3468
|
let t = e;
|
|
3394
|
-
for (const r of
|
|
3469
|
+
for (const r of Qe) {
|
|
3395
3470
|
const n = new RegExp(r.source, r.flags);
|
|
3396
3471
|
t = t.replace(n, "[REDACTED]");
|
|
3397
3472
|
}
|
|
@@ -3430,7 +3505,7 @@ class or extends _ {
|
|
|
3430
3505
|
};
|
|
3431
3506
|
}
|
|
3432
3507
|
}
|
|
3433
|
-
class
|
|
3508
|
+
class lr extends _ {
|
|
3434
3509
|
eventManager;
|
|
3435
3510
|
containers = [];
|
|
3436
3511
|
limitWarningLogged = !1;
|
|
@@ -3543,7 +3618,7 @@ class ar extends _ {
|
|
|
3543
3618
|
isPrimary: o,
|
|
3544
3619
|
lastScrollPos: n,
|
|
3545
3620
|
lastDepth: i,
|
|
3546
|
-
lastDirection:
|
|
3621
|
+
lastDirection: Q.DOWN,
|
|
3547
3622
|
lastEventTime: 0,
|
|
3548
3623
|
firstScrollEventTime: null,
|
|
3549
3624
|
maxDepthReached: i,
|
|
@@ -3602,7 +3677,7 @@ class ar extends _ {
|
|
|
3602
3677
|
e.debounceTimer !== null && (clearTimeout(e.debounceTimer), e.debounceTimer = null);
|
|
3603
3678
|
}
|
|
3604
3679
|
getScrollDirection(e, t) {
|
|
3605
|
-
return e > t ?
|
|
3680
|
+
return e > t ? Q.DOWN : Q.UP;
|
|
3606
3681
|
}
|
|
3607
3682
|
calculateScrollDepth(e, t, r) {
|
|
3608
3683
|
if (t <= r)
|
|
@@ -3658,7 +3733,7 @@ class ar extends _ {
|
|
|
3658
3733
|
e.isPrimary = t;
|
|
3659
3734
|
}
|
|
3660
3735
|
}
|
|
3661
|
-
class
|
|
3736
|
+
class cr extends _ {
|
|
3662
3737
|
eventManager;
|
|
3663
3738
|
trackedElements = /* @__PURE__ */ new Map();
|
|
3664
3739
|
observer = null;
|
|
@@ -3819,7 +3894,7 @@ class lr extends _ {
|
|
|
3819
3894
|
});
|
|
3820
3895
|
}
|
|
3821
3896
|
}
|
|
3822
|
-
class
|
|
3897
|
+
class ur {
|
|
3823
3898
|
storage;
|
|
3824
3899
|
sessionStorageRef;
|
|
3825
3900
|
fallbackStorage = /* @__PURE__ */ new Map();
|
|
@@ -4102,7 +4177,7 @@ class cr {
|
|
|
4102
4177
|
this.fallbackSessionStorage.delete(e);
|
|
4103
4178
|
}
|
|
4104
4179
|
}
|
|
4105
|
-
class
|
|
4180
|
+
class dr extends _ {
|
|
4106
4181
|
eventManager;
|
|
4107
4182
|
reportedByNav = /* @__PURE__ */ new Map();
|
|
4108
4183
|
navigationHistory = [];
|
|
@@ -4113,7 +4188,7 @@ class ur extends _ {
|
|
|
4113
4188
|
navigationCounter = 0;
|
|
4114
4189
|
// Counter for handling simultaneous navigations edge case
|
|
4115
4190
|
constructor(e) {
|
|
4116
|
-
super(), this.eventManager = e, this.vitalThresholds =
|
|
4191
|
+
super(), this.eventManager = e, this.vitalThresholds = ke(ue);
|
|
4117
4192
|
}
|
|
4118
4193
|
/**
|
|
4119
4194
|
* Starts tracking Web Vitals and performance metrics.
|
|
@@ -4130,8 +4205,8 @@ class ur extends _ {
|
|
|
4130
4205
|
* @returns Promise that resolves when tracking is initialized
|
|
4131
4206
|
*/
|
|
4132
4207
|
async startTracking() {
|
|
4133
|
-
const e = this.get("config"), t = e?.webVitalsMode ??
|
|
4134
|
-
this.vitalThresholds =
|
|
4208
|
+
const e = this.get("config"), t = e?.webVitalsMode ?? ue;
|
|
4209
|
+
this.vitalThresholds = ke(t), e?.webVitalsThresholds && (this.vitalThresholds = { ...this.vitalThresholds, ...e.webVitalsThresholds }), await this.initWebVitals(), this.observeLongTasks();
|
|
4135
4210
|
}
|
|
4136
4211
|
/**
|
|
4137
4212
|
* Stops tracking Web Vitals and cleans up resources.
|
|
@@ -4201,7 +4276,7 @@ class ur extends _ {
|
|
|
4201
4276
|
}
|
|
4202
4277
|
async initWebVitals() {
|
|
4203
4278
|
try {
|
|
4204
|
-
const { onLCP: e, onCLS: t, onFCP: r, onTTFB: n, onINP: i } = await Promise.resolve().then(() =>
|
|
4279
|
+
const { onLCP: e, onCLS: t, onFCP: r, onTTFB: n, onINP: i } = await Promise.resolve().then(() => Hr), o = (l) => (c) => {
|
|
4205
4280
|
const u = Number(c.value.toFixed(2));
|
|
4206
4281
|
this.sendVital({ type: l, value: u });
|
|
4207
4282
|
};
|
|
@@ -4228,7 +4303,7 @@ class ur extends _ {
|
|
|
4228
4303
|
const t = e.getEntries();
|
|
4229
4304
|
for (const r of t) {
|
|
4230
4305
|
const n = Number(r.duration.toFixed(2)), i = Date.now();
|
|
4231
|
-
i - this.lastLongTaskSentAt >=
|
|
4306
|
+
i - this.lastLongTaskSentAt >= Nt && (this.shouldSendVital("LONG_TASK", n) && this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = i);
|
|
4232
4307
|
}
|
|
4233
4308
|
},
|
|
4234
4309
|
{ type: "longtask", buffered: !0 }
|
|
@@ -4244,7 +4319,7 @@ class ur extends _ {
|
|
|
4244
4319
|
return;
|
|
4245
4320
|
if (r)
|
|
4246
4321
|
r.add(e.type);
|
|
4247
|
-
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length >
|
|
4322
|
+
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length > Ot) {
|
|
4248
4323
|
const i = this.navigationHistory.shift();
|
|
4249
4324
|
i && this.reportedByNav.delete(i);
|
|
4250
4325
|
}
|
|
@@ -4335,7 +4410,7 @@ class ur extends _ {
|
|
|
4335
4410
|
return !(typeof r == "number" && t <= r);
|
|
4336
4411
|
}
|
|
4337
4412
|
}
|
|
4338
|
-
class
|
|
4413
|
+
class hr extends _ {
|
|
4339
4414
|
eventManager;
|
|
4340
4415
|
recentErrors = /* @__PURE__ */ new Map();
|
|
4341
4416
|
errorBurstCounter = 0;
|
|
@@ -4371,24 +4446,24 @@ class dr extends _ {
|
|
|
4371
4446
|
const e = Date.now();
|
|
4372
4447
|
if (e < this.burstBackoffUntil)
|
|
4373
4448
|
return !1;
|
|
4374
|
-
if (e - this.burstWindowStart >
|
|
4375
|
-
return this.burstBackoffUntil = e +
|
|
4449
|
+
if (e - this.burstWindowStart > Lt && (this.errorBurstCounter = 0, this.burstWindowStart = e), this.errorBurstCounter++, this.errorBurstCounter > Mt)
|
|
4450
|
+
return this.burstBackoffUntil = e + Pe, a("debug", "Error burst detected - entering cooldown", {
|
|
4376
4451
|
data: {
|
|
4377
4452
|
errorsInWindow: this.errorBurstCounter,
|
|
4378
|
-
cooldownMs:
|
|
4453
|
+
cooldownMs: Pe
|
|
4379
4454
|
}
|
|
4380
4455
|
}), !1;
|
|
4381
|
-
const r = this.get("config")?.errorSampling ??
|
|
4456
|
+
const r = this.get("config")?.errorSampling ?? je;
|
|
4382
4457
|
return Math.random() < r;
|
|
4383
4458
|
}
|
|
4384
4459
|
handleError = (e) => {
|
|
4385
4460
|
if (!this.shouldSample())
|
|
4386
4461
|
return;
|
|
4387
4462
|
const t = this.sanitize(e.message || "Unknown error");
|
|
4388
|
-
this.shouldSuppressError(
|
|
4463
|
+
this.shouldSuppressError(H.JS_ERROR, t) || this.eventManager.track({
|
|
4389
4464
|
type: d.ERROR,
|
|
4390
4465
|
error_data: {
|
|
4391
|
-
type:
|
|
4466
|
+
type: H.JS_ERROR,
|
|
4392
4467
|
message: t,
|
|
4393
4468
|
...e.filename && { filename: e.filename },
|
|
4394
4469
|
...e.lineno && { line: e.lineno },
|
|
@@ -4400,10 +4475,10 @@ class dr extends _ {
|
|
|
4400
4475
|
if (!this.shouldSample())
|
|
4401
4476
|
return;
|
|
4402
4477
|
const t = this.extractRejectionMessage(e.reason), r = this.sanitize(t);
|
|
4403
|
-
this.shouldSuppressError(
|
|
4478
|
+
this.shouldSuppressError(H.PROMISE_REJECTION, r) || this.eventManager.track({
|
|
4404
4479
|
type: d.ERROR,
|
|
4405
4480
|
error_data: {
|
|
4406
|
-
type:
|
|
4481
|
+
type: H.PROMISE_REJECTION,
|
|
4407
4482
|
message: r
|
|
4408
4483
|
}
|
|
4409
4484
|
});
|
|
@@ -4422,8 +4497,8 @@ class dr extends _ {
|
|
|
4422
4497
|
}
|
|
4423
4498
|
}
|
|
4424
4499
|
sanitize(e) {
|
|
4425
|
-
let t = e.length >
|
|
4426
|
-
for (const r of
|
|
4500
|
+
let t = e.length > Ne ? e.slice(0, Ne) + "..." : e;
|
|
4501
|
+
for (const r of Qe) {
|
|
4427
4502
|
const n = new RegExp(r.source, r.flags);
|
|
4428
4503
|
t = t.replace(n, "[REDACTED]");
|
|
4429
4504
|
}
|
|
@@ -4431,26 +4506,27 @@ class dr extends _ {
|
|
|
4431
4506
|
}
|
|
4432
4507
|
shouldSuppressError(e, t) {
|
|
4433
4508
|
const r = Date.now(), n = `${e}:${t}`, i = this.recentErrors.get(n);
|
|
4434
|
-
return i && r - i <
|
|
4509
|
+
return i && r - i < Oe ? (this.recentErrors.set(n, r), !0) : (this.recentErrors.set(n, r), this.recentErrors.size > At ? (this.recentErrors.clear(), this.recentErrors.set(n, r), !1) : (this.recentErrors.size > j && this.pruneOldErrors(), !1));
|
|
4435
4510
|
}
|
|
4436
4511
|
pruneOldErrors() {
|
|
4437
4512
|
const e = Date.now();
|
|
4438
4513
|
for (const [n, i] of this.recentErrors.entries())
|
|
4439
|
-
e - i >
|
|
4440
|
-
if (this.recentErrors.size <=
|
|
4514
|
+
e - i > Oe && this.recentErrors.delete(n);
|
|
4515
|
+
if (this.recentErrors.size <= j)
|
|
4441
4516
|
return;
|
|
4442
|
-
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), r = this.recentErrors.size -
|
|
4517
|
+
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), r = this.recentErrors.size - j;
|
|
4443
4518
|
for (let n = 0; n < r; n += 1) {
|
|
4444
4519
|
const i = t[n];
|
|
4445
4520
|
i && this.recentErrors.delete(i[0]);
|
|
4446
4521
|
}
|
|
4447
4522
|
}
|
|
4448
4523
|
}
|
|
4449
|
-
class
|
|
4524
|
+
class fr extends _ {
|
|
4450
4525
|
isInitialized = !1;
|
|
4451
4526
|
suppressNextScrollTimer = null;
|
|
4452
|
-
emitter = new
|
|
4527
|
+
emitter = new Jt();
|
|
4453
4528
|
transformers = {};
|
|
4529
|
+
customHeadersProvider;
|
|
4454
4530
|
managers = {};
|
|
4455
4531
|
handlers = {};
|
|
4456
4532
|
get initialized() {
|
|
@@ -4465,10 +4541,18 @@ class hr extends _ {
|
|
|
4465
4541
|
*/
|
|
4466
4542
|
async init(e = {}) {
|
|
4467
4543
|
if (!this.isInitialized) {
|
|
4468
|
-
this.managers.storage = new
|
|
4544
|
+
this.managers.storage = new ur();
|
|
4469
4545
|
try {
|
|
4470
|
-
this.setupState(e)
|
|
4471
|
-
|
|
4546
|
+
this.setupState(e);
|
|
4547
|
+
const t = e.integrations?.custom?.headers ?? {};
|
|
4548
|
+
this.managers.event = new tr(
|
|
4549
|
+
this.managers.storage,
|
|
4550
|
+
this.emitter,
|
|
4551
|
+
this.transformers,
|
|
4552
|
+
t,
|
|
4553
|
+
this.customHeadersProvider
|
|
4554
|
+
), this.initializeHandlers(), await this.managers.event.recoverPersistedEvents().catch((r) => {
|
|
4555
|
+
a("warn", "Failed to recover persisted events", { error: r });
|
|
4472
4556
|
}), this.isInitialized = !0;
|
|
4473
4557
|
} catch (t) {
|
|
4474
4558
|
this.destroy(!0);
|
|
@@ -4491,9 +4575,9 @@ class hr extends _ {
|
|
|
4491
4575
|
}
|
|
4492
4576
|
let r = t;
|
|
4493
4577
|
t && typeof t == "object" && !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && (r = Object.assign({}, t));
|
|
4494
|
-
const { valid: n, error: i, sanitizedMetadata: o } =
|
|
4578
|
+
const { valid: n, error: i, sanitizedMetadata: o } = qt(e, r);
|
|
4495
4579
|
if (!n) {
|
|
4496
|
-
if (this.get("mode") ===
|
|
4580
|
+
if (this.get("mode") === K.QA)
|
|
4497
4581
|
throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${i}`);
|
|
4498
4582
|
return;
|
|
4499
4583
|
}
|
|
@@ -4522,6 +4606,27 @@ class hr extends _ {
|
|
|
4522
4606
|
getTransformer(e) {
|
|
4523
4607
|
return this.transformers[e];
|
|
4524
4608
|
}
|
|
4609
|
+
/**
|
|
4610
|
+
* Sets a callback to provide custom HTTP headers for requests to custom backends.
|
|
4611
|
+
* Only applies to custom backend integration (not TraceLog SaaS).
|
|
4612
|
+
*
|
|
4613
|
+
* @param provider - Callback function that returns custom headers
|
|
4614
|
+
* @throws {Error} If provider is not a function
|
|
4615
|
+
* @internal Called from api.setCustomHeaders()
|
|
4616
|
+
*/
|
|
4617
|
+
setCustomHeaders(e) {
|
|
4618
|
+
if (typeof e != "function")
|
|
4619
|
+
throw new Error(`[TraceLog] Custom headers provider must be a function, received: ${typeof e}`);
|
|
4620
|
+
this.customHeadersProvider = e, this.managers.event && this.managers.event.setCustomHeadersProvider(e);
|
|
4621
|
+
}
|
|
4622
|
+
/**
|
|
4623
|
+
* Removes the custom headers provider callback.
|
|
4624
|
+
*
|
|
4625
|
+
* @internal Called from api.removeCustomHeaders()
|
|
4626
|
+
*/
|
|
4627
|
+
removeCustomHeaders() {
|
|
4628
|
+
this.customHeadersProvider = void 0, this.managers.event && this.managers.event.removeCustomHeadersProvider();
|
|
4629
|
+
}
|
|
4525
4630
|
/**
|
|
4526
4631
|
* Destroys the TraceLog instance and cleans up all resources.
|
|
4527
4632
|
*
|
|
@@ -4535,18 +4640,18 @@ class hr extends _ {
|
|
|
4535
4640
|
} catch (r) {
|
|
4536
4641
|
a("warn", "Failed to stop tracking", { error: r });
|
|
4537
4642
|
}
|
|
4538
|
-
}), this.suppressNextScrollTimer && (clearTimeout(this.suppressNextScrollTimer), this.suppressNextScrollTimer = null), this.managers.event?.stop(), this.emitter.removeAllListeners(), this.transformers.beforeSend = void 0, this.transformers.beforeBatch = void 0, this.set("suppressNextScroll", !1), this.set("sessionId", null), this.isInitialized = !1, this.handlers = {}, this.managers = {});
|
|
4643
|
+
}), this.suppressNextScrollTimer && (clearTimeout(this.suppressNextScrollTimer), this.suppressNextScrollTimer = null), this.managers.event?.stop(), this.emitter.removeAllListeners(), this.transformers.beforeSend = void 0, this.transformers.beforeBatch = void 0, this.customHeadersProvider = void 0, this.set("suppressNextScroll", !1), this.set("sessionId", null), this.isInitialized = !1, this.handlers = {}, this.managers = {});
|
|
4539
4644
|
}
|
|
4540
4645
|
setupState(e = {}) {
|
|
4541
4646
|
this.set("config", e);
|
|
4542
|
-
const t =
|
|
4647
|
+
const t = rr.getId(this.managers.storage);
|
|
4543
4648
|
this.set("userId", t);
|
|
4544
|
-
const r =
|
|
4649
|
+
const r = Wt(e);
|
|
4545
4650
|
this.set("collectApiUrls", r);
|
|
4546
|
-
const n =
|
|
4651
|
+
const n = bt();
|
|
4547
4652
|
this.set("device", n);
|
|
4548
|
-
const i =
|
|
4549
|
-
this.set("pageUrl", i),
|
|
4653
|
+
const i = de(window.location.href, e.sensitiveQueryParams);
|
|
4654
|
+
this.set("pageUrl", i), Vt() && this.set("mode", K.QA);
|
|
4550
4655
|
}
|
|
4551
4656
|
/**
|
|
4552
4657
|
* Returns the current configuration object.
|
|
@@ -4588,7 +4693,7 @@ class hr extends _ {
|
|
|
4588
4693
|
valid: !1,
|
|
4589
4694
|
error: "Global metadata must be a plain object"
|
|
4590
4695
|
};
|
|
4591
|
-
const t =
|
|
4696
|
+
const t = qe("Global", e, "globalMetadata");
|
|
4592
4697
|
return t.valid ? { valid: !0 } : {
|
|
4593
4698
|
valid: !1,
|
|
4594
4699
|
error: t.error
|
|
@@ -4633,7 +4738,7 @@ class hr extends _ {
|
|
|
4633
4738
|
}
|
|
4634
4739
|
initializeHandlers() {
|
|
4635
4740
|
const e = this.get("config");
|
|
4636
|
-
this.handlers.session = new
|
|
4741
|
+
this.handlers.session = new ir(
|
|
4637
4742
|
this.managers.storage,
|
|
4638
4743
|
this.managers.event
|
|
4639
4744
|
), this.handlers.session.startTracking();
|
|
@@ -4642,30 +4747,30 @@ class hr extends _ {
|
|
|
4642
4747
|
this.set("suppressNextScroll", !1);
|
|
4643
4748
|
}, 500);
|
|
4644
4749
|
};
|
|
4645
|
-
this.handlers.pageView = new
|
|
4750
|
+
this.handlers.pageView = new or(this.managers.event, t), this.handlers.pageView.startTracking(), this.handlers.click = new ar(this.managers.event), this.handlers.click.startTracking(), this.handlers.scroll = new lr(this.managers.event), this.handlers.scroll.startTracking(), this.handlers.performance = new dr(this.managers.event), this.handlers.performance.startTracking().catch((r) => {
|
|
4646
4751
|
a("warn", "Failed to start performance tracking", { error: r });
|
|
4647
|
-
}), this.handlers.error = new
|
|
4752
|
+
}), this.handlers.error = new hr(this.managers.event), this.handlers.error.startTracking(), e.viewport && (this.handlers.viewport = new cr(this.managers.event), this.handlers.viewport.startTracking());
|
|
4648
4753
|
}
|
|
4649
4754
|
}
|
|
4650
|
-
const
|
|
4651
|
-
let
|
|
4652
|
-
const
|
|
4653
|
-
if (!(typeof window > "u" || typeof document > "u") && (v = !1, window.__traceLogDisabled !== !0 && !
|
|
4654
|
-
|
|
4755
|
+
const N = [], M = [];
|
|
4756
|
+
let R = null, h = null, C = !1, v = !1;
|
|
4757
|
+
const mr = async (s) => {
|
|
4758
|
+
if (!(typeof window > "u" || typeof document > "u") && (v = !1, window.__traceLogDisabled !== !0 && !h && !C)) {
|
|
4759
|
+
C = !0;
|
|
4655
4760
|
try {
|
|
4656
|
-
const e =
|
|
4761
|
+
const e = zt(s ?? {}), t = new fr();
|
|
4657
4762
|
try {
|
|
4658
|
-
|
|
4763
|
+
N.forEach(({ event: i, callback: o }) => {
|
|
4659
4764
|
t.on(i, o);
|
|
4660
|
-
}),
|
|
4765
|
+
}), N.length = 0, M.forEach(({ hook: i, fn: o }) => {
|
|
4661
4766
|
i === "beforeSend" ? t.setTransformer("beforeSend", o) : t.setTransformer("beforeBatch", o);
|
|
4662
|
-
}), M.length = 0;
|
|
4767
|
+
}), M.length = 0, R && (t.setCustomHeaders(R), R = null);
|
|
4663
4768
|
const r = t.init(e), n = new Promise((i, o) => {
|
|
4664
4769
|
setTimeout(() => {
|
|
4665
4770
|
o(new Error("[TraceLog] Initialization timeout after 10000ms"));
|
|
4666
4771
|
}, 1e4);
|
|
4667
4772
|
});
|
|
4668
|
-
await Promise.race([r, n]),
|
|
4773
|
+
await Promise.race([r, n]), h = t;
|
|
4669
4774
|
} catch (r) {
|
|
4670
4775
|
try {
|
|
4671
4776
|
t.destroy(!0);
|
|
@@ -4675,122 +4780,146 @@ const fr = async (s) => {
|
|
|
4675
4780
|
throw r;
|
|
4676
4781
|
}
|
|
4677
4782
|
} catch (e) {
|
|
4678
|
-
throw
|
|
4783
|
+
throw h = null, e;
|
|
4679
4784
|
} finally {
|
|
4680
|
-
|
|
4785
|
+
C = !1;
|
|
4681
4786
|
}
|
|
4682
4787
|
}
|
|
4683
|
-
},
|
|
4788
|
+
}, gr = (s, e) => {
|
|
4684
4789
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4685
|
-
if (!
|
|
4790
|
+
if (!h)
|
|
4686
4791
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4687
4792
|
if (v)
|
|
4688
4793
|
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
4689
|
-
|
|
4794
|
+
h.sendCustomEvent(s, e);
|
|
4690
4795
|
}
|
|
4691
|
-
},
|
|
4796
|
+
}, Er = (s, e) => {
|
|
4692
4797
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4693
|
-
if (!
|
|
4694
|
-
|
|
4798
|
+
if (!h || C) {
|
|
4799
|
+
N.push({ event: s, callback: e });
|
|
4695
4800
|
return;
|
|
4696
4801
|
}
|
|
4697
|
-
|
|
4802
|
+
h.on(s, e);
|
|
4698
4803
|
}
|
|
4699
|
-
},
|
|
4804
|
+
}, Sr = (s, e) => {
|
|
4700
4805
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4701
|
-
if (!
|
|
4702
|
-
const t =
|
|
4703
|
-
t !== -1 &&
|
|
4806
|
+
if (!h) {
|
|
4807
|
+
const t = N.findIndex((r) => r.event === s && r.callback === e);
|
|
4808
|
+
t !== -1 && N.splice(t, 1);
|
|
4704
4809
|
return;
|
|
4705
4810
|
}
|
|
4706
|
-
|
|
4811
|
+
h.off(s, e);
|
|
4707
4812
|
}
|
|
4708
4813
|
};
|
|
4709
|
-
function
|
|
4814
|
+
function pr(s, e) {
|
|
4710
4815
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4711
4816
|
if (typeof e != "function")
|
|
4712
4817
|
throw new Error(`[TraceLog] Transformer must be a function, received: ${typeof e}`);
|
|
4713
|
-
if (!
|
|
4818
|
+
if (!h || C) {
|
|
4714
4819
|
const t = M.findIndex((r) => r.hook === s);
|
|
4715
4820
|
t !== -1 && M.splice(t, 1), M.push({ hook: s, fn: e });
|
|
4716
4821
|
return;
|
|
4717
4822
|
}
|
|
4718
4823
|
if (v)
|
|
4719
4824
|
throw new Error("[TraceLog] Cannot set transformers while TraceLog is being destroyed");
|
|
4720
|
-
s === "beforeSend" ?
|
|
4825
|
+
s === "beforeSend" ? h.setTransformer("beforeSend", e) : h.setTransformer("beforeBatch", e);
|
|
4721
4826
|
}
|
|
4722
4827
|
}
|
|
4723
|
-
const
|
|
4828
|
+
const Tr = (s) => {
|
|
4724
4829
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4725
|
-
if (!
|
|
4830
|
+
if (!h) {
|
|
4726
4831
|
const e = M.findIndex((t) => t.hook === s);
|
|
4727
4832
|
e !== -1 && M.splice(e, 1);
|
|
4728
4833
|
return;
|
|
4729
4834
|
}
|
|
4730
4835
|
if (v)
|
|
4731
4836
|
throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
|
|
4732
|
-
|
|
4837
|
+
h.removeTransformer(s);
|
|
4838
|
+
}
|
|
4839
|
+
}, vr = (s) => {
|
|
4840
|
+
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4841
|
+
if (typeof s != "function")
|
|
4842
|
+
throw new Error(`[TraceLog] Custom headers provider must be a function, received: ${typeof s}`);
|
|
4843
|
+
if (!h || C) {
|
|
4844
|
+
R = s;
|
|
4845
|
+
return;
|
|
4846
|
+
}
|
|
4847
|
+
if (v)
|
|
4848
|
+
throw new Error("[TraceLog] Cannot set custom headers while TraceLog is being destroyed");
|
|
4849
|
+
h.setCustomHeaders(s);
|
|
4850
|
+
}
|
|
4851
|
+
}, _r = () => {
|
|
4852
|
+
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4853
|
+
if (!h) {
|
|
4854
|
+
R = null;
|
|
4855
|
+
return;
|
|
4856
|
+
}
|
|
4857
|
+
if (v)
|
|
4858
|
+
throw new Error("[TraceLog] Cannot remove custom headers while TraceLog is being destroyed");
|
|
4859
|
+
h.removeCustomHeaders();
|
|
4733
4860
|
}
|
|
4734
|
-
},
|
|
4861
|
+
}, Ir = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, wr = () => {
|
|
4735
4862
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4736
4863
|
if (v)
|
|
4737
4864
|
throw new Error("[TraceLog] Destroy operation already in progress");
|
|
4738
|
-
if (!
|
|
4865
|
+
if (!h) {
|
|
4739
4866
|
v = !1;
|
|
4740
4867
|
return;
|
|
4741
4868
|
}
|
|
4742
4869
|
v = !0;
|
|
4743
4870
|
try {
|
|
4744
|
-
|
|
4871
|
+
h.destroy(), h = null, C = !1, N.length = 0, M.length = 0, R = null, v = !1;
|
|
4745
4872
|
} catch (s) {
|
|
4746
|
-
|
|
4873
|
+
h = null, C = !1, N.length = 0, M.length = 0, R = null, v = !1, a("warn", "Error during destroy, forced cleanup completed", { error: s });
|
|
4747
4874
|
}
|
|
4748
4875
|
}
|
|
4749
|
-
},
|
|
4750
|
-
typeof window > "u" || typeof document > "u" ||
|
|
4751
|
-
},
|
|
4876
|
+
}, yr = (s) => {
|
|
4877
|
+
typeof window > "u" || typeof document > "u" || Ut(s);
|
|
4878
|
+
}, br = (s) => {
|
|
4752
4879
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4753
|
-
if (!
|
|
4880
|
+
if (!h)
|
|
4754
4881
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4755
4882
|
if (v)
|
|
4756
4883
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
4757
|
-
|
|
4884
|
+
h.updateGlobalMetadata(s);
|
|
4758
4885
|
}
|
|
4759
|
-
},
|
|
4886
|
+
}, Ar = (s) => {
|
|
4760
4887
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
4761
|
-
if (!
|
|
4888
|
+
if (!h)
|
|
4762
4889
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
4763
4890
|
if (v)
|
|
4764
4891
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
4765
|
-
|
|
4766
|
-
}
|
|
4767
|
-
},
|
|
4768
|
-
init:
|
|
4769
|
-
event:
|
|
4770
|
-
on:
|
|
4771
|
-
off:
|
|
4772
|
-
setTransformer:
|
|
4773
|
-
removeTransformer:
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4892
|
+
h.mergeGlobalMetadata(s);
|
|
4893
|
+
}
|
|
4894
|
+
}, Zr = {
|
|
4895
|
+
init: mr,
|
|
4896
|
+
event: gr,
|
|
4897
|
+
on: Er,
|
|
4898
|
+
off: Sr,
|
|
4899
|
+
setTransformer: pr,
|
|
4900
|
+
removeTransformer: Tr,
|
|
4901
|
+
setCustomHeaders: vr,
|
|
4902
|
+
removeCustomHeaders: _r,
|
|
4903
|
+
isInitialized: Ir,
|
|
4904
|
+
destroy: wr,
|
|
4905
|
+
setQaMode: yr,
|
|
4906
|
+
updateGlobalMetadata: br,
|
|
4907
|
+
mergeGlobalMetadata: Ar
|
|
4779
4908
|
};
|
|
4780
|
-
var
|
|
4909
|
+
var fe, et = -1, D = function(s) {
|
|
4781
4910
|
addEventListener("pageshow", (function(e) {
|
|
4782
|
-
e.persisted && (
|
|
4911
|
+
e.persisted && (et = e.timeStamp, s(e));
|
|
4783
4912
|
}), !0);
|
|
4784
|
-
},
|
|
4913
|
+
}, Te = function() {
|
|
4785
4914
|
var s = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
|
|
4786
4915
|
if (s && s.responseStart > 0 && s.responseStart < performance.now()) return s;
|
|
4787
|
-
},
|
|
4788
|
-
var s =
|
|
4916
|
+
}, J = function() {
|
|
4917
|
+
var s = Te();
|
|
4789
4918
|
return s && s.activationStart || 0;
|
|
4790
4919
|
}, b = function(s, e) {
|
|
4791
|
-
var t =
|
|
4792
|
-
return
|
|
4793
|
-
},
|
|
4920
|
+
var t = Te(), r = "navigate";
|
|
4921
|
+
return et >= 0 ? r = "back-forward-cache" : t && (document.prerendering || J() > 0 ? r = "prerender" : document.wasDiscarded ? r = "restore" : t.type && (r = t.type.replace(/_/g, "-"))), { name: s, value: e === void 0 ? -1 : e, rating: "good", delta: 0, entries: [], id: "v4-".concat(Date.now(), "-").concat(Math.floor(8999999999999 * Math.random()) + 1e12), navigationType: r };
|
|
4922
|
+
}, $ = function(s, e, t) {
|
|
4794
4923
|
try {
|
|
4795
4924
|
if (PerformanceObserver.supportedEntryTypes.includes(s)) {
|
|
4796
4925
|
var r = new PerformanceObserver((function(n) {
|
|
@@ -4809,13 +4938,13 @@ var he, Ze = -1, P = function(s) {
|
|
|
4809
4938
|
return l > c[1] ? "poor" : l > c[0] ? "needs-improvement" : "good";
|
|
4810
4939
|
})(e.value, t), s(e));
|
|
4811
4940
|
};
|
|
4812
|
-
},
|
|
4941
|
+
}, ve = function(s) {
|
|
4813
4942
|
requestAnimationFrame((function() {
|
|
4814
4943
|
return requestAnimationFrame((function() {
|
|
4815
4944
|
return s();
|
|
4816
4945
|
}));
|
|
4817
4946
|
}));
|
|
4818
|
-
},
|
|
4947
|
+
}, Z = function(s) {
|
|
4819
4948
|
document.addEventListener("visibilitychange", (function() {
|
|
4820
4949
|
document.visibilityState === "hidden" && s();
|
|
4821
4950
|
}));
|
|
@@ -4824,41 +4953,41 @@ var he, Ze = -1, P = function(s) {
|
|
|
4824
4953
|
return function() {
|
|
4825
4954
|
e || (s(), e = !0);
|
|
4826
4955
|
};
|
|
4827
|
-
},
|
|
4956
|
+
}, P = -1, Fe = function() {
|
|
4828
4957
|
return document.visibilityState !== "hidden" || document.prerendering ? 1 / 0 : 0;
|
|
4829
|
-
},
|
|
4830
|
-
document.visibilityState === "hidden" &&
|
|
4831
|
-
},
|
|
4832
|
-
addEventListener("visibilitychange",
|
|
4833
|
-
},
|
|
4834
|
-
removeEventListener("visibilitychange",
|
|
4835
|
-
},
|
|
4836
|
-
return
|
|
4958
|
+
}, q = function(s) {
|
|
4959
|
+
document.visibilityState === "hidden" && P > -1 && (P = s.type === "visibilitychange" ? s.timeStamp : 0, Lr());
|
|
4960
|
+
}, $e = function() {
|
|
4961
|
+
addEventListener("visibilitychange", q, !0), addEventListener("prerenderingchange", q, !0);
|
|
4962
|
+
}, Lr = function() {
|
|
4963
|
+
removeEventListener("visibilitychange", q, !0), removeEventListener("prerenderingchange", q, !0);
|
|
4964
|
+
}, tt = function() {
|
|
4965
|
+
return P < 0 && (P = Fe(), $e(), D((function() {
|
|
4837
4966
|
setTimeout((function() {
|
|
4838
|
-
|
|
4967
|
+
P = Fe(), $e();
|
|
4839
4968
|
}), 0);
|
|
4840
4969
|
}))), { get firstHiddenTime() {
|
|
4841
|
-
return
|
|
4970
|
+
return P;
|
|
4842
4971
|
} };
|
|
4843
|
-
},
|
|
4972
|
+
}, ee = function(s) {
|
|
4844
4973
|
document.prerendering ? addEventListener("prerenderingchange", (function() {
|
|
4845
4974
|
return s();
|
|
4846
4975
|
}), !0) : s();
|
|
4847
|
-
},
|
|
4848
|
-
e = e || {},
|
|
4849
|
-
var t, r =
|
|
4976
|
+
}, me = [1800, 3e3], rt = function(s, e) {
|
|
4977
|
+
e = e || {}, ee((function() {
|
|
4978
|
+
var t, r = tt(), n = b("FCP"), i = $("paint", (function(o) {
|
|
4850
4979
|
o.forEach((function(l) {
|
|
4851
|
-
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime < r.firstHiddenTime && (n.value = Math.max(l.startTime -
|
|
4980
|
+
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime < r.firstHiddenTime && (n.value = Math.max(l.startTime - J(), 0), n.entries.push(l), t(!0)));
|
|
4852
4981
|
}));
|
|
4853
4982
|
}));
|
|
4854
|
-
i && (t = A(s, n,
|
|
4855
|
-
n = b("FCP"), t = A(s, n,
|
|
4983
|
+
i && (t = A(s, n, me, e.reportAllChanges), D((function(o) {
|
|
4984
|
+
n = b("FCP"), t = A(s, n, me, e.reportAllChanges), ve((function() {
|
|
4856
4985
|
n.value = performance.now() - o.timeStamp, t(!0);
|
|
4857
4986
|
}));
|
|
4858
4987
|
})));
|
|
4859
4988
|
}));
|
|
4860
|
-
},
|
|
4861
|
-
e = e || {},
|
|
4989
|
+
}, ge = [0.1, 0.25], Mr = function(s, e) {
|
|
4990
|
+
e = e || {}, rt(_e((function() {
|
|
4862
4991
|
var t, r = b("CLS", 0), n = 0, i = [], o = function(c) {
|
|
4863
4992
|
c.forEach((function(u) {
|
|
4864
4993
|
if (!u.hadRecentInput) {
|
|
@@ -4866,148 +4995,148 @@ var he, Ze = -1, P = function(s) {
|
|
|
4866
4995
|
n && u.startTime - g.startTime < 1e3 && u.startTime - S.startTime < 5e3 ? (n += u.value, i.push(u)) : (n = u.value, i = [u]);
|
|
4867
4996
|
}
|
|
4868
4997
|
})), n > r.value && (r.value = n, r.entries = i, t());
|
|
4869
|
-
}, l =
|
|
4870
|
-
l && (t = A(s, r,
|
|
4998
|
+
}, l = $("layout-shift", o);
|
|
4999
|
+
l && (t = A(s, r, ge, e.reportAllChanges), Z((function() {
|
|
4871
5000
|
o(l.takeRecords()), t(!0);
|
|
4872
|
-
})),
|
|
4873
|
-
n = 0, r = b("CLS", 0), t = A(s, r,
|
|
5001
|
+
})), D((function() {
|
|
5002
|
+
n = 0, r = b("CLS", 0), t = A(s, r, ge, e.reportAllChanges), ve((function() {
|
|
4874
5003
|
return t();
|
|
4875
5004
|
}));
|
|
4876
5005
|
})), setTimeout(t, 0));
|
|
4877
5006
|
})));
|
|
4878
|
-
},
|
|
5007
|
+
}, st = 0, ie = 1 / 0, X = 0, Cr = function(s) {
|
|
4879
5008
|
s.forEach((function(e) {
|
|
4880
|
-
e.interactionId && (
|
|
5009
|
+
e.interactionId && (ie = Math.min(ie, e.interactionId), X = Math.max(X, e.interactionId), st = X ? (X - ie) / 7 + 1 : 0);
|
|
4881
5010
|
}));
|
|
4882
|
-
},
|
|
4883
|
-
return
|
|
4884
|
-
},
|
|
4885
|
-
"interactionCount" in performance ||
|
|
4886
|
-
}, y = [],
|
|
4887
|
-
var s = Math.min(y.length - 1, Math.floor((
|
|
5011
|
+
}, nt = function() {
|
|
5012
|
+
return fe ? st : performance.interactionCount || 0;
|
|
5013
|
+
}, Rr = function() {
|
|
5014
|
+
"interactionCount" in performance || fe || (fe = $("event", Cr, { type: "event", buffered: !0, durationThreshold: 0 }));
|
|
5015
|
+
}, y = [], z = /* @__PURE__ */ new Map(), it = 0, Nr = function() {
|
|
5016
|
+
var s = Math.min(y.length - 1, Math.floor((nt() - it) / 50));
|
|
4888
5017
|
return y[s];
|
|
4889
|
-
},
|
|
4890
|
-
if (
|
|
5018
|
+
}, Or = [], Pr = function(s) {
|
|
5019
|
+
if (Or.forEach((function(n) {
|
|
4891
5020
|
return n(s);
|
|
4892
5021
|
})), s.interactionId || s.entryType === "first-input") {
|
|
4893
|
-
var e = y[y.length - 1], t =
|
|
5022
|
+
var e = y[y.length - 1], t = z.get(s.interactionId);
|
|
4894
5023
|
if (t || y.length < 10 || s.duration > e.latency) {
|
|
4895
5024
|
if (t) s.duration > t.latency ? (t.entries = [s], t.latency = s.duration) : s.duration === t.latency && s.startTime === t.entries[0].startTime && t.entries.push(s);
|
|
4896
5025
|
else {
|
|
4897
5026
|
var r = { id: s.interactionId, latency: s.duration, entries: [s] };
|
|
4898
|
-
|
|
5027
|
+
z.set(r.id, r), y.push(r);
|
|
4899
5028
|
}
|
|
4900
5029
|
y.sort((function(n, i) {
|
|
4901
5030
|
return i.latency - n.latency;
|
|
4902
5031
|
})), y.length > 10 && y.splice(10).forEach((function(n) {
|
|
4903
|
-
return
|
|
5032
|
+
return z.delete(n.id);
|
|
4904
5033
|
}));
|
|
4905
5034
|
}
|
|
4906
5035
|
}
|
|
4907
|
-
},
|
|
5036
|
+
}, ot = function(s) {
|
|
4908
5037
|
var e = self.requestIdleCallback || self.setTimeout, t = -1;
|
|
4909
|
-
return s = _e(s), document.visibilityState === "hidden" ? s() : (t = e(s),
|
|
4910
|
-
},
|
|
4911
|
-
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {},
|
|
5038
|
+
return s = _e(s), document.visibilityState === "hidden" ? s() : (t = e(s), Z(s)), t;
|
|
5039
|
+
}, Ee = [200, 500], Dr = function(s, e) {
|
|
5040
|
+
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, ee((function() {
|
|
4912
5041
|
var t;
|
|
4913
|
-
|
|
5042
|
+
Rr();
|
|
4914
5043
|
var r, n = b("INP"), i = function(l) {
|
|
4915
|
-
|
|
4916
|
-
l.forEach(
|
|
4917
|
-
var c =
|
|
5044
|
+
ot((function() {
|
|
5045
|
+
l.forEach(Pr);
|
|
5046
|
+
var c = Nr();
|
|
4918
5047
|
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, r());
|
|
4919
5048
|
}));
|
|
4920
|
-
}, o =
|
|
4921
|
-
r = A(s, n,
|
|
5049
|
+
}, o = $("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
|
|
5050
|
+
r = A(s, n, Ee, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), Z((function() {
|
|
4922
5051
|
i(o.takeRecords()), r(!0);
|
|
4923
|
-
})),
|
|
4924
|
-
|
|
5052
|
+
})), D((function() {
|
|
5053
|
+
it = nt(), y.length = 0, z.clear(), n = b("INP"), r = A(s, n, Ee, e.reportAllChanges);
|
|
4925
5054
|
})));
|
|
4926
5055
|
})));
|
|
4927
|
-
},
|
|
4928
|
-
e = e || {},
|
|
4929
|
-
var t, r =
|
|
5056
|
+
}, Se = [2500, 4e3], oe = {}, kr = function(s, e) {
|
|
5057
|
+
e = e || {}, ee((function() {
|
|
5058
|
+
var t, r = tt(), n = b("LCP"), i = function(c) {
|
|
4930
5059
|
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(u) {
|
|
4931
|
-
u.startTime < r.firstHiddenTime && (n.value = Math.max(u.startTime -
|
|
5060
|
+
u.startTime < r.firstHiddenTime && (n.value = Math.max(u.startTime - J(), 0), n.entries = [u], t());
|
|
4932
5061
|
}));
|
|
4933
|
-
}, o =
|
|
5062
|
+
}, o = $("largest-contentful-paint", i);
|
|
4934
5063
|
if (o) {
|
|
4935
|
-
t = A(s, n,
|
|
5064
|
+
t = A(s, n, Se, e.reportAllChanges);
|
|
4936
5065
|
var l = _e((function() {
|
|
4937
|
-
|
|
5066
|
+
oe[n.id] || (i(o.takeRecords()), o.disconnect(), oe[n.id] = !0, t(!0));
|
|
4938
5067
|
}));
|
|
4939
5068
|
["keydown", "click"].forEach((function(c) {
|
|
4940
5069
|
addEventListener(c, (function() {
|
|
4941
|
-
return
|
|
5070
|
+
return ot(l);
|
|
4942
5071
|
}), { once: !0, capture: !0 });
|
|
4943
|
-
})),
|
|
4944
|
-
n = b("LCP"), t = A(s, n,
|
|
4945
|
-
n.value = performance.now() - c.timeStamp,
|
|
5072
|
+
})), Z(l), D((function(c) {
|
|
5073
|
+
n = b("LCP"), t = A(s, n, Se, e.reportAllChanges), ve((function() {
|
|
5074
|
+
n.value = performance.now() - c.timeStamp, oe[n.id] = !0, t(!0);
|
|
4946
5075
|
}));
|
|
4947
5076
|
}));
|
|
4948
5077
|
}
|
|
4949
5078
|
}));
|
|
4950
|
-
},
|
|
4951
|
-
document.prerendering ?
|
|
5079
|
+
}, pe = [800, 1800], Vr = function s(e) {
|
|
5080
|
+
document.prerendering ? ee((function() {
|
|
4952
5081
|
return s(e);
|
|
4953
5082
|
})) : document.readyState !== "complete" ? addEventListener("load", (function() {
|
|
4954
5083
|
return s(e);
|
|
4955
5084
|
}), !0) : setTimeout(e, 0);
|
|
4956
|
-
},
|
|
5085
|
+
}, Ur = function(s, e) {
|
|
4957
5086
|
e = e || {};
|
|
4958
|
-
var t = b("TTFB"), r = A(s, t,
|
|
4959
|
-
|
|
4960
|
-
var n =
|
|
4961
|
-
n && (t.value = Math.max(n.responseStart -
|
|
4962
|
-
t = b("TTFB", 0), (r = A(s, t,
|
|
5087
|
+
var t = b("TTFB"), r = A(s, t, pe, e.reportAllChanges);
|
|
5088
|
+
Vr((function() {
|
|
5089
|
+
var n = Te();
|
|
5090
|
+
n && (t.value = Math.max(n.responseStart - J(), 0), t.entries = [n], r(!0), D((function() {
|
|
5091
|
+
t = b("TTFB", 0), (r = A(s, t, pe, e.reportAllChanges))(!0);
|
|
4963
5092
|
})));
|
|
4964
5093
|
}));
|
|
4965
5094
|
};
|
|
4966
|
-
const
|
|
5095
|
+
const Hr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4967
5096
|
__proto__: null,
|
|
4968
|
-
CLSThresholds:
|
|
4969
|
-
FCPThresholds:
|
|
4970
|
-
INPThresholds:
|
|
4971
|
-
LCPThresholds:
|
|
4972
|
-
TTFBThresholds:
|
|
4973
|
-
onCLS:
|
|
4974
|
-
onFCP:
|
|
4975
|
-
onINP:
|
|
4976
|
-
onLCP:
|
|
4977
|
-
onTTFB:
|
|
5097
|
+
CLSThresholds: ge,
|
|
5098
|
+
FCPThresholds: me,
|
|
5099
|
+
INPThresholds: Ee,
|
|
5100
|
+
LCPThresholds: Se,
|
|
5101
|
+
TTFBThresholds: pe,
|
|
5102
|
+
onCLS: Mr,
|
|
5103
|
+
onFCP: rt,
|
|
5104
|
+
onINP: Dr,
|
|
5105
|
+
onLCP: kr,
|
|
5106
|
+
onTTFB: Ur
|
|
4978
5107
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
4979
5108
|
export {
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
5109
|
+
f as AppConfigValidationError,
|
|
5110
|
+
xr as DEFAULT_SESSION_TIMEOUT,
|
|
5111
|
+
ue as DEFAULT_WEB_VITALS_MODE,
|
|
4983
5112
|
L as DeviceType,
|
|
4984
|
-
|
|
4985
|
-
|
|
5113
|
+
ae as EmitterEvent,
|
|
5114
|
+
H as ErrorType,
|
|
4986
5115
|
d as EventType,
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5116
|
+
qr as InitializationTimeoutError,
|
|
5117
|
+
V as IntegrationValidationError,
|
|
5118
|
+
zr as MAX_ARRAY_LENGTH,
|
|
5119
|
+
Wr as MAX_CUSTOM_EVENT_ARRAY_SIZE,
|
|
5120
|
+
Br as MAX_CUSTOM_EVENT_KEYS,
|
|
5121
|
+
Fr as MAX_CUSTOM_EVENT_NAME_LENGTH,
|
|
5122
|
+
$r as MAX_CUSTOM_EVENT_STRING_SIZE,
|
|
5123
|
+
Xr as MAX_METADATA_NESTING_DEPTH,
|
|
5124
|
+
Gr as MAX_NESTED_OBJECT_KEYS,
|
|
5125
|
+
Qr as MAX_STRING_LENGTH,
|
|
5126
|
+
jr as MAX_STRING_LENGTH_IN_ARRAY,
|
|
5127
|
+
K as Mode,
|
|
5128
|
+
Qe as PII_PATTERNS,
|
|
5129
|
+
O as PermanentError,
|
|
5001
5130
|
Re as SamplingRateValidationError,
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5131
|
+
Q as ScrollDirection,
|
|
5132
|
+
mt as SessionTimeoutValidationError,
|
|
5133
|
+
U as SpecialApiUrl,
|
|
5134
|
+
F as TraceLogValidationError,
|
|
5135
|
+
Jr as WEB_VITALS_GOOD_THRESHOLDS,
|
|
5136
|
+
De as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
|
|
5008
5137
|
Rt as WEB_VITALS_POOR_THRESHOLDS,
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5138
|
+
ke as getWebVitalsThresholds,
|
|
5139
|
+
Kr as isPrimaryScrollEvent,
|
|
5140
|
+
Yr as isSecondaryScrollEvent,
|
|
5141
|
+
Zr as tracelog
|
|
5013
5142
|
};
|