@tracelog/lib 2.7.3 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/tracelog.esm.js +848 -797
- package/dist/browser/tracelog.esm.js.map +1 -1
- package/dist/browser/tracelog.js +2 -2
- package/dist/browser/tracelog.js.map +1 -1
- package/dist/public-api.cjs +2 -2
- package/dist/public-api.cjs.map +1 -1
- package/dist/public-api.d.mts +2 -0
- package/dist/public-api.d.ts +2 -0
- package/dist/public-api.js +2 -2
- package/dist/public-api.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
1
|
+
const ur = 9e5;
|
|
2
|
+
const dr = 120, hr = 49152, fr = 100, mr = 500, gr = 200;
|
|
3
|
+
const Er = 1e3, Sr = 500, pr = 1e3;
|
|
4
4
|
const b = "data-tlog", bt = [
|
|
5
5
|
"button",
|
|
6
6
|
"a",
|
|
@@ -79,28 +79,28 @@ const m = {
|
|
|
79
79
|
/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
|
|
80
80
|
/<embed\b[^>]*>/gi,
|
|
81
81
|
/<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi
|
|
82
|
-
], I = "tlog", G = `${I}:qa_mode`,
|
|
83
|
-
var B = /* @__PURE__ */ ((
|
|
84
|
-
class
|
|
82
|
+
], I = "tlog", G = `${I}:qa_mode`, Te = `${I}:uid`, rt = "tlog_mode", Ue = "qa", He = "qa_off", Ct = (r) => r ? `${I}:${r}:queue` : `${I}:queue`, Rt = (r) => r ? `${I}:${r}:session` : `${I}:session`, Nt = (r) => r ? `${I}:${r}:broadcast` : `${I}:broadcast`, Fe = (r, e) => `${I}:${r}:session_counts:${e}`, xe = 10080 * 60 * 1e3, $e = `${I}:session_counts_last_cleanup`, Be = 3600 * 1e3, fe = (r) => r ? `${I}:${r}:identity` : `${I}:identity`, H = `${I}:pending_identity`;
|
|
83
|
+
var B = /* @__PURE__ */ ((r) => (r.Localhost = "localhost:8080", r.Fail = "localhost:9999", r))(B || {}), L = /* @__PURE__ */ ((r) => (r.Mobile = "mobile", r.Tablet = "tablet", r.Desktop = "desktop", r.Unknown = "unknown", r))(L || {}), re = /* @__PURE__ */ ((r) => (r.EVENT = "event", r.QUEUE = "queue", r))(re || {});
|
|
84
|
+
class O extends Error {
|
|
85
85
|
constructor(e, t) {
|
|
86
|
-
super(e), this.statusCode = t, this.name = "PermanentError", Error.captureStackTrace && Error.captureStackTrace(this,
|
|
86
|
+
super(e), this.statusCode = t, this.name = "PermanentError", Error.captureStackTrace && Error.captureStackTrace(this, O);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
class
|
|
89
|
+
class ne extends Error {
|
|
90
90
|
constructor(e) {
|
|
91
|
-
super(e), this.name = "RateLimitError", Error.captureStackTrace && Error.captureStackTrace(this,
|
|
91
|
+
super(e), this.name = "RateLimitError", Error.captureStackTrace && Error.captureStackTrace(this, ne);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
class
|
|
94
|
+
class P extends Error {
|
|
95
95
|
constructor(e) {
|
|
96
|
-
super(e), this.name = "TimeoutError", Error.captureStackTrace && Error.captureStackTrace(this,
|
|
96
|
+
super(e), this.name = "TimeoutError", Error.captureStackTrace && Error.captureStackTrace(this, P);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
var d = /* @__PURE__ */ ((
|
|
100
|
-
const
|
|
99
|
+
var d = /* @__PURE__ */ ((r) => (r.PAGE_VIEW = "page_view", r.CLICK = "click", r.SCROLL = "scroll", r.SESSION_START = "session_start", r.CUSTOM = "custom", r.WEB_VITALS = "web_vitals", r.ERROR = "error", r.VIEWPORT_VISIBLE = "viewport_visible", r))(d || {}), ee = /* @__PURE__ */ ((r) => (r.UP = "up", r.DOWN = "down", r))(ee || {}), W = /* @__PURE__ */ ((r) => (r.JS_ERROR = "js_error", r.PROMISE_REJECTION = "promise_rejection", r))(W || {}), ie = /* @__PURE__ */ ((r) => (r.QA = "qa", r))(ie || {});
|
|
100
|
+
const Tr = (r) => r.type === d.SCROLL && "scroll_data" in r && r.scroll_data.is_primary === !0, Ir = (r) => r.type === d.SCROLL && "scroll_data" in r && r.scroll_data.is_primary === !1;
|
|
101
101
|
class z extends Error {
|
|
102
|
-
constructor(e, t,
|
|
103
|
-
super(e), this.errorCode = t, this.layer =
|
|
102
|
+
constructor(e, t, s) {
|
|
103
|
+
super(e), this.errorCode = t, this.layer = s, this.name = this.constructor.name, Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
class f extends z {
|
|
@@ -118,35 +118,35 @@ class We extends z {
|
|
|
118
118
|
super(e, "SAMPLING_RATE_INVALID", t);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
class
|
|
121
|
+
class N extends z {
|
|
122
122
|
constructor(e, t = "config") {
|
|
123
123
|
super(e, "INTEGRATION_INVALID", t);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
class
|
|
127
|
-
constructor(e, t,
|
|
128
|
-
super(e, "INITIALIZATION_TIMEOUT",
|
|
126
|
+
class vr extends z {
|
|
127
|
+
constructor(e, t, s = "runtime") {
|
|
128
|
+
super(e, "INITIALIZATION_TIMEOUT", s), this.timeoutMs = t;
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
const nt = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", it = "background: #9e9e9e; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", Pt = "background: #d32f2f; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", Dt = (
|
|
131
|
+
const nt = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", it = "background: #9e9e9e; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", Pt = "background: #d32f2f; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;", Dt = (r, e) => {
|
|
132
132
|
if (e) {
|
|
133
133
|
if (e instanceof Error) {
|
|
134
134
|
const t = e.message.replace(/\s+at\s+.*$/gm, "").replace(/\s*\([^()]+:\d+:\d+\)/g, "");
|
|
135
|
-
return `[TraceLog] ${
|
|
135
|
+
return `[TraceLog] ${r}: ${t}`;
|
|
136
136
|
}
|
|
137
137
|
if (e instanceof Error)
|
|
138
|
-
return `[TraceLog] ${
|
|
138
|
+
return `[TraceLog] ${r}: ${e.message}`;
|
|
139
139
|
if (typeof e == "string")
|
|
140
|
-
return `[TraceLog] ${
|
|
140
|
+
return `[TraceLog] ${r}: ${e}`;
|
|
141
141
|
if (typeof e == "object")
|
|
142
142
|
try {
|
|
143
|
-
return `[TraceLog] ${
|
|
143
|
+
return `[TraceLog] ${r}: ${JSON.stringify(e)}`;
|
|
144
144
|
} catch {
|
|
145
|
-
return `[TraceLog] ${
|
|
145
|
+
return `[TraceLog] ${r}: [Unable to serialize error]`;
|
|
146
146
|
}
|
|
147
|
-
return `[TraceLog] ${
|
|
147
|
+
return `[TraceLog] ${r}: ${String(e)}`;
|
|
148
148
|
}
|
|
149
|
-
return `[TraceLog] ${
|
|
149
|
+
return `[TraceLog] ${r}`;
|
|
150
150
|
}, kt = () => {
|
|
151
151
|
if (typeof window > "u" || typeof sessionStorage > "u")
|
|
152
152
|
return !1;
|
|
@@ -155,34 +155,34 @@ const nt = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8
|
|
|
155
155
|
} catch {
|
|
156
156
|
return !1;
|
|
157
157
|
}
|
|
158
|
-
}, a = (
|
|
159
|
-
const { error:
|
|
158
|
+
}, a = (r, e, t) => {
|
|
159
|
+
const { error: s, data: n, showToClient: i = !1, style: o, visibility: l } = t ?? {}, c = s ? Dt(e, s) : `[TraceLog] ${e}`, u = r === "error" ? "error" : r === "warn" ? "warn" : "log";
|
|
160
160
|
if (!Vt(l, i))
|
|
161
161
|
return;
|
|
162
162
|
const E = Ut(l, o), T = n !== void 0 ? Ie(n) : void 0;
|
|
163
163
|
Ht(u, c, E, T);
|
|
164
|
-
}, Vt = (
|
|
164
|
+
}, Vt = (r, e) => r === "critical" ? !0 : r === "qa" || e ? kt() : !1, Ut = (r, e) => e !== void 0 && e !== "" ? e : r === "critical" ? Pt : "", Ht = (r, e, t, s) => {
|
|
165
165
|
const n = t !== void 0 && t !== "", i = n ? `%c${e}` : e;
|
|
166
|
-
|
|
167
|
-
}, Ie = (
|
|
166
|
+
s !== void 0 ? n ? console[r](i, t, s) : console[r](i, s) : n ? console[r](i, t) : console[r](i);
|
|
167
|
+
}, Ie = (r) => {
|
|
168
168
|
const e = {}, t = ["token", "password", "secret", "key", "apikey", "api_key", "sessionid", "session_id"];
|
|
169
|
-
for (const [
|
|
170
|
-
const i =
|
|
169
|
+
for (const [s, n] of Object.entries(r)) {
|
|
170
|
+
const i = s.toLowerCase();
|
|
171
171
|
if (t.some((o) => i.includes(o))) {
|
|
172
|
-
e[
|
|
172
|
+
e[s] = "[REDACTED]";
|
|
173
173
|
continue;
|
|
174
174
|
}
|
|
175
|
-
n !== null && typeof n == "object" && !Array.isArray(n) ? e[
|
|
175
|
+
n !== null && typeof n == "object" && !Array.isArray(n) ? e[s] = Ie(n) : Array.isArray(n) ? e[s] = n.map(
|
|
176
176
|
(o) => o !== null && typeof o == "object" && !Array.isArray(o) ? Ie(o) : o
|
|
177
|
-
) : e[
|
|
177
|
+
) : e[s] = n;
|
|
178
178
|
}
|
|
179
179
|
return e;
|
|
180
180
|
};
|
|
181
181
|
let ve, ot;
|
|
182
182
|
const Ft = () => {
|
|
183
183
|
typeof window < "u" && !ve && (ve = window.matchMedia("(pointer: coarse)"), ot = window.matchMedia("(hover: none)"));
|
|
184
|
-
},
|
|
185
|
-
const e =
|
|
184
|
+
}, oe = "Unknown", xt = (r) => {
|
|
185
|
+
const e = r.userAgentData?.platform;
|
|
186
186
|
if (e != null && e !== "") {
|
|
187
187
|
if (/windows/i.test(e)) return "Windows";
|
|
188
188
|
if (/macos/i.test(e)) return "macOS";
|
|
@@ -192,9 +192,9 @@ const Ft = () => {
|
|
|
192
192
|
if (/ios/i.test(e)) return "iOS";
|
|
193
193
|
}
|
|
194
194
|
const t = navigator.userAgent;
|
|
195
|
-
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" :
|
|
196
|
-
}, $t = (
|
|
197
|
-
const e =
|
|
195
|
+
return /Windows/i.test(t) ? "Windows" : /iPhone|iPad|iPod/i.test(t) ? "iOS" : /Mac OS X|Macintosh/i.test(t) ? "macOS" : /Android/i.test(t) ? "Android" : /CrOS/i.test(t) ? "ChromeOS" : /Linux/i.test(t) ? "Linux" : oe;
|
|
196
|
+
}, $t = (r) => {
|
|
197
|
+
const e = r.userAgentData?.brands;
|
|
198
198
|
if (e != null && e.length > 0) {
|
|
199
199
|
const n = e.filter((i) => !/not.?a.?brand|chromium/i.test(i.brand))[0];
|
|
200
200
|
if (n != null) {
|
|
@@ -203,33 +203,33 @@ const Ft = () => {
|
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
const t = navigator.userAgent;
|
|
206
|
-
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" :
|
|
206
|
+
return /Edg\//i.test(t) ? "Edge" : /OPR\//i.test(t) ? "Opera" : /Chrome/i.test(t) ? "Chrome" : /Firefox/i.test(t) ? "Firefox" : /Safari/i.test(t) && !/Chrome/i.test(t) ? "Safari" : oe;
|
|
207
207
|
}, Bt = () => {
|
|
208
208
|
try {
|
|
209
|
-
const
|
|
210
|
-
if (
|
|
211
|
-
const c =
|
|
212
|
-
return c != null && c !== "" && /ipad|tablet/i.test(c) ? L.Tablet :
|
|
209
|
+
const r = navigator;
|
|
210
|
+
if (r.userAgentData != null && typeof r.userAgentData.mobile == "boolean") {
|
|
211
|
+
const c = r.userAgentData.platform;
|
|
212
|
+
return c != null && c !== "" && /ipad|tablet/i.test(c) ? L.Tablet : r.userAgentData.mobile ? L.Mobile : L.Desktop;
|
|
213
213
|
}
|
|
214
214
|
Ft();
|
|
215
|
-
const e = window.innerWidth, t = ve?.matches ?? !1,
|
|
216
|
-
return e <= 767 || o && n ? L.Mobile : e >= 768 && e <= 1024 || l || t &&
|
|
217
|
-
} catch (
|
|
218
|
-
return a("debug", "Device detection failed, defaulting to desktop", { error:
|
|
215
|
+
const e = window.innerWidth, t = ve?.matches ?? !1, s = ot?.matches ?? !1, n = "ontouchstart" in window || navigator.maxTouchPoints > 0, i = navigator.userAgent.toLowerCase(), o = /mobile|android|iphone|ipod|blackberry|iemobile|opera mini/.test(i), l = /tablet|ipad|android(?!.*mobile)/.test(i);
|
|
216
|
+
return e <= 767 || o && n ? L.Mobile : e >= 768 && e <= 1024 || l || t && s && n ? L.Tablet : L.Desktop;
|
|
217
|
+
} catch (r) {
|
|
218
|
+
return a("debug", "Device detection failed, defaulting to desktop", { error: r }), L.Desktop;
|
|
219
219
|
}
|
|
220
220
|
}, Wt = () => {
|
|
221
221
|
try {
|
|
222
|
-
const
|
|
222
|
+
const r = navigator;
|
|
223
223
|
return {
|
|
224
224
|
type: Bt(),
|
|
225
|
-
os: xt(
|
|
226
|
-
browser: $t(
|
|
225
|
+
os: xt(r),
|
|
226
|
+
browser: $t(r)
|
|
227
227
|
};
|
|
228
|
-
} catch (
|
|
229
|
-
return a("debug", "Device info detection failed, using defaults", { error:
|
|
228
|
+
} catch (r) {
|
|
229
|
+
return a("debug", "Device info detection failed, using defaults", { error: r }), {
|
|
230
230
|
type: L.Desktop,
|
|
231
|
-
os:
|
|
232
|
-
browser:
|
|
231
|
+
os: oe,
|
|
232
|
+
browser: oe
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
235
|
}, at = [
|
|
@@ -249,7 +249,7 @@ const Ft = () => {
|
|
|
249
249
|
/:\/\/[^:/]+:([^@]+)@/gi,
|
|
250
250
|
// Sensitive URL query parameters (token=, password=, auth=, secret=, api_key=, etc.)
|
|
251
251
|
/[?&](token|password|passwd|auth|secret|secret_key|private_key|auth_key|api_key|apikey|access_token)=[^&\s]+/gi
|
|
252
|
-
], Xe = 500, Ge = 2e3, je = 5e3, te = 50, Xt = te * 2, lt = 1, Gt = 1e3, jt = 10, ze = 5e3, zt = 6e4,
|
|
252
|
+
], Xe = 500, Ge = 2e3, je = 5e3, te = 50, Xt = te * 2, lt = 1, Gt = 1e3, jt = 10, ze = 5e3, zt = 6e4, _r = {
|
|
253
253
|
LCP: 2500,
|
|
254
254
|
// Good: ≤ 2.5s
|
|
255
255
|
FCP: 1800,
|
|
@@ -285,8 +285,8 @@ const Ft = () => {
|
|
|
285
285
|
TTFB: 1800,
|
|
286
286
|
// Poor: > 1800ms
|
|
287
287
|
LONG_TASK: 50
|
|
288
|
-
}, _e = "needs-improvement", Ke = (
|
|
289
|
-
switch (
|
|
288
|
+
}, _e = "needs-improvement", Ke = (r = _e) => {
|
|
289
|
+
switch (r) {
|
|
290
290
|
case "all":
|
|
291
291
|
return { LCP: 0, FCP: 0, CLS: 0, INP: 0, TTFB: 0, LONG_TASK: 0 };
|
|
292
292
|
// Track everything
|
|
@@ -297,41 +297,41 @@ const Ft = () => {
|
|
|
297
297
|
default:
|
|
298
298
|
return Qe;
|
|
299
299
|
}
|
|
300
|
-
}, Kt = 1e3, Yt = 50, qt = "2.7.
|
|
300
|
+
}, Kt = 1e3, Yt = 50, qt = "2.7.3", Jt = qt, ct = () => typeof window < "u" && typeof sessionStorage < "u", Zt = () => {
|
|
301
301
|
try {
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
const e =
|
|
302
|
+
const r = new URLSearchParams(window.location.search);
|
|
303
|
+
r.delete(rt);
|
|
304
|
+
const e = r.toString(), t = window.location.pathname + (e ? "?" + e : "") + window.location.hash;
|
|
305
305
|
window.history.replaceState({}, "", t);
|
|
306
306
|
} catch {
|
|
307
307
|
}
|
|
308
|
-
},
|
|
308
|
+
}, es = () => {
|
|
309
309
|
if (!ct())
|
|
310
310
|
return !1;
|
|
311
311
|
try {
|
|
312
|
-
const e = new URLSearchParams(window.location.search).get(
|
|
313
|
-
let
|
|
314
|
-
return e === Ue ? (
|
|
312
|
+
const e = new URLSearchParams(window.location.search).get(rt), t = sessionStorage.getItem(G);
|
|
313
|
+
let s = null;
|
|
314
|
+
return e === Ue ? (s = !0, sessionStorage.setItem(G, "true"), a("info", "QA Mode ACTIVE", {
|
|
315
315
|
visibility: "qa",
|
|
316
316
|
style: nt
|
|
317
|
-
})) : e === He && (
|
|
317
|
+
})) : e === He && (s = !1, sessionStorage.setItem(G, "false"), a("info", "QA Mode DISABLED", {
|
|
318
318
|
visibility: "qa",
|
|
319
319
|
style: it
|
|
320
|
-
})), (e === Ue || e === He) && Zt(),
|
|
320
|
+
})), (e === Ue || e === He) && Zt(), s ?? t === "true";
|
|
321
321
|
} catch {
|
|
322
322
|
return !1;
|
|
323
323
|
}
|
|
324
|
-
},
|
|
324
|
+
}, ts = (r) => {
|
|
325
325
|
if (ct())
|
|
326
326
|
try {
|
|
327
|
-
sessionStorage.setItem(G,
|
|
327
|
+
sessionStorage.setItem(G, r ? "true" : "false"), a("info", r ? "QA Mode ACTIVE" : "QA Mode DISABLED", {
|
|
328
328
|
visibility: "qa",
|
|
329
|
-
style:
|
|
329
|
+
style: r ? nt : it
|
|
330
330
|
});
|
|
331
331
|
} catch {
|
|
332
332
|
a("debug", "Cannot set QA mode: sessionStorage unavailable");
|
|
333
333
|
}
|
|
334
|
-
},
|
|
334
|
+
}, ss = [
|
|
335
335
|
"co.uk",
|
|
336
336
|
"org.uk",
|
|
337
337
|
"com.au",
|
|
@@ -343,57 +343,57 @@ const Ft = () => {
|
|
|
343
343
|
"co.in",
|
|
344
344
|
"com.cn",
|
|
345
345
|
"co.za"
|
|
346
|
-
], Ye = (
|
|
347
|
-
const e =
|
|
346
|
+
], Ye = (r) => {
|
|
347
|
+
const e = r.toLowerCase().split(".");
|
|
348
348
|
if (e.length <= 2)
|
|
349
|
-
return
|
|
349
|
+
return r.toLowerCase();
|
|
350
350
|
const t = e.slice(-2).join(".");
|
|
351
|
-
return
|
|
352
|
-
},
|
|
353
|
-
const
|
|
354
|
-
if (!
|
|
351
|
+
return ss.includes(t) ? e.slice(-3).join(".") : e.slice(-2).join(".");
|
|
352
|
+
}, rs = (r, e) => r === e ? !0 : Ye(r) === Ye(e), me = () => {
|
|
353
|
+
const r = document.referrer;
|
|
354
|
+
if (!r)
|
|
355
355
|
return "Direct";
|
|
356
356
|
try {
|
|
357
|
-
const e = new URL(
|
|
358
|
-
return
|
|
357
|
+
const e = new URL(r).hostname.toLowerCase(), t = window.location.hostname.toLowerCase();
|
|
358
|
+
return rs(e, t) ? "Direct" : r;
|
|
359
359
|
} catch (e) {
|
|
360
|
-
return a("debug", "Failed to parse referrer URL, using raw value", { error: e, data: { referrer:
|
|
360
|
+
return a("debug", "Failed to parse referrer URL, using raw value", { error: e, data: { referrer: r } }), r;
|
|
361
361
|
}
|
|
362
|
-
},
|
|
363
|
-
const
|
|
364
|
-
return At.forEach((
|
|
365
|
-
const n =
|
|
362
|
+
}, ge = () => {
|
|
363
|
+
const r = new URLSearchParams(window.location.search), e = {};
|
|
364
|
+
return At.forEach((s) => {
|
|
365
|
+
const n = r.get(s);
|
|
366
366
|
if (n) {
|
|
367
|
-
const i =
|
|
367
|
+
const i = s.split("utm_")[1];
|
|
368
368
|
e[i] = n;
|
|
369
369
|
}
|
|
370
370
|
}), Object.keys(e).length ? e : void 0;
|
|
371
|
-
}, ut = () => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (
|
|
371
|
+
}, ut = () => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (r) => {
|
|
372
372
|
const e = Math.random() * 16 | 0;
|
|
373
|
-
return (
|
|
373
|
+
return (r === "x" ? e : e & 3 | 8).toString(16);
|
|
374
374
|
});
|
|
375
375
|
let q = 0, J = 0;
|
|
376
|
-
const
|
|
377
|
-
let
|
|
378
|
-
|
|
376
|
+
const ns = () => {
|
|
377
|
+
let r = Date.now();
|
|
378
|
+
r < J && (r = J), r === J ? q = (q + 1) % 1e3 : q = 0, J = r;
|
|
379
379
|
const e = q.toString().padStart(3, "0");
|
|
380
380
|
let t = "";
|
|
381
381
|
try {
|
|
382
382
|
if (typeof crypto < "u" && crypto.getRandomValues) {
|
|
383
|
-
const
|
|
384
|
-
|
|
383
|
+
const s = crypto.getRandomValues(new Uint8Array(3));
|
|
384
|
+
s && (t = Array.from(s, (n) => n.toString(16).padStart(2, "0")).join(""));
|
|
385
385
|
}
|
|
386
386
|
} catch {
|
|
387
387
|
}
|
|
388
|
-
return t || (t = Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")), `${
|
|
389
|
-
}, dt = (
|
|
388
|
+
return t || (t = Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")), `${r}-${e}-${t}`;
|
|
389
|
+
}, dt = (r, e = !1) => {
|
|
390
390
|
try {
|
|
391
|
-
const t = new URL(
|
|
392
|
-
return
|
|
391
|
+
const t = new URL(r), s = t.protocol === "https:", n = t.protocol === "http:";
|
|
392
|
+
return s || e && n;
|
|
393
393
|
} catch {
|
|
394
394
|
return !1;
|
|
395
395
|
}
|
|
396
|
-
},
|
|
396
|
+
}, is = (r) => {
|
|
397
397
|
try {
|
|
398
398
|
const t = new URL(window.location.href).hostname;
|
|
399
399
|
if (!t || typeof t != "string")
|
|
@@ -402,50 +402,50 @@ const nr = () => {
|
|
|
402
402
|
throw new Error(
|
|
403
403
|
"SaaS integration not supported on localhost or IP addresses. Use custom backend integration instead."
|
|
404
404
|
);
|
|
405
|
-
const
|
|
406
|
-
if (!
|
|
405
|
+
const s = t.split(".");
|
|
406
|
+
if (!s || !Array.isArray(s) || s.length === 0 || s.length === 1 && s[0] === "")
|
|
407
407
|
throw new Error("Invalid hostname structure");
|
|
408
|
-
if (
|
|
408
|
+
if (s.length === 1)
|
|
409
409
|
throw new Error("Single-part domain not supported for SaaS integration");
|
|
410
410
|
let n;
|
|
411
|
-
if (
|
|
411
|
+
if (s.length === 2 ? n = s.join(".") : n = s.slice(-2).join("."), !n || n.split(".").length < 2)
|
|
412
412
|
throw new Error("Invalid domain structure for SaaS");
|
|
413
|
-
const i = `https://${
|
|
413
|
+
const i = `https://${r}.${n}/collect`;
|
|
414
414
|
if (!dt(i))
|
|
415
415
|
throw new Error("Generated URL failed validation");
|
|
416
416
|
return i;
|
|
417
417
|
} catch (e) {
|
|
418
418
|
throw new Error(`Invalid SaaS URL configuration: ${e instanceof Error ? e.message : String(e)}`);
|
|
419
419
|
}
|
|
420
|
-
},
|
|
420
|
+
}, os = (r) => {
|
|
421
421
|
const e = {};
|
|
422
|
-
|
|
423
|
-
const t =
|
|
422
|
+
r.integrations?.tracelog?.projectId && (e.saas = is(r.integrations.tracelog.projectId));
|
|
423
|
+
const t = r.integrations?.custom?.collectApiUrl;
|
|
424
424
|
if (t) {
|
|
425
|
-
const
|
|
426
|
-
if (!dt(t,
|
|
425
|
+
const s = r.integrations?.custom?.allowHttp ?? !1;
|
|
426
|
+
if (!dt(t, s))
|
|
427
427
|
throw new Error("Invalid custom API URL");
|
|
428
428
|
e.custom = t;
|
|
429
429
|
}
|
|
430
430
|
return e;
|
|
431
|
-
}, ye = (
|
|
432
|
-
if (!
|
|
433
|
-
return a("warn", "Invalid URL provided to normalizeUrl", { data: { type: typeof
|
|
431
|
+
}, ye = (r, e = []) => {
|
|
432
|
+
if (!r || typeof r != "string")
|
|
433
|
+
return a("warn", "Invalid URL provided to normalizeUrl", { data: { type: typeof r } }), r || "";
|
|
434
434
|
try {
|
|
435
|
-
const t = new URL(
|
|
435
|
+
const t = new URL(r), s = t.searchParams, n = [.../* @__PURE__ */ new Set([...Lt, ...e])];
|
|
436
436
|
let i = !1;
|
|
437
437
|
const o = [];
|
|
438
438
|
return n.forEach((c) => {
|
|
439
|
-
|
|
440
|
-
}), !i &&
|
|
439
|
+
s.has(c) && (s.delete(c), i = !0, o.push(c));
|
|
440
|
+
}), !i && r.includes("?") ? r : (t.search = s.toString(), t.toString());
|
|
441
441
|
} catch (t) {
|
|
442
|
-
return a("warn", "URL normalization failed, returning original", { error: t, data: { urlLength:
|
|
442
|
+
return a("warn", "URL normalization failed, returning original", { error: t, data: { urlLength: r?.length } }), r;
|
|
443
443
|
}
|
|
444
|
-
}, qe = (
|
|
445
|
-
if (!
|
|
444
|
+
}, qe = (r) => {
|
|
445
|
+
if (!r || typeof r != "string" || r.trim().length === 0)
|
|
446
446
|
return "";
|
|
447
|
-
let e =
|
|
448
|
-
|
|
447
|
+
let e = r;
|
|
448
|
+
r.length > 1e3 && (e = r.slice(0, Math.max(0, 1e3)));
|
|
449
449
|
let t = 0;
|
|
450
450
|
for (const n of Mt) {
|
|
451
451
|
const i = e;
|
|
@@ -454,24 +454,24 @@ const nr = () => {
|
|
|
454
454
|
return t > 0 && a("warn", "XSS patterns detected and removed", {
|
|
455
455
|
data: {
|
|
456
456
|
patternMatches: t,
|
|
457
|
-
valueLength:
|
|
457
|
+
valueLength: r.length
|
|
458
458
|
}
|
|
459
459
|
}), e.trim();
|
|
460
|
-
}, we = (
|
|
461
|
-
if (
|
|
460
|
+
}, we = (r, e = 0) => {
|
|
461
|
+
if (r == null)
|
|
462
462
|
return null;
|
|
463
|
-
if (typeof
|
|
464
|
-
return qe(
|
|
465
|
-
if (typeof
|
|
466
|
-
return !Number.isFinite(
|
|
467
|
-
if (typeof
|
|
468
|
-
return
|
|
463
|
+
if (typeof r == "string")
|
|
464
|
+
return qe(r);
|
|
465
|
+
if (typeof r == "number")
|
|
466
|
+
return !Number.isFinite(r) || r < -Number.MAX_SAFE_INTEGER || r > Number.MAX_SAFE_INTEGER ? 0 : r;
|
|
467
|
+
if (typeof r == "boolean")
|
|
468
|
+
return r;
|
|
469
469
|
if (e > 10)
|
|
470
470
|
return null;
|
|
471
|
-
if (Array.isArray(
|
|
472
|
-
return
|
|
473
|
-
if (typeof
|
|
474
|
-
const t = {}, n = Object.entries(
|
|
471
|
+
if (Array.isArray(r))
|
|
472
|
+
return r.slice(0, 1e3).map((n) => we(n, e + 1)).filter((n) => n !== null);
|
|
473
|
+
if (typeof r == "object") {
|
|
474
|
+
const t = {}, n = Object.entries(r).slice(0, 200);
|
|
475
475
|
for (const [i, o] of n) {
|
|
476
476
|
const l = qe(i);
|
|
477
477
|
if (l) {
|
|
@@ -482,151 +482,153 @@ const nr = () => {
|
|
|
482
482
|
return t;
|
|
483
483
|
}
|
|
484
484
|
return null;
|
|
485
|
-
},
|
|
486
|
-
if (typeof
|
|
485
|
+
}, as = (r) => {
|
|
486
|
+
if (typeof r != "object" || r === null)
|
|
487
487
|
return {};
|
|
488
488
|
try {
|
|
489
|
-
const e = we(
|
|
489
|
+
const e = we(r);
|
|
490
490
|
return typeof e == "object" && e !== null ? e : {};
|
|
491
491
|
} catch (e) {
|
|
492
492
|
const t = e instanceof Error ? e.message : String(e);
|
|
493
493
|
throw new Error(`[TraceLog] Metadata sanitization failed: ${t}`);
|
|
494
494
|
}
|
|
495
|
-
},
|
|
496
|
-
if (
|
|
495
|
+
}, ls = (r) => {
|
|
496
|
+
if (r !== void 0 && (r === null || typeof r != "object"))
|
|
497
497
|
throw new f("Configuration must be an object", "config");
|
|
498
|
-
if (
|
|
499
|
-
if (
|
|
498
|
+
if (r) {
|
|
499
|
+
if (r.sessionTimeout !== void 0 && (typeof r.sessionTimeout != "number" || r.sessionTimeout < 3e4 || r.sessionTimeout > 864e5))
|
|
500
500
|
throw new Ot(m.INVALID_SESSION_TIMEOUT, "config");
|
|
501
|
-
if (
|
|
501
|
+
if (r.globalMetadata !== void 0 && (typeof r.globalMetadata != "object" || r.globalMetadata === null))
|
|
502
502
|
throw new f(m.INVALID_GLOBAL_METADATA, "config");
|
|
503
|
-
if (
|
|
504
|
-
if (!Array.isArray(
|
|
503
|
+
if (r.integrations && us(r.integrations), r.sensitiveQueryParams !== void 0) {
|
|
504
|
+
if (!Array.isArray(r.sensitiveQueryParams))
|
|
505
505
|
throw new f(m.INVALID_SENSITIVE_QUERY_PARAMS, "config");
|
|
506
|
-
for (const e of
|
|
506
|
+
for (const e of r.sensitiveQueryParams)
|
|
507
507
|
if (typeof e != "string")
|
|
508
508
|
throw new f("All sensitive query params must be strings", "config");
|
|
509
509
|
}
|
|
510
|
-
if (
|
|
510
|
+
if (r.errorSampling !== void 0 && (typeof r.errorSampling != "number" || r.errorSampling < 0 || r.errorSampling > 1))
|
|
511
511
|
throw new We(m.INVALID_ERROR_SAMPLING_RATE, "config");
|
|
512
|
-
if (
|
|
512
|
+
if (r.samplingRate !== void 0 && (typeof r.samplingRate != "number" || r.samplingRate < 0 || r.samplingRate > 1))
|
|
513
513
|
throw new We(m.INVALID_SAMPLING_RATE, "config");
|
|
514
|
-
if (
|
|
515
|
-
if (typeof
|
|
514
|
+
if (r.primaryScrollSelector !== void 0) {
|
|
515
|
+
if (typeof r.primaryScrollSelector != "string" || !r.primaryScrollSelector.trim())
|
|
516
516
|
throw new f(m.INVALID_PRIMARY_SCROLL_SELECTOR, "config");
|
|
517
|
-
if (
|
|
517
|
+
if (r.primaryScrollSelector !== "window")
|
|
518
518
|
try {
|
|
519
|
-
document.querySelector(
|
|
519
|
+
document.querySelector(r.primaryScrollSelector);
|
|
520
520
|
} catch {
|
|
521
521
|
throw new f(
|
|
522
|
-
`${m.INVALID_PRIMARY_SCROLL_SELECTOR_SYNTAX}: "${
|
|
522
|
+
`${m.INVALID_PRIMARY_SCROLL_SELECTOR_SYNTAX}: "${r.primaryScrollSelector}"`,
|
|
523
523
|
"config"
|
|
524
524
|
);
|
|
525
525
|
}
|
|
526
526
|
}
|
|
527
|
-
if (
|
|
527
|
+
if (r.pageViewThrottleMs !== void 0 && (typeof r.pageViewThrottleMs != "number" || r.pageViewThrottleMs < 0))
|
|
528
528
|
throw new f(m.INVALID_PAGE_VIEW_THROTTLE, "config");
|
|
529
|
-
if (
|
|
529
|
+
if (r.clickThrottleMs !== void 0 && (typeof r.clickThrottleMs != "number" || r.clickThrottleMs < 0))
|
|
530
530
|
throw new f(m.INVALID_CLICK_THROTTLE, "config");
|
|
531
|
-
if (
|
|
531
|
+
if (r.maxSameEventPerMinute !== void 0 && (typeof r.maxSameEventPerMinute != "number" || r.maxSameEventPerMinute <= 0))
|
|
532
532
|
throw new f(m.INVALID_MAX_SAME_EVENT_PER_MINUTE, "config");
|
|
533
|
-
if (
|
|
533
|
+
if (r.sendIntervalMs !== void 0 && (!Number.isFinite(r.sendIntervalMs) || r.sendIntervalMs < 1e3 || r.sendIntervalMs > 6e4))
|
|
534
534
|
throw new f(m.INVALID_SEND_INTERVAL, "config");
|
|
535
|
-
if (
|
|
536
|
-
if (typeof
|
|
535
|
+
if (r.viewport !== void 0 && cs(r.viewport), r.webVitalsMode !== void 0) {
|
|
536
|
+
if (typeof r.webVitalsMode != "string")
|
|
537
537
|
throw new f(
|
|
538
|
-
`Invalid webVitalsMode type: ${typeof
|
|
538
|
+
`Invalid webVitalsMode type: ${typeof r.webVitalsMode}. Must be a string`,
|
|
539
539
|
"config"
|
|
540
540
|
);
|
|
541
541
|
const e = ["all", "needs-improvement", "poor"];
|
|
542
|
-
if (!e.includes(
|
|
542
|
+
if (!e.includes(r.webVitalsMode))
|
|
543
543
|
throw new f(
|
|
544
|
-
`Invalid webVitalsMode: "${
|
|
544
|
+
`Invalid webVitalsMode: "${r.webVitalsMode}". Must be one of: ${e.join(", ")}`,
|
|
545
545
|
"config"
|
|
546
546
|
);
|
|
547
547
|
}
|
|
548
|
-
if (
|
|
549
|
-
if (typeof
|
|
548
|
+
if (r.webVitalsThresholds !== void 0) {
|
|
549
|
+
if (typeof r.webVitalsThresholds != "object" || r.webVitalsThresholds === null || Array.isArray(r.webVitalsThresholds))
|
|
550
550
|
throw new f("webVitalsThresholds must be an object", "config");
|
|
551
551
|
const e = ["LCP", "FCP", "CLS", "INP", "TTFB", "LONG_TASK"];
|
|
552
|
-
for (const [t,
|
|
552
|
+
for (const [t, s] of Object.entries(r.webVitalsThresholds)) {
|
|
553
553
|
if (!e.includes(t))
|
|
554
554
|
throw new f(
|
|
555
555
|
`Invalid Web Vitals threshold key: "${t}". Must be one of: ${e.join(", ")}`,
|
|
556
556
|
"config"
|
|
557
557
|
);
|
|
558
|
-
if (typeof
|
|
558
|
+
if (typeof s != "number" || !Number.isFinite(s) || s < 0)
|
|
559
559
|
throw new f(
|
|
560
|
-
`Invalid Web Vitals threshold value for ${t}: ${
|
|
560
|
+
`Invalid Web Vitals threshold value for ${t}: ${s}. Must be a non-negative finite number`,
|
|
561
561
|
"config"
|
|
562
562
|
);
|
|
563
563
|
}
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
|
-
},
|
|
567
|
-
if (typeof
|
|
566
|
+
}, cs = (r) => {
|
|
567
|
+
if (typeof r != "object" || r === null)
|
|
568
568
|
throw new f(m.INVALID_VIEWPORT_CONFIG, "config");
|
|
569
|
-
if (!
|
|
569
|
+
if (!r.elements || !Array.isArray(r.elements))
|
|
570
570
|
throw new f(m.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
571
|
-
if (
|
|
571
|
+
if (r.elements.length === 0)
|
|
572
572
|
throw new f(m.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
573
573
|
const e = /* @__PURE__ */ new Set();
|
|
574
|
-
for (const t of
|
|
574
|
+
for (const t of r.elements) {
|
|
575
575
|
if (!t.selector || typeof t.selector != "string" || !t.selector.trim())
|
|
576
576
|
throw new f(m.INVALID_VIEWPORT_ELEMENT, "config");
|
|
577
|
-
const
|
|
578
|
-
if (e.has(
|
|
577
|
+
const s = t.selector.trim();
|
|
578
|
+
if (e.has(s))
|
|
579
579
|
throw new f(
|
|
580
|
-
`Duplicate viewport selector found: "${
|
|
580
|
+
`Duplicate viewport selector found: "${s}". Each selector should appear only once.`,
|
|
581
581
|
"config"
|
|
582
582
|
);
|
|
583
|
-
if (e.add(
|
|
583
|
+
if (e.add(s), t.id !== void 0 && (typeof t.id != "string" || !t.id.trim()))
|
|
584
584
|
throw new f(m.INVALID_VIEWPORT_ELEMENT_ID, "config");
|
|
585
585
|
if (t.name !== void 0 && (typeof t.name != "string" || !t.name.trim()))
|
|
586
586
|
throw new f(m.INVALID_VIEWPORT_ELEMENT_NAME, "config");
|
|
587
587
|
}
|
|
588
|
-
if (
|
|
588
|
+
if (r.threshold !== void 0 && (typeof r.threshold != "number" || r.threshold < 0 || r.threshold > 1))
|
|
589
589
|
throw new f(m.INVALID_VIEWPORT_THRESHOLD, "config");
|
|
590
|
-
if (
|
|
590
|
+
if (r.minDwellTime !== void 0 && (typeof r.minDwellTime != "number" || r.minDwellTime < 0))
|
|
591
591
|
throw new f(m.INVALID_VIEWPORT_MIN_DWELL_TIME, "config");
|
|
592
|
-
if (
|
|
592
|
+
if (r.cooldownPeriod !== void 0 && (typeof r.cooldownPeriod != "number" || r.cooldownPeriod < 0))
|
|
593
593
|
throw new f(m.INVALID_VIEWPORT_COOLDOWN_PERIOD, "config");
|
|
594
|
-
if (
|
|
594
|
+
if (r.maxTrackedElements !== void 0 && (typeof r.maxTrackedElements != "number" || r.maxTrackedElements <= 0))
|
|
595
595
|
throw new f(m.INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS, "config");
|
|
596
|
-
},
|
|
597
|
-
if (
|
|
598
|
-
if (
|
|
599
|
-
throw new
|
|
600
|
-
if (
|
|
601
|
-
if (!
|
|
602
|
-
throw new
|
|
603
|
-
if (
|
|
604
|
-
throw new
|
|
605
|
-
const e =
|
|
596
|
+
}, us = (r) => {
|
|
597
|
+
if (r) {
|
|
598
|
+
if (r.tracelog && (!r.tracelog.projectId || typeof r.tracelog.projectId != "string" || r.tracelog.projectId.trim() === ""))
|
|
599
|
+
throw new N(m.INVALID_TRACELOG_PROJECT_ID, "config");
|
|
600
|
+
if (r.custom) {
|
|
601
|
+
if (!r.custom.collectApiUrl || typeof r.custom.collectApiUrl != "string" || r.custom.collectApiUrl.trim() === "")
|
|
602
|
+
throw new N(m.INVALID_CUSTOM_API_URL, "config");
|
|
603
|
+
if (r.custom.allowHttp !== void 0 && typeof r.custom.allowHttp != "boolean")
|
|
604
|
+
throw new N("allowHttp must be a boolean", "config");
|
|
605
|
+
const e = r.custom.collectApiUrl.trim();
|
|
606
606
|
if (!e.startsWith("http://") && !e.startsWith("https://"))
|
|
607
|
-
throw new
|
|
608
|
-
if (!(
|
|
609
|
-
throw new
|
|
607
|
+
throw new N('Custom API URL must start with "http://" or "https://"', "config");
|
|
608
|
+
if (!(r.custom.allowHttp ?? !1) && e.startsWith("http://"))
|
|
609
|
+
throw new N(
|
|
610
610
|
"Custom API URL must use HTTPS in production. Set allowHttp: true in integration config to allow HTTP (not recommended)",
|
|
611
611
|
"config"
|
|
612
612
|
);
|
|
613
|
-
if (
|
|
614
|
-
throw new
|
|
613
|
+
if (r.custom.fetchCredentials !== void 0 && !["include", "same-origin", "omit"].includes(r.custom.fetchCredentials))
|
|
614
|
+
throw new N('fetchCredentials must be "include", "same-origin", or "omit"', "config");
|
|
615
615
|
}
|
|
616
|
+
if (r.tracelog?.shopify !== void 0 && typeof r.tracelog.shopify != "boolean")
|
|
617
|
+
throw new N("tracelog.shopify must be a boolean", "config");
|
|
616
618
|
}
|
|
617
|
-
},
|
|
618
|
-
|
|
619
|
+
}, ds = (r) => {
|
|
620
|
+
ls(r);
|
|
619
621
|
const e = {
|
|
620
|
-
...
|
|
621
|
-
sessionTimeout:
|
|
622
|
-
globalMetadata:
|
|
623
|
-
sensitiveQueryParams:
|
|
624
|
-
errorSampling:
|
|
625
|
-
samplingRate:
|
|
626
|
-
pageViewThrottleMs:
|
|
627
|
-
clickThrottleMs:
|
|
628
|
-
maxSameEventPerMinute:
|
|
629
|
-
sendIntervalMs:
|
|
622
|
+
...r ?? {},
|
|
623
|
+
sessionTimeout: r?.sessionTimeout ?? 9e5,
|
|
624
|
+
globalMetadata: r?.globalMetadata ?? {},
|
|
625
|
+
sensitiveQueryParams: r?.sensitiveQueryParams ?? [],
|
|
626
|
+
errorSampling: r?.errorSampling ?? lt,
|
|
627
|
+
samplingRate: r?.samplingRate ?? 1,
|
|
628
|
+
pageViewThrottleMs: r?.pageViewThrottleMs ?? 1e3,
|
|
629
|
+
clickThrottleMs: r?.clickThrottleMs ?? 300,
|
|
630
|
+
maxSameEventPerMinute: r?.maxSameEventPerMinute ?? 60,
|
|
631
|
+
sendIntervalMs: r?.sendIntervalMs ?? 1e4
|
|
630
632
|
};
|
|
631
633
|
return e.integrations?.custom && (e.integrations.custom = {
|
|
632
634
|
...e.integrations.custom,
|
|
@@ -638,42 +640,42 @@ const nr = () => {
|
|
|
638
640
|
cooldownPeriod: e.viewport.cooldownPeriod ?? 6e4,
|
|
639
641
|
maxTrackedElements: e.viewport.maxTrackedElements ?? 100
|
|
640
642
|
}), e;
|
|
641
|
-
}, be = (
|
|
642
|
-
if (
|
|
643
|
+
}, be = (r, e = /* @__PURE__ */ new Set()) => {
|
|
644
|
+
if (r == null)
|
|
643
645
|
return !0;
|
|
644
|
-
const t = typeof
|
|
645
|
-
return t === "string" || t === "number" || t === "boolean" ? !0 : t === "function" || t === "symbol" || t === "bigint" || e.has(
|
|
646
|
-
},
|
|
647
|
-
if (typeof
|
|
646
|
+
const t = typeof r;
|
|
647
|
+
return t === "string" || t === "number" || t === "boolean" ? !0 : t === "function" || t === "symbol" || t === "bigint" || e.has(r) ? !1 : (e.add(r), Array.isArray(r) ? r.every((s) => be(s, e)) : t === "object" ? Object.values(r).every((s) => be(s, e)) : !1);
|
|
648
|
+
}, hs = (r) => typeof r != "object" || r === null ? !1 : be(r), ht = (r) => {
|
|
649
|
+
if (typeof r != "object" || r === null || Array.isArray(r)) return;
|
|
648
650
|
const e = {};
|
|
649
|
-
for (const [t,
|
|
650
|
-
typeof
|
|
651
|
+
for (const [t, s] of Object.entries(r))
|
|
652
|
+
typeof s == "string" && (e[t] = s);
|
|
651
653
|
return Object.keys(e).length > 0 ? e : void 0;
|
|
652
|
-
},
|
|
654
|
+
}, fs = (r) => typeof r != "string" ? {
|
|
653
655
|
valid: !1,
|
|
654
656
|
error: "Event name must be a string"
|
|
655
|
-
} :
|
|
657
|
+
} : r.length === 0 ? {
|
|
656
658
|
valid: !1,
|
|
657
659
|
error: "Event name cannot be empty"
|
|
658
|
-
} :
|
|
660
|
+
} : r.length > 120 ? {
|
|
659
661
|
valid: !1,
|
|
660
662
|
error: "Event name is too long (max 120 characters)"
|
|
661
|
-
} :
|
|
663
|
+
} : r.includes("<") || r.includes(">") || r.includes("&") ? {
|
|
662
664
|
valid: !1,
|
|
663
665
|
error: "Event name contains invalid characters"
|
|
664
|
-
} : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(
|
|
666
|
+
} : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(r.toLowerCase()) ? {
|
|
665
667
|
valid: !1,
|
|
666
668
|
error: "Event name cannot be a reserved word"
|
|
667
|
-
} : { valid: !0 }, Je = (
|
|
668
|
-
const
|
|
669
|
-
if (!
|
|
669
|
+
} : { valid: !0 }, Je = (r, e, t) => {
|
|
670
|
+
const s = as(e), n = t && t === "customEvent" ? `${t} "${r}" metadata error` : `${r} metadata error`;
|
|
671
|
+
if (!hs(s))
|
|
670
672
|
return {
|
|
671
673
|
valid: !1,
|
|
672
674
|
error: `${n}: object has invalid types. Valid types are string, number, boolean or string arrays.`
|
|
673
675
|
};
|
|
674
676
|
let i;
|
|
675
677
|
try {
|
|
676
|
-
i = JSON.stringify(
|
|
678
|
+
i = JSON.stringify(s);
|
|
677
679
|
} catch {
|
|
678
680
|
return {
|
|
679
681
|
valid: !1,
|
|
@@ -685,12 +687,12 @@ const nr = () => {
|
|
|
685
687
|
valid: !1,
|
|
686
688
|
error: `${n}: object is too large (max ${49152 / 1024} KB).`
|
|
687
689
|
};
|
|
688
|
-
if (Object.keys(
|
|
690
|
+
if (Object.keys(s).length > 100)
|
|
689
691
|
return {
|
|
690
692
|
valid: !1,
|
|
691
693
|
error: `${n}: object has too many keys (max 100 keys).`
|
|
692
694
|
};
|
|
693
|
-
for (const [c, u] of Object.entries(
|
|
695
|
+
for (const [c, u] of Object.entries(s)) {
|
|
694
696
|
if (Array.isArray(u)) {
|
|
695
697
|
if (u.length > 500)
|
|
696
698
|
return {
|
|
@@ -712,11 +714,11 @@ const nr = () => {
|
|
|
712
714
|
}
|
|
713
715
|
return {
|
|
714
716
|
valid: !0,
|
|
715
|
-
sanitizedMetadata:
|
|
717
|
+
sanitizedMetadata: s
|
|
716
718
|
};
|
|
717
|
-
}, ft = (
|
|
719
|
+
}, ft = (r, e, t) => {
|
|
718
720
|
if (Array.isArray(e)) {
|
|
719
|
-
const
|
|
721
|
+
const s = [], n = t && t === "customEvent" ? `${t} "${r}" metadata error` : `${r} metadata error`;
|
|
720
722
|
for (let i = 0; i < e.length; i++) {
|
|
721
723
|
const o = e[i];
|
|
722
724
|
if (typeof o != "object" || o === null || Array.isArray(o))
|
|
@@ -724,37 +726,37 @@ const nr = () => {
|
|
|
724
726
|
valid: !1,
|
|
725
727
|
error: `${n}: array item at index ${i} must be an object.`
|
|
726
728
|
};
|
|
727
|
-
const l = Je(
|
|
729
|
+
const l = Je(r, o, t);
|
|
728
730
|
if (!l.valid)
|
|
729
731
|
return {
|
|
730
732
|
valid: !1,
|
|
731
733
|
error: `${n}: array item at index ${i} is invalid: ${l.error}`
|
|
732
734
|
};
|
|
733
|
-
l.sanitizedMetadata &&
|
|
735
|
+
l.sanitizedMetadata && s.push(l.sanitizedMetadata);
|
|
734
736
|
}
|
|
735
737
|
return {
|
|
736
738
|
valid: !0,
|
|
737
|
-
sanitizedMetadata:
|
|
739
|
+
sanitizedMetadata: s
|
|
738
740
|
};
|
|
739
741
|
}
|
|
740
|
-
return Je(
|
|
741
|
-
},
|
|
742
|
-
const t =
|
|
742
|
+
return Je(r, e, t);
|
|
743
|
+
}, ms = (r, e) => {
|
|
744
|
+
const t = fs(r);
|
|
743
745
|
if (!t.valid)
|
|
744
746
|
return a("error", "Event name validation failed", {
|
|
745
|
-
data: { eventName:
|
|
747
|
+
data: { eventName: r, error: t.error }
|
|
746
748
|
}), t;
|
|
747
749
|
if (!e)
|
|
748
750
|
return { valid: !0 };
|
|
749
|
-
const
|
|
750
|
-
return
|
|
751
|
+
const s = ft(r, e, "customEvent");
|
|
752
|
+
return s.valid || a("error", "Event metadata validation failed", {
|
|
751
753
|
data: {
|
|
752
|
-
eventName:
|
|
753
|
-
error:
|
|
754
|
+
eventName: r,
|
|
755
|
+
error: s.error
|
|
754
756
|
}
|
|
755
|
-
}),
|
|
757
|
+
}), s;
|
|
756
758
|
};
|
|
757
|
-
class
|
|
759
|
+
class gs {
|
|
758
760
|
listeners = /* @__PURE__ */ new Map();
|
|
759
761
|
/**
|
|
760
762
|
* Subscribes to an event channel
|
|
@@ -805,10 +807,10 @@ class gr {
|
|
|
805
807
|
* ```
|
|
806
808
|
*/
|
|
807
809
|
off(e, t) {
|
|
808
|
-
const
|
|
809
|
-
if (
|
|
810
|
-
const n =
|
|
811
|
-
n > -1 &&
|
|
810
|
+
const s = this.listeners.get(e);
|
|
811
|
+
if (s) {
|
|
812
|
+
const n = s.indexOf(t);
|
|
813
|
+
n > -1 && s.splice(n, 1);
|
|
812
814
|
}
|
|
813
815
|
}
|
|
814
816
|
/**
|
|
@@ -840,8 +842,8 @@ class gr {
|
|
|
840
842
|
* ```
|
|
841
843
|
*/
|
|
842
844
|
emit(e, t) {
|
|
843
|
-
const
|
|
844
|
-
|
|
845
|
+
const s = this.listeners.get(e);
|
|
846
|
+
s && s.forEach((n) => {
|
|
845
847
|
n(t);
|
|
846
848
|
});
|
|
847
849
|
}
|
|
@@ -871,38 +873,38 @@ class gr {
|
|
|
871
873
|
this.listeners.clear();
|
|
872
874
|
}
|
|
873
875
|
}
|
|
874
|
-
function mt(
|
|
876
|
+
function mt(r, e, t) {
|
|
875
877
|
try {
|
|
876
|
-
const
|
|
877
|
-
return
|
|
878
|
-
} catch (
|
|
878
|
+
const s = e(r);
|
|
879
|
+
return s === null ? null : typeof s == "object" && s !== null && "type" in s ? s : (a("warn", `beforeSend transformer returned invalid data, using original [${t}]`), r);
|
|
880
|
+
} catch (s) {
|
|
879
881
|
return a("error", `beforeSend transformer threw error, using original event [${t}]`, {
|
|
880
|
-
error:
|
|
882
|
+
error: s,
|
|
881
883
|
visibility: "critical"
|
|
882
|
-
}),
|
|
884
|
+
}), r;
|
|
883
885
|
}
|
|
884
886
|
}
|
|
885
|
-
function
|
|
886
|
-
return
|
|
887
|
+
function Es(r, e, t) {
|
|
888
|
+
return r.map((s) => mt(s, e, t)).filter((s) => s !== null);
|
|
887
889
|
}
|
|
888
|
-
function gt(
|
|
890
|
+
function gt(r, e, t) {
|
|
889
891
|
try {
|
|
890
|
-
const
|
|
891
|
-
return
|
|
892
|
-
data: { eventCount:
|
|
893
|
-
}), null) : typeof
|
|
894
|
-
data: { eventCount:
|
|
895
|
-
}),
|
|
896
|
-
} catch (
|
|
892
|
+
const s = e(r);
|
|
893
|
+
return s === null ? (a("debug", `Batch filtered by beforeBatch transformer [${t}]`, {
|
|
894
|
+
data: { eventCount: r.events.length }
|
|
895
|
+
}), null) : typeof s == "object" && s !== null && Array.isArray(s.events) ? s : (a("warn", `beforeBatch transformer returned invalid data, using original [${t}]`, {
|
|
896
|
+
data: { eventCount: r.events.length }
|
|
897
|
+
}), r);
|
|
898
|
+
} catch (s) {
|
|
897
899
|
return a("error", `beforeBatch transformer threw error, using original batch [${t}]`, {
|
|
898
|
-
error:
|
|
899
|
-
data: { eventCount:
|
|
900
|
+
error: s,
|
|
901
|
+
data: { eventCount: r.events.length },
|
|
900
902
|
visibility: "critical"
|
|
901
|
-
}),
|
|
903
|
+
}), r;
|
|
902
904
|
}
|
|
903
905
|
}
|
|
904
|
-
const
|
|
905
|
-
class
|
|
906
|
+
const Ee = { config: {} };
|
|
907
|
+
class _ {
|
|
906
908
|
/**
|
|
907
909
|
* Retrieves a value from global state.
|
|
908
910
|
*
|
|
@@ -920,7 +922,7 @@ class w {
|
|
|
920
922
|
* ```
|
|
921
923
|
*/
|
|
922
924
|
get(e) {
|
|
923
|
-
return
|
|
925
|
+
return Ee[e];
|
|
924
926
|
}
|
|
925
927
|
/**
|
|
926
928
|
* Sets a value in global state.
|
|
@@ -940,7 +942,7 @@ class w {
|
|
|
940
942
|
* ```
|
|
941
943
|
*/
|
|
942
944
|
set(e, t) {
|
|
943
|
-
|
|
945
|
+
Ee[e] = t;
|
|
944
946
|
}
|
|
945
947
|
/**
|
|
946
948
|
* Returns an immutable snapshot of the entire global state.
|
|
@@ -957,10 +959,10 @@ class w {
|
|
|
957
959
|
* ```
|
|
958
960
|
*/
|
|
959
961
|
getState() {
|
|
960
|
-
return { ...
|
|
962
|
+
return { ...Ee };
|
|
961
963
|
}
|
|
962
964
|
}
|
|
963
|
-
class Ze extends
|
|
965
|
+
class Ze extends _ {
|
|
964
966
|
storeManager;
|
|
965
967
|
integrationId;
|
|
966
968
|
apiUrl;
|
|
@@ -995,10 +997,10 @@ class Ze extends w {
|
|
|
995
997
|
* @param customHeadersProvider - Optional callback for dynamic headers
|
|
996
998
|
* @throws Error if integrationId and apiUrl are not both provided or both undefined
|
|
997
999
|
*/
|
|
998
|
-
constructor(e, t,
|
|
999
|
-
if (super(), t && !
|
|
1000
|
+
constructor(e, t, s, n = {}, i = {}, o, l = "include") {
|
|
1001
|
+
if (super(), t && !s || !t && s)
|
|
1000
1002
|
throw new Error("SenderManager: integrationId and apiUrl must either both be provided or both be undefined");
|
|
1001
|
-
this.storeManager = e, this.integrationId = t, this.apiUrl =
|
|
1003
|
+
this.storeManager = e, this.integrationId = t, this.apiUrl = s, this.transformers = n, this.staticHeaders = i, this.customHeadersProvider = o, this.fetchCredentials = l;
|
|
1002
1004
|
}
|
|
1003
1005
|
/**
|
|
1004
1006
|
* Get the integration ID for this sender
|
|
@@ -1133,10 +1135,10 @@ class Ze extends w {
|
|
|
1133
1135
|
*/
|
|
1134
1136
|
async sendEventsQueue(e, t) {
|
|
1135
1137
|
try {
|
|
1136
|
-
const
|
|
1137
|
-
return
|
|
1138
|
-
} catch (
|
|
1139
|
-
return
|
|
1138
|
+
const s = await this.send(e);
|
|
1139
|
+
return s ? (this.clearPersistedEvents(), t?.onSuccess?.(e.events.length, e.events, e)) : (this.persistEvents(e), t?.onFailure?.()), s;
|
|
1140
|
+
} catch (s) {
|
|
1141
|
+
return s instanceof O ? (this.logPermanentError("Permanent error, not retrying", s), this.clearPersistedEvents(), t?.onFailure?.(), !1) : s instanceof P ? (a(
|
|
1140
1142
|
"debug",
|
|
1141
1143
|
`All attempts timed out, skipping persistence (server likely received events)${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1142
1144
|
), this.clearPersistedEvents(), t?.onFailure?.(), !1) : (this.persistEvents(e), t?.onFailure?.(), !1);
|
|
@@ -1203,7 +1205,7 @@ class Ze extends w {
|
|
|
1203
1205
|
this.clearPersistedEvents();
|
|
1204
1206
|
return;
|
|
1205
1207
|
}
|
|
1206
|
-
const
|
|
1208
|
+
const s = t.recoveryFailures, n = typeof s == "number" && Number.isFinite(s) && s >= 0 ? s : 0;
|
|
1207
1209
|
if (n >= 3) {
|
|
1208
1210
|
a(
|
|
1209
1211
|
"debug",
|
|
@@ -1214,11 +1216,11 @@ class Ze extends w {
|
|
|
1214
1216
|
const i = this.createRecoveryBody(t);
|
|
1215
1217
|
await this.send(i) ? (this.clearPersistedEvents(), e?.onSuccess?.(t.events.length, t.events, i)) : (this.persistEventsWithFailureCount(i, n + 1, !0), e?.onFailure?.());
|
|
1216
1218
|
} catch (t) {
|
|
1217
|
-
if (t instanceof
|
|
1219
|
+
if (t instanceof O) {
|
|
1218
1220
|
this.logPermanentError("Permanent error during recovery, clearing persisted events", t), this.clearPersistedEvents(), e?.onFailure?.();
|
|
1219
1221
|
return;
|
|
1220
1222
|
}
|
|
1221
|
-
if (t instanceof
|
|
1223
|
+
if (t instanceof P) {
|
|
1222
1224
|
a(
|
|
1223
1225
|
"debug",
|
|
1224
1226
|
`Recovery timed out, clearing persisted events (server likely received them)${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
@@ -1275,14 +1277,14 @@ class Ze extends w {
|
|
|
1275
1277
|
const t = this.transformers.beforeSend;
|
|
1276
1278
|
if (!t)
|
|
1277
1279
|
return e;
|
|
1278
|
-
const
|
|
1280
|
+
const s = Es(
|
|
1279
1281
|
e.events,
|
|
1280
1282
|
t,
|
|
1281
1283
|
this.integrationId || "SenderManager"
|
|
1282
1284
|
);
|
|
1283
|
-
return
|
|
1285
|
+
return s.length === 0 ? null : {
|
|
1284
1286
|
...e,
|
|
1285
|
-
events:
|
|
1287
|
+
events: s
|
|
1286
1288
|
};
|
|
1287
1289
|
}
|
|
1288
1290
|
/**
|
|
@@ -1342,7 +1344,7 @@ class Ze extends w {
|
|
|
1342
1344
|
* @returns Promise that resolves after calculated delay
|
|
1343
1345
|
*/
|
|
1344
1346
|
async backoffDelay(e) {
|
|
1345
|
-
const t = 100 * Math.pow(2, e),
|
|
1347
|
+
const t = 100 * Math.pow(2, e), s = Math.random() * 100, n = t + s;
|
|
1346
1348
|
return new Promise((i) => setTimeout(i, n));
|
|
1347
1349
|
}
|
|
1348
1350
|
/**
|
|
@@ -1386,16 +1388,16 @@ class Ze extends w {
|
|
|
1386
1388
|
const t = this.applyBeforeSendTransformer(e);
|
|
1387
1389
|
if (!t)
|
|
1388
1390
|
return !0;
|
|
1389
|
-
const
|
|
1390
|
-
if (!
|
|
1391
|
+
const s = this.applyBeforeBatchTransformer(t);
|
|
1392
|
+
if (!s)
|
|
1391
1393
|
return !0;
|
|
1392
1394
|
if (this.apiUrl?.includes(B.Fail))
|
|
1393
1395
|
return a("debug", `Fail mode: simulating network failure${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1394
|
-
data: { events:
|
|
1396
|
+
data: { events: s.events.length }
|
|
1395
1397
|
}), !1;
|
|
1396
1398
|
if (this.apiUrl?.includes(B.Localhost))
|
|
1397
1399
|
return a("debug", `Success mode: simulating successful send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1398
|
-
data: { events:
|
|
1400
|
+
data: { events: s.events.length }
|
|
1399
1401
|
}), !0;
|
|
1400
1402
|
if (this.consecutiveNetworkFailures >= 3) {
|
|
1401
1403
|
const c = Date.now() - this.circuitOpenedAt;
|
|
@@ -1407,7 +1409,7 @@ class Ze extends w {
|
|
|
1407
1409
|
}
|
|
1408
1410
|
}), !1;
|
|
1409
1411
|
}
|
|
1410
|
-
const { url: n, payload: i } = this.prepareRequest(
|
|
1412
|
+
const { url: n, payload: i } = this.prepareRequest(s);
|
|
1411
1413
|
let o = !0, l = !1;
|
|
1412
1414
|
for (let c = 1; c <= 3; c++)
|
|
1413
1415
|
try {
|
|
@@ -1415,20 +1417,20 @@ class Ze extends w {
|
|
|
1415
1417
|
"info",
|
|
1416
1418
|
`Send succeeded after ${c - 1} retry attempt(s)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1417
1419
|
{
|
|
1418
|
-
data: { events:
|
|
1420
|
+
data: { events: s.events.length, attempt: c }
|
|
1419
1421
|
}
|
|
1420
1422
|
), this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, !0) : !1;
|
|
1421
1423
|
} catch (u) {
|
|
1422
1424
|
const g = c === 3;
|
|
1423
|
-
if (u instanceof
|
|
1425
|
+
if (u instanceof O)
|
|
1424
1426
|
throw this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, u;
|
|
1425
|
-
if (u instanceof
|
|
1427
|
+
if (u instanceof ne) {
|
|
1426
1428
|
this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, o = !1, l = !0, a("warn", `Rate limited, skipping retries${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1427
1429
|
data: { events: e.events.length, attempt: c }
|
|
1428
1430
|
});
|
|
1429
1431
|
break;
|
|
1430
1432
|
}
|
|
1431
|
-
if (u instanceof
|
|
1433
|
+
if (u instanceof P || (o = !1), u instanceof TypeError || (l = !0), a(
|
|
1432
1434
|
g ? "error" : "warn",
|
|
1433
1435
|
`Send attempt ${c} failed${this.integrationId ? ` [${this.integrationId}]` : ""}${g ? " (all retries exhausted)" : ", will retry"}`,
|
|
1434
1436
|
{
|
|
@@ -1445,7 +1447,7 @@ class Ze extends w {
|
|
|
1445
1447
|
continue;
|
|
1446
1448
|
}
|
|
1447
1449
|
if (o)
|
|
1448
|
-
throw new
|
|
1450
|
+
throw new P("All retry attempts timed out (server likely received the request)");
|
|
1449
1451
|
return l ? (this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0) : (this.consecutiveNetworkFailures = Math.min(
|
|
1450
1452
|
this.consecutiveNetworkFailures + 1,
|
|
1451
1453
|
3
|
|
@@ -1477,11 +1479,11 @@ class Ze extends w {
|
|
|
1477
1479
|
* @private
|
|
1478
1480
|
*/
|
|
1479
1481
|
async sendWithTimeout(e, t) {
|
|
1480
|
-
const
|
|
1481
|
-
this.pendingControllers.add(
|
|
1482
|
+
const s = new AbortController();
|
|
1483
|
+
this.pendingControllers.add(s);
|
|
1482
1484
|
let n = !1;
|
|
1483
1485
|
const i = setTimeout(() => {
|
|
1484
|
-
n = !0,
|
|
1486
|
+
n = !0, s.abort();
|
|
1485
1487
|
}, 15e3);
|
|
1486
1488
|
try {
|
|
1487
1489
|
const o = this.getCustomHeaders(), l = await fetch(e, {
|
|
@@ -1489,19 +1491,19 @@ class Ze extends w {
|
|
|
1489
1491
|
body: t,
|
|
1490
1492
|
keepalive: !0,
|
|
1491
1493
|
credentials: this.fetchCredentials,
|
|
1492
|
-
signal:
|
|
1494
|
+
signal: s.signal,
|
|
1493
1495
|
headers: {
|
|
1494
1496
|
...o,
|
|
1495
1497
|
"Content-Type": "application/json"
|
|
1496
1498
|
}
|
|
1497
1499
|
});
|
|
1498
1500
|
if (!l.ok)
|
|
1499
|
-
throw l.status >= 400 && l.status < 500 && l.status !== 408 && l.status !== 429 ? new
|
|
1501
|
+
throw l.status >= 400 && l.status < 500 && l.status !== 408 && l.status !== 429 ? new O(`HTTP ${l.status}: ${l.statusText}`, l.status) : l.status === 429 ? new ne(`HTTP 429: ${l.statusText}`) : new Error(`HTTP ${l.status}: ${l.statusText}`);
|
|
1500
1502
|
return l;
|
|
1501
1503
|
} catch (o) {
|
|
1502
|
-
throw o instanceof
|
|
1504
|
+
throw o instanceof O ? o : n ? new P("Request timed out (server likely received the request)") : o;
|
|
1503
1505
|
} finally {
|
|
1504
|
-
clearTimeout(i), this.pendingControllers.delete(
|
|
1506
|
+
clearTimeout(i), this.pendingControllers.delete(s);
|
|
1505
1507
|
}
|
|
1506
1508
|
}
|
|
1507
1509
|
/**
|
|
@@ -1528,10 +1530,10 @@ class Ze extends w {
|
|
|
1528
1530
|
const t = this.applyBeforeSendTransformer(e);
|
|
1529
1531
|
if (!t)
|
|
1530
1532
|
return !0;
|
|
1531
|
-
const
|
|
1532
|
-
if (!
|
|
1533
|
+
const s = this.applyBeforeBatchTransformer(t);
|
|
1534
|
+
if (!s)
|
|
1533
1535
|
return !0;
|
|
1534
|
-
const { url: n, payload: i } = this.prepareRequest(
|
|
1536
|
+
const { url: n, payload: i } = this.prepareRequest(s);
|
|
1535
1537
|
if (i.length > 65536)
|
|
1536
1538
|
return a(
|
|
1537
1539
|
"warn",
|
|
@@ -1540,21 +1542,21 @@ class Ze extends w {
|
|
|
1540
1542
|
data: {
|
|
1541
1543
|
size: i.length,
|
|
1542
1544
|
limit: 65536,
|
|
1543
|
-
events:
|
|
1545
|
+
events: s.events.length
|
|
1544
1546
|
}
|
|
1545
1547
|
}
|
|
1546
|
-
), this.persistEvents(
|
|
1548
|
+
), this.persistEvents(s), !1;
|
|
1547
1549
|
const o = new Blob([i], { type: "application/json" });
|
|
1548
1550
|
if (!this.isSendBeaconAvailable())
|
|
1549
1551
|
return a(
|
|
1550
1552
|
"warn",
|
|
1551
1553
|
`sendBeacon not available, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1552
|
-
), this.persistEvents(
|
|
1554
|
+
), this.persistEvents(s), !1;
|
|
1553
1555
|
const l = navigator.sendBeacon(n, o);
|
|
1554
1556
|
return l || (a(
|
|
1555
1557
|
"warn",
|
|
1556
1558
|
`sendBeacon rejected request, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1557
|
-
), this.persistEvents(
|
|
1559
|
+
), this.persistEvents(s)), l;
|
|
1558
1560
|
}
|
|
1559
1561
|
/**
|
|
1560
1562
|
* Prepares request by enriching payload with metadata and serializing to JSON.
|
|
@@ -1577,7 +1579,7 @@ class Ze extends w {
|
|
|
1577
1579
|
prepareRequest(e) {
|
|
1578
1580
|
let t = Date.now();
|
|
1579
1581
|
t < this.lastMetadataTimestamp && (t = this.lastMetadataTimestamp), this.lastMetadataTimestamp = t;
|
|
1580
|
-
const
|
|
1582
|
+
const s = {
|
|
1581
1583
|
...e,
|
|
1582
1584
|
_metadata: {
|
|
1583
1585
|
referer: typeof window < "u" ? window.location.href : void 0,
|
|
@@ -1587,7 +1589,7 @@ class Ze extends w {
|
|
|
1587
1589
|
};
|
|
1588
1590
|
return {
|
|
1589
1591
|
url: this.apiUrl || "",
|
|
1590
|
-
payload: JSON.stringify(
|
|
1592
|
+
payload: JSON.stringify(s)
|
|
1591
1593
|
};
|
|
1592
1594
|
}
|
|
1593
1595
|
/**
|
|
@@ -1638,7 +1640,7 @@ class Ze extends w {
|
|
|
1638
1640
|
* @private
|
|
1639
1641
|
*/
|
|
1640
1642
|
createRecoveryBody(e) {
|
|
1641
|
-
const { timestamp: t, recoveryFailures:
|
|
1643
|
+
const { timestamp: t, recoveryFailures: s, ...n } = e;
|
|
1642
1644
|
return n;
|
|
1643
1645
|
}
|
|
1644
1646
|
/**
|
|
@@ -1675,10 +1677,10 @@ class Ze extends w {
|
|
|
1675
1677
|
* @returns `true` on successful persistence or throttled write, `false` on error
|
|
1676
1678
|
* @private
|
|
1677
1679
|
*/
|
|
1678
|
-
persistEventsWithFailureCount(e, t,
|
|
1680
|
+
persistEventsWithFailureCount(e, t, s = !1) {
|
|
1679
1681
|
try {
|
|
1680
1682
|
const n = this.getPersistedData();
|
|
1681
|
-
if (!
|
|
1683
|
+
if (!s && n && n.timestamp) {
|
|
1682
1684
|
const l = Date.now() - n.timestamp;
|
|
1683
1685
|
if (l < 1e3)
|
|
1684
1686
|
return a(
|
|
@@ -1720,13 +1722,13 @@ class Ze extends w {
|
|
|
1720
1722
|
return typeof navigator < "u" && typeof navigator.sendBeacon == "function";
|
|
1721
1723
|
}
|
|
1722
1724
|
logPermanentError(e, t) {
|
|
1723
|
-
const
|
|
1724
|
-
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode ||
|
|
1725
|
+
const s = Date.now();
|
|
1726
|
+
(!this.lastPermanentErrorLog || this.lastPermanentErrorLog.statusCode !== t.statusCode || s - this.lastPermanentErrorLog.timestamp >= zt) && (a("error", `${e}${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1725
1727
|
data: { status: t.statusCode, message: t.message }
|
|
1726
|
-
}), this.lastPermanentErrorLog = { statusCode: t.statusCode, timestamp:
|
|
1728
|
+
}), this.lastPermanentErrorLog = { statusCode: t.statusCode, timestamp: s });
|
|
1727
1729
|
}
|
|
1728
1730
|
}
|
|
1729
|
-
class
|
|
1731
|
+
class Ss extends _ {
|
|
1730
1732
|
bootTime;
|
|
1731
1733
|
bootTimestamp;
|
|
1732
1734
|
hasPerformanceNow;
|
|
@@ -1818,13 +1820,13 @@ class Sr extends w {
|
|
|
1818
1820
|
if (e - this.lastClockSkewCheck < 5e3)
|
|
1819
1821
|
return this.detectedSkew;
|
|
1820
1822
|
this.lastClockSkewCheck = e;
|
|
1821
|
-
const t = this.now(),
|
|
1822
|
-
return this.detectedSkew =
|
|
1823
|
+
const t = this.now(), s = Date.now();
|
|
1824
|
+
return this.detectedSkew = s - t, Math.abs(this.detectedSkew) > 3e4 && a("warn", "Significant clock skew detected", {
|
|
1823
1825
|
data: {
|
|
1824
1826
|
skewMs: this.detectedSkew,
|
|
1825
1827
|
skewMinutes: (this.detectedSkew / 1e3 / 60).toFixed(2),
|
|
1826
1828
|
monotonicTime: new Date(t).toISOString(),
|
|
1827
|
-
systemTime: new Date(
|
|
1829
|
+
systemTime: new Date(s).toISOString()
|
|
1828
1830
|
}
|
|
1829
1831
|
}), this.detectedSkew;
|
|
1830
1832
|
}
|
|
@@ -1853,7 +1855,7 @@ class Sr extends w {
|
|
|
1853
1855
|
* ```
|
|
1854
1856
|
*/
|
|
1855
1857
|
validateTimestamp(e) {
|
|
1856
|
-
const
|
|
1858
|
+
const s = this.now(), n = e - s;
|
|
1857
1859
|
return n > 12e4 ? {
|
|
1858
1860
|
valid: !1,
|
|
1859
1861
|
error: `Timestamp is ${(n / 1e3 / 60).toFixed(2)} minutes in the future (max allowed: 2 minutes)`
|
|
@@ -1875,8 +1877,8 @@ class Sr extends w {
|
|
|
1875
1877
|
};
|
|
1876
1878
|
}
|
|
1877
1879
|
}
|
|
1878
|
-
const
|
|
1879
|
-
class
|
|
1880
|
+
const ps = new Set(Object.values(d));
|
|
1881
|
+
class Ts extends _ {
|
|
1880
1882
|
dataSenders;
|
|
1881
1883
|
emitter;
|
|
1882
1884
|
transformers;
|
|
@@ -1914,15 +1916,15 @@ class Tr extends w {
|
|
|
1914
1916
|
* @param customHeadersProvider - Optional callback for dynamic headers
|
|
1915
1917
|
* @param fetchCredentials - Fetch credentials mode for custom backend. @default 'include'
|
|
1916
1918
|
*/
|
|
1917
|
-
constructor(e, t = null,
|
|
1918
|
-
super(), this.emitter = t, this.transformers =
|
|
1919
|
+
constructor(e, t = null, s = {}, n = {}, i, o = "include") {
|
|
1920
|
+
super(), this.emitter = t, this.transformers = s, this.timeManager = new Ss(), this.dataSenders = [];
|
|
1919
1921
|
const l = this.get("collectApiUrls");
|
|
1920
|
-
l?.saas && this.dataSenders.push(new Ze(e, "saas", l.saas,
|
|
1922
|
+
l?.saas && this.dataSenders.push(new Ze(e, "saas", l.saas, s)), l?.custom && this.dataSenders.push(
|
|
1921
1923
|
new Ze(
|
|
1922
1924
|
e,
|
|
1923
1925
|
"custom",
|
|
1924
1926
|
l.custom,
|
|
1925
|
-
|
|
1927
|
+
s,
|
|
1926
1928
|
n,
|
|
1927
1929
|
i,
|
|
1928
1930
|
o
|
|
@@ -1958,7 +1960,7 @@ class Tr extends w {
|
|
|
1958
1960
|
async recoverPersistedEvents() {
|
|
1959
1961
|
const e = this.dataSenders.map(
|
|
1960
1962
|
async (t) => t.recoverPersistedEvents({
|
|
1961
|
-
onSuccess: (
|
|
1963
|
+
onSuccess: (s, n, i) => {
|
|
1962
1964
|
if (n && n.length > 0) {
|
|
1963
1965
|
const o = n.map((l) => l.id);
|
|
1964
1966
|
this.removeProcessedEvents(o), i && this.emitEventsQueue(i);
|
|
@@ -2033,7 +2035,7 @@ class Tr extends w {
|
|
|
2033
2035
|
track({
|
|
2034
2036
|
type: e,
|
|
2035
2037
|
page_url: t,
|
|
2036
|
-
from_page_url:
|
|
2038
|
+
from_page_url: s,
|
|
2037
2039
|
scroll_data: n,
|
|
2038
2040
|
click_data: i,
|
|
2039
2041
|
custom_event: o,
|
|
@@ -2046,7 +2048,7 @@ class Tr extends w {
|
|
|
2046
2048
|
a("error", "Event type is required - event will be ignored");
|
|
2047
2049
|
return;
|
|
2048
2050
|
}
|
|
2049
|
-
if (!
|
|
2051
|
+
if (!ps.has(e)) {
|
|
2050
2052
|
a("error", "Invalid event type - event will be ignored", {
|
|
2051
2053
|
data: { type: e }
|
|
2052
2054
|
});
|
|
@@ -2059,7 +2061,7 @@ class Tr extends w {
|
|
|
2059
2061
|
})), this.pendingEventsBuffer.push({
|
|
2060
2062
|
type: e,
|
|
2061
2063
|
page_url: t,
|
|
2062
|
-
from_page_url:
|
|
2064
|
+
from_page_url: s,
|
|
2063
2065
|
scroll_data: n,
|
|
2064
2066
|
click_data: i,
|
|
2065
2067
|
custom_event: o,
|
|
@@ -2090,12 +2092,12 @@ class Tr extends w {
|
|
|
2090
2092
|
}
|
|
2091
2093
|
const v = this.getTypeLimitForEvent(S);
|
|
2092
2094
|
if (v) {
|
|
2093
|
-
const
|
|
2094
|
-
if (
|
|
2095
|
+
const he = this.sessionEventCounts[S];
|
|
2096
|
+
if (he !== void 0 && he >= v) {
|
|
2095
2097
|
a("warn", "Session event type limit reached", {
|
|
2096
2098
|
data: {
|
|
2097
2099
|
type: S,
|
|
2098
|
-
count:
|
|
2100
|
+
count: he,
|
|
2099
2101
|
limit: v
|
|
2100
2102
|
}
|
|
2101
2103
|
});
|
|
@@ -2111,7 +2113,7 @@ class Tr extends w {
|
|
|
2111
2113
|
const Ve = S === d.SESSION_START, Y = t || this.get("pageUrl"), $ = this.buildEventPayload({
|
|
2112
2114
|
type: S,
|
|
2113
2115
|
page_url: Y,
|
|
2114
|
-
from_page_url:
|
|
2116
|
+
from_page_url: s,
|
|
2115
2117
|
scroll_data: n,
|
|
2116
2118
|
click_data: i,
|
|
2117
2119
|
custom_event: o,
|
|
@@ -2136,7 +2138,7 @@ class Tr extends w {
|
|
|
2136
2138
|
this.set("hasStartSession", !0);
|
|
2137
2139
|
}
|
|
2138
2140
|
if (!this.isDuplicateEvent($)) {
|
|
2139
|
-
if (this.get("mode") ===
|
|
2141
|
+
if (this.get("mode") === ie.QA) {
|
|
2140
2142
|
if (S === d.CUSTOM && o) {
|
|
2141
2143
|
a("info", `Custom Event: ${o.name}`, {
|
|
2142
2144
|
visibility: "qa",
|
|
@@ -2414,8 +2416,8 @@ class Tr extends w {
|
|
|
2414
2416
|
return;
|
|
2415
2417
|
}
|
|
2416
2418
|
const t = [...this.pendingEventsBuffer];
|
|
2417
|
-
this.pendingEventsBuffer = [], t.forEach((
|
|
2418
|
-
this.track(
|
|
2419
|
+
this.pendingEventsBuffer = [], t.forEach((s) => {
|
|
2420
|
+
this.track(s);
|
|
2419
2421
|
});
|
|
2420
2422
|
}
|
|
2421
2423
|
clearSendTimeout() {
|
|
@@ -2429,7 +2431,7 @@ class Tr extends w {
|
|
|
2429
2431
|
return e ? !0 : Promise.resolve(!0);
|
|
2430
2432
|
if (!e && this.sendInProgress)
|
|
2431
2433
|
return a("debug", "Async flush skipped: send already in progress"), Promise.resolve(!1);
|
|
2432
|
-
const t = this.buildEventsPayload(),
|
|
2434
|
+
const t = this.buildEventsPayload(), s = [...this.eventsQueue], n = s.map((i) => i.id);
|
|
2433
2435
|
if (this.dataSenders.length === 0)
|
|
2434
2436
|
return this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t), e ? !0 : Promise.resolve(!0);
|
|
2435
2437
|
if (e) {
|
|
@@ -2449,7 +2451,7 @@ class Tr extends w {
|
|
|
2449
2451
|
return Promise.allSettled(i).then((o) => {
|
|
2450
2452
|
const l = o.some((c) => this.isSuccessfulResult(c));
|
|
2451
2453
|
return l ? (this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t)) : a("debug", "Async flush complete failure, events kept in queue for retry", {
|
|
2452
|
-
data: { eventCount:
|
|
2454
|
+
data: { eventCount: s.length }
|
|
2453
2455
|
}), l;
|
|
2454
2456
|
});
|
|
2455
2457
|
}
|
|
@@ -2463,7 +2465,7 @@ class Tr extends w {
|
|
|
2463
2465
|
this.emitEventsQueue(e);
|
|
2464
2466
|
return;
|
|
2465
2467
|
}
|
|
2466
|
-
const t = [...this.eventsQueue],
|
|
2468
|
+
const t = [...this.eventsQueue], s = t.map((l) => l.id), n = this.dataSenders.map(
|
|
2467
2469
|
async (l) => l.sendEventsQueue(e, {
|
|
2468
2470
|
onSuccess: () => {
|
|
2469
2471
|
},
|
|
@@ -2472,7 +2474,7 @@ class Tr extends w {
|
|
|
2472
2474
|
})
|
|
2473
2475
|
), i = await Promise.allSettled(n);
|
|
2474
2476
|
if (i.some((l) => this.isSuccessfulResult(l))) {
|
|
2475
|
-
this.consecutiveSendFailures = 0, this.removeProcessedEvents(
|
|
2477
|
+
this.consecutiveSendFailures = 0, this.removeProcessedEvents(s), this.emitEventsQueue(e);
|
|
2476
2478
|
const l = i.filter((c) => !this.isSuccessfulResult(c)).length;
|
|
2477
2479
|
l > 0 && a("debug", "Periodic send completed with some failures, removed from queue and persisted per-integration", {
|
|
2478
2480
|
data: { eventCount: t.length, failedCount: l }
|
|
@@ -2493,12 +2495,12 @@ class Tr extends w {
|
|
|
2493
2495
|
const u = this.createEventSignature(c);
|
|
2494
2496
|
e.has(u) || t.push(u), e.set(u, c);
|
|
2495
2497
|
}
|
|
2496
|
-
const
|
|
2498
|
+
const s = t.map((c) => e.get(c)).filter((c) => !!c).sort((c, u) => c.type === d.SESSION_START && u.type !== d.SESSION_START ? -1 : u.type === d.SESSION_START && c.type !== d.SESSION_START ? 1 : c.timestamp - u.timestamp);
|
|
2497
2499
|
let n = {
|
|
2498
2500
|
user_id: this.get("userId"),
|
|
2499
2501
|
session_id: this.get("sessionId"),
|
|
2500
2502
|
device: this.get("device"),
|
|
2501
|
-
events:
|
|
2503
|
+
events: s,
|
|
2502
2504
|
...this.get("config")?.globalMetadata && { global_metadata: this.get("config")?.globalMetadata },
|
|
2503
2505
|
...this.get("identity") && { identify: this.get("identity") }
|
|
2504
2506
|
};
|
|
@@ -2510,16 +2512,16 @@ class Tr extends w {
|
|
|
2510
2512
|
return n;
|
|
2511
2513
|
}
|
|
2512
2514
|
buildEventPayload(e) {
|
|
2513
|
-
const t = e.page_url ?? this.get("pageUrl"),
|
|
2515
|
+
const t = e.page_url ?? this.get("pageUrl"), s = this.timeManager.now(), n = this.timeManager.validateTimestamp(s);
|
|
2514
2516
|
n.valid || a("warn", "Event timestamp validation failed", {
|
|
2515
2517
|
data: { type: e.type, error: n.error }
|
|
2516
2518
|
});
|
|
2517
2519
|
const i = this.get("sessionReferrer"), o = this.get("sessionUtm");
|
|
2518
2520
|
let l = {
|
|
2519
|
-
id:
|
|
2521
|
+
id: ns(),
|
|
2520
2522
|
type: e.type,
|
|
2521
2523
|
page_url: t,
|
|
2522
|
-
timestamp:
|
|
2524
|
+
timestamp: s,
|
|
2523
2525
|
...i && { referrer: i },
|
|
2524
2526
|
...e.from_page_url && { from_page_url: e.from_page_url },
|
|
2525
2527
|
...e.scroll_data && { scroll_data: e.scroll_data },
|
|
@@ -2541,15 +2543,15 @@ class Tr extends w {
|
|
|
2541
2543
|
return l;
|
|
2542
2544
|
}
|
|
2543
2545
|
isDuplicateEvent(e) {
|
|
2544
|
-
const t = Date.now(),
|
|
2545
|
-
return n && t - n < 1e3 ? (this.recentEventFingerprints.set(
|
|
2546
|
+
const t = Date.now(), s = this.createEventFingerprint(e), n = this.recentEventFingerprints.get(s);
|
|
2547
|
+
return n && t - n < 1e3 ? (this.recentEventFingerprints.set(s, t), !0) : (this.recentEventFingerprints.set(s, t), this.recentEventFingerprints.size > 1500 && this.pruneOldFingerprints(), this.recentEventFingerprints.size > 3e3 && (this.recentEventFingerprints.clear(), this.recentEventFingerprints.set(s, t), a("debug", "Event fingerprint cache exceeded hard limit, cleared", {
|
|
2546
2548
|
data: { hardLimit: 3e3 }
|
|
2547
2549
|
})), !1);
|
|
2548
2550
|
}
|
|
2549
2551
|
pruneOldFingerprints() {
|
|
2550
2552
|
const e = Date.now(), t = 1e3 * 10;
|
|
2551
|
-
for (const [
|
|
2552
|
-
e - n > t && this.recentEventFingerprints.delete(
|
|
2553
|
+
for (const [s, n] of this.recentEventFingerprints.entries())
|
|
2554
|
+
e - n > t && this.recentEventFingerprints.delete(s);
|
|
2553
2555
|
a("debug", "Pruned old event fingerprints", {
|
|
2554
2556
|
data: {
|
|
2555
2557
|
remaining: this.recentEventFingerprints.size,
|
|
@@ -2560,8 +2562,8 @@ class Tr extends w {
|
|
|
2560
2562
|
createEventFingerprint(e) {
|
|
2561
2563
|
let t = `${e.type}_${e.page_url}`;
|
|
2562
2564
|
if (e.click_data) {
|
|
2563
|
-
const
|
|
2564
|
-
t += `_click_${
|
|
2565
|
+
const s = Math.round((e.click_data.x || 0) / 10) * 10, n = Math.round((e.click_data.y || 0) / 10) * 10;
|
|
2566
|
+
t += `_click_${s}_${n}`;
|
|
2565
2567
|
}
|
|
2566
2568
|
return e.scroll_data && (t += `_scroll_${e.scroll_data.depth}_${e.scroll_data.direction}`), e.custom_event && (t += `_custom_${e.custom_event.name}`, e.custom_event.metadata && (t += `_${this.stableStringify(e.custom_event.metadata)}`)), e.web_vitals && (t += `_vitals_${e.web_vitals.type}`), e.error_data && (t += `_error_${e.error_data.type}_${e.error_data.message}`), t;
|
|
2567
2569
|
}
|
|
@@ -2570,17 +2572,17 @@ class Tr extends w {
|
|
|
2570
2572
|
}
|
|
2571
2573
|
/** Deterministic JSON string with sorted keys to ensure consistent fingerprints regardless of property insertion order */
|
|
2572
2574
|
stableStringify(e) {
|
|
2573
|
-
return JSON.stringify(e, (t,
|
|
2575
|
+
return JSON.stringify(e, (t, s) => s && typeof s == "object" && !Array.isArray(s) ? Object.keys(s).sort().reduce((n, i) => (n[i] = s[i], n), {}) : s);
|
|
2574
2576
|
}
|
|
2575
2577
|
addToQueue(e) {
|
|
2576
2578
|
if (this.emitEvent(e), this.eventsQueue.push(e), this.eventsQueue.length > 100) {
|
|
2577
|
-
const t = this.eventsQueue.findIndex((n) => n.type !== d.SESSION_START),
|
|
2579
|
+
const t = this.eventsQueue.findIndex((n) => n.type !== d.SESSION_START), s = t >= 0 ? this.eventsQueue.splice(t, 1)[0] : this.eventsQueue.shift();
|
|
2578
2580
|
a("warn", "Event queue overflow, oldest non-critical event removed", {
|
|
2579
2581
|
data: {
|
|
2580
2582
|
maxLength: 100,
|
|
2581
2583
|
currentLength: this.eventsQueue.length,
|
|
2582
|
-
removedEventType:
|
|
2583
|
-
wasCritical:
|
|
2584
|
+
removedEventType: s?.type,
|
|
2585
|
+
wasCritical: s?.type === d.SESSION_START
|
|
2584
2586
|
}
|
|
2585
2587
|
});
|
|
2586
2588
|
}
|
|
@@ -2608,14 +2610,14 @@ class Tr extends w {
|
|
|
2608
2610
|
return e - this.rateLimitWindowStart > 1e3 && (this.rateLimitCounter = 0, this.rateLimitWindowStart = e), this.rateLimitCounter >= 50 ? !1 : (this.rateLimitCounter++, !0);
|
|
2609
2611
|
}
|
|
2610
2612
|
checkPerEventRateLimit(e, t) {
|
|
2611
|
-
const
|
|
2613
|
+
const s = Date.now(), i = (this.perEventRateLimits.get(e) ?? []).filter((o) => s - o < 6e4);
|
|
2612
2614
|
return i.length >= t ? (a("warn", "Per-event rate limit exceeded for custom event", {
|
|
2613
2615
|
data: {
|
|
2614
2616
|
eventName: e,
|
|
2615
2617
|
limit: t,
|
|
2616
2618
|
window: `${6e4 / 1e3}s`
|
|
2617
2619
|
}
|
|
2618
|
-
}), !1) : (i.push(
|
|
2620
|
+
}), !1) : (i.push(s), this.perEventRateLimits.set(e, i), !0);
|
|
2619
2621
|
}
|
|
2620
2622
|
getTypeLimitForEvent(e) {
|
|
2621
2623
|
return {
|
|
@@ -2628,13 +2630,13 @@ class Tr extends w {
|
|
|
2628
2630
|
}
|
|
2629
2631
|
removeProcessedEvents(e) {
|
|
2630
2632
|
const t = new Set(e);
|
|
2631
|
-
this.eventsQueue = this.eventsQueue.filter((
|
|
2633
|
+
this.eventsQueue = this.eventsQueue.filter((s) => !t.has(s.id));
|
|
2632
2634
|
}
|
|
2633
2635
|
emitEvent(e) {
|
|
2634
|
-
this.emitter && this.emitter.emit(
|
|
2636
|
+
this.emitter && this.emitter.emit(re.EVENT, e);
|
|
2635
2637
|
}
|
|
2636
2638
|
emitEventsQueue(e) {
|
|
2637
|
-
this.emitter && this.emitter.emit(
|
|
2639
|
+
this.emitter && this.emitter.emit(re.QUEUE, e);
|
|
2638
2640
|
}
|
|
2639
2641
|
/**
|
|
2640
2642
|
* Creates a debounced version of a function that delays execution until after
|
|
@@ -2657,10 +2659,10 @@ class Tr extends w {
|
|
|
2657
2659
|
* @internal
|
|
2658
2660
|
*/
|
|
2659
2661
|
debounce(e, t) {
|
|
2660
|
-
let
|
|
2662
|
+
let s = null;
|
|
2661
2663
|
return ((...n) => {
|
|
2662
|
-
|
|
2663
|
-
e(...n),
|
|
2664
|
+
s !== null && clearTimeout(s), s = setTimeout(() => {
|
|
2665
|
+
e(...n), s = null;
|
|
2664
2666
|
}, t);
|
|
2665
2667
|
});
|
|
2666
2668
|
}
|
|
@@ -2710,15 +2712,15 @@ class Tr extends w {
|
|
|
2710
2712
|
loadSessionCounts(e) {
|
|
2711
2713
|
if (typeof window > "u" || typeof localStorage > "u")
|
|
2712
2714
|
return this.getInitialCounts();
|
|
2713
|
-
const t = this.get("userId") || "anonymous",
|
|
2715
|
+
const t = this.get("userId") || "anonymous", s = Fe(t, e);
|
|
2714
2716
|
try {
|
|
2715
|
-
const n = localStorage.getItem(
|
|
2717
|
+
const n = localStorage.getItem(s);
|
|
2716
2718
|
if (!n)
|
|
2717
2719
|
return this.getInitialCounts();
|
|
2718
2720
|
const i = JSON.parse(n);
|
|
2719
2721
|
return i._timestamp && Date.now() - i._timestamp > xe ? (a("debug", "Session counts expired, clearing", {
|
|
2720
2722
|
data: { sessionId: e, age: Date.now() - i._timestamp }
|
|
2721
|
-
}), localStorage.removeItem(
|
|
2723
|
+
}), localStorage.removeItem(s), 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" ? {
|
|
2722
2724
|
total: i.total,
|
|
2723
2725
|
[d.CLICK]: i[d.CLICK],
|
|
2724
2726
|
[d.PAGE_VIEW]: i[d.PAGE_VIEW],
|
|
@@ -2727,7 +2729,7 @@ class Tr extends w {
|
|
|
2727
2729
|
[d.SCROLL]: i[d.SCROLL]
|
|
2728
2730
|
} : (a("warn", "Invalid session counts structure in localStorage, resetting", {
|
|
2729
2731
|
data: { sessionId: e, parsed: i }
|
|
2730
|
-
}), localStorage.removeItem(
|
|
2732
|
+
}), localStorage.removeItem(s), a("debug", "Session counts removed due to invalid/corrupted data", {
|
|
2731
2733
|
data: { sessionId: e, parsed: i }
|
|
2732
2734
|
}), this.getInitialCounts());
|
|
2733
2735
|
} catch (n) {
|
|
@@ -2771,10 +2773,10 @@ class Tr extends w {
|
|
|
2771
2773
|
return;
|
|
2772
2774
|
}
|
|
2773
2775
|
}
|
|
2774
|
-
const t = this.get("userId") || "anonymous",
|
|
2776
|
+
const t = this.get("userId") || "anonymous", s = `${I}:${t}:session_counts:`, n = [];
|
|
2775
2777
|
for (let i = 0; i < localStorage.length; i++) {
|
|
2776
2778
|
const o = localStorage.key(i);
|
|
2777
|
-
if (o?.startsWith(
|
|
2779
|
+
if (o?.startsWith(s))
|
|
2778
2780
|
try {
|
|
2779
2781
|
const l = localStorage.getItem(o);
|
|
2780
2782
|
if (l) {
|
|
@@ -2820,14 +2822,14 @@ class Tr extends w {
|
|
|
2820
2822
|
* @internal
|
|
2821
2823
|
*/
|
|
2822
2824
|
saveSessionCounts(e) {
|
|
2823
|
-
const t = this.get("userId") || "anonymous",
|
|
2825
|
+
const t = this.get("userId") || "anonymous", s = Fe(t, e);
|
|
2824
2826
|
try {
|
|
2825
2827
|
const n = {
|
|
2826
2828
|
...this.sessionEventCounts,
|
|
2827
2829
|
_timestamp: Date.now(),
|
|
2828
2830
|
_version: 1
|
|
2829
2831
|
};
|
|
2830
|
-
localStorage.setItem(
|
|
2832
|
+
localStorage.setItem(s, JSON.stringify(n));
|
|
2831
2833
|
} catch (n) {
|
|
2832
2834
|
a("warn", "Failed to persist session counts to localStorage", {
|
|
2833
2835
|
error: n,
|
|
@@ -2836,7 +2838,7 @@ class Tr extends w {
|
|
|
2836
2838
|
}
|
|
2837
2839
|
}
|
|
2838
2840
|
}
|
|
2839
|
-
class
|
|
2841
|
+
class Is {
|
|
2840
2842
|
/**
|
|
2841
2843
|
* Gets or creates a unique user ID.
|
|
2842
2844
|
*
|
|
@@ -2854,15 +2856,15 @@ class Ir {
|
|
|
2854
2856
|
* @returns Persistent unique user ID (UUID v4 format)
|
|
2855
2857
|
*/
|
|
2856
2858
|
static getId(e) {
|
|
2857
|
-
const t = e.getItem(
|
|
2859
|
+
const t = e.getItem(Te);
|
|
2858
2860
|
if (t)
|
|
2859
2861
|
return t;
|
|
2860
|
-
const
|
|
2861
|
-
return e.setItem(
|
|
2862
|
+
const s = ut();
|
|
2863
|
+
return e.setItem(Te, s), s;
|
|
2862
2864
|
}
|
|
2863
2865
|
}
|
|
2864
|
-
const
|
|
2865
|
-
class
|
|
2866
|
+
const vs = /^\d{13}-[a-z0-9]{9}$/;
|
|
2867
|
+
class _s extends _ {
|
|
2866
2868
|
storageManager;
|
|
2867
2869
|
eventManager;
|
|
2868
2870
|
projectId;
|
|
@@ -2879,8 +2881,8 @@ class _r extends w {
|
|
|
2879
2881
|
* @param eventManager - Event manager for SESSION_START events
|
|
2880
2882
|
* @param projectId - Project identifier for namespacing session storage
|
|
2881
2883
|
*/
|
|
2882
|
-
constructor(e, t,
|
|
2883
|
-
super(), this.storageManager = e, this.eventManager = t, this.projectId =
|
|
2884
|
+
constructor(e, t, s) {
|
|
2885
|
+
super(), this.storageManager = e, this.eventManager = t, this.projectId = s;
|
|
2884
2886
|
}
|
|
2885
2887
|
initCrossTabSync() {
|
|
2886
2888
|
if (typeof BroadcastChannel > "u") {
|
|
@@ -2889,8 +2891,8 @@ class _r extends w {
|
|
|
2889
2891
|
}
|
|
2890
2892
|
const e = this.getProjectId();
|
|
2891
2893
|
this.broadcastChannel = new BroadcastChannel(Nt(e)), this.broadcastChannel.onmessage = (t) => {
|
|
2892
|
-
const { action:
|
|
2893
|
-
o === e && (
|
|
2894
|
+
const { action: s, sessionId: n, timestamp: i, projectId: o } = t.data ?? {};
|
|
2895
|
+
o === e && (s === "session_start" && n && typeof i == "number" && i > Date.now() - 5e3 ? (this.set("sessionId", n), this.persistSession(n, i), this.isTracking && this.setupSessionTimeout()) : s && s !== "session_start" && a("debug", "Ignored BroadcastChannel message with unknown action", { data: { action: s } }));
|
|
2894
2896
|
};
|
|
2895
2897
|
}
|
|
2896
2898
|
shareSession(e) {
|
|
@@ -2908,18 +2910,18 @@ class _r extends w {
|
|
|
2908
2910
|
const e = this.loadStoredSession();
|
|
2909
2911
|
if (!e)
|
|
2910
2912
|
return null;
|
|
2911
|
-
if (!
|
|
2913
|
+
if (!vs.test(e.id))
|
|
2912
2914
|
return a("warn", "Invalid session ID format recovered from storage, clearing", {
|
|
2913
2915
|
data: { sessionId: e.id }
|
|
2914
2916
|
}), this.clearStoredSession(), null;
|
|
2915
2917
|
const t = this.get("config")?.sessionTimeout ?? 9e5;
|
|
2916
2918
|
return Date.now() - e.lastActivity > t ? (this.clearStoredSession(), null) : e.id;
|
|
2917
2919
|
}
|
|
2918
|
-
persistSession(e, t = Date.now(),
|
|
2920
|
+
persistSession(e, t = Date.now(), s, n) {
|
|
2919
2921
|
this.saveStoredSession({
|
|
2920
2922
|
id: e,
|
|
2921
2923
|
lastActivity: t,
|
|
2922
|
-
...
|
|
2924
|
+
...s && { referrer: s },
|
|
2923
2925
|
...n && { utm: n }
|
|
2924
2926
|
});
|
|
2925
2927
|
}
|
|
@@ -2937,10 +2939,10 @@ class _r extends w {
|
|
|
2937
2939
|
} catch {
|
|
2938
2940
|
this.storageManager.removeItem(e);
|
|
2939
2941
|
}
|
|
2940
|
-
const
|
|
2941
|
-
if (
|
|
2942
|
+
const s = this.storageManager.getSessionItem(e);
|
|
2943
|
+
if (s !== null)
|
|
2942
2944
|
try {
|
|
2943
|
-
const n = JSON.parse(
|
|
2945
|
+
const n = JSON.parse(s);
|
|
2944
2946
|
if (n.id && typeof n.lastActivity == "number")
|
|
2945
2947
|
return n;
|
|
2946
2948
|
} catch {
|
|
@@ -2949,8 +2951,8 @@ class _r extends w {
|
|
|
2949
2951
|
return null;
|
|
2950
2952
|
}
|
|
2951
2953
|
saveStoredSession(e) {
|
|
2952
|
-
const t = this.getSessionStorageKey(),
|
|
2953
|
-
this.storageManager.setItem(t,
|
|
2954
|
+
const t = this.getSessionStorageKey(), s = JSON.stringify(e);
|
|
2955
|
+
this.storageManager.setItem(t, s), this.storageManager.setSessionItem(t, s);
|
|
2954
2956
|
}
|
|
2955
2957
|
getSessionStorageKey() {
|
|
2956
2958
|
return Rt(this.getProjectId());
|
|
@@ -3016,23 +3018,23 @@ class _r extends w {
|
|
|
3016
3018
|
return;
|
|
3017
3019
|
}
|
|
3018
3020
|
const e = this.recoverSession(), t = e ?? this.generateSessionId();
|
|
3019
|
-
let
|
|
3021
|
+
let s, n;
|
|
3020
3022
|
if (e) {
|
|
3021
3023
|
const i = this.loadStoredSession();
|
|
3022
|
-
|
|
3024
|
+
s = i?.referrer ?? me(), n = i?.utm ?? ge();
|
|
3023
3025
|
} else
|
|
3024
|
-
|
|
3026
|
+
s = me(), n = ge();
|
|
3025
3027
|
a("debug", "Session tracking initialized", {
|
|
3026
3028
|
data: {
|
|
3027
3029
|
sessionId: t,
|
|
3028
3030
|
wasRecovered: !!e,
|
|
3029
3031
|
willEmitSessionStart: !e,
|
|
3030
|
-
sessionReferrer:
|
|
3032
|
+
sessionReferrer: s,
|
|
3031
3033
|
hasUtm: !!n
|
|
3032
3034
|
}
|
|
3033
3035
|
}), this.isTracking = !0;
|
|
3034
3036
|
try {
|
|
3035
|
-
this.set("sessionId", t), this.set("sessionReferrer",
|
|
3037
|
+
this.set("sessionId", t), this.set("sessionReferrer", s), this.set("sessionUtm", n), this.persistSession(t, Date.now(), s, n), this.initCrossTabSync(), this.shareSession(t), e ? a("debug", "Session recovered, skipping SESSION_START", {
|
|
3036
3038
|
data: { sessionId: t }
|
|
3037
3039
|
}) : (a("debug", "Emitting SESSION_START event", {
|
|
3038
3040
|
data: { sessionId: t }
|
|
@@ -3072,10 +3074,10 @@ class _r extends w {
|
|
|
3072
3074
|
*/
|
|
3073
3075
|
renewSession() {
|
|
3074
3076
|
this.needsRenewal = !1;
|
|
3075
|
-
const e = this.generateSessionId(), t =
|
|
3077
|
+
const e = this.generateSessionId(), t = me(), s = ge();
|
|
3076
3078
|
a("debug", "Renewing session after timeout", {
|
|
3077
3079
|
data: { newSessionId: e }
|
|
3078
|
-
}), this.set("sessionId", e), this.set("sessionReferrer", t), this.set("sessionUtm",
|
|
3080
|
+
}), this.set("sessionId", e), this.set("sessionReferrer", t), this.set("sessionUtm", s), this.persistSession(e, Date.now(), t, s), this.cleanupCrossTabSync(), this.initCrossTabSync(), this.shareSession(e), this.eventManager.track({
|
|
3079
3081
|
type: d.SESSION_START
|
|
3080
3082
|
}), this.eventManager.flushPendingEvents(), this.setupSessionTimeout();
|
|
3081
3083
|
}
|
|
@@ -3105,8 +3107,8 @@ class _r extends w {
|
|
|
3105
3107
|
const t = this.loadStoredSession();
|
|
3106
3108
|
if (!t)
|
|
3107
3109
|
return !1;
|
|
3108
|
-
const
|
|
3109
|
-
return Date.now() - t.lastActivity >
|
|
3110
|
+
const s = this.get("config")?.sessionTimeout ?? 9e5;
|
|
3111
|
+
return Date.now() - t.lastActivity > s;
|
|
3110
3112
|
}
|
|
3111
3113
|
cleanupLifecycleListeners() {
|
|
3112
3114
|
this.visibilityChangeHandler && (document.removeEventListener("visibilitychange", this.visibilityChangeHandler), this.visibilityChangeHandler = null);
|
|
@@ -3193,7 +3195,7 @@ class _r extends w {
|
|
|
3193
3195
|
this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupCrossTabSync(), this.cleanupLifecycleListeners(), this.isTracking = !1, this.needsRenewal = !1, this.set("hasStartSession", !1);
|
|
3194
3196
|
}
|
|
3195
3197
|
}
|
|
3196
|
-
class
|
|
3198
|
+
class ys extends _ {
|
|
3197
3199
|
eventManager;
|
|
3198
3200
|
storageManager;
|
|
3199
3201
|
sessionManager = null;
|
|
@@ -3228,8 +3230,8 @@ class yr extends w {
|
|
|
3228
3230
|
}
|
|
3229
3231
|
const t = this.get("config")?.integrations?.tracelog?.projectId ?? "custom";
|
|
3230
3232
|
try {
|
|
3231
|
-
this.sessionManager = new
|
|
3232
|
-
} catch (
|
|
3233
|
+
this.sessionManager = new _s(this.storageManager, this.eventManager, t), this.sessionManager.startTracking(), this.eventManager.flushPendingEvents();
|
|
3234
|
+
} catch (s) {
|
|
3233
3235
|
if (this.sessionManager) {
|
|
3234
3236
|
try {
|
|
3235
3237
|
this.sessionManager.destroy();
|
|
@@ -3237,7 +3239,7 @@ class yr extends w {
|
|
|
3237
3239
|
}
|
|
3238
3240
|
this.sessionManager = null;
|
|
3239
3241
|
}
|
|
3240
|
-
throw a("error", "Failed to start session tracking", { error:
|
|
3242
|
+
throw a("error", "Failed to start session tracking", { error: s }), s;
|
|
3241
3243
|
}
|
|
3242
3244
|
}
|
|
3243
3245
|
isActive() {
|
|
@@ -3281,7 +3283,7 @@ class yr extends w {
|
|
|
3281
3283
|
this.destroyed || (this.sessionManager && (this.sessionManager.destroy(), this.sessionManager = null), this.destroyed = !0);
|
|
3282
3284
|
}
|
|
3283
3285
|
}
|
|
3284
|
-
class
|
|
3286
|
+
class ws extends _ {
|
|
3285
3287
|
eventManager;
|
|
3286
3288
|
onTrack;
|
|
3287
3289
|
originalPushState;
|
|
@@ -3316,18 +3318,18 @@ class wr extends w {
|
|
|
3316
3318
|
}
|
|
3317
3319
|
patchHistory(e) {
|
|
3318
3320
|
const t = window.history[e];
|
|
3319
|
-
e === "pushState" && !this.originalPushState ? this.originalPushState = t : e === "replaceState" && !this.originalReplaceState && (this.originalReplaceState = t), window.history[e] = (...
|
|
3320
|
-
t.apply(window.history,
|
|
3321
|
+
e === "pushState" && !this.originalPushState ? this.originalPushState = t : e === "replaceState" && !this.originalReplaceState && (this.originalReplaceState = t), window.history[e] = (...s) => {
|
|
3322
|
+
t.apply(window.history, s), this.trackCurrentPage();
|
|
3321
3323
|
};
|
|
3322
3324
|
}
|
|
3323
3325
|
trackCurrentPage = () => {
|
|
3324
3326
|
const e = window.location.href, t = ye(e, this.get("config").sensitiveQueryParams);
|
|
3325
3327
|
if (this.get("pageUrl") === t)
|
|
3326
3328
|
return;
|
|
3327
|
-
const
|
|
3328
|
-
if (
|
|
3329
|
+
const s = Date.now(), n = this.get("config").pageViewThrottleMs ?? 1e3;
|
|
3330
|
+
if (s - this.lastPageViewTime < n)
|
|
3329
3331
|
return;
|
|
3330
|
-
this.lastPageViewTime =
|
|
3332
|
+
this.lastPageViewTime = s, this.onTrack();
|
|
3331
3333
|
const i = this.get("pageUrl");
|
|
3332
3334
|
this.set("pageUrl", t);
|
|
3333
3335
|
const o = this.extractPageViewData();
|
|
@@ -3347,17 +3349,17 @@ class wr extends w {
|
|
|
3347
3349
|
}), this.onTrack();
|
|
3348
3350
|
}
|
|
3349
3351
|
extractPageViewData() {
|
|
3350
|
-
const { pathname: e, search: t, hash:
|
|
3351
|
-
return !n && !i && !e && !t && !
|
|
3352
|
+
const { pathname: e, search: t, hash: s } = window.location, { referrer: n } = document, { title: i } = document;
|
|
3353
|
+
return !n && !i && !e && !t && !s ? void 0 : {
|
|
3352
3354
|
...n && { referrer: n },
|
|
3353
3355
|
...i && { title: i },
|
|
3354
3356
|
...e && { pathname: e },
|
|
3355
3357
|
...t && { search: t },
|
|
3356
|
-
...
|
|
3358
|
+
...s && { hash: s }
|
|
3357
3359
|
};
|
|
3358
3360
|
}
|
|
3359
3361
|
}
|
|
3360
|
-
class
|
|
3362
|
+
class bs extends _ {
|
|
3361
3363
|
eventManager;
|
|
3362
3364
|
lastClickTimes = /* @__PURE__ */ new Map();
|
|
3363
3365
|
clickHandler;
|
|
@@ -3380,7 +3382,7 @@ class br extends w {
|
|
|
3380
3382
|
*/
|
|
3381
3383
|
startTracking() {
|
|
3382
3384
|
this.clickHandler || (this.clickHandler = (e) => {
|
|
3383
|
-
const t = e,
|
|
3385
|
+
const t = e, s = t.target, n = typeof HTMLElement < "u" && s instanceof HTMLElement ? s : typeof HTMLElement < "u" && s instanceof Node && s.parentElement instanceof HTMLElement ? s.parentElement : null;
|
|
3384
3386
|
if (!n) {
|
|
3385
3387
|
a("debug", "Click target not found or not an element");
|
|
3386
3388
|
return;
|
|
@@ -3428,15 +3430,15 @@ class br extends w {
|
|
|
3428
3430
|
* Returns true if the click should be tracked, false if throttled
|
|
3429
3431
|
*/
|
|
3430
3432
|
checkClickThrottle(e, t) {
|
|
3431
|
-
const
|
|
3433
|
+
const s = this.getElementSignature(e), n = Date.now();
|
|
3432
3434
|
this.pruneThrottleCache(n);
|
|
3433
|
-
const i = this.lastClickTimes.get(
|
|
3435
|
+
const i = this.lastClickTimes.get(s);
|
|
3434
3436
|
return i !== void 0 && n - i < t ? (a("debug", "ClickHandler: Click suppressed by throttle", {
|
|
3435
3437
|
data: {
|
|
3436
|
-
signature:
|
|
3438
|
+
signature: s,
|
|
3437
3439
|
throttleRemaining: t - (n - i)
|
|
3438
3440
|
}
|
|
3439
|
-
}), !1) : (this.lastClickTimes.set(
|
|
3441
|
+
}), !1) : (this.lastClickTimes.set(s, n), !0);
|
|
3440
3442
|
}
|
|
3441
3443
|
/**
|
|
3442
3444
|
* Prunes stale entries from the throttle cache to prevent memory leaks
|
|
@@ -3448,10 +3450,10 @@ class br extends w {
|
|
|
3448
3450
|
return;
|
|
3449
3451
|
this.lastPruneTime = e;
|
|
3450
3452
|
const t = e - 3e5;
|
|
3451
|
-
for (const [
|
|
3452
|
-
n < t && this.lastClickTimes.delete(
|
|
3453
|
+
for (const [s, n] of this.lastClickTimes.entries())
|
|
3454
|
+
n < t && this.lastClickTimes.delete(s);
|
|
3453
3455
|
if (this.lastClickTimes.size > 1e3) {
|
|
3454
|
-
const
|
|
3456
|
+
const s = Array.from(this.lastClickTimes.entries()).sort((o, l) => o[1] - l[1]), n = this.lastClickTimes.size - 1e3, i = s.slice(0, n);
|
|
3455
3457
|
for (const [o] of i)
|
|
3456
3458
|
this.lastClickTimes.delete(o);
|
|
3457
3459
|
a("debug", "ClickHandler: Pruned throttle cache", {
|
|
@@ -3472,22 +3474,22 @@ class br extends w {
|
|
|
3472
3474
|
const t = e.getAttribute("data-testid");
|
|
3473
3475
|
if (t)
|
|
3474
3476
|
return `[data-testid="${t}"]`;
|
|
3475
|
-
const
|
|
3476
|
-
return
|
|
3477
|
+
const s = e.getAttribute(`${b}-name`);
|
|
3478
|
+
return s ? `[${b}-name="${s}"]` : this.getElementPath(e);
|
|
3477
3479
|
}
|
|
3478
3480
|
/**
|
|
3479
3481
|
* Generates a DOM path for an element (e.g., "body>div>button")
|
|
3480
3482
|
*/
|
|
3481
3483
|
getElementPath(e) {
|
|
3482
3484
|
const t = [];
|
|
3483
|
-
let
|
|
3484
|
-
for (;
|
|
3485
|
-
let n =
|
|
3486
|
-
if (
|
|
3487
|
-
const i =
|
|
3485
|
+
let s = e;
|
|
3486
|
+
for (; s && s !== document.body; ) {
|
|
3487
|
+
let n = s.tagName.toLowerCase();
|
|
3488
|
+
if (s.className) {
|
|
3489
|
+
const i = s.className.split(" ")[0];
|
|
3488
3490
|
i && (n += `.${i}`);
|
|
3489
3491
|
}
|
|
3490
|
-
t.unshift(n),
|
|
3492
|
+
t.unshift(n), s = s.parentElement;
|
|
3491
3493
|
}
|
|
3492
3494
|
return t.join(">") || "unknown";
|
|
3493
3495
|
}
|
|
@@ -3499,11 +3501,11 @@ class br extends w {
|
|
|
3499
3501
|
try {
|
|
3500
3502
|
if (e.matches(t))
|
|
3501
3503
|
return e;
|
|
3502
|
-
const
|
|
3503
|
-
if (
|
|
3504
|
-
return
|
|
3505
|
-
} catch (
|
|
3506
|
-
a("debug", "Invalid selector in element search", { error:
|
|
3504
|
+
const s = e.closest(t);
|
|
3505
|
+
if (s)
|
|
3506
|
+
return s;
|
|
3507
|
+
} catch (s) {
|
|
3508
|
+
a("debug", "Invalid selector in element search", { error: s, data: { selector: t } });
|
|
3507
3509
|
continue;
|
|
3508
3510
|
}
|
|
3509
3511
|
return e;
|
|
@@ -3523,20 +3525,20 @@ class br extends w {
|
|
|
3523
3525
|
return Math.max(0, Math.min(1, Number(e.toFixed(3))));
|
|
3524
3526
|
}
|
|
3525
3527
|
calculateClickCoordinates(e, t) {
|
|
3526
|
-
const
|
|
3528
|
+
const s = t.getBoundingClientRect(), n = e.clientX, i = e.clientY, o = s.width > 0 ? this.clamp((n - s.left) / s.width) : 0, l = s.height > 0 ? this.clamp((i - s.top) / s.height) : 0;
|
|
3527
3529
|
return { x: n, y: i, relativeX: o, relativeY: l };
|
|
3528
3530
|
}
|
|
3529
3531
|
extractTrackingData(e) {
|
|
3530
|
-
const t = e.getAttribute(`${b}-name`),
|
|
3532
|
+
const t = e.getAttribute(`${b}-name`), s = e.getAttribute(`${b}-value`);
|
|
3531
3533
|
if (t)
|
|
3532
3534
|
return {
|
|
3533
3535
|
element: e,
|
|
3534
3536
|
name: t,
|
|
3535
|
-
...
|
|
3537
|
+
...s && { value: s }
|
|
3536
3538
|
};
|
|
3537
3539
|
}
|
|
3538
|
-
generateClickData(e, t,
|
|
3539
|
-
const { x: n, y: i, relativeX: o, relativeY: l } =
|
|
3540
|
+
generateClickData(e, t, s) {
|
|
3541
|
+
const { x: n, y: i, relativeX: o, relativeY: l } = s, c = this.getRelevantText(e, t), u = this.extractElementAttributes(t);
|
|
3540
3542
|
return {
|
|
3541
3543
|
x: n,
|
|
3542
3544
|
y: i,
|
|
@@ -3575,18 +3577,18 @@ class br extends w {
|
|
|
3575
3577
|
*/
|
|
3576
3578
|
sanitizeText(e) {
|
|
3577
3579
|
let t = e;
|
|
3578
|
-
for (const
|
|
3579
|
-
const n = new RegExp(
|
|
3580
|
+
for (const s of at) {
|
|
3581
|
+
const n = new RegExp(s.source, s.flags);
|
|
3580
3582
|
t = t.replace(n, "[REDACTED]");
|
|
3581
3583
|
}
|
|
3582
3584
|
return t;
|
|
3583
3585
|
}
|
|
3584
3586
|
getRelevantText(e, t) {
|
|
3585
|
-
const
|
|
3586
|
-
if (!
|
|
3587
|
+
const s = e.textContent?.trim() ?? "", n = t.textContent?.trim() ?? "";
|
|
3588
|
+
if (!s && !n)
|
|
3587
3589
|
return "";
|
|
3588
3590
|
let i = "";
|
|
3589
|
-
return
|
|
3591
|
+
return s && s.length <= 255 ? i = s : n.length <= 255 ? i = n : i = n.slice(0, 252) + "...", this.sanitizeText(i);
|
|
3590
3592
|
}
|
|
3591
3593
|
extractElementAttributes(e) {
|
|
3592
3594
|
const t = [
|
|
@@ -3600,12 +3602,12 @@ class br extends w {
|
|
|
3600
3602
|
"name",
|
|
3601
3603
|
"alt",
|
|
3602
3604
|
"role"
|
|
3603
|
-
],
|
|
3605
|
+
], s = {};
|
|
3604
3606
|
for (const n of t) {
|
|
3605
3607
|
const i = e.getAttribute(n);
|
|
3606
|
-
i && (
|
|
3608
|
+
i && (s[n] = i);
|
|
3607
3609
|
}
|
|
3608
|
-
return
|
|
3610
|
+
return s;
|
|
3609
3611
|
}
|
|
3610
3612
|
createCustomEventData(e) {
|
|
3611
3613
|
return {
|
|
@@ -3614,7 +3616,7 @@ class br extends w {
|
|
|
3614
3616
|
};
|
|
3615
3617
|
}
|
|
3616
3618
|
}
|
|
3617
|
-
class
|
|
3619
|
+
class As extends _ {
|
|
3618
3620
|
eventManager;
|
|
3619
3621
|
containers = [];
|
|
3620
3622
|
limitWarningLogged = !1;
|
|
@@ -3660,9 +3662,9 @@ class Ar extends w {
|
|
|
3660
3662
|
tryDetectScrollContainers(e) {
|
|
3661
3663
|
const t = this.findScrollableElements();
|
|
3662
3664
|
if (this.isWindowScrollable() && this.setupScrollContainer(window, "window"), t.length > 0) {
|
|
3663
|
-
for (const
|
|
3664
|
-
const n = this.getElementSelector(
|
|
3665
|
-
this.setupScrollContainer(
|
|
3665
|
+
for (const s of t) {
|
|
3666
|
+
const n = this.getElementSelector(s);
|
|
3667
|
+
this.setupScrollContainer(s, n);
|
|
3666
3668
|
}
|
|
3667
3669
|
this.applyPrimaryScrollSelectorIfConfigured();
|
|
3668
3670
|
return;
|
|
@@ -3691,9 +3693,9 @@ class Ar extends w {
|
|
|
3691
3693
|
return o.overflowY === "auto" || o.overflowY === "scroll" || o.overflow === "auto" || o.overflow === "scroll" ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
3692
3694
|
}
|
|
3693
3695
|
});
|
|
3694
|
-
let
|
|
3695
|
-
for (; (
|
|
3696
|
-
const n =
|
|
3696
|
+
let s;
|
|
3697
|
+
for (; (s = t.nextNode()) && e.length < 10; ) {
|
|
3698
|
+
const n = s;
|
|
3697
3699
|
this.isElementScrollable(n) && e.push(n);
|
|
3698
3700
|
}
|
|
3699
3701
|
return e;
|
|
@@ -3705,9 +3707,9 @@ class Ar extends w {
|
|
|
3705
3707
|
if (t.id)
|
|
3706
3708
|
return `#${t.id}`;
|
|
3707
3709
|
if (t.className && typeof t.className == "string") {
|
|
3708
|
-
const
|
|
3709
|
-
if (
|
|
3710
|
-
return `.${
|
|
3710
|
+
const s = t.className.split(" ").filter((n) => n.trim())[0];
|
|
3711
|
+
if (s)
|
|
3712
|
+
return `.${s}`;
|
|
3711
3713
|
}
|
|
3712
3714
|
return t.tagName.toLowerCase();
|
|
3713
3715
|
}
|
|
@@ -3745,10 +3747,10 @@ class Ar extends w {
|
|
|
3745
3747
|
};
|
|
3746
3748
|
l.listener = c, this.containers.push(l), e === window ? window.addEventListener("scroll", c, { passive: !0 }) : e.addEventListener("scroll", c, { passive: !0 });
|
|
3747
3749
|
}
|
|
3748
|
-
processScrollEvent(e, t,
|
|
3749
|
-
if (!this.shouldEmitScrollEvent(e, t,
|
|
3750
|
+
processScrollEvent(e, t, s) {
|
|
3751
|
+
if (!this.shouldEmitScrollEvent(e, t, s))
|
|
3750
3752
|
return;
|
|
3751
|
-
e.lastEventTime =
|
|
3753
|
+
e.lastEventTime = s, e.lastDepth = t.depth, e.lastDirection = t.direction;
|
|
3752
3754
|
const n = this.get("scrollEventCount") ?? 0;
|
|
3753
3755
|
this.set("scrollEventCount", n + 1), this.eventManager.track({
|
|
3754
3756
|
type: d.SCROLL,
|
|
@@ -3759,8 +3761,8 @@ class Ar extends w {
|
|
|
3759
3761
|
}
|
|
3760
3762
|
});
|
|
3761
3763
|
}
|
|
3762
|
-
shouldEmitScrollEvent(e, t,
|
|
3763
|
-
return this.hasReachedSessionLimit() ? (this.logLimitOnce(), !1) : !(!this.hasElapsedMinimumInterval(e,
|
|
3764
|
+
shouldEmitScrollEvent(e, t, s) {
|
|
3765
|
+
return this.hasReachedSessionLimit() ? (this.logLimitOnce(), !1) : !(!this.hasElapsedMinimumInterval(e, s) || !this.hasSignificantDepthChange(e, t.depth));
|
|
3764
3766
|
}
|
|
3765
3767
|
hasReachedSessionLimit() {
|
|
3766
3768
|
return (this.get("scrollEventCount") ?? 0) >= this.maxEventsPerSession;
|
|
@@ -3788,17 +3790,17 @@ class Ar extends w {
|
|
|
3788
3790
|
getScrollDirection(e, t) {
|
|
3789
3791
|
return e > t ? ee.DOWN : ee.UP;
|
|
3790
3792
|
}
|
|
3791
|
-
calculateScrollDepth(e, t,
|
|
3792
|
-
if (t <=
|
|
3793
|
+
calculateScrollDepth(e, t, s) {
|
|
3794
|
+
if (t <= s)
|
|
3793
3795
|
return 0;
|
|
3794
|
-
const n = t -
|
|
3796
|
+
const n = t - s;
|
|
3795
3797
|
return Math.min(100, Math.max(0, Math.floor(e / n * 100)));
|
|
3796
3798
|
}
|
|
3797
3799
|
calculateScrollData(e) {
|
|
3798
|
-
const { element: t, lastScrollPos:
|
|
3800
|
+
const { element: t, lastScrollPos: s, lastEventTime: n } = e, i = this.getScrollTop(t), o = Date.now(), l = Math.abs(i - s);
|
|
3799
3801
|
if (l < 10 || t === window && !this.isWindowScrollable())
|
|
3800
3802
|
return null;
|
|
3801
|
-
const c = this.getViewportHeight(t), u = this.getScrollHeight(t), g = this.getScrollDirection(i,
|
|
3803
|
+
const c = this.getViewportHeight(t), u = this.getScrollHeight(t), g = this.getScrollDirection(i, s), E = this.calculateScrollDepth(i, u, c);
|
|
3802
3804
|
let T;
|
|
3803
3805
|
n > 0 ? T = o - n : e.firstScrollEventTime !== null ? T = o - e.firstScrollEventTime : T = 250;
|
|
3804
3806
|
const S = Math.round(l / T * 1e3);
|
|
@@ -3819,8 +3821,8 @@ class Ar extends w {
|
|
|
3819
3821
|
return e === window ? document.documentElement.scrollHeight : e.scrollHeight;
|
|
3820
3822
|
}
|
|
3821
3823
|
isElementScrollable(e) {
|
|
3822
|
-
const t = getComputedStyle(e),
|
|
3823
|
-
return
|
|
3824
|
+
const t = getComputedStyle(e), s = t.overflowY === "auto" || t.overflowY === "scroll" || t.overflow === "auto" || t.overflow === "scroll", n = e.scrollHeight > e.clientHeight;
|
|
3825
|
+
return s && n;
|
|
3824
3826
|
}
|
|
3825
3827
|
applyPrimaryScrollSelector(e) {
|
|
3826
3828
|
let t;
|
|
@@ -3842,7 +3844,7 @@ class Ar extends w {
|
|
|
3842
3844
|
e.isPrimary = t;
|
|
3843
3845
|
}
|
|
3844
3846
|
}
|
|
3845
|
-
class
|
|
3847
|
+
class Ls extends _ {
|
|
3846
3848
|
eventManager;
|
|
3847
3849
|
trackedElements = /* @__PURE__ */ new Map();
|
|
3848
3850
|
observer = null;
|
|
@@ -3859,12 +3861,12 @@ class Lr extends w {
|
|
|
3859
3861
|
const e = this.get("config");
|
|
3860
3862
|
if (this.config = e.viewport ?? null, !this.config?.elements || this.config.elements.length === 0)
|
|
3861
3863
|
return;
|
|
3862
|
-
const t = this.config.threshold ?? 0.5,
|
|
3864
|
+
const t = this.config.threshold ?? 0.5, s = this.config.minDwellTime ?? 1e3;
|
|
3863
3865
|
if (t < 0 || t > 1) {
|
|
3864
3866
|
a("debug", "ViewportHandler: Invalid threshold, must be between 0 and 1");
|
|
3865
3867
|
return;
|
|
3866
3868
|
}
|
|
3867
|
-
if (
|
|
3869
|
+
if (s < 0) {
|
|
3868
3870
|
a("debug", "ViewportHandler: Invalid minDwellTime, must be non-negative");
|
|
3869
3871
|
return;
|
|
3870
3872
|
}
|
|
@@ -3892,15 +3894,15 @@ class Lr extends w {
|
|
|
3892
3894
|
if (!this.config || !this.observer) return;
|
|
3893
3895
|
const e = this.config.maxTrackedElements ?? 100;
|
|
3894
3896
|
let t = this.trackedElements.size;
|
|
3895
|
-
for (const
|
|
3897
|
+
for (const s of this.config.elements)
|
|
3896
3898
|
try {
|
|
3897
|
-
const n = document.querySelectorAll(
|
|
3899
|
+
const n = document.querySelectorAll(s.selector);
|
|
3898
3900
|
for (const i of Array.from(n)) {
|
|
3899
3901
|
if (t >= e) {
|
|
3900
3902
|
a("debug", "ViewportHandler: Maximum tracked elements reached", {
|
|
3901
3903
|
data: {
|
|
3902
3904
|
limit: e,
|
|
3903
|
-
selector:
|
|
3905
|
+
selector: s.selector,
|
|
3904
3906
|
message: "Some elements will not be tracked. Consider more specific selectors."
|
|
3905
3907
|
}
|
|
3906
3908
|
});
|
|
@@ -3908,16 +3910,16 @@ class Lr extends w {
|
|
|
3908
3910
|
}
|
|
3909
3911
|
i.hasAttribute(`${b}-ignore`) || this.trackedElements.has(i) || (this.trackedElements.set(i, {
|
|
3910
3912
|
element: i,
|
|
3911
|
-
selector:
|
|
3912
|
-
id:
|
|
3913
|
-
name:
|
|
3913
|
+
selector: s.selector,
|
|
3914
|
+
id: s.id,
|
|
3915
|
+
name: s.name,
|
|
3914
3916
|
startTime: null,
|
|
3915
3917
|
timeoutId: null,
|
|
3916
3918
|
lastFiredTime: null
|
|
3917
3919
|
}), this.observer?.observe(i), t++);
|
|
3918
3920
|
}
|
|
3919
3921
|
} catch (n) {
|
|
3920
|
-
a("debug", `ViewportHandler: Invalid selector "${
|
|
3922
|
+
a("debug", `ViewportHandler: Invalid selector "${s.selector}"`, { error: n });
|
|
3921
3923
|
}
|
|
3922
3924
|
a("debug", "ViewportHandler: Elements tracked", {
|
|
3923
3925
|
data: { count: t, limit: e }
|
|
@@ -3929,10 +3931,10 @@ class Lr extends w {
|
|
|
3929
3931
|
handleIntersection = (e) => {
|
|
3930
3932
|
if (!this.config) return;
|
|
3931
3933
|
const t = this.config.minDwellTime ?? 1e3;
|
|
3932
|
-
for (const
|
|
3933
|
-
const n = this.trackedElements.get(
|
|
3934
|
-
n && (
|
|
3935
|
-
const i = Math.round(
|
|
3934
|
+
for (const s of e) {
|
|
3935
|
+
const n = this.trackedElements.get(s.target);
|
|
3936
|
+
n && (s.isIntersecting ? n.startTime === null && (n.startTime = performance.now(), n.timeoutId = window.setTimeout(() => {
|
|
3937
|
+
const i = Math.round(s.intersectionRatio * 100) / 100;
|
|
3936
3938
|
this.fireViewportEvent(n, i);
|
|
3937
3939
|
}, t)) : n.startTime !== null && (n.timeoutId !== null && (window.clearTimeout(n.timeoutId), n.timeoutId = null), n.startTime = null));
|
|
3938
3940
|
}
|
|
@@ -3942,7 +3944,7 @@ class Lr extends w {
|
|
|
3942
3944
|
*/
|
|
3943
3945
|
fireViewportEvent(e, t) {
|
|
3944
3946
|
if (e.startTime === null) return;
|
|
3945
|
-
const
|
|
3947
|
+
const s = Math.round(performance.now() - e.startTime);
|
|
3946
3948
|
if (e.element.hasAttribute(`${b}-ignore`))
|
|
3947
3949
|
return;
|
|
3948
3950
|
const n = this.config?.cooldownPeriod ?? 6e4, i = Date.now();
|
|
@@ -3957,7 +3959,7 @@ class Lr extends w {
|
|
|
3957
3959
|
}
|
|
3958
3960
|
const o = {
|
|
3959
3961
|
selector: e.selector,
|
|
3960
|
-
dwellTime:
|
|
3962
|
+
dwellTime: s,
|
|
3961
3963
|
visibilityRatio: t,
|
|
3962
3964
|
...e.id !== void 0 && { id: e.id },
|
|
3963
3965
|
...e.name !== void 0 && { name: e.name }
|
|
@@ -3978,8 +3980,8 @@ class Lr extends w {
|
|
|
3978
3980
|
}
|
|
3979
3981
|
this.mutationObserver = new MutationObserver((e) => {
|
|
3980
3982
|
let t = !1;
|
|
3981
|
-
for (const
|
|
3982
|
-
|
|
3983
|
+
for (const s of e)
|
|
3984
|
+
s.type === "childList" && (s.addedNodes.length > 0 && (t = !0), s.removedNodes.length > 0 && this.cleanupRemovedNodes(s.removedNodes));
|
|
3983
3985
|
t && (this.mutationDebounceTimer !== null && window.clearTimeout(this.mutationDebounceTimer), this.mutationDebounceTimer = window.setTimeout(() => {
|
|
3984
3986
|
this.observeElements(), this.mutationDebounceTimer = null;
|
|
3985
3987
|
}, 100));
|
|
@@ -3995,15 +3997,58 @@ class Lr extends w {
|
|
|
3995
3997
|
cleanupRemovedNodes(e) {
|
|
3996
3998
|
e.forEach((t) => {
|
|
3997
3999
|
if (t.nodeType !== 1) return;
|
|
3998
|
-
const
|
|
3999
|
-
n && (n.timeoutId !== null && window.clearTimeout(n.timeoutId), this.observer?.unobserve(
|
|
4000
|
+
const s = t, n = this.trackedElements.get(s);
|
|
4001
|
+
n && (n.timeoutId !== null && window.clearTimeout(n.timeoutId), this.observer?.unobserve(s), this.trackedElements.delete(s)), Array.from(this.trackedElements.keys()).filter((o) => s.contains(o)).forEach((o) => {
|
|
4000
4002
|
const l = this.trackedElements.get(o);
|
|
4001
4003
|
l && l.timeoutId !== null && window.clearTimeout(l.timeoutId), this.observer?.unobserve(o), this.trackedElements.delete(o);
|
|
4002
4004
|
});
|
|
4003
4005
|
});
|
|
4004
4006
|
}
|
|
4005
4007
|
}
|
|
4006
|
-
|
|
4008
|
+
const Ms = "tracelog_session_id";
|
|
4009
|
+
class Cs extends _ {
|
|
4010
|
+
visibilityHandler = null;
|
|
4011
|
+
lastSyncedSessionId = null;
|
|
4012
|
+
activate() {
|
|
4013
|
+
this.cleanupVisibilityListener(), this.syncCartAttribute(), this.setupVisibilityListener();
|
|
4014
|
+
}
|
|
4015
|
+
deactivate() {
|
|
4016
|
+
this.cleanupVisibilityListener(), this.lastSyncedSessionId = null;
|
|
4017
|
+
}
|
|
4018
|
+
/** Re-syncs the cart attribute when session rotates (called by App on SESSION_START). */
|
|
4019
|
+
onSessionChange() {
|
|
4020
|
+
this.syncCartAttribute();
|
|
4021
|
+
}
|
|
4022
|
+
syncCartAttribute() {
|
|
4023
|
+
const e = this.get("sessionId");
|
|
4024
|
+
!e || e === this.lastSyncedSessionId || (this.lastSyncedSessionId = e, this.postCartUpdate(e));
|
|
4025
|
+
}
|
|
4026
|
+
postCartUpdate(e) {
|
|
4027
|
+
try {
|
|
4028
|
+
fetch("/cart/update.js", {
|
|
4029
|
+
method: "POST",
|
|
4030
|
+
headers: { "Content-Type": "application/json" },
|
|
4031
|
+
body: JSON.stringify({ attributes: { [Ms]: e } }),
|
|
4032
|
+
credentials: "same-origin"
|
|
4033
|
+
}).then((t) => {
|
|
4034
|
+
t.ok || (this.lastSyncedSessionId = null, a("debug", "Shopify cart attribute update failed", { data: { status: t.status } }));
|
|
4035
|
+
}).catch(() => {
|
|
4036
|
+
this.lastSyncedSessionId = null, a("debug", "Shopify cart attribute update failed");
|
|
4037
|
+
});
|
|
4038
|
+
} catch {
|
|
4039
|
+
this.lastSyncedSessionId = null, a("debug", "Shopify cart attribute update failed");
|
|
4040
|
+
}
|
|
4041
|
+
}
|
|
4042
|
+
setupVisibilityListener() {
|
|
4043
|
+
this.visibilityHandler = () => {
|
|
4044
|
+
document.hidden || this.syncCartAttribute();
|
|
4045
|
+
}, document.addEventListener("visibilitychange", this.visibilityHandler);
|
|
4046
|
+
}
|
|
4047
|
+
cleanupVisibilityListener() {
|
|
4048
|
+
this.visibilityHandler && (document.removeEventListener("visibilitychange", this.visibilityHandler), this.visibilityHandler = null);
|
|
4049
|
+
}
|
|
4050
|
+
}
|
|
4051
|
+
class Rs {
|
|
4007
4052
|
storage;
|
|
4008
4053
|
sessionStorageRef;
|
|
4009
4054
|
fallbackStorage = /* @__PURE__ */ new Map();
|
|
@@ -4051,8 +4096,8 @@ class Mr {
|
|
|
4051
4096
|
this.storage.setItem(e, t);
|
|
4052
4097
|
return;
|
|
4053
4098
|
}
|
|
4054
|
-
} catch (
|
|
4055
|
-
if (
|
|
4099
|
+
} catch (s) {
|
|
4100
|
+
if (s instanceof DOMException && s.name === "QuotaExceededError" || s instanceof Error && s.name === "QuotaExceededError")
|
|
4056
4101
|
if (this.hasQuotaExceededError = !0, a("warn", "localStorage quota exceeded, attempting cleanup", {
|
|
4057
4102
|
data: { key: e, valueSize: t.length }
|
|
4058
4103
|
}), this.cleanupOldData())
|
|
@@ -4069,7 +4114,7 @@ class Mr {
|
|
|
4069
4114
|
}
|
|
4070
4115
|
else
|
|
4071
4116
|
a("error", "localStorage quota exceeded and no data to cleanup - data will not persist", {
|
|
4072
|
-
error:
|
|
4117
|
+
error: s,
|
|
4073
4118
|
data: { key: e, valueSize: t.length }
|
|
4074
4119
|
});
|
|
4075
4120
|
}
|
|
@@ -4107,8 +4152,8 @@ class Mr {
|
|
|
4107
4152
|
try {
|
|
4108
4153
|
const e = [];
|
|
4109
4154
|
for (let t = 0; t < this.storage.length; t++) {
|
|
4110
|
-
const
|
|
4111
|
-
|
|
4155
|
+
const s = this.storage.key(t);
|
|
4156
|
+
s?.startsWith("tracelog_") && e.push(s);
|
|
4112
4157
|
}
|
|
4113
4158
|
e.forEach((t) => {
|
|
4114
4159
|
this.storage.removeItem(t);
|
|
@@ -4183,7 +4228,7 @@ class Mr {
|
|
|
4183
4228
|
} catch {
|
|
4184
4229
|
}
|
|
4185
4230
|
}), !0;
|
|
4186
|
-
const
|
|
4231
|
+
const s = ["tracelog_session_", "tracelog_user_id", "tracelog_device_id", "tracelog_config"], n = e.filter((i) => !s.some((o) => i.startsWith(o)));
|
|
4187
4232
|
return n.length > 0 ? (n.slice(0, 5).forEach((o) => {
|
|
4188
4233
|
try {
|
|
4189
4234
|
this.storage.removeItem(o);
|
|
@@ -4222,8 +4267,8 @@ class Mr {
|
|
|
4222
4267
|
if (typeof window > "u")
|
|
4223
4268
|
return null;
|
|
4224
4269
|
try {
|
|
4225
|
-
const t = e === "localStorage" ? window.localStorage : window.sessionStorage,
|
|
4226
|
-
return t.setItem(
|
|
4270
|
+
const t = e === "localStorage" ? window.localStorage : window.sessionStorage, s = "__tracelog_test__";
|
|
4271
|
+
return t.setItem(s, "test"), t.removeItem(s), t;
|
|
4227
4272
|
} catch {
|
|
4228
4273
|
return null;
|
|
4229
4274
|
}
|
|
@@ -4264,9 +4309,9 @@ class Mr {
|
|
|
4264
4309
|
this.sessionStorageRef.setItem(e, t);
|
|
4265
4310
|
return;
|
|
4266
4311
|
}
|
|
4267
|
-
} catch (
|
|
4268
|
-
(
|
|
4269
|
-
error:
|
|
4312
|
+
} catch (s) {
|
|
4313
|
+
(s instanceof DOMException && s.name === "QuotaExceededError" || s instanceof Error && s.name === "QuotaExceededError") && a("error", "sessionStorage quota exceeded - data will not persist", {
|
|
4314
|
+
error: s,
|
|
4270
4315
|
data: { key: e, valueSize: t.length }
|
|
4271
4316
|
});
|
|
4272
4317
|
}
|
|
@@ -4286,7 +4331,7 @@ class Mr {
|
|
|
4286
4331
|
this.fallbackSessionStorage.delete(e);
|
|
4287
4332
|
}
|
|
4288
4333
|
}
|
|
4289
|
-
class
|
|
4334
|
+
class Ns extends _ {
|
|
4290
4335
|
eventManager;
|
|
4291
4336
|
reportedByNav = /* @__PURE__ */ new Map();
|
|
4292
4337
|
navigationHistory = [];
|
|
@@ -4330,16 +4375,16 @@ class Cr extends w {
|
|
|
4330
4375
|
this.observers.forEach((e, t) => {
|
|
4331
4376
|
try {
|
|
4332
4377
|
e.disconnect();
|
|
4333
|
-
} catch (
|
|
4334
|
-
a("debug", "Failed to disconnect performance observer", { error:
|
|
4378
|
+
} catch (s) {
|
|
4379
|
+
a("debug", "Failed to disconnect performance observer", { error: s, data: { observerIndex: t } });
|
|
4335
4380
|
}
|
|
4336
4381
|
}), this.observers.length = 0, this.reportedByNav.clear(), this.navigationHistory.length = 0;
|
|
4337
4382
|
}
|
|
4338
4383
|
observeWebVitalsFallback() {
|
|
4339
4384
|
this.reportTTFB(), this.safeObserve(
|
|
4340
4385
|
"largest-contentful-paint",
|
|
4341
|
-
(
|
|
4342
|
-
const n =
|
|
4386
|
+
(s) => {
|
|
4387
|
+
const n = s.getEntries(), i = n[n.length - 1];
|
|
4343
4388
|
i && this.sendVital({ type: "LCP", value: Number(i.startTime.toFixed(2)) });
|
|
4344
4389
|
},
|
|
4345
4390
|
{ type: "largest-contentful-paint", buffered: !0 },
|
|
@@ -4348,10 +4393,10 @@ class Cr extends w {
|
|
|
4348
4393
|
let e = 0, t = this.getNavigationId();
|
|
4349
4394
|
this.safeObserve(
|
|
4350
4395
|
"layout-shift",
|
|
4351
|
-
(
|
|
4396
|
+
(s) => {
|
|
4352
4397
|
const n = this.getNavigationId();
|
|
4353
4398
|
n !== t && (e = 0, t = n);
|
|
4354
|
-
const i =
|
|
4399
|
+
const i = s.getEntries();
|
|
4355
4400
|
for (const o of i) {
|
|
4356
4401
|
if (o.hadRecentInput === !0)
|
|
4357
4402
|
continue;
|
|
@@ -4363,17 +4408,17 @@ class Cr extends w {
|
|
|
4363
4408
|
{ type: "layout-shift", buffered: !0 }
|
|
4364
4409
|
), this.safeObserve(
|
|
4365
4410
|
"paint",
|
|
4366
|
-
(
|
|
4367
|
-
for (const n of
|
|
4411
|
+
(s) => {
|
|
4412
|
+
for (const n of s.getEntries())
|
|
4368
4413
|
n.name === "first-contentful-paint" && this.sendVital({ type: "FCP", value: Number(n.startTime.toFixed(2)) });
|
|
4369
4414
|
},
|
|
4370
4415
|
{ type: "paint", buffered: !0 },
|
|
4371
4416
|
!0
|
|
4372
4417
|
), this.safeObserve(
|
|
4373
4418
|
"event",
|
|
4374
|
-
(
|
|
4419
|
+
(s) => {
|
|
4375
4420
|
let n = 0;
|
|
4376
|
-
const i =
|
|
4421
|
+
const i = s.getEntries();
|
|
4377
4422
|
for (const o of i) {
|
|
4378
4423
|
const l = (o.processingEnd ?? 0) - (o.startTime ?? 0);
|
|
4379
4424
|
n = Math.max(n, l);
|
|
@@ -4385,11 +4430,11 @@ class Cr extends w {
|
|
|
4385
4430
|
}
|
|
4386
4431
|
async initWebVitals() {
|
|
4387
4432
|
try {
|
|
4388
|
-
const { onLCP: e, onCLS: t, onFCP:
|
|
4433
|
+
const { onLCP: e, onCLS: t, onFCP: s, onTTFB: n, onINP: i } = await Promise.resolve().then(() => cr), o = (l) => (c) => {
|
|
4389
4434
|
const u = Number(c.value.toFixed(2));
|
|
4390
4435
|
this.sendVital({ type: l, value: u });
|
|
4391
4436
|
};
|
|
4392
|
-
e(o("LCP"), { reportAllChanges: !1 }), t(o("CLS"), { reportAllChanges: !1 }),
|
|
4437
|
+
e(o("LCP"), { reportAllChanges: !1 }), t(o("CLS"), { reportAllChanges: !1 }), s(o("FCP"), { reportAllChanges: !1 }), n(o("TTFB"), { reportAllChanges: !1 }), i(o("INP"), { reportAllChanges: !1 });
|
|
4393
4438
|
} catch (e) {
|
|
4394
4439
|
a("debug", "Failed to load web-vitals library, using fallback", { error: e }), this.observeWebVitalsFallback();
|
|
4395
4440
|
}
|
|
@@ -4410,8 +4455,8 @@ class Cr extends w {
|
|
|
4410
4455
|
"longtask",
|
|
4411
4456
|
(e) => {
|
|
4412
4457
|
const t = e.getEntries();
|
|
4413
|
-
for (const
|
|
4414
|
-
const n = Number(
|
|
4458
|
+
for (const s of t) {
|
|
4459
|
+
const n = Number(s.duration.toFixed(2)), i = Date.now();
|
|
4415
4460
|
i - this.lastLongTaskSentAt >= Kt && (this.shouldSendVital("LONG_TASK", n) && this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = i);
|
|
4416
4461
|
}
|
|
4417
4462
|
},
|
|
@@ -4423,11 +4468,11 @@ class Cr extends w {
|
|
|
4423
4468
|
return;
|
|
4424
4469
|
const t = this.getNavigationId();
|
|
4425
4470
|
if (t) {
|
|
4426
|
-
const
|
|
4427
|
-
if (
|
|
4471
|
+
const s = this.reportedByNav.get(t);
|
|
4472
|
+
if (s?.has(e.type))
|
|
4428
4473
|
return;
|
|
4429
|
-
if (
|
|
4430
|
-
|
|
4474
|
+
if (s)
|
|
4475
|
+
s.add(e.type);
|
|
4431
4476
|
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length > Yt) {
|
|
4432
4477
|
const i = this.navigationHistory.shift();
|
|
4433
4478
|
i && this.reportedByNav.delete(i);
|
|
@@ -4474,8 +4519,8 @@ class Cr extends w {
|
|
|
4474
4519
|
const e = performance.getEntriesByType("navigation")[0];
|
|
4475
4520
|
if (!e)
|
|
4476
4521
|
return null;
|
|
4477
|
-
const t = e.startTime || performance.now(),
|
|
4478
|
-
return
|
|
4522
|
+
const t = e.startTime || performance.now(), s = ++this.navigationCounter, n = `${t.toFixed(2)}_${window.location.pathname}`;
|
|
4523
|
+
return s > 1 ? `${n}_${s}` : n;
|
|
4479
4524
|
} catch (e) {
|
|
4480
4525
|
return a("debug", "Failed to get navigation ID", { error: e }), null;
|
|
4481
4526
|
}
|
|
@@ -4485,7 +4530,7 @@ class Cr extends w {
|
|
|
4485
4530
|
const t = PerformanceObserver.supportedEntryTypes;
|
|
4486
4531
|
return !t || t.includes(e);
|
|
4487
4532
|
}
|
|
4488
|
-
safeObserve(e, t,
|
|
4533
|
+
safeObserve(e, t, s, n = !1) {
|
|
4489
4534
|
try {
|
|
4490
4535
|
if (!this.isObserverSupported(e))
|
|
4491
4536
|
return !1;
|
|
@@ -4504,7 +4549,7 @@ class Cr extends w {
|
|
|
4504
4549
|
} catch {
|
|
4505
4550
|
}
|
|
4506
4551
|
});
|
|
4507
|
-
return i.observe(
|
|
4552
|
+
return i.observe(s ?? { type: e, buffered: !0 }), n || this.observers.push(i), !0;
|
|
4508
4553
|
} catch (i) {
|
|
4509
4554
|
return a("debug", "Failed to create performance observer", {
|
|
4510
4555
|
error: i,
|
|
@@ -4515,11 +4560,11 @@ class Cr extends w {
|
|
|
4515
4560
|
shouldSendVital(e, t) {
|
|
4516
4561
|
if (typeof t != "number" || !Number.isFinite(t))
|
|
4517
4562
|
return a("debug", "Invalid web vital value", { data: { type: e, value: t } }), !1;
|
|
4518
|
-
const
|
|
4519
|
-
return !(typeof
|
|
4563
|
+
const s = this.vitalThresholds[e];
|
|
4564
|
+
return !(typeof s == "number" && t <= s);
|
|
4520
4565
|
}
|
|
4521
4566
|
}
|
|
4522
|
-
class
|
|
4567
|
+
class ae extends _ {
|
|
4523
4568
|
eventManager;
|
|
4524
4569
|
recentErrors = /* @__PURE__ */ new Map();
|
|
4525
4570
|
errorBurstCounter = 0;
|
|
@@ -4562,8 +4607,8 @@ class oe extends w {
|
|
|
4562
4607
|
cooldownMs: ze
|
|
4563
4608
|
}
|
|
4564
4609
|
}), !1;
|
|
4565
|
-
const
|
|
4566
|
-
return Math.random() <
|
|
4610
|
+
const s = this.get("config").errorSampling ?? lt;
|
|
4611
|
+
return Math.random() < s;
|
|
4567
4612
|
}
|
|
4568
4613
|
handleError = (e) => {
|
|
4569
4614
|
if (!this.shouldSample())
|
|
@@ -4571,7 +4616,7 @@ class oe extends w {
|
|
|
4571
4616
|
const t = this.sanitize(e.message || "Unknown error");
|
|
4572
4617
|
if (this.shouldSuppressError(W.JS_ERROR, t))
|
|
4573
4618
|
return;
|
|
4574
|
-
const
|
|
4619
|
+
const s = typeof e.error?.stack == "string" ? this.truncateStack(e.error.stack) : void 0;
|
|
4575
4620
|
this.eventManager.track({
|
|
4576
4621
|
type: d.ERROR,
|
|
4577
4622
|
error_data: {
|
|
@@ -4580,22 +4625,22 @@ class oe extends w {
|
|
|
4580
4625
|
...e.filename !== "" && { filename: e.filename },
|
|
4581
4626
|
...e.lineno !== 0 && { line: e.lineno },
|
|
4582
4627
|
...e.colno !== 0 && { column: e.colno },
|
|
4583
|
-
...
|
|
4628
|
+
...s !== void 0 && { stack: s }
|
|
4584
4629
|
}
|
|
4585
4630
|
});
|
|
4586
4631
|
};
|
|
4587
4632
|
handleRejection = (e) => {
|
|
4588
4633
|
if (!this.shouldSample())
|
|
4589
4634
|
return;
|
|
4590
|
-
const t = this.extractRejectionMessage(e.reason),
|
|
4591
|
-
if (this.shouldSuppressError(W.PROMISE_REJECTION,
|
|
4635
|
+
const t = this.extractRejectionMessage(e.reason), s = this.sanitize(t);
|
|
4636
|
+
if (this.shouldSuppressError(W.PROMISE_REJECTION, s))
|
|
4592
4637
|
return;
|
|
4593
4638
|
const n = e.reason instanceof Error && typeof e.reason.stack == "string" ? this.truncateStack(e.reason.stack) : void 0;
|
|
4594
4639
|
this.eventManager.track({
|
|
4595
4640
|
type: d.ERROR,
|
|
4596
4641
|
error_data: {
|
|
4597
4642
|
type: W.PROMISE_REJECTION,
|
|
4598
|
-
message:
|
|
4643
|
+
message: s,
|
|
4599
4644
|
...n !== void 0 && { stack: n }
|
|
4600
4645
|
}
|
|
4601
4646
|
});
|
|
@@ -4619,22 +4664,22 @@ class oe extends w {
|
|
|
4619
4664
|
}
|
|
4620
4665
|
sanitizePii(e) {
|
|
4621
4666
|
let t = e;
|
|
4622
|
-
for (const
|
|
4623
|
-
const n = new RegExp(
|
|
4667
|
+
for (const s of at) {
|
|
4668
|
+
const n = new RegExp(s.source, s.flags);
|
|
4624
4669
|
t = t.replace(n, "[REDACTED]");
|
|
4625
4670
|
}
|
|
4626
4671
|
return t;
|
|
4627
4672
|
}
|
|
4628
4673
|
shouldSuppressError(e, t) {
|
|
4629
|
-
const
|
|
4630
|
-
return i !== void 0 &&
|
|
4674
|
+
const s = Date.now(), n = `${e}:${t}`, i = this.recentErrors.get(n);
|
|
4675
|
+
return i !== void 0 && s - i < je ? (this.recentErrors.set(n, s), !0) : (this.recentErrors.set(n, s), this.recentErrors.size > Xt ? (this.recentErrors.clear(), this.recentErrors.set(n, s), !1) : (this.recentErrors.size > te && this.pruneOldErrors(), !1));
|
|
4631
4676
|
}
|
|
4632
4677
|
static TRUNCATION_SUFFIX = `
|
|
4633
4678
|
...truncated`;
|
|
4634
4679
|
truncateStack(e) {
|
|
4635
4680
|
if (e.length <= Ge) return this.sanitizePii(e);
|
|
4636
|
-
const t = Ge -
|
|
4637
|
-
return this.sanitizePii(
|
|
4681
|
+
const t = Ge - ae.TRUNCATION_SUFFIX.length, s = e.slice(0, t) + ae.TRUNCATION_SUFFIX;
|
|
4682
|
+
return this.sanitizePii(s);
|
|
4638
4683
|
}
|
|
4639
4684
|
pruneOldErrors() {
|
|
4640
4685
|
const e = Date.now();
|
|
@@ -4642,22 +4687,23 @@ class oe extends w {
|
|
|
4642
4687
|
e - i > je && this.recentErrors.delete(n);
|
|
4643
4688
|
if (this.recentErrors.size <= te)
|
|
4644
4689
|
return;
|
|
4645
|
-
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]),
|
|
4646
|
-
for (let n = 0; n <
|
|
4690
|
+
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), s = this.recentErrors.size - te;
|
|
4691
|
+
for (let n = 0; n < s; n += 1) {
|
|
4647
4692
|
const i = t[n];
|
|
4648
4693
|
i && this.recentErrors.delete(i[0]);
|
|
4649
4694
|
}
|
|
4650
4695
|
}
|
|
4651
4696
|
}
|
|
4652
|
-
class
|
|
4697
|
+
class Os extends _ {
|
|
4653
4698
|
isInitialized = !1;
|
|
4654
4699
|
suppressNextScrollTimer = null;
|
|
4655
4700
|
pageUnloadHandler = null;
|
|
4656
|
-
emitter = new
|
|
4701
|
+
emitter = new gs();
|
|
4657
4702
|
transformers = {};
|
|
4658
4703
|
customHeadersProvider;
|
|
4659
4704
|
managers = {};
|
|
4660
4705
|
handlers = {};
|
|
4706
|
+
integrationInstances = {};
|
|
4661
4707
|
get initialized() {
|
|
4662
4708
|
return this.isInitialized;
|
|
4663
4709
|
}
|
|
@@ -4671,24 +4717,24 @@ class Rr extends w {
|
|
|
4671
4717
|
async init(e = {}) {
|
|
4672
4718
|
if (this.isInitialized)
|
|
4673
4719
|
return { sessionId: this.get("sessionId") ?? "" };
|
|
4674
|
-
this.managers.storage = new
|
|
4720
|
+
this.managers.storage = new Rs();
|
|
4675
4721
|
try {
|
|
4676
4722
|
this.setupState(e);
|
|
4677
|
-
const t = e.integrations?.custom?.headers ?? {},
|
|
4678
|
-
return this.managers.event = new
|
|
4723
|
+
const t = e.integrations?.custom?.headers ?? {}, s = e.integrations?.custom?.fetchCredentials ?? "include";
|
|
4724
|
+
return this.managers.event = new Ts(
|
|
4679
4725
|
this.managers.storage,
|
|
4680
4726
|
this.emitter,
|
|
4681
4727
|
this.transformers,
|
|
4682
4728
|
t,
|
|
4683
4729
|
this.customHeadersProvider,
|
|
4684
|
-
|
|
4730
|
+
s
|
|
4685
4731
|
), this.loadPersistedIdentity(), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((n) => {
|
|
4686
4732
|
a("warn", "Failed to recover persisted events", { error: n });
|
|
4687
4733
|
}), this.isInitialized = !0, { sessionId: this.get("sessionId") ?? "" };
|
|
4688
4734
|
} catch (t) {
|
|
4689
4735
|
this.destroy(!0);
|
|
4690
|
-
const
|
|
4691
|
-
throw new Error(`[TraceLog] TraceLog initialization failed: ${
|
|
4736
|
+
const s = t instanceof Error ? t.message : String(t);
|
|
4737
|
+
throw new Error(`[TraceLog] TraceLog initialization failed: ${s}`);
|
|
4692
4738
|
}
|
|
4693
4739
|
}
|
|
4694
4740
|
/**
|
|
@@ -4703,11 +4749,11 @@ class Rr extends w {
|
|
|
4703
4749
|
a("warn", "Cannot send custom event: TraceLog not initialized", { data: { name: e } });
|
|
4704
4750
|
return;
|
|
4705
4751
|
}
|
|
4706
|
-
let
|
|
4707
|
-
t && typeof t == "object" && !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && (
|
|
4708
|
-
const { valid: n, error: i, sanitizedMetadata: o } =
|
|
4752
|
+
let s = t;
|
|
4753
|
+
t && typeof t == "object" && !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && (s = Object.assign({}, t));
|
|
4754
|
+
const { valid: n, error: i, sanitizedMetadata: o } = ms(e, s);
|
|
4709
4755
|
if (!n) {
|
|
4710
|
-
if (this.get("mode") ===
|
|
4756
|
+
if (this.get("mode") === ie.QA)
|
|
4711
4757
|
throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${i}`);
|
|
4712
4758
|
a("warn", `Custom event "${e}" dropped: ${i}`);
|
|
4713
4759
|
return;
|
|
@@ -4768,21 +4814,21 @@ class Rr extends w {
|
|
|
4768
4814
|
!this.isInitialized && !e || (Object.values(this.handlers).filter(Boolean).forEach((t) => {
|
|
4769
4815
|
try {
|
|
4770
4816
|
t.stopTracking();
|
|
4771
|
-
} catch (
|
|
4772
|
-
a("warn", "Failed to stop tracking", { error:
|
|
4817
|
+
} catch (s) {
|
|
4818
|
+
a("warn", "Failed to stop tracking", { error: s });
|
|
4773
4819
|
}
|
|
4774
|
-
}), this.suppressNextScrollTimer && (clearTimeout(this.suppressNextScrollTimer), this.suppressNextScrollTimer = null), this.pageUnloadHandler && (window.removeEventListener("pagehide", this.pageUnloadHandler), window.removeEventListener("beforeunload", this.pageUnloadHandler), this.pageUnloadHandler = null), this.managers.event?.flushImmediatelySync(), 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.set("identity", void 0), this.clearPersistedIdentity(), this.isInitialized = !1, this.handlers = {}, this.managers = {});
|
|
4820
|
+
}), this.suppressNextScrollTimer && (clearTimeout(this.suppressNextScrollTimer), this.suppressNextScrollTimer = null), this.pageUnloadHandler && (window.removeEventListener("pagehide", this.pageUnloadHandler), window.removeEventListener("beforeunload", this.pageUnloadHandler), this.pageUnloadHandler = null), this.managers.event?.flushImmediatelySync(), 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.set("identity", void 0), this.clearPersistedIdentity(), this.integrationInstances.shopifyCartLinker?.deactivate(), this.integrationInstances = {}, this.isInitialized = !1, this.handlers = {}, this.managers = {});
|
|
4775
4821
|
}
|
|
4776
4822
|
setupState(e = {}) {
|
|
4777
4823
|
this.set("config", e);
|
|
4778
|
-
const t =
|
|
4824
|
+
const t = Is.getId(this.managers.storage);
|
|
4779
4825
|
this.set("userId", t);
|
|
4780
|
-
const
|
|
4781
|
-
this.set("collectApiUrls",
|
|
4826
|
+
const s = os(e);
|
|
4827
|
+
this.set("collectApiUrls", s);
|
|
4782
4828
|
const n = Wt();
|
|
4783
4829
|
this.set("device", n);
|
|
4784
4830
|
const i = ye(window.location.href, e.sensitiveQueryParams);
|
|
4785
|
-
this.set("pageUrl", i),
|
|
4831
|
+
this.set("pageUrl", i), es() && this.set("mode", ie.QA);
|
|
4786
4832
|
}
|
|
4787
4833
|
/**
|
|
4788
4834
|
* Returns the current configuration object.
|
|
@@ -4867,11 +4913,11 @@ class Rr extends w {
|
|
|
4867
4913
|
const t = this.validateGlobalMetadata(e);
|
|
4868
4914
|
if (!t.valid)
|
|
4869
4915
|
throw new Error(`[TraceLog] Invalid global metadata: ${t.error}`);
|
|
4870
|
-
const
|
|
4871
|
-
...
|
|
4916
|
+
const s = this.get("config"), i = {
|
|
4917
|
+
...s.globalMetadata ?? {},
|
|
4872
4918
|
...e
|
|
4873
4919
|
}, o = {
|
|
4874
|
-
...
|
|
4920
|
+
...s,
|
|
4875
4921
|
globalMetadata: i
|
|
4876
4922
|
};
|
|
4877
4923
|
this.set("config", o), a("debug", "Global metadata updated (merged)", { data: { keys: Object.keys(e) } });
|
|
@@ -4900,12 +4946,12 @@ class Rr extends w {
|
|
|
4900
4946
|
a("warn", "identify() userId exceeds 256 characters", { data: { length: e.trim().length } });
|
|
4901
4947
|
return;
|
|
4902
4948
|
}
|
|
4903
|
-
const
|
|
4904
|
-
userId:
|
|
4949
|
+
const s = e.trim(), n = ht(t), i = {
|
|
4950
|
+
userId: s,
|
|
4905
4951
|
...n ? { traits: n } : {}
|
|
4906
4952
|
};
|
|
4907
4953
|
this.set("identity", i), this.persistIdentity(i), a("debug", "Visitor identified", {
|
|
4908
|
-
data: { userIdLength:
|
|
4954
|
+
data: { userIdLength: s.length, traitKeys: n ? Object.keys(n) : [] }
|
|
4909
4955
|
});
|
|
4910
4956
|
}
|
|
4911
4957
|
/**
|
|
@@ -4920,7 +4966,7 @@ class Rr extends w {
|
|
|
4920
4966
|
async resetIdentity() {
|
|
4921
4967
|
await this.managers.event?.flushImmediately(), this.set("identity", void 0), this.clearPersistedIdentity();
|
|
4922
4968
|
const e = ut();
|
|
4923
|
-
this.managers.storage.setItem(
|
|
4969
|
+
this.managers.storage.setItem(Te, e), this.set("userId", e), this.set("hasStartSession", !1), this.set("sessionId", null), this.handlers.session?.stopTracking(), this.handlers.session?.startTracking(), a("debug", "Identity reset, new UUID generated");
|
|
4924
4970
|
}
|
|
4925
4971
|
/**
|
|
4926
4972
|
* Returns the project ID used for identity storage scoping.
|
|
@@ -4934,8 +4980,8 @@ class Rr extends w {
|
|
|
4934
4980
|
*/
|
|
4935
4981
|
persistIdentity(e) {
|
|
4936
4982
|
try {
|
|
4937
|
-
const t = this.getProjectId(),
|
|
4938
|
-
this.managers.storage.setItem(
|
|
4983
|
+
const t = this.getProjectId(), s = fe(t);
|
|
4984
|
+
this.managers.storage.setItem(s, JSON.stringify(e));
|
|
4939
4985
|
} catch {
|
|
4940
4986
|
a("debug", "Failed to persist identity to localStorage");
|
|
4941
4987
|
}
|
|
@@ -4945,7 +4991,7 @@ class Rr extends w {
|
|
|
4945
4991
|
* Also migrates pending identity (set before init) to the project-scoped key.
|
|
4946
4992
|
*/
|
|
4947
4993
|
loadPersistedIdentity() {
|
|
4948
|
-
const e = this.managers.storage, t = this.getProjectId(),
|
|
4994
|
+
const e = this.managers.storage, t = this.getProjectId(), s = fe(t);
|
|
4949
4995
|
try {
|
|
4950
4996
|
const n = e.getItem(H);
|
|
4951
4997
|
if (n) {
|
|
@@ -4955,18 +5001,18 @@ class Rr extends w {
|
|
|
4955
5001
|
return;
|
|
4956
5002
|
}
|
|
4957
5003
|
const o = { ...i, userId: i.userId.trim() };
|
|
4958
|
-
e.setItem(
|
|
5004
|
+
e.setItem(s, JSON.stringify(o)), this.set("identity", o), a("debug", "Migrated pending identity to project-scoped key");
|
|
4959
5005
|
return;
|
|
4960
5006
|
}
|
|
4961
5007
|
} catch {
|
|
4962
5008
|
e.removeItem(H);
|
|
4963
5009
|
}
|
|
4964
5010
|
try {
|
|
4965
|
-
const n = e.getItem(
|
|
5011
|
+
const n = e.getItem(s);
|
|
4966
5012
|
if (n) {
|
|
4967
5013
|
const i = JSON.parse(n);
|
|
4968
5014
|
if (!this.isValidIdentityData(i)) {
|
|
4969
|
-
e.removeItem(
|
|
5015
|
+
e.removeItem(s), a("debug", "Invalid persisted identity in localStorage, discarded");
|
|
4970
5016
|
return;
|
|
4971
5017
|
}
|
|
4972
5018
|
const o = { ...i, userId: i.userId.trim() };
|
|
@@ -4982,11 +5028,11 @@ class Rr extends w {
|
|
|
4982
5028
|
*/
|
|
4983
5029
|
isValidIdentityData(e) {
|
|
4984
5030
|
if (!e || typeof e != "object") return !1;
|
|
4985
|
-
const { userId: t, traits:
|
|
5031
|
+
const { userId: t, traits: s } = e;
|
|
4986
5032
|
if (typeof t != "string" || t.trim().length === 0 || t.trim().length > 256) return !1;
|
|
4987
|
-
if (
|
|
4988
|
-
if (typeof
|
|
4989
|
-
for (const n of Object.values(
|
|
5033
|
+
if (s !== void 0) {
|
|
5034
|
+
if (typeof s != "object" || s === null || Array.isArray(s)) return !1;
|
|
5035
|
+
for (const n of Object.values(s))
|
|
4990
5036
|
if (typeof n != "string") return !1;
|
|
4991
5037
|
}
|
|
4992
5038
|
return !0;
|
|
@@ -4997,7 +5043,7 @@ class Rr extends w {
|
|
|
4997
5043
|
clearPersistedIdentity() {
|
|
4998
5044
|
try {
|
|
4999
5045
|
const e = this.managers.storage, t = this.getProjectId();
|
|
5000
|
-
e.removeItem(
|
|
5046
|
+
e.removeItem(fe(t)), e.removeItem(H);
|
|
5001
5047
|
} catch {
|
|
5002
5048
|
a("debug", "Failed to clear persisted identity");
|
|
5003
5049
|
}
|
|
@@ -5009,7 +5055,7 @@ class Rr extends w {
|
|
|
5009
5055
|
}
|
|
5010
5056
|
initializeHandlers() {
|
|
5011
5057
|
const e = this.get("config");
|
|
5012
|
-
this.handlers.session = new
|
|
5058
|
+
this.handlers.session = new ys(
|
|
5013
5059
|
this.managers.storage,
|
|
5014
5060
|
this.managers.event
|
|
5015
5061
|
), this.handlers.session.startTracking();
|
|
@@ -5018,115 +5064,120 @@ class Rr extends w {
|
|
|
5018
5064
|
this.set("suppressNextScroll", !1);
|
|
5019
5065
|
}, 500);
|
|
5020
5066
|
};
|
|
5021
|
-
this.handlers.pageView = new
|
|
5022
|
-
a("warn", "Failed to start performance tracking", { error:
|
|
5023
|
-
}), this.handlers.error = new
|
|
5067
|
+
if (this.handlers.pageView = new ws(this.managers.event, t), this.handlers.pageView.startTracking(), this.handlers.click = new bs(this.managers.event), this.handlers.click.startTracking(), this.handlers.scroll = new As(this.managers.event), this.handlers.scroll.startTracking(), this.handlers.performance = new Ns(this.managers.event), this.handlers.performance.startTracking().catch((s) => {
|
|
5068
|
+
a("warn", "Failed to start performance tracking", { error: s });
|
|
5069
|
+
}), this.handlers.error = new ae(this.managers.event), this.handlers.error.startTracking(), e.viewport && (this.handlers.viewport = new Ls(this.managers.event), this.handlers.viewport.startTracking()), e.integrations?.tracelog?.shopify) {
|
|
5070
|
+
const s = new Cs();
|
|
5071
|
+
s.activate(), this.integrationInstances.shopifyCartLinker = s, this.emitter.on(re.EVENT, (n) => {
|
|
5072
|
+
n.type === d.SESSION_START && s.onSessionChange();
|
|
5073
|
+
});
|
|
5074
|
+
}
|
|
5024
5075
|
}
|
|
5025
5076
|
}
|
|
5026
|
-
const
|
|
5027
|
-
let
|
|
5028
|
-
const
|
|
5077
|
+
const V = [], M = [];
|
|
5078
|
+
let k = null, h = null, R = !1, p = !1, D = null;
|
|
5079
|
+
const Ps = async (r) => typeof window > "u" || typeof document > "u" ? { sessionId: "" } : (p = !1, window.__traceLogDisabled === !0 ? { sessionId: "" } : h ? { sessionId: h.getSessionId() ?? "" } : (R && D || (R = !0, D = (async () => {
|
|
5029
5080
|
try {
|
|
5030
|
-
const e =
|
|
5081
|
+
const e = ds(r ?? {}), t = new Os();
|
|
5031
5082
|
try {
|
|
5032
|
-
|
|
5083
|
+
V.forEach(({ event: o, callback: l }) => {
|
|
5033
5084
|
t.on(o, l);
|
|
5034
|
-
}),
|
|
5085
|
+
}), V.length = 0, M.forEach(({ hook: o, fn: l }) => {
|
|
5035
5086
|
o === "beforeSend" ? t.setTransformer("beforeSend", l) : t.setTransformer("beforeBatch", l);
|
|
5036
|
-
}), M.length = 0,
|
|
5037
|
-
const
|
|
5087
|
+
}), M.length = 0, k && (t.setCustomHeaders(k), k = null);
|
|
5088
|
+
const s = t.init(e), n = new Promise((o, l) => {
|
|
5038
5089
|
setTimeout(() => {
|
|
5039
5090
|
l(new Error("[TraceLog] Initialization timeout after 10000ms"));
|
|
5040
5091
|
}, 1e4);
|
|
5041
|
-
}), i = await Promise.race([
|
|
5092
|
+
}), i = await Promise.race([s, n]);
|
|
5042
5093
|
return h = t, i;
|
|
5043
|
-
} catch (
|
|
5094
|
+
} catch (s) {
|
|
5044
5095
|
try {
|
|
5045
5096
|
t.destroy(!0);
|
|
5046
5097
|
} catch (n) {
|
|
5047
5098
|
a("error", "Failed to cleanup partially initialized app", { error: n });
|
|
5048
5099
|
}
|
|
5049
|
-
throw
|
|
5100
|
+
throw s;
|
|
5050
5101
|
}
|
|
5051
5102
|
} catch (e) {
|
|
5052
5103
|
throw h = null, e;
|
|
5053
5104
|
} finally {
|
|
5054
|
-
R = !1,
|
|
5105
|
+
R = !1, D = null;
|
|
5055
5106
|
}
|
|
5056
|
-
})()),
|
|
5107
|
+
})()), D)), Ds = (r, e) => {
|
|
5057
5108
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5058
5109
|
if (!h)
|
|
5059
5110
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
5060
5111
|
if (p)
|
|
5061
5112
|
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
5062
|
-
h.sendCustomEvent(
|
|
5113
|
+
h.sendCustomEvent(r, e);
|
|
5063
5114
|
}
|
|
5064
|
-
},
|
|
5115
|
+
}, ks = (r, e) => {
|
|
5065
5116
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5066
5117
|
if (!h || R) {
|
|
5067
|
-
|
|
5118
|
+
V.push({ event: r, callback: e });
|
|
5068
5119
|
return;
|
|
5069
5120
|
}
|
|
5070
|
-
h.on(
|
|
5121
|
+
h.on(r, e);
|
|
5071
5122
|
}
|
|
5072
|
-
},
|
|
5123
|
+
}, Vs = (r, e) => {
|
|
5073
5124
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5074
5125
|
if (!h) {
|
|
5075
|
-
const t =
|
|
5076
|
-
t !== -1 &&
|
|
5126
|
+
const t = V.findIndex((s) => s.event === r && s.callback === e);
|
|
5127
|
+
t !== -1 && V.splice(t, 1);
|
|
5077
5128
|
return;
|
|
5078
5129
|
}
|
|
5079
|
-
h.off(
|
|
5130
|
+
h.off(r, e);
|
|
5080
5131
|
}
|
|
5081
5132
|
};
|
|
5082
|
-
function
|
|
5133
|
+
function Us(r, e) {
|
|
5083
5134
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5084
5135
|
if (typeof e != "function")
|
|
5085
5136
|
throw new Error(`[TraceLog] Transformer must be a function, received: ${typeof e}`);
|
|
5086
5137
|
if (!h || R) {
|
|
5087
|
-
const t = M.findIndex((
|
|
5088
|
-
t !== -1 && M.splice(t, 1), M.push({ hook:
|
|
5138
|
+
const t = M.findIndex((s) => s.hook === r);
|
|
5139
|
+
t !== -1 && M.splice(t, 1), M.push({ hook: r, fn: e });
|
|
5089
5140
|
return;
|
|
5090
5141
|
}
|
|
5091
5142
|
if (p)
|
|
5092
5143
|
throw new Error("[TraceLog] Cannot set transformers while TraceLog is being destroyed");
|
|
5093
|
-
|
|
5144
|
+
r === "beforeSend" ? h.setTransformer("beforeSend", e) : h.setTransformer("beforeBatch", e);
|
|
5094
5145
|
}
|
|
5095
5146
|
}
|
|
5096
|
-
const
|
|
5147
|
+
const Hs = (r) => {
|
|
5097
5148
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5098
5149
|
if (!h) {
|
|
5099
|
-
const e = M.findIndex((t) => t.hook ===
|
|
5150
|
+
const e = M.findIndex((t) => t.hook === r);
|
|
5100
5151
|
e !== -1 && M.splice(e, 1);
|
|
5101
5152
|
return;
|
|
5102
5153
|
}
|
|
5103
5154
|
if (p)
|
|
5104
5155
|
throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
|
|
5105
|
-
h.removeTransformer(
|
|
5156
|
+
h.removeTransformer(r);
|
|
5106
5157
|
}
|
|
5107
|
-
},
|
|
5158
|
+
}, Fs = (r) => {
|
|
5108
5159
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5109
|
-
if (typeof
|
|
5110
|
-
throw new Error(`[TraceLog] Custom headers provider must be a function, received: ${typeof
|
|
5160
|
+
if (typeof r != "function")
|
|
5161
|
+
throw new Error(`[TraceLog] Custom headers provider must be a function, received: ${typeof r}`);
|
|
5111
5162
|
if (!h || R) {
|
|
5112
|
-
|
|
5163
|
+
k = r;
|
|
5113
5164
|
return;
|
|
5114
5165
|
}
|
|
5115
5166
|
if (p)
|
|
5116
5167
|
throw new Error("[TraceLog] Cannot set custom headers while TraceLog is being destroyed");
|
|
5117
|
-
h.setCustomHeaders(
|
|
5168
|
+
h.setCustomHeaders(r);
|
|
5118
5169
|
}
|
|
5119
|
-
},
|
|
5170
|
+
}, xs = () => {
|
|
5120
5171
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5121
5172
|
if (!h) {
|
|
5122
|
-
|
|
5173
|
+
k = null;
|
|
5123
5174
|
return;
|
|
5124
5175
|
}
|
|
5125
5176
|
if (p)
|
|
5126
5177
|
throw new Error("[TraceLog] Cannot remove custom headers while TraceLog is being destroyed");
|
|
5127
5178
|
h.removeCustomHeaders();
|
|
5128
5179
|
}
|
|
5129
|
-
},
|
|
5180
|
+
}, $s = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, Bs = () => typeof window > "u" || typeof document > "u" || !h ? null : h.getSessionId(), Ws = () => {
|
|
5130
5181
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5131
5182
|
if (p)
|
|
5132
5183
|
throw new Error("[TraceLog] Destroy operation already in progress");
|
|
@@ -5136,36 +5187,36 @@ const Vr = (s) => {
|
|
|
5136
5187
|
}
|
|
5137
5188
|
p = !0;
|
|
5138
5189
|
try {
|
|
5139
|
-
h.destroy(), h = null, R = !1,
|
|
5140
|
-
} catch (
|
|
5141
|
-
h = null, R = !1,
|
|
5190
|
+
h.destroy(), h = null, R = !1, D = null, V.length = 0, M.length = 0, k = null, p = !1;
|
|
5191
|
+
} catch (r) {
|
|
5192
|
+
h = null, R = !1, D = null, V.length = 0, M.length = 0, k = null, p = !1, a("warn", "Error during destroy, forced cleanup completed", { error: r });
|
|
5142
5193
|
}
|
|
5143
5194
|
}
|
|
5144
|
-
},
|
|
5145
|
-
typeof window > "u" || typeof document > "u" ||
|
|
5146
|
-
},
|
|
5195
|
+
}, Xs = (r) => {
|
|
5196
|
+
typeof window > "u" || typeof document > "u" || ts(r);
|
|
5197
|
+
}, Gs = (r) => {
|
|
5147
5198
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5148
5199
|
if (!h)
|
|
5149
5200
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
5150
5201
|
if (p)
|
|
5151
5202
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
5152
|
-
h.updateGlobalMetadata(
|
|
5203
|
+
h.updateGlobalMetadata(r);
|
|
5153
5204
|
}
|
|
5154
|
-
},
|
|
5205
|
+
}, js = (r) => {
|
|
5155
5206
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5156
5207
|
if (!h)
|
|
5157
5208
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
5158
5209
|
if (p)
|
|
5159
5210
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
5160
|
-
h.mergeGlobalMetadata(
|
|
5211
|
+
h.mergeGlobalMetadata(r);
|
|
5161
5212
|
}
|
|
5162
|
-
},
|
|
5213
|
+
}, zs = (r, e) => {
|
|
5163
5214
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5164
|
-
if (!
|
|
5215
|
+
if (!r || typeof r != "string" || r.trim().length === 0) {
|
|
5165
5216
|
a("warn", "identify() called with invalid userId");
|
|
5166
5217
|
return;
|
|
5167
5218
|
}
|
|
5168
|
-
if (
|
|
5219
|
+
if (r.trim().length > 256) {
|
|
5169
5220
|
a("warn", "identify() userId exceeds 256 characters");
|
|
5170
5221
|
return;
|
|
5171
5222
|
}
|
|
@@ -5174,20 +5225,20 @@ const Vr = (s) => {
|
|
|
5174
5225
|
return;
|
|
5175
5226
|
}
|
|
5176
5227
|
if (h) {
|
|
5177
|
-
h.identify(
|
|
5228
|
+
h.identify(r, e);
|
|
5178
5229
|
return;
|
|
5179
5230
|
}
|
|
5180
5231
|
try {
|
|
5181
|
-
const t = ht(e),
|
|
5182
|
-
userId:
|
|
5232
|
+
const t = ht(e), s = {
|
|
5233
|
+
userId: r.trim(),
|
|
5183
5234
|
...t ? { traits: t } : {}
|
|
5184
5235
|
};
|
|
5185
|
-
localStorage.setItem(H, JSON.stringify(
|
|
5236
|
+
localStorage.setItem(H, JSON.stringify(s)), a("debug", "Identity persisted pre-init (will be applied on init)");
|
|
5186
5237
|
} catch {
|
|
5187
5238
|
a("debug", "Failed to persist pre-init identity");
|
|
5188
5239
|
}
|
|
5189
5240
|
}
|
|
5190
|
-
},
|
|
5241
|
+
}, Qs = async () => {
|
|
5191
5242
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5192
5243
|
if (!h) {
|
|
5193
5244
|
try {
|
|
@@ -5200,252 +5251,252 @@ const Vr = (s) => {
|
|
|
5200
5251
|
throw new Error("[TraceLog] Cannot reset identity while TraceLog is being destroyed");
|
|
5201
5252
|
await h.resetIdentity();
|
|
5202
5253
|
}
|
|
5203
|
-
},
|
|
5204
|
-
init:
|
|
5205
|
-
event:
|
|
5206
|
-
on:
|
|
5207
|
-
off:
|
|
5208
|
-
setTransformer:
|
|
5209
|
-
removeTransformer:
|
|
5210
|
-
setCustomHeaders:
|
|
5211
|
-
removeCustomHeaders:
|
|
5212
|
-
isInitialized:
|
|
5213
|
-
getSessionId:
|
|
5214
|
-
destroy:
|
|
5215
|
-
setQaMode:
|
|
5216
|
-
updateGlobalMetadata:
|
|
5217
|
-
mergeGlobalMetadata:
|
|
5218
|
-
identify:
|
|
5219
|
-
resetIdentity:
|
|
5254
|
+
}, yr = {
|
|
5255
|
+
init: Ps,
|
|
5256
|
+
event: Ds,
|
|
5257
|
+
on: ks,
|
|
5258
|
+
off: Vs,
|
|
5259
|
+
setTransformer: Us,
|
|
5260
|
+
removeTransformer: Hs,
|
|
5261
|
+
setCustomHeaders: Fs,
|
|
5262
|
+
removeCustomHeaders: xs,
|
|
5263
|
+
isInitialized: $s,
|
|
5264
|
+
getSessionId: Bs,
|
|
5265
|
+
destroy: Ws,
|
|
5266
|
+
setQaMode: Xs,
|
|
5267
|
+
updateGlobalMetadata: Gs,
|
|
5268
|
+
mergeGlobalMetadata: js,
|
|
5269
|
+
identify: zs,
|
|
5270
|
+
resetIdentity: Qs
|
|
5220
5271
|
};
|
|
5221
|
-
var Ae, C, j, Et,
|
|
5272
|
+
var Ae, C, j, Et, le, St = -1, U = function(r) {
|
|
5222
5273
|
addEventListener("pageshow", (function(e) {
|
|
5223
|
-
e.persisted && (St = e.timeStamp,
|
|
5274
|
+
e.persisted && (St = e.timeStamp, r(e));
|
|
5224
5275
|
}), !0);
|
|
5225
5276
|
}, Pe = function() {
|
|
5226
|
-
var
|
|
5227
|
-
if (
|
|
5228
|
-
},
|
|
5229
|
-
var
|
|
5230
|
-
return
|
|
5231
|
-
},
|
|
5232
|
-
var t = Pe(),
|
|
5233
|
-
return St >= 0 ?
|
|
5234
|
-
}, x = function(
|
|
5277
|
+
var r = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
|
|
5278
|
+
if (r && r.responseStart > 0 && r.responseStart < performance.now()) return r;
|
|
5279
|
+
}, ue = function() {
|
|
5280
|
+
var r = Pe();
|
|
5281
|
+
return r && r.activationStart || 0;
|
|
5282
|
+
}, y = function(r, e) {
|
|
5283
|
+
var t = Pe(), s = "navigate";
|
|
5284
|
+
return St >= 0 ? s = "back-forward-cache" : t && (document.prerendering || ue() > 0 ? s = "prerender" : document.wasDiscarded ? s = "restore" : t.type && (s = t.type.replace(/_/g, "-"))), { name: r, value: e === void 0 ? -1 : e, rating: "good", delta: 0, entries: [], id: "v4-".concat(Date.now(), "-").concat(Math.floor(8999999999999 * Math.random()) + 1e12), navigationType: s };
|
|
5285
|
+
}, x = function(r, e, t) {
|
|
5235
5286
|
try {
|
|
5236
|
-
if (PerformanceObserver.supportedEntryTypes.includes(
|
|
5237
|
-
var
|
|
5287
|
+
if (PerformanceObserver.supportedEntryTypes.includes(r)) {
|
|
5288
|
+
var s = new PerformanceObserver((function(n) {
|
|
5238
5289
|
Promise.resolve().then((function() {
|
|
5239
5290
|
e(n.getEntries());
|
|
5240
5291
|
}));
|
|
5241
5292
|
}));
|
|
5242
|
-
return
|
|
5293
|
+
return s.observe(Object.assign({ type: r, buffered: !0 }, t || {})), s;
|
|
5243
5294
|
}
|
|
5244
5295
|
} catch {
|
|
5245
5296
|
}
|
|
5246
|
-
},
|
|
5297
|
+
}, w = function(r, e, t, s) {
|
|
5247
5298
|
var n, i;
|
|
5248
5299
|
return function(o) {
|
|
5249
|
-
e.value >= 0 && (o ||
|
|
5300
|
+
e.value >= 0 && (o || s) && ((i = e.value - (n || 0)) || n === void 0) && (n = e.value, e.delta = i, e.rating = (function(l, c) {
|
|
5250
5301
|
return l > c[1] ? "poor" : l > c[0] ? "needs-improvement" : "good";
|
|
5251
|
-
})(e.value, t),
|
|
5302
|
+
})(e.value, t), r(e));
|
|
5252
5303
|
};
|
|
5253
|
-
}, De = function(
|
|
5304
|
+
}, De = function(r) {
|
|
5254
5305
|
requestAnimationFrame((function() {
|
|
5255
5306
|
return requestAnimationFrame((function() {
|
|
5256
|
-
return
|
|
5307
|
+
return r();
|
|
5257
5308
|
}));
|
|
5258
5309
|
}));
|
|
5259
|
-
}, Q = function(
|
|
5310
|
+
}, Q = function(r) {
|
|
5260
5311
|
document.addEventListener("visibilitychange", (function() {
|
|
5261
|
-
document.visibilityState === "hidden" &&
|
|
5312
|
+
document.visibilityState === "hidden" && r();
|
|
5262
5313
|
}));
|
|
5263
|
-
},
|
|
5314
|
+
}, de = function(r) {
|
|
5264
5315
|
var e = !1;
|
|
5265
5316
|
return function() {
|
|
5266
|
-
e || (
|
|
5317
|
+
e || (r(), e = !0);
|
|
5267
5318
|
};
|
|
5268
5319
|
}, F = -1, et = function() {
|
|
5269
5320
|
return document.visibilityState !== "hidden" || document.prerendering ? 1 / 0 : 0;
|
|
5270
|
-
},
|
|
5271
|
-
document.visibilityState === "hidden" && F > -1 && (F =
|
|
5321
|
+
}, ce = function(r) {
|
|
5322
|
+
document.visibilityState === "hidden" && F > -1 && (F = r.type === "visibilitychange" ? r.timeStamp : 0, Ks());
|
|
5272
5323
|
}, tt = function() {
|
|
5273
|
-
addEventListener("visibilitychange",
|
|
5274
|
-
},
|
|
5275
|
-
removeEventListener("visibilitychange",
|
|
5324
|
+
addEventListener("visibilitychange", ce, !0), addEventListener("prerenderingchange", ce, !0);
|
|
5325
|
+
}, Ks = function() {
|
|
5326
|
+
removeEventListener("visibilitychange", ce, !0), removeEventListener("prerenderingchange", ce, !0);
|
|
5276
5327
|
}, ke = function() {
|
|
5277
|
-
return F < 0 && (F = et(), tt(),
|
|
5328
|
+
return F < 0 && (F = et(), tt(), U((function() {
|
|
5278
5329
|
setTimeout((function() {
|
|
5279
5330
|
F = et(), tt();
|
|
5280
5331
|
}), 0);
|
|
5281
5332
|
}))), { get firstHiddenTime() {
|
|
5282
5333
|
return F;
|
|
5283
5334
|
} };
|
|
5284
|
-
}, K = function(
|
|
5335
|
+
}, K = function(r) {
|
|
5285
5336
|
document.prerendering ? addEventListener("prerenderingchange", (function() {
|
|
5286
|
-
return
|
|
5287
|
-
}), !0) :
|
|
5288
|
-
}, Le = [1800, 3e3], pt = function(
|
|
5337
|
+
return r();
|
|
5338
|
+
}), !0) : r();
|
|
5339
|
+
}, Le = [1800, 3e3], pt = function(r, e) {
|
|
5289
5340
|
e = e || {}, K((function() {
|
|
5290
|
-
var t,
|
|
5341
|
+
var t, s = ke(), n = y("FCP"), i = x("paint", (function(o) {
|
|
5291
5342
|
o.forEach((function(l) {
|
|
5292
|
-
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime <
|
|
5343
|
+
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime < s.firstHiddenTime && (n.value = Math.max(l.startTime - ue(), 0), n.entries.push(l), t(!0)));
|
|
5293
5344
|
}));
|
|
5294
5345
|
}));
|
|
5295
|
-
i && (t =
|
|
5296
|
-
n =
|
|
5346
|
+
i && (t = w(r, n, Le, e.reportAllChanges), U((function(o) {
|
|
5347
|
+
n = y("FCP"), t = w(r, n, Le, e.reportAllChanges), De((function() {
|
|
5297
5348
|
n.value = performance.now() - o.timeStamp, t(!0);
|
|
5298
5349
|
}));
|
|
5299
5350
|
})));
|
|
5300
5351
|
}));
|
|
5301
|
-
}, Me = [0.1, 0.25],
|
|
5302
|
-
e = e || {}, pt(
|
|
5303
|
-
var t,
|
|
5352
|
+
}, Me = [0.1, 0.25], Ys = function(r, e) {
|
|
5353
|
+
e = e || {}, pt(de((function() {
|
|
5354
|
+
var t, s = y("CLS", 0), n = 0, i = [], o = function(c) {
|
|
5304
5355
|
c.forEach((function(u) {
|
|
5305
5356
|
if (!u.hadRecentInput) {
|
|
5306
5357
|
var g = i[0], E = i[i.length - 1];
|
|
5307
5358
|
n && u.startTime - E.startTime < 1e3 && u.startTime - g.startTime < 5e3 ? (n += u.value, i.push(u)) : (n = u.value, i = [u]);
|
|
5308
5359
|
}
|
|
5309
|
-
})), n >
|
|
5360
|
+
})), n > s.value && (s.value = n, s.entries = i, t());
|
|
5310
5361
|
}, l = x("layout-shift", o);
|
|
5311
|
-
l && (t =
|
|
5362
|
+
l && (t = w(r, s, Me, e.reportAllChanges), Q((function() {
|
|
5312
5363
|
o(l.takeRecords()), t(!0);
|
|
5313
|
-
})),
|
|
5314
|
-
n = 0,
|
|
5364
|
+
})), U((function() {
|
|
5365
|
+
n = 0, s = y("CLS", 0), t = w(r, s, Me, e.reportAllChanges), De((function() {
|
|
5315
5366
|
return t();
|
|
5316
5367
|
}));
|
|
5317
5368
|
})), setTimeout(t, 0));
|
|
5318
5369
|
})));
|
|
5319
|
-
}, Tt = 0,
|
|
5320
|
-
|
|
5321
|
-
e.interactionId && (
|
|
5370
|
+
}, Tt = 0, Se = 1 / 0, Z = 0, qs = function(r) {
|
|
5371
|
+
r.forEach((function(e) {
|
|
5372
|
+
e.interactionId && (Se = Math.min(Se, e.interactionId), Z = Math.max(Z, e.interactionId), Tt = Z ? (Z - Se) / 7 + 1 : 0);
|
|
5322
5373
|
}));
|
|
5323
5374
|
}, It = function() {
|
|
5324
5375
|
return Ae ? Tt : performance.interactionCount || 0;
|
|
5325
|
-
},
|
|
5326
|
-
"interactionCount" in performance || Ae || (Ae = x("event",
|
|
5327
|
-
}, A = [],
|
|
5328
|
-
var
|
|
5329
|
-
return A[
|
|
5330
|
-
},
|
|
5331
|
-
if (
|
|
5332
|
-
return n(
|
|
5333
|
-
})),
|
|
5334
|
-
var e = A[A.length - 1], t =
|
|
5335
|
-
if (t || A.length < 10 ||
|
|
5336
|
-
if (t)
|
|
5376
|
+
}, Js = function() {
|
|
5377
|
+
"interactionCount" in performance || Ae || (Ae = x("event", qs, { type: "event", buffered: !0, durationThreshold: 0 }));
|
|
5378
|
+
}, A = [], se = /* @__PURE__ */ new Map(), vt = 0, Zs = function() {
|
|
5379
|
+
var r = Math.min(A.length - 1, Math.floor((It() - vt) / 50));
|
|
5380
|
+
return A[r];
|
|
5381
|
+
}, er = [], tr = function(r) {
|
|
5382
|
+
if (er.forEach((function(n) {
|
|
5383
|
+
return n(r);
|
|
5384
|
+
})), r.interactionId || r.entryType === "first-input") {
|
|
5385
|
+
var e = A[A.length - 1], t = se.get(r.interactionId);
|
|
5386
|
+
if (t || A.length < 10 || r.duration > e.latency) {
|
|
5387
|
+
if (t) r.duration > t.latency ? (t.entries = [r], t.latency = r.duration) : r.duration === t.latency && r.startTime === t.entries[0].startTime && t.entries.push(r);
|
|
5337
5388
|
else {
|
|
5338
|
-
var
|
|
5339
|
-
|
|
5389
|
+
var s = { id: r.interactionId, latency: r.duration, entries: [r] };
|
|
5390
|
+
se.set(s.id, s), A.push(s);
|
|
5340
5391
|
}
|
|
5341
5392
|
A.sort((function(n, i) {
|
|
5342
5393
|
return i.latency - n.latency;
|
|
5343
5394
|
})), A.length > 10 && A.splice(10).forEach((function(n) {
|
|
5344
|
-
return
|
|
5395
|
+
return se.delete(n.id);
|
|
5345
5396
|
}));
|
|
5346
5397
|
}
|
|
5347
5398
|
}
|
|
5348
|
-
}, _t = function(
|
|
5399
|
+
}, _t = function(r) {
|
|
5349
5400
|
var e = self.requestIdleCallback || self.setTimeout, t = -1;
|
|
5350
|
-
return
|
|
5351
|
-
}, Ce = [200, 500],
|
|
5401
|
+
return r = de(r), document.visibilityState === "hidden" ? r() : (t = e(r), Q(r)), t;
|
|
5402
|
+
}, Ce = [200, 500], sr = function(r, e) {
|
|
5352
5403
|
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, K((function() {
|
|
5353
5404
|
var t;
|
|
5354
|
-
|
|
5355
|
-
var
|
|
5405
|
+
Js();
|
|
5406
|
+
var s, n = y("INP"), i = function(l) {
|
|
5356
5407
|
_t((function() {
|
|
5357
|
-
l.forEach(
|
|
5358
|
-
var c =
|
|
5359
|
-
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries,
|
|
5408
|
+
l.forEach(tr);
|
|
5409
|
+
var c = Zs();
|
|
5410
|
+
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, s());
|
|
5360
5411
|
}));
|
|
5361
5412
|
}, o = x("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
|
|
5362
|
-
|
|
5363
|
-
i(o.takeRecords()),
|
|
5364
|
-
})),
|
|
5365
|
-
vt = It(), A.length = 0,
|
|
5413
|
+
s = w(r, n, Ce, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), Q((function() {
|
|
5414
|
+
i(o.takeRecords()), s(!0);
|
|
5415
|
+
})), U((function() {
|
|
5416
|
+
vt = It(), A.length = 0, se.clear(), n = y("INP"), s = w(r, n, Ce, e.reportAllChanges);
|
|
5366
5417
|
})));
|
|
5367
5418
|
})));
|
|
5368
|
-
}, Re = [2500, 4e3],
|
|
5419
|
+
}, Re = [2500, 4e3], pe = {}, rr = function(r, e) {
|
|
5369
5420
|
e = e || {}, K((function() {
|
|
5370
|
-
var t,
|
|
5421
|
+
var t, s = ke(), n = y("LCP"), i = function(c) {
|
|
5371
5422
|
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(u) {
|
|
5372
|
-
u.startTime <
|
|
5423
|
+
u.startTime < s.firstHiddenTime && (n.value = Math.max(u.startTime - ue(), 0), n.entries = [u], t());
|
|
5373
5424
|
}));
|
|
5374
5425
|
}, o = x("largest-contentful-paint", i);
|
|
5375
5426
|
if (o) {
|
|
5376
|
-
t =
|
|
5377
|
-
var l =
|
|
5378
|
-
|
|
5427
|
+
t = w(r, n, Re, e.reportAllChanges);
|
|
5428
|
+
var l = de((function() {
|
|
5429
|
+
pe[n.id] || (i(o.takeRecords()), o.disconnect(), pe[n.id] = !0, t(!0));
|
|
5379
5430
|
}));
|
|
5380
5431
|
["keydown", "click"].forEach((function(c) {
|
|
5381
5432
|
addEventListener(c, (function() {
|
|
5382
5433
|
return _t(l);
|
|
5383
5434
|
}), { once: !0, capture: !0 });
|
|
5384
|
-
})), Q(l),
|
|
5385
|
-
n =
|
|
5386
|
-
n.value = performance.now() - c.timeStamp,
|
|
5435
|
+
})), Q(l), U((function(c) {
|
|
5436
|
+
n = y("LCP"), t = w(r, n, Re, e.reportAllChanges), De((function() {
|
|
5437
|
+
n.value = performance.now() - c.timeStamp, pe[n.id] = !0, t(!0);
|
|
5387
5438
|
}));
|
|
5388
5439
|
}));
|
|
5389
5440
|
}
|
|
5390
5441
|
}));
|
|
5391
|
-
}, Ne = [800, 1800],
|
|
5442
|
+
}, Ne = [800, 1800], nr = function r(e) {
|
|
5392
5443
|
document.prerendering ? K((function() {
|
|
5393
|
-
return
|
|
5444
|
+
return r(e);
|
|
5394
5445
|
})) : document.readyState !== "complete" ? addEventListener("load", (function() {
|
|
5395
|
-
return
|
|
5446
|
+
return r(e);
|
|
5396
5447
|
}), !0) : setTimeout(e, 0);
|
|
5397
|
-
},
|
|
5448
|
+
}, ir = function(r, e) {
|
|
5398
5449
|
e = e || {};
|
|
5399
|
-
var t =
|
|
5400
|
-
|
|
5450
|
+
var t = y("TTFB"), s = w(r, t, Ne, e.reportAllChanges);
|
|
5451
|
+
nr((function() {
|
|
5401
5452
|
var n = Pe();
|
|
5402
|
-
n && (t.value = Math.max(n.responseStart -
|
|
5403
|
-
t =
|
|
5453
|
+
n && (t.value = Math.max(n.responseStart - ue(), 0), t.entries = [n], s(!0), U((function() {
|
|
5454
|
+
t = y("TTFB", 0), (s = w(r, t, Ne, e.reportAllChanges))(!0);
|
|
5404
5455
|
})));
|
|
5405
5456
|
}));
|
|
5406
|
-
}, X = { passive: !0, capture: !0 },
|
|
5407
|
-
C || (C = e, j =
|
|
5457
|
+
}, X = { passive: !0, capture: !0 }, or = /* @__PURE__ */ new Date(), st = function(r, e) {
|
|
5458
|
+
C || (C = e, j = r, Et = /* @__PURE__ */ new Date(), wt(removeEventListener), yt());
|
|
5408
5459
|
}, yt = function() {
|
|
5409
|
-
if (j >= 0 && j < Et -
|
|
5410
|
-
var
|
|
5411
|
-
|
|
5412
|
-
e(
|
|
5413
|
-
})),
|
|
5414
|
-
}
|
|
5415
|
-
},
|
|
5416
|
-
if (
|
|
5417
|
-
var e = (
|
|
5418
|
-
|
|
5460
|
+
if (j >= 0 && j < Et - or) {
|
|
5461
|
+
var r = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp + j };
|
|
5462
|
+
le.forEach((function(e) {
|
|
5463
|
+
e(r);
|
|
5464
|
+
})), le = [];
|
|
5465
|
+
}
|
|
5466
|
+
}, ar = function(r) {
|
|
5467
|
+
if (r.cancelable) {
|
|
5468
|
+
var e = (r.timeStamp > 1e12 ? /* @__PURE__ */ new Date() : performance.now()) - r.timeStamp;
|
|
5469
|
+
r.type == "pointerdown" ? (function(t, s) {
|
|
5419
5470
|
var n = function() {
|
|
5420
|
-
|
|
5471
|
+
st(t, s), o();
|
|
5421
5472
|
}, i = function() {
|
|
5422
5473
|
o();
|
|
5423
5474
|
}, o = function() {
|
|
5424
5475
|
removeEventListener("pointerup", n, X), removeEventListener("pointercancel", i, X);
|
|
5425
5476
|
};
|
|
5426
5477
|
addEventListener("pointerup", n, X), addEventListener("pointercancel", i, X);
|
|
5427
|
-
})(e,
|
|
5478
|
+
})(e, r) : st(e, r);
|
|
5428
5479
|
}
|
|
5429
|
-
}, wt = function(
|
|
5480
|
+
}, wt = function(r) {
|
|
5430
5481
|
["mousedown", "keydown", "touchstart", "pointerdown"].forEach((function(e) {
|
|
5431
|
-
return
|
|
5482
|
+
return r(e, ar, X);
|
|
5432
5483
|
}));
|
|
5433
|
-
}, Oe = [100, 300],
|
|
5484
|
+
}, Oe = [100, 300], lr = function(r, e) {
|
|
5434
5485
|
e = e || {}, K((function() {
|
|
5435
|
-
var t,
|
|
5436
|
-
c.startTime <
|
|
5486
|
+
var t, s = ke(), n = y("FID"), i = function(c) {
|
|
5487
|
+
c.startTime < s.firstHiddenTime && (n.value = c.processingStart - c.startTime, n.entries.push(c), t(!0));
|
|
5437
5488
|
}, o = function(c) {
|
|
5438
5489
|
c.forEach(i);
|
|
5439
5490
|
}, l = x("first-input", o);
|
|
5440
|
-
t =
|
|
5491
|
+
t = w(r, n, Oe, e.reportAllChanges), l && (Q(de((function() {
|
|
5441
5492
|
o(l.takeRecords()), l.disconnect();
|
|
5442
|
-
}))),
|
|
5493
|
+
}))), U((function() {
|
|
5443
5494
|
var c;
|
|
5444
|
-
n =
|
|
5495
|
+
n = y("FID"), t = w(r, n, Oe, e.reportAllChanges), le = [], j = -1, C = null, wt(addEventListener), c = i, le.push(c), yt();
|
|
5445
5496
|
})));
|
|
5446
5497
|
}));
|
|
5447
5498
|
};
|
|
5448
|
-
const
|
|
5499
|
+
const cr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5449
5500
|
__proto__: null,
|
|
5450
5501
|
CLSThresholds: Me,
|
|
5451
5502
|
FCPThresholds: Le,
|
|
@@ -5453,46 +5504,46 @@ const as = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
5453
5504
|
INPThresholds: Ce,
|
|
5454
5505
|
LCPThresholds: Re,
|
|
5455
5506
|
TTFBThresholds: Ne,
|
|
5456
|
-
onCLS:
|
|
5507
|
+
onCLS: Ys,
|
|
5457
5508
|
onFCP: pt,
|
|
5458
|
-
onFID:
|
|
5459
|
-
onINP:
|
|
5460
|
-
onLCP:
|
|
5461
|
-
onTTFB:
|
|
5509
|
+
onFID: lr,
|
|
5510
|
+
onINP: sr,
|
|
5511
|
+
onLCP: rr,
|
|
5512
|
+
onTTFB: ir
|
|
5462
5513
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
5463
5514
|
export {
|
|
5464
5515
|
f as AppConfigValidationError,
|
|
5465
|
-
|
|
5516
|
+
ur as DEFAULT_SESSION_TIMEOUT,
|
|
5466
5517
|
_e as DEFAULT_WEB_VITALS_MODE,
|
|
5467
5518
|
L as DeviceType,
|
|
5468
|
-
|
|
5519
|
+
re as EmitterEvent,
|
|
5469
5520
|
W as ErrorType,
|
|
5470
5521
|
d as EventType,
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5522
|
+
vr as InitializationTimeoutError,
|
|
5523
|
+
N as IntegrationValidationError,
|
|
5524
|
+
pr as MAX_ARRAY_LENGTH,
|
|
5525
|
+
mr as MAX_CUSTOM_EVENT_ARRAY_SIZE,
|
|
5526
|
+
fr as MAX_CUSTOM_EVENT_KEYS,
|
|
5527
|
+
dr as MAX_CUSTOM_EVENT_NAME_LENGTH,
|
|
5528
|
+
hr as MAX_CUSTOM_EVENT_STRING_SIZE,
|
|
5529
|
+
gr as MAX_NESTED_OBJECT_KEYS,
|
|
5530
|
+
Er as MAX_STRING_LENGTH,
|
|
5531
|
+
Sr as MAX_STRING_LENGTH_IN_ARRAY,
|
|
5532
|
+
ie as Mode,
|
|
5482
5533
|
at as PII_PATTERNS,
|
|
5483
|
-
|
|
5484
|
-
|
|
5534
|
+
O as PermanentError,
|
|
5535
|
+
ne as RateLimitError,
|
|
5485
5536
|
We as SamplingRateValidationError,
|
|
5486
5537
|
ee as ScrollDirection,
|
|
5487
5538
|
Ot as SessionTimeoutValidationError,
|
|
5488
5539
|
B as SpecialApiUrl,
|
|
5489
|
-
|
|
5540
|
+
P as TimeoutError,
|
|
5490
5541
|
z as TraceLogValidationError,
|
|
5491
|
-
|
|
5542
|
+
_r as WEB_VITALS_GOOD_THRESHOLDS,
|
|
5492
5543
|
Qe as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
|
|
5493
5544
|
Qt as WEB_VITALS_POOR_THRESHOLDS,
|
|
5494
5545
|
Ke as getWebVitalsThresholds,
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5546
|
+
Tr as isPrimaryScrollEvent,
|
|
5547
|
+
Ir as isSecondaryScrollEvent,
|
|
5548
|
+
yr as tracelog
|
|
5498
5549
|
};
|