@tracelog/lib 2.7.2 → 2.7.3-rc.98.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/dist/browser/tracelog.esm.js +946 -885
- 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 +13 -1
- package/dist/public-api.d.ts +13 -1
- package/dist/public-api.js +2 -2
- package/dist/public-api.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const b = "data-tlog",
|
|
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
|
+
const b = "data-tlog", bt = [
|
|
5
5
|
"button",
|
|
6
6
|
"a",
|
|
7
7
|
'input[type="button"]',
|
|
@@ -33,7 +33,7 @@ const b = "data-tlog", wt = [
|
|
|
33
33
|
".menu-item",
|
|
34
34
|
"[data-testid]",
|
|
35
35
|
'[tabindex="0"]'
|
|
36
|
-
],
|
|
36
|
+
], At = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"], Lt = [
|
|
37
37
|
"token",
|
|
38
38
|
"auth",
|
|
39
39
|
"key",
|
|
@@ -72,30 +72,35 @@ const m = {
|
|
|
72
72
|
INVALID_VIEWPORT_COOLDOWN_PERIOD: "Viewport cooldownPeriod must be a non-negative number",
|
|
73
73
|
INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS: "Viewport maxTrackedElements must be a positive number",
|
|
74
74
|
INVALID_SEND_INTERVAL: "Send interval must be between 1000ms (1 second) and 60000ms (60 seconds)"
|
|
75
|
-
},
|
|
75
|
+
}, Mt = [
|
|
76
76
|
/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
|
77
77
|
/javascript:/gi,
|
|
78
78
|
/on\w+\s*=/gi,
|
|
79
79
|
/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
|
|
80
80
|
/<embed\b[^>]*>/gi,
|
|
81
81
|
/<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi
|
|
82
|
-
], I = "tlog", 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 = "
|
|
91
|
+
super(e), this.name = "RateLimitError", Error.captureStackTrace && Error.captureStackTrace(this, ne);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
class P extends Error {
|
|
95
|
+
constructor(e) {
|
|
96
|
+
super(e), this.name = "TimeoutError", Error.captureStackTrace && Error.captureStackTrace(this, P);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
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;
|
|
96
101
|
class z extends Error {
|
|
97
|
-
constructor(e, t,
|
|
98
|
-
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);
|
|
99
104
|
}
|
|
100
105
|
}
|
|
101
106
|
class f extends z {
|
|
@@ -103,46 +108,46 @@ class f extends z {
|
|
|
103
108
|
super(e, "APP_CONFIG_INVALID", t);
|
|
104
109
|
}
|
|
105
110
|
}
|
|
106
|
-
class
|
|
111
|
+
class Ot extends z {
|
|
107
112
|
constructor(e, t = "config") {
|
|
108
113
|
super(e, "SESSION_TIMEOUT_INVALID", t);
|
|
109
114
|
}
|
|
110
115
|
}
|
|
111
|
-
class
|
|
116
|
+
class We extends z {
|
|
112
117
|
constructor(e, t = "config") {
|
|
113
118
|
super(e, "SAMPLING_RATE_INVALID", t);
|
|
114
119
|
}
|
|
115
120
|
}
|
|
116
|
-
class
|
|
121
|
+
class N extends z {
|
|
117
122
|
constructor(e, t = "config") {
|
|
118
123
|
super(e, "INTEGRATION_INVALID", t);
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
|
-
class
|
|
122
|
-
constructor(e, t,
|
|
123
|
-
super(e, "INITIALIZATION_TIMEOUT",
|
|
126
|
+
class vr extends z {
|
|
127
|
+
constructor(e, t, s = "runtime") {
|
|
128
|
+
super(e, "INITIALIZATION_TIMEOUT", s), this.timeoutMs = t;
|
|
124
129
|
}
|
|
125
130
|
}
|
|
126
|
-
const
|
|
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) => {
|
|
127
132
|
if (e) {
|
|
128
133
|
if (e instanceof Error) {
|
|
129
134
|
const t = e.message.replace(/\s+at\s+.*$/gm, "").replace(/\s*\([^()]+:\d+:\d+\)/g, "");
|
|
130
|
-
return `[TraceLog] ${
|
|
135
|
+
return `[TraceLog] ${r}: ${t}`;
|
|
131
136
|
}
|
|
132
137
|
if (e instanceof Error)
|
|
133
|
-
return `[TraceLog] ${
|
|
138
|
+
return `[TraceLog] ${r}: ${e.message}`;
|
|
134
139
|
if (typeof e == "string")
|
|
135
|
-
return `[TraceLog] ${
|
|
140
|
+
return `[TraceLog] ${r}: ${e}`;
|
|
136
141
|
if (typeof e == "object")
|
|
137
142
|
try {
|
|
138
|
-
return `[TraceLog] ${
|
|
143
|
+
return `[TraceLog] ${r}: ${JSON.stringify(e)}`;
|
|
139
144
|
} catch {
|
|
140
|
-
return `[TraceLog] ${
|
|
145
|
+
return `[TraceLog] ${r}: [Unable to serialize error]`;
|
|
141
146
|
}
|
|
142
|
-
return `[TraceLog] ${
|
|
147
|
+
return `[TraceLog] ${r}: ${String(e)}`;
|
|
143
148
|
}
|
|
144
|
-
return `[TraceLog] ${
|
|
145
|
-
},
|
|
149
|
+
return `[TraceLog] ${r}`;
|
|
150
|
+
}, kt = () => {
|
|
146
151
|
if (typeof window > "u" || typeof sessionStorage > "u")
|
|
147
152
|
return !1;
|
|
148
153
|
try {
|
|
@@ -150,34 +155,34 @@ const st = "background: #ff9800; color: white; font-weight: bold; padding: 2px 8
|
|
|
150
155
|
} catch {
|
|
151
156
|
return !1;
|
|
152
157
|
}
|
|
153
|
-
}, a = (
|
|
154
|
-
const { error:
|
|
155
|
-
if (!
|
|
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
|
+
if (!Vt(l, i))
|
|
156
161
|
return;
|
|
157
|
-
const E =
|
|
158
|
-
|
|
159
|
-
},
|
|
162
|
+
const E = Ut(l, o), T = n !== void 0 ? Ie(n) : void 0;
|
|
163
|
+
Ht(u, c, E, T);
|
|
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) => {
|
|
160
165
|
const n = t !== void 0 && t !== "", i = n ? `%c${e}` : e;
|
|
161
|
-
|
|
162
|
-
},
|
|
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) => {
|
|
163
168
|
const e = {}, t = ["token", "password", "secret", "key", "apikey", "api_key", "sessionid", "session_id"];
|
|
164
|
-
for (const [
|
|
165
|
-
const i =
|
|
169
|
+
for (const [s, n] of Object.entries(r)) {
|
|
170
|
+
const i = s.toLowerCase();
|
|
166
171
|
if (t.some((o) => i.includes(o))) {
|
|
167
|
-
e[
|
|
172
|
+
e[s] = "[REDACTED]";
|
|
168
173
|
continue;
|
|
169
174
|
}
|
|
170
|
-
n !== null && typeof n == "object" && !Array.isArray(n) ? e[
|
|
171
|
-
(o) => o !== null && typeof o == "object" && !Array.isArray(o) ?
|
|
172
|
-
) : e[
|
|
175
|
+
n !== null && typeof n == "object" && !Array.isArray(n) ? e[s] = Ie(n) : Array.isArray(n) ? e[s] = n.map(
|
|
176
|
+
(o) => o !== null && typeof o == "object" && !Array.isArray(o) ? Ie(o) : o
|
|
177
|
+
) : e[s] = n;
|
|
173
178
|
}
|
|
174
179
|
return e;
|
|
175
180
|
};
|
|
176
|
-
let
|
|
177
|
-
const
|
|
178
|
-
typeof window < "u" && !
|
|
179
|
-
},
|
|
180
|
-
const e =
|
|
181
|
+
let ve, ot;
|
|
182
|
+
const Ft = () => {
|
|
183
|
+
typeof window < "u" && !ve && (ve = window.matchMedia("(pointer: coarse)"), ot = window.matchMedia("(hover: none)"));
|
|
184
|
+
}, oe = "Unknown", xt = (r) => {
|
|
185
|
+
const e = r.userAgentData?.platform;
|
|
181
186
|
if (e != null && e !== "") {
|
|
182
187
|
if (/windows/i.test(e)) return "Windows";
|
|
183
188
|
if (/macos/i.test(e)) return "macOS";
|
|
@@ -187,9 +192,9 @@ const Ht = () => {
|
|
|
187
192
|
if (/ios/i.test(e)) return "iOS";
|
|
188
193
|
}
|
|
189
194
|
const t = navigator.userAgent;
|
|
190
|
-
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" :
|
|
191
|
-
},
|
|
192
|
-
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;
|
|
193
198
|
if (e != null && e.length > 0) {
|
|
194
199
|
const n = e.filter((i) => !/not.?a.?brand|chromium/i.test(i.brand))[0];
|
|
195
200
|
if (n != null) {
|
|
@@ -198,36 +203,36 @@ const Ht = () => {
|
|
|
198
203
|
}
|
|
199
204
|
}
|
|
200
205
|
const t = navigator.userAgent;
|
|
201
|
-
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" :
|
|
202
|
-
},
|
|
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
|
+
}, Bt = () => {
|
|
203
208
|
try {
|
|
204
|
-
const
|
|
205
|
-
if (
|
|
206
|
-
const c =
|
|
207
|
-
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;
|
|
208
213
|
}
|
|
209
|
-
|
|
210
|
-
const e = window.innerWidth, t =
|
|
211
|
-
return e <= 767 || o && n ? L.Mobile : e >= 768 && e <= 1024 || l || t &&
|
|
212
|
-
} catch (
|
|
213
|
-
return a("debug", "Device detection failed, defaulting to desktop", { error:
|
|
214
|
+
Ft();
|
|
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;
|
|
214
219
|
}
|
|
215
|
-
},
|
|
220
|
+
}, Wt = () => {
|
|
216
221
|
try {
|
|
217
|
-
const
|
|
222
|
+
const r = navigator;
|
|
218
223
|
return {
|
|
219
|
-
type:
|
|
220
|
-
os:
|
|
221
|
-
browser:
|
|
224
|
+
type: Bt(),
|
|
225
|
+
os: xt(r),
|
|
226
|
+
browser: $t(r)
|
|
222
227
|
};
|
|
223
|
-
} catch (
|
|
224
|
-
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 }), {
|
|
225
230
|
type: L.Desktop,
|
|
226
|
-
os:
|
|
227
|
-
browser:
|
|
231
|
+
os: oe,
|
|
232
|
+
browser: oe
|
|
228
233
|
};
|
|
229
234
|
}
|
|
230
|
-
},
|
|
235
|
+
}, at = [
|
|
231
236
|
// Email addresses
|
|
232
237
|
/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/gi,
|
|
233
238
|
// US Phone numbers (various formats)
|
|
@@ -244,7 +249,7 @@ const Ht = () => {
|
|
|
244
249
|
/:\/\/[^:/]+:([^@]+)@/gi,
|
|
245
250
|
// Sensitive URL query parameters (token=, password=, auth=, secret=, api_key=, etc.)
|
|
246
251
|
/[?&](token|password|passwd|auth|secret|secret_key|private_key|auth_key|api_key|apikey|access_token)=[^&\s]+/gi
|
|
247
|
-
],
|
|
252
|
+
], Xe = 500, Ge = 2e3, je = 5e3, te = 50, Xt = te * 2, lt = 1, Gt = 1e3, jt = 10, ze = 5e3, zt = 6e4, _r = {
|
|
248
253
|
LCP: 2500,
|
|
249
254
|
// Good: ≤ 2.5s
|
|
250
255
|
FCP: 1800,
|
|
@@ -256,7 +261,7 @@ const Ht = () => {
|
|
|
256
261
|
TTFB: 800,
|
|
257
262
|
// Good: ≤ 800ms
|
|
258
263
|
LONG_TASK: 50
|
|
259
|
-
},
|
|
264
|
+
}, Qe = {
|
|
260
265
|
LCP: 2500,
|
|
261
266
|
// Needs improvement: > 2.5s (same as good boundary)
|
|
262
267
|
FCP: 1800,
|
|
@@ -268,7 +273,7 @@ const Ht = () => {
|
|
|
268
273
|
TTFB: 800,
|
|
269
274
|
// Needs improvement: > 800ms
|
|
270
275
|
LONG_TASK: 50
|
|
271
|
-
},
|
|
276
|
+
}, Qt = {
|
|
272
277
|
LCP: 4e3,
|
|
273
278
|
// Poor: > 4s
|
|
274
279
|
FCP: 3e3,
|
|
@@ -280,53 +285,53 @@ const Ht = () => {
|
|
|
280
285
|
TTFB: 1800,
|
|
281
286
|
// Poor: > 1800ms
|
|
282
287
|
LONG_TASK: 50
|
|
283
|
-
},
|
|
284
|
-
switch (
|
|
288
|
+
}, _e = "needs-improvement", Ke = (r = _e) => {
|
|
289
|
+
switch (r) {
|
|
285
290
|
case "all":
|
|
286
291
|
return { LCP: 0, FCP: 0, CLS: 0, INP: 0, TTFB: 0, LONG_TASK: 0 };
|
|
287
292
|
// Track everything
|
|
288
293
|
case "needs-improvement":
|
|
289
|
-
return
|
|
294
|
+
return Qe;
|
|
290
295
|
case "poor":
|
|
291
|
-
return
|
|
296
|
+
return Qt;
|
|
292
297
|
default:
|
|
293
|
-
return
|
|
298
|
+
return Qe;
|
|
294
299
|
}
|
|
295
|
-
},
|
|
300
|
+
}, Kt = 1e3, Yt = 50, qt = "2.7.3", Jt = qt, ct = () => typeof window < "u" && typeof sessionStorage < "u", Zt = () => {
|
|
296
301
|
try {
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
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;
|
|
300
305
|
window.history.replaceState({}, "", t);
|
|
301
306
|
} catch {
|
|
302
307
|
}
|
|
303
|
-
},
|
|
304
|
-
if (!
|
|
308
|
+
}, es = () => {
|
|
309
|
+
if (!ct())
|
|
305
310
|
return !1;
|
|
306
311
|
try {
|
|
307
312
|
const e = new URLSearchParams(window.location.search).get(rt), t = sessionStorage.getItem(G);
|
|
308
|
-
let
|
|
309
|
-
return e ===
|
|
310
|
-
visibility: "qa",
|
|
311
|
-
style: st
|
|
312
|
-
})) : e === Ue && (r = !1, sessionStorage.setItem(G, "false"), a("info", "QA Mode DISABLED", {
|
|
313
|
+
let s = null;
|
|
314
|
+
return e === Ue ? (s = !0, sessionStorage.setItem(G, "true"), a("info", "QA Mode ACTIVE", {
|
|
313
315
|
visibility: "qa",
|
|
314
316
|
style: nt
|
|
315
|
-
}))
|
|
317
|
+
})) : e === He && (s = !1, sessionStorage.setItem(G, "false"), a("info", "QA Mode DISABLED", {
|
|
318
|
+
visibility: "qa",
|
|
319
|
+
style: it
|
|
320
|
+
})), (e === Ue || e === He) && Zt(), s ?? t === "true";
|
|
316
321
|
} catch {
|
|
317
322
|
return !1;
|
|
318
323
|
}
|
|
319
|
-
},
|
|
320
|
-
if (
|
|
324
|
+
}, ts = (r) => {
|
|
325
|
+
if (ct())
|
|
321
326
|
try {
|
|
322
|
-
sessionStorage.setItem(G,
|
|
327
|
+
sessionStorage.setItem(G, r ? "true" : "false"), a("info", r ? "QA Mode ACTIVE" : "QA Mode DISABLED", {
|
|
323
328
|
visibility: "qa",
|
|
324
|
-
style:
|
|
329
|
+
style: r ? nt : it
|
|
325
330
|
});
|
|
326
331
|
} catch {
|
|
327
332
|
a("debug", "Cannot set QA mode: sessionStorage unavailable");
|
|
328
333
|
}
|
|
329
|
-
},
|
|
334
|
+
}, ss = [
|
|
330
335
|
"co.uk",
|
|
331
336
|
"org.uk",
|
|
332
337
|
"com.au",
|
|
@@ -338,57 +343,57 @@ const Ht = () => {
|
|
|
338
343
|
"co.in",
|
|
339
344
|
"com.cn",
|
|
340
345
|
"co.za"
|
|
341
|
-
],
|
|
342
|
-
const e =
|
|
346
|
+
], Ye = (r) => {
|
|
347
|
+
const e = r.toLowerCase().split(".");
|
|
343
348
|
if (e.length <= 2)
|
|
344
|
-
return
|
|
349
|
+
return r.toLowerCase();
|
|
345
350
|
const t = e.slice(-2).join(".");
|
|
346
|
-
return
|
|
347
|
-
},
|
|
348
|
-
const
|
|
349
|
-
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)
|
|
350
355
|
return "Direct";
|
|
351
356
|
try {
|
|
352
|
-
const e = new URL(
|
|
353
|
-
return
|
|
357
|
+
const e = new URL(r).hostname.toLowerCase(), t = window.location.hostname.toLowerCase();
|
|
358
|
+
return rs(e, t) ? "Direct" : r;
|
|
354
359
|
} catch (e) {
|
|
355
|
-
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;
|
|
356
361
|
}
|
|
357
|
-
},
|
|
358
|
-
const
|
|
359
|
-
return
|
|
360
|
-
const n =
|
|
362
|
+
}, ge = () => {
|
|
363
|
+
const r = new URLSearchParams(window.location.search), e = {};
|
|
364
|
+
return At.forEach((s) => {
|
|
365
|
+
const n = r.get(s);
|
|
361
366
|
if (n) {
|
|
362
|
-
const i =
|
|
367
|
+
const i = s.split("utm_")[1];
|
|
363
368
|
e[i] = n;
|
|
364
369
|
}
|
|
365
370
|
}), Object.keys(e).length ? e : void 0;
|
|
366
|
-
},
|
|
371
|
+
}, ut = () => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (r) => {
|
|
367
372
|
const e = Math.random() * 16 | 0;
|
|
368
|
-
return (
|
|
373
|
+
return (r === "x" ? e : e & 3 | 8).toString(16);
|
|
369
374
|
});
|
|
370
375
|
let q = 0, J = 0;
|
|
371
|
-
const
|
|
372
|
-
let
|
|
373
|
-
|
|
376
|
+
const ns = () => {
|
|
377
|
+
let r = Date.now();
|
|
378
|
+
r < J && (r = J), r === J ? q = (q + 1) % 1e3 : q = 0, J = r;
|
|
374
379
|
const e = q.toString().padStart(3, "0");
|
|
375
380
|
let t = "";
|
|
376
381
|
try {
|
|
377
382
|
if (typeof crypto < "u" && crypto.getRandomValues) {
|
|
378
|
-
const
|
|
379
|
-
|
|
383
|
+
const s = crypto.getRandomValues(new Uint8Array(3));
|
|
384
|
+
s && (t = Array.from(s, (n) => n.toString(16).padStart(2, "0")).join(""));
|
|
380
385
|
}
|
|
381
386
|
} catch {
|
|
382
387
|
}
|
|
383
|
-
return t || (t = Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")), `${
|
|
384
|
-
},
|
|
388
|
+
return t || (t = Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")), `${r}-${e}-${t}`;
|
|
389
|
+
}, dt = (r, e = !1) => {
|
|
385
390
|
try {
|
|
386
|
-
const t = new URL(
|
|
387
|
-
return
|
|
391
|
+
const t = new URL(r), s = t.protocol === "https:", n = t.protocol === "http:";
|
|
392
|
+
return s || e && n;
|
|
388
393
|
} catch {
|
|
389
394
|
return !1;
|
|
390
395
|
}
|
|
391
|
-
},
|
|
396
|
+
}, is = (r) => {
|
|
392
397
|
try {
|
|
393
398
|
const t = new URL(window.location.href).hostname;
|
|
394
399
|
if (!t || typeof t != "string")
|
|
@@ -397,231 +402,233 @@ const sr = () => {
|
|
|
397
402
|
throw new Error(
|
|
398
403
|
"SaaS integration not supported on localhost or IP addresses. Use custom backend integration instead."
|
|
399
404
|
);
|
|
400
|
-
const
|
|
401
|
-
if (!
|
|
405
|
+
const s = t.split(".");
|
|
406
|
+
if (!s || !Array.isArray(s) || s.length === 0 || s.length === 1 && s[0] === "")
|
|
402
407
|
throw new Error("Invalid hostname structure");
|
|
403
|
-
if (
|
|
408
|
+
if (s.length === 1)
|
|
404
409
|
throw new Error("Single-part domain not supported for SaaS integration");
|
|
405
410
|
let n;
|
|
406
|
-
if (
|
|
411
|
+
if (s.length === 2 ? n = s.join(".") : n = s.slice(-2).join("."), !n || n.split(".").length < 2)
|
|
407
412
|
throw new Error("Invalid domain structure for SaaS");
|
|
408
|
-
const i = `https://${
|
|
409
|
-
if (!
|
|
413
|
+
const i = `https://${r}.${n}/collect`;
|
|
414
|
+
if (!dt(i))
|
|
410
415
|
throw new Error("Generated URL failed validation");
|
|
411
416
|
return i;
|
|
412
417
|
} catch (e) {
|
|
413
418
|
throw new Error(`Invalid SaaS URL configuration: ${e instanceof Error ? e.message : String(e)}`);
|
|
414
419
|
}
|
|
415
|
-
},
|
|
420
|
+
}, os = (r) => {
|
|
416
421
|
const e = {};
|
|
417
|
-
|
|
418
|
-
const t =
|
|
422
|
+
r.integrations?.tracelog?.projectId && (e.saas = is(r.integrations.tracelog.projectId));
|
|
423
|
+
const t = r.integrations?.custom?.collectApiUrl;
|
|
419
424
|
if (t) {
|
|
420
|
-
const
|
|
421
|
-
if (!
|
|
425
|
+
const s = r.integrations?.custom?.allowHttp ?? !1;
|
|
426
|
+
if (!dt(t, s))
|
|
422
427
|
throw new Error("Invalid custom API URL");
|
|
423
428
|
e.custom = t;
|
|
424
429
|
}
|
|
425
430
|
return e;
|
|
426
|
-
},
|
|
427
|
-
if (!
|
|
428
|
-
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 || "";
|
|
429
434
|
try {
|
|
430
|
-
const t = new URL(
|
|
435
|
+
const t = new URL(r), s = t.searchParams, n = [.../* @__PURE__ */ new Set([...Lt, ...e])];
|
|
431
436
|
let i = !1;
|
|
432
437
|
const o = [];
|
|
433
438
|
return n.forEach((c) => {
|
|
434
|
-
|
|
435
|
-
}), !i &&
|
|
439
|
+
s.has(c) && (s.delete(c), i = !0, o.push(c));
|
|
440
|
+
}), !i && r.includes("?") ? r : (t.search = s.toString(), t.toString());
|
|
436
441
|
} catch (t) {
|
|
437
|
-
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;
|
|
438
443
|
}
|
|
439
|
-
},
|
|
440
|
-
if (!
|
|
444
|
+
}, qe = (r) => {
|
|
445
|
+
if (!r || typeof r != "string" || r.trim().length === 0)
|
|
441
446
|
return "";
|
|
442
|
-
let e =
|
|
443
|
-
|
|
447
|
+
let e = r;
|
|
448
|
+
r.length > 1e3 && (e = r.slice(0, Math.max(0, 1e3)));
|
|
444
449
|
let t = 0;
|
|
445
|
-
for (const n of
|
|
450
|
+
for (const n of Mt) {
|
|
446
451
|
const i = e;
|
|
447
452
|
e = e.replace(n, ""), i !== e && t++;
|
|
448
453
|
}
|
|
449
454
|
return t > 0 && a("warn", "XSS patterns detected and removed", {
|
|
450
455
|
data: {
|
|
451
456
|
patternMatches: t,
|
|
452
|
-
valueLength:
|
|
457
|
+
valueLength: r.length
|
|
453
458
|
}
|
|
454
459
|
}), e.trim();
|
|
455
|
-
},
|
|
456
|
-
if (
|
|
460
|
+
}, we = (r, e = 0) => {
|
|
461
|
+
if (r == null)
|
|
457
462
|
return null;
|
|
458
|
-
if (typeof
|
|
459
|
-
return
|
|
460
|
-
if (typeof
|
|
461
|
-
return !Number.isFinite(
|
|
462
|
-
if (typeof
|
|
463
|
-
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;
|
|
464
469
|
if (e > 10)
|
|
465
470
|
return null;
|
|
466
|
-
if (Array.isArray(
|
|
467
|
-
return
|
|
468
|
-
if (typeof
|
|
469
|
-
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);
|
|
470
475
|
for (const [i, o] of n) {
|
|
471
|
-
const l =
|
|
476
|
+
const l = qe(i);
|
|
472
477
|
if (l) {
|
|
473
|
-
const c =
|
|
478
|
+
const c = we(o, e + 1);
|
|
474
479
|
c !== null && (t[l] = c);
|
|
475
480
|
}
|
|
476
481
|
}
|
|
477
482
|
return t;
|
|
478
483
|
}
|
|
479
484
|
return null;
|
|
480
|
-
},
|
|
481
|
-
if (typeof
|
|
485
|
+
}, as = (r) => {
|
|
486
|
+
if (typeof r != "object" || r === null)
|
|
482
487
|
return {};
|
|
483
488
|
try {
|
|
484
|
-
const e =
|
|
489
|
+
const e = we(r);
|
|
485
490
|
return typeof e == "object" && e !== null ? e : {};
|
|
486
491
|
} catch (e) {
|
|
487
492
|
const t = e instanceof Error ? e.message : String(e);
|
|
488
493
|
throw new Error(`[TraceLog] Metadata sanitization failed: ${t}`);
|
|
489
494
|
}
|
|
490
|
-
},
|
|
491
|
-
if (
|
|
495
|
+
}, ls = (r) => {
|
|
496
|
+
if (r !== void 0 && (r === null || typeof r != "object"))
|
|
492
497
|
throw new f("Configuration must be an object", "config");
|
|
493
|
-
if (
|
|
494
|
-
if (
|
|
495
|
-
throw new
|
|
496
|
-
if (
|
|
498
|
+
if (r) {
|
|
499
|
+
if (r.sessionTimeout !== void 0 && (typeof r.sessionTimeout != "number" || r.sessionTimeout < 3e4 || r.sessionTimeout > 864e5))
|
|
500
|
+
throw new Ot(m.INVALID_SESSION_TIMEOUT, "config");
|
|
501
|
+
if (r.globalMetadata !== void 0 && (typeof r.globalMetadata != "object" || r.globalMetadata === null))
|
|
497
502
|
throw new f(m.INVALID_GLOBAL_METADATA, "config");
|
|
498
|
-
if (
|
|
499
|
-
if (!Array.isArray(
|
|
503
|
+
if (r.integrations && us(r.integrations), r.sensitiveQueryParams !== void 0) {
|
|
504
|
+
if (!Array.isArray(r.sensitiveQueryParams))
|
|
500
505
|
throw new f(m.INVALID_SENSITIVE_QUERY_PARAMS, "config");
|
|
501
|
-
for (const e of
|
|
506
|
+
for (const e of r.sensitiveQueryParams)
|
|
502
507
|
if (typeof e != "string")
|
|
503
508
|
throw new f("All sensitive query params must be strings", "config");
|
|
504
509
|
}
|
|
505
|
-
if (
|
|
506
|
-
throw new
|
|
507
|
-
if (
|
|
508
|
-
throw new
|
|
509
|
-
if (
|
|
510
|
-
if (typeof
|
|
510
|
+
if (r.errorSampling !== void 0 && (typeof r.errorSampling != "number" || r.errorSampling < 0 || r.errorSampling > 1))
|
|
511
|
+
throw new We(m.INVALID_ERROR_SAMPLING_RATE, "config");
|
|
512
|
+
if (r.samplingRate !== void 0 && (typeof r.samplingRate != "number" || r.samplingRate < 0 || r.samplingRate > 1))
|
|
513
|
+
throw new We(m.INVALID_SAMPLING_RATE, "config");
|
|
514
|
+
if (r.primaryScrollSelector !== void 0) {
|
|
515
|
+
if (typeof r.primaryScrollSelector != "string" || !r.primaryScrollSelector.trim())
|
|
511
516
|
throw new f(m.INVALID_PRIMARY_SCROLL_SELECTOR, "config");
|
|
512
|
-
if (
|
|
517
|
+
if (r.primaryScrollSelector !== "window")
|
|
513
518
|
try {
|
|
514
|
-
document.querySelector(
|
|
519
|
+
document.querySelector(r.primaryScrollSelector);
|
|
515
520
|
} catch {
|
|
516
521
|
throw new f(
|
|
517
|
-
`${m.INVALID_PRIMARY_SCROLL_SELECTOR_SYNTAX}: "${
|
|
522
|
+
`${m.INVALID_PRIMARY_SCROLL_SELECTOR_SYNTAX}: "${r.primaryScrollSelector}"`,
|
|
518
523
|
"config"
|
|
519
524
|
);
|
|
520
525
|
}
|
|
521
526
|
}
|
|
522
|
-
if (
|
|
527
|
+
if (r.pageViewThrottleMs !== void 0 && (typeof r.pageViewThrottleMs != "number" || r.pageViewThrottleMs < 0))
|
|
523
528
|
throw new f(m.INVALID_PAGE_VIEW_THROTTLE, "config");
|
|
524
|
-
if (
|
|
529
|
+
if (r.clickThrottleMs !== void 0 && (typeof r.clickThrottleMs != "number" || r.clickThrottleMs < 0))
|
|
525
530
|
throw new f(m.INVALID_CLICK_THROTTLE, "config");
|
|
526
|
-
if (
|
|
531
|
+
if (r.maxSameEventPerMinute !== void 0 && (typeof r.maxSameEventPerMinute != "number" || r.maxSameEventPerMinute <= 0))
|
|
527
532
|
throw new f(m.INVALID_MAX_SAME_EVENT_PER_MINUTE, "config");
|
|
528
|
-
if (
|
|
533
|
+
if (r.sendIntervalMs !== void 0 && (!Number.isFinite(r.sendIntervalMs) || r.sendIntervalMs < 1e3 || r.sendIntervalMs > 6e4))
|
|
529
534
|
throw new f(m.INVALID_SEND_INTERVAL, "config");
|
|
530
|
-
if (
|
|
531
|
-
if (typeof
|
|
535
|
+
if (r.viewport !== void 0 && cs(r.viewport), r.webVitalsMode !== void 0) {
|
|
536
|
+
if (typeof r.webVitalsMode != "string")
|
|
532
537
|
throw new f(
|
|
533
|
-
`Invalid webVitalsMode type: ${typeof
|
|
538
|
+
`Invalid webVitalsMode type: ${typeof r.webVitalsMode}. Must be a string`,
|
|
534
539
|
"config"
|
|
535
540
|
);
|
|
536
541
|
const e = ["all", "needs-improvement", "poor"];
|
|
537
|
-
if (!e.includes(
|
|
542
|
+
if (!e.includes(r.webVitalsMode))
|
|
538
543
|
throw new f(
|
|
539
|
-
`Invalid webVitalsMode: "${
|
|
544
|
+
`Invalid webVitalsMode: "${r.webVitalsMode}". Must be one of: ${e.join(", ")}`,
|
|
540
545
|
"config"
|
|
541
546
|
);
|
|
542
547
|
}
|
|
543
|
-
if (
|
|
544
|
-
if (typeof
|
|
548
|
+
if (r.webVitalsThresholds !== void 0) {
|
|
549
|
+
if (typeof r.webVitalsThresholds != "object" || r.webVitalsThresholds === null || Array.isArray(r.webVitalsThresholds))
|
|
545
550
|
throw new f("webVitalsThresholds must be an object", "config");
|
|
546
551
|
const e = ["LCP", "FCP", "CLS", "INP", "TTFB", "LONG_TASK"];
|
|
547
|
-
for (const [t,
|
|
552
|
+
for (const [t, s] of Object.entries(r.webVitalsThresholds)) {
|
|
548
553
|
if (!e.includes(t))
|
|
549
554
|
throw new f(
|
|
550
555
|
`Invalid Web Vitals threshold key: "${t}". Must be one of: ${e.join(", ")}`,
|
|
551
556
|
"config"
|
|
552
557
|
);
|
|
553
|
-
if (typeof
|
|
558
|
+
if (typeof s != "number" || !Number.isFinite(s) || s < 0)
|
|
554
559
|
throw new f(
|
|
555
|
-
`Invalid Web Vitals threshold value for ${t}: ${
|
|
560
|
+
`Invalid Web Vitals threshold value for ${t}: ${s}. Must be a non-negative finite number`,
|
|
556
561
|
"config"
|
|
557
562
|
);
|
|
558
563
|
}
|
|
559
564
|
}
|
|
560
565
|
}
|
|
561
|
-
},
|
|
562
|
-
if (typeof
|
|
566
|
+
}, cs = (r) => {
|
|
567
|
+
if (typeof r != "object" || r === null)
|
|
563
568
|
throw new f(m.INVALID_VIEWPORT_CONFIG, "config");
|
|
564
|
-
if (!
|
|
569
|
+
if (!r.elements || !Array.isArray(r.elements))
|
|
565
570
|
throw new f(m.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
566
|
-
if (
|
|
571
|
+
if (r.elements.length === 0)
|
|
567
572
|
throw new f(m.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
568
573
|
const e = /* @__PURE__ */ new Set();
|
|
569
|
-
for (const t of
|
|
574
|
+
for (const t of r.elements) {
|
|
570
575
|
if (!t.selector || typeof t.selector != "string" || !t.selector.trim())
|
|
571
576
|
throw new f(m.INVALID_VIEWPORT_ELEMENT, "config");
|
|
572
|
-
const
|
|
573
|
-
if (e.has(
|
|
577
|
+
const s = t.selector.trim();
|
|
578
|
+
if (e.has(s))
|
|
574
579
|
throw new f(
|
|
575
|
-
`Duplicate viewport selector found: "${
|
|
580
|
+
`Duplicate viewport selector found: "${s}". Each selector should appear only once.`,
|
|
576
581
|
"config"
|
|
577
582
|
);
|
|
578
|
-
if (e.add(
|
|
583
|
+
if (e.add(s), t.id !== void 0 && (typeof t.id != "string" || !t.id.trim()))
|
|
579
584
|
throw new f(m.INVALID_VIEWPORT_ELEMENT_ID, "config");
|
|
580
585
|
if (t.name !== void 0 && (typeof t.name != "string" || !t.name.trim()))
|
|
581
586
|
throw new f(m.INVALID_VIEWPORT_ELEMENT_NAME, "config");
|
|
582
587
|
}
|
|
583
|
-
if (
|
|
588
|
+
if (r.threshold !== void 0 && (typeof r.threshold != "number" || r.threshold < 0 || r.threshold > 1))
|
|
584
589
|
throw new f(m.INVALID_VIEWPORT_THRESHOLD, "config");
|
|
585
|
-
if (
|
|
590
|
+
if (r.minDwellTime !== void 0 && (typeof r.minDwellTime != "number" || r.minDwellTime < 0))
|
|
586
591
|
throw new f(m.INVALID_VIEWPORT_MIN_DWELL_TIME, "config");
|
|
587
|
-
if (
|
|
592
|
+
if (r.cooldownPeriod !== void 0 && (typeof r.cooldownPeriod != "number" || r.cooldownPeriod < 0))
|
|
588
593
|
throw new f(m.INVALID_VIEWPORT_COOLDOWN_PERIOD, "config");
|
|
589
|
-
if (
|
|
594
|
+
if (r.maxTrackedElements !== void 0 && (typeof r.maxTrackedElements != "number" || r.maxTrackedElements <= 0))
|
|
590
595
|
throw new f(m.INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS, "config");
|
|
591
|
-
},
|
|
592
|
-
if (
|
|
593
|
-
if (
|
|
594
|
-
throw new
|
|
595
|
-
if (
|
|
596
|
-
if (!
|
|
597
|
-
throw new
|
|
598
|
-
if (
|
|
599
|
-
throw new
|
|
600
|
-
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();
|
|
601
606
|
if (!e.startsWith("http://") && !e.startsWith("https://"))
|
|
602
|
-
throw new
|
|
603
|
-
if (!(
|
|
604
|
-
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(
|
|
605
610
|
"Custom API URL must use HTTPS in production. Set allowHttp: true in integration config to allow HTTP (not recommended)",
|
|
606
611
|
"config"
|
|
607
612
|
);
|
|
608
|
-
if (
|
|
609
|
-
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");
|
|
610
615
|
}
|
|
616
|
+
if (r.tracelog?.shopify !== void 0 && typeof r.tracelog.shopify != "boolean")
|
|
617
|
+
throw new N("tracelog.shopify must be a boolean", "config");
|
|
611
618
|
}
|
|
612
|
-
},
|
|
613
|
-
|
|
619
|
+
}, ds = (r) => {
|
|
620
|
+
ls(r);
|
|
614
621
|
const e = {
|
|
615
|
-
...
|
|
616
|
-
sessionTimeout:
|
|
617
|
-
globalMetadata:
|
|
618
|
-
sensitiveQueryParams:
|
|
619
|
-
errorSampling:
|
|
620
|
-
samplingRate:
|
|
621
|
-
pageViewThrottleMs:
|
|
622
|
-
clickThrottleMs:
|
|
623
|
-
maxSameEventPerMinute:
|
|
624
|
-
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
|
|
625
632
|
};
|
|
626
633
|
return e.integrations?.custom && (e.integrations.custom = {
|
|
627
634
|
...e.integrations.custom,
|
|
@@ -633,42 +640,42 @@ const sr = () => {
|
|
|
633
640
|
cooldownPeriod: e.viewport.cooldownPeriod ?? 6e4,
|
|
634
641
|
maxTrackedElements: e.viewport.maxTrackedElements ?? 100
|
|
635
642
|
}), e;
|
|
636
|
-
},
|
|
637
|
-
if (
|
|
643
|
+
}, be = (r, e = /* @__PURE__ */ new Set()) => {
|
|
644
|
+
if (r == null)
|
|
638
645
|
return !0;
|
|
639
|
-
const t = typeof
|
|
640
|
-
return t === "string" || t === "number" || t === "boolean" ? !0 : t === "function" || t === "symbol" || t === "bigint" || e.has(
|
|
641
|
-
},
|
|
642
|
-
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;
|
|
643
650
|
const e = {};
|
|
644
|
-
for (const [t,
|
|
645
|
-
typeof
|
|
651
|
+
for (const [t, s] of Object.entries(r))
|
|
652
|
+
typeof s == "string" && (e[t] = s);
|
|
646
653
|
return Object.keys(e).length > 0 ? e : void 0;
|
|
647
|
-
},
|
|
654
|
+
}, fs = (r) => typeof r != "string" ? {
|
|
648
655
|
valid: !1,
|
|
649
656
|
error: "Event name must be a string"
|
|
650
|
-
} :
|
|
657
|
+
} : r.length === 0 ? {
|
|
651
658
|
valid: !1,
|
|
652
659
|
error: "Event name cannot be empty"
|
|
653
|
-
} :
|
|
660
|
+
} : r.length > 120 ? {
|
|
654
661
|
valid: !1,
|
|
655
662
|
error: "Event name is too long (max 120 characters)"
|
|
656
|
-
} :
|
|
663
|
+
} : r.includes("<") || r.includes(">") || r.includes("&") ? {
|
|
657
664
|
valid: !1,
|
|
658
665
|
error: "Event name contains invalid characters"
|
|
659
|
-
} : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(
|
|
666
|
+
} : ["constructor", "prototype", "__proto__", "eval", "function", "var", "let", "const"].includes(r.toLowerCase()) ? {
|
|
660
667
|
valid: !1,
|
|
661
668
|
error: "Event name cannot be a reserved word"
|
|
662
|
-
} : { valid: !0 },
|
|
663
|
-
const
|
|
664
|
-
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))
|
|
665
672
|
return {
|
|
666
673
|
valid: !1,
|
|
667
674
|
error: `${n}: object has invalid types. Valid types are string, number, boolean or string arrays.`
|
|
668
675
|
};
|
|
669
676
|
let i;
|
|
670
677
|
try {
|
|
671
|
-
i = JSON.stringify(
|
|
678
|
+
i = JSON.stringify(s);
|
|
672
679
|
} catch {
|
|
673
680
|
return {
|
|
674
681
|
valid: !1,
|
|
@@ -680,12 +687,12 @@ const sr = () => {
|
|
|
680
687
|
valid: !1,
|
|
681
688
|
error: `${n}: object is too large (max ${49152 / 1024} KB).`
|
|
682
689
|
};
|
|
683
|
-
if (Object.keys(
|
|
690
|
+
if (Object.keys(s).length > 100)
|
|
684
691
|
return {
|
|
685
692
|
valid: !1,
|
|
686
693
|
error: `${n}: object has too many keys (max 100 keys).`
|
|
687
694
|
};
|
|
688
|
-
for (const [c, u] of Object.entries(
|
|
695
|
+
for (const [c, u] of Object.entries(s)) {
|
|
689
696
|
if (Array.isArray(u)) {
|
|
690
697
|
if (u.length > 500)
|
|
691
698
|
return {
|
|
@@ -707,11 +714,11 @@ const sr = () => {
|
|
|
707
714
|
}
|
|
708
715
|
return {
|
|
709
716
|
valid: !0,
|
|
710
|
-
sanitizedMetadata:
|
|
717
|
+
sanitizedMetadata: s
|
|
711
718
|
};
|
|
712
|
-
},
|
|
719
|
+
}, ft = (r, e, t) => {
|
|
713
720
|
if (Array.isArray(e)) {
|
|
714
|
-
const
|
|
721
|
+
const s = [], n = t && t === "customEvent" ? `${t} "${r}" metadata error` : `${r} metadata error`;
|
|
715
722
|
for (let i = 0; i < e.length; i++) {
|
|
716
723
|
const o = e[i];
|
|
717
724
|
if (typeof o != "object" || o === null || Array.isArray(o))
|
|
@@ -719,37 +726,37 @@ const sr = () => {
|
|
|
719
726
|
valid: !1,
|
|
720
727
|
error: `${n}: array item at index ${i} must be an object.`
|
|
721
728
|
};
|
|
722
|
-
const l =
|
|
729
|
+
const l = Je(r, o, t);
|
|
723
730
|
if (!l.valid)
|
|
724
731
|
return {
|
|
725
732
|
valid: !1,
|
|
726
733
|
error: `${n}: array item at index ${i} is invalid: ${l.error}`
|
|
727
734
|
};
|
|
728
|
-
l.sanitizedMetadata &&
|
|
735
|
+
l.sanitizedMetadata && s.push(l.sanitizedMetadata);
|
|
729
736
|
}
|
|
730
737
|
return {
|
|
731
738
|
valid: !0,
|
|
732
|
-
sanitizedMetadata:
|
|
739
|
+
sanitizedMetadata: s
|
|
733
740
|
};
|
|
734
741
|
}
|
|
735
|
-
return
|
|
736
|
-
},
|
|
737
|
-
const t =
|
|
742
|
+
return Je(r, e, t);
|
|
743
|
+
}, ms = (r, e) => {
|
|
744
|
+
const t = fs(r);
|
|
738
745
|
if (!t.valid)
|
|
739
746
|
return a("error", "Event name validation failed", {
|
|
740
|
-
data: { eventName:
|
|
747
|
+
data: { eventName: r, error: t.error }
|
|
741
748
|
}), t;
|
|
742
749
|
if (!e)
|
|
743
750
|
return { valid: !0 };
|
|
744
|
-
const
|
|
745
|
-
return
|
|
751
|
+
const s = ft(r, e, "customEvent");
|
|
752
|
+
return s.valid || a("error", "Event metadata validation failed", {
|
|
746
753
|
data: {
|
|
747
|
-
eventName:
|
|
748
|
-
error:
|
|
754
|
+
eventName: r,
|
|
755
|
+
error: s.error
|
|
749
756
|
}
|
|
750
|
-
}),
|
|
757
|
+
}), s;
|
|
751
758
|
};
|
|
752
|
-
class
|
|
759
|
+
class gs {
|
|
753
760
|
listeners = /* @__PURE__ */ new Map();
|
|
754
761
|
/**
|
|
755
762
|
* Subscribes to an event channel
|
|
@@ -800,10 +807,10 @@ class mr {
|
|
|
800
807
|
* ```
|
|
801
808
|
*/
|
|
802
809
|
off(e, t) {
|
|
803
|
-
const
|
|
804
|
-
if (
|
|
805
|
-
const n =
|
|
806
|
-
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);
|
|
807
814
|
}
|
|
808
815
|
}
|
|
809
816
|
/**
|
|
@@ -835,8 +842,8 @@ class mr {
|
|
|
835
842
|
* ```
|
|
836
843
|
*/
|
|
837
844
|
emit(e, t) {
|
|
838
|
-
const
|
|
839
|
-
|
|
845
|
+
const s = this.listeners.get(e);
|
|
846
|
+
s && s.forEach((n) => {
|
|
840
847
|
n(t);
|
|
841
848
|
});
|
|
842
849
|
}
|
|
@@ -866,38 +873,38 @@ class mr {
|
|
|
866
873
|
this.listeners.clear();
|
|
867
874
|
}
|
|
868
875
|
}
|
|
869
|
-
function
|
|
876
|
+
function mt(r, e, t) {
|
|
870
877
|
try {
|
|
871
|
-
const
|
|
872
|
-
return
|
|
873
|
-
} 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) {
|
|
874
881
|
return a("error", `beforeSend transformer threw error, using original event [${t}]`, {
|
|
875
|
-
error:
|
|
882
|
+
error: s,
|
|
876
883
|
visibility: "critical"
|
|
877
|
-
}),
|
|
884
|
+
}), r;
|
|
878
885
|
}
|
|
879
886
|
}
|
|
880
|
-
function
|
|
881
|
-
return
|
|
887
|
+
function Es(r, e, t) {
|
|
888
|
+
return r.map((s) => mt(s, e, t)).filter((s) => s !== null);
|
|
882
889
|
}
|
|
883
|
-
function
|
|
890
|
+
function gt(r, e, t) {
|
|
884
891
|
try {
|
|
885
|
-
const
|
|
886
|
-
return
|
|
887
|
-
data: { eventCount:
|
|
888
|
-
}), null) : typeof
|
|
889
|
-
data: { eventCount:
|
|
890
|
-
}),
|
|
891
|
-
} 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) {
|
|
892
899
|
return a("error", `beforeBatch transformer threw error, using original batch [${t}]`, {
|
|
893
|
-
error:
|
|
894
|
-
data: { eventCount:
|
|
900
|
+
error: s,
|
|
901
|
+
data: { eventCount: r.events.length },
|
|
895
902
|
visibility: "critical"
|
|
896
|
-
}),
|
|
903
|
+
}), r;
|
|
897
904
|
}
|
|
898
905
|
}
|
|
899
|
-
const
|
|
900
|
-
class
|
|
906
|
+
const Ee = { config: {} };
|
|
907
|
+
class _ {
|
|
901
908
|
/**
|
|
902
909
|
* Retrieves a value from global state.
|
|
903
910
|
*
|
|
@@ -915,7 +922,7 @@ class w {
|
|
|
915
922
|
* ```
|
|
916
923
|
*/
|
|
917
924
|
get(e) {
|
|
918
|
-
return
|
|
925
|
+
return Ee[e];
|
|
919
926
|
}
|
|
920
927
|
/**
|
|
921
928
|
* Sets a value in global state.
|
|
@@ -935,7 +942,7 @@ class w {
|
|
|
935
942
|
* ```
|
|
936
943
|
*/
|
|
937
944
|
set(e, t) {
|
|
938
|
-
|
|
945
|
+
Ee[e] = t;
|
|
939
946
|
}
|
|
940
947
|
/**
|
|
941
948
|
* Returns an immutable snapshot of the entire global state.
|
|
@@ -952,10 +959,10 @@ class w {
|
|
|
952
959
|
* ```
|
|
953
960
|
*/
|
|
954
961
|
getState() {
|
|
955
|
-
return { ...
|
|
962
|
+
return { ...Ee };
|
|
956
963
|
}
|
|
957
964
|
}
|
|
958
|
-
class
|
|
965
|
+
class Ze extends _ {
|
|
959
966
|
storeManager;
|
|
960
967
|
integrationId;
|
|
961
968
|
apiUrl;
|
|
@@ -990,10 +997,10 @@ class Je extends w {
|
|
|
990
997
|
* @param customHeadersProvider - Optional callback for dynamic headers
|
|
991
998
|
* @throws Error if integrationId and apiUrl are not both provided or both undefined
|
|
992
999
|
*/
|
|
993
|
-
constructor(e, t,
|
|
994
|
-
if (super(), t && !
|
|
1000
|
+
constructor(e, t, s, n = {}, i = {}, o, l = "include") {
|
|
1001
|
+
if (super(), t && !s || !t && s)
|
|
995
1002
|
throw new Error("SenderManager: integrationId and apiUrl must either both be provided or both be undefined");
|
|
996
|
-
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;
|
|
997
1004
|
}
|
|
998
1005
|
/**
|
|
999
1006
|
* Get the integration ID for this sender
|
|
@@ -1040,7 +1047,7 @@ class Je extends w {
|
|
|
1040
1047
|
return { ...this.staticHeaders, ...e };
|
|
1041
1048
|
}
|
|
1042
1049
|
getQueueStorageKey() {
|
|
1043
|
-
const e = this.get("userId") || "anonymous", t =
|
|
1050
|
+
const e = this.get("userId") || "anonymous", t = Ct(e);
|
|
1044
1051
|
return this.integrationId ? `${t}:${this.integrationId}` : t;
|
|
1045
1052
|
}
|
|
1046
1053
|
/**
|
|
@@ -1128,10 +1135,10 @@ class Je extends w {
|
|
|
1128
1135
|
*/
|
|
1129
1136
|
async sendEventsQueue(e, t) {
|
|
1130
1137
|
try {
|
|
1131
|
-
const
|
|
1132
|
-
return
|
|
1133
|
-
} catch (
|
|
1134
|
-
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(
|
|
1135
1142
|
"debug",
|
|
1136
1143
|
`All attempts timed out, skipping persistence (server likely received events)${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1137
1144
|
), this.clearPersistedEvents(), t?.onFailure?.(), !1) : (this.persistEvents(e), t?.onFailure?.(), !1);
|
|
@@ -1198,7 +1205,7 @@ class Je extends w {
|
|
|
1198
1205
|
this.clearPersistedEvents();
|
|
1199
1206
|
return;
|
|
1200
1207
|
}
|
|
1201
|
-
const
|
|
1208
|
+
const s = t.recoveryFailures, n = typeof s == "number" && Number.isFinite(s) && s >= 0 ? s : 0;
|
|
1202
1209
|
if (n >= 3) {
|
|
1203
1210
|
a(
|
|
1204
1211
|
"debug",
|
|
@@ -1209,11 +1216,11 @@ class Je extends w {
|
|
|
1209
1216
|
const i = this.createRecoveryBody(t);
|
|
1210
1217
|
await this.send(i) ? (this.clearPersistedEvents(), e?.onSuccess?.(t.events.length, t.events, i)) : (this.persistEventsWithFailureCount(i, n + 1, !0), e?.onFailure?.());
|
|
1211
1218
|
} catch (t) {
|
|
1212
|
-
if (t instanceof
|
|
1219
|
+
if (t instanceof O) {
|
|
1213
1220
|
this.logPermanentError("Permanent error during recovery, clearing persisted events", t), this.clearPersistedEvents(), e?.onFailure?.();
|
|
1214
1221
|
return;
|
|
1215
1222
|
}
|
|
1216
|
-
if (t instanceof
|
|
1223
|
+
if (t instanceof P) {
|
|
1217
1224
|
a(
|
|
1218
1225
|
"debug",
|
|
1219
1226
|
`Recovery timed out, clearing persisted events (server likely received them)${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
@@ -1270,14 +1277,14 @@ class Je extends w {
|
|
|
1270
1277
|
const t = this.transformers.beforeSend;
|
|
1271
1278
|
if (!t)
|
|
1272
1279
|
return e;
|
|
1273
|
-
const
|
|
1280
|
+
const s = Es(
|
|
1274
1281
|
e.events,
|
|
1275
1282
|
t,
|
|
1276
1283
|
this.integrationId || "SenderManager"
|
|
1277
1284
|
);
|
|
1278
|
-
return
|
|
1285
|
+
return s.length === 0 ? null : {
|
|
1279
1286
|
...e,
|
|
1280
|
-
events:
|
|
1287
|
+
events: s
|
|
1281
1288
|
};
|
|
1282
1289
|
}
|
|
1283
1290
|
/**
|
|
@@ -1315,7 +1322,7 @@ class Je extends w {
|
|
|
1315
1322
|
if (this.integrationId === "saas")
|
|
1316
1323
|
return e;
|
|
1317
1324
|
const t = this.transformers.beforeBatch;
|
|
1318
|
-
return t ?
|
|
1325
|
+
return t ? gt(e, t, this.integrationId || "SenderManager") : e;
|
|
1319
1326
|
}
|
|
1320
1327
|
/**
|
|
1321
1328
|
* Calculates exponential backoff delay with jitter for retry attempts.
|
|
@@ -1337,7 +1344,7 @@ class Je extends w {
|
|
|
1337
1344
|
* @returns Promise that resolves after calculated delay
|
|
1338
1345
|
*/
|
|
1339
1346
|
async backoffDelay(e) {
|
|
1340
|
-
const t = 100 * Math.pow(2, e),
|
|
1347
|
+
const t = 100 * Math.pow(2, e), s = Math.random() * 100, n = t + s;
|
|
1341
1348
|
return new Promise((i) => setTimeout(i, n));
|
|
1342
1349
|
}
|
|
1343
1350
|
/**
|
|
@@ -1381,16 +1388,16 @@ class Je extends w {
|
|
|
1381
1388
|
const t = this.applyBeforeSendTransformer(e);
|
|
1382
1389
|
if (!t)
|
|
1383
1390
|
return !0;
|
|
1384
|
-
const
|
|
1385
|
-
if (!
|
|
1391
|
+
const s = this.applyBeforeBatchTransformer(t);
|
|
1392
|
+
if (!s)
|
|
1386
1393
|
return !0;
|
|
1387
1394
|
if (this.apiUrl?.includes(B.Fail))
|
|
1388
1395
|
return a("debug", `Fail mode: simulating network failure${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1389
|
-
data: { events:
|
|
1396
|
+
data: { events: s.events.length }
|
|
1390
1397
|
}), !1;
|
|
1391
1398
|
if (this.apiUrl?.includes(B.Localhost))
|
|
1392
1399
|
return a("debug", `Success mode: simulating successful send${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1393
|
-
data: { events:
|
|
1400
|
+
data: { events: s.events.length }
|
|
1394
1401
|
}), !0;
|
|
1395
1402
|
if (this.consecutiveNetworkFailures >= 3) {
|
|
1396
1403
|
const c = Date.now() - this.circuitOpenedAt;
|
|
@@ -1402,7 +1409,7 @@ class Je extends w {
|
|
|
1402
1409
|
}
|
|
1403
1410
|
}), !1;
|
|
1404
1411
|
}
|
|
1405
|
-
const { url: n, payload: i } = this.prepareRequest(
|
|
1412
|
+
const { url: n, payload: i } = this.prepareRequest(s);
|
|
1406
1413
|
let o = !0, l = !1;
|
|
1407
1414
|
for (let c = 1; c <= 3; c++)
|
|
1408
1415
|
try {
|
|
@@ -1410,14 +1417,20 @@ class Je extends w {
|
|
|
1410
1417
|
"info",
|
|
1411
1418
|
`Send succeeded after ${c - 1} retry attempt(s)${this.integrationId ? ` [${this.integrationId}]` : ""}`,
|
|
1412
1419
|
{
|
|
1413
|
-
data: { events:
|
|
1420
|
+
data: { events: s.events.length, attempt: c }
|
|
1414
1421
|
}
|
|
1415
1422
|
), this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, !0) : !1;
|
|
1416
1423
|
} catch (u) {
|
|
1417
1424
|
const g = c === 3;
|
|
1418
|
-
if (u instanceof
|
|
1425
|
+
if (u instanceof O)
|
|
1419
1426
|
throw this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, u;
|
|
1420
|
-
if (u instanceof
|
|
1427
|
+
if (u instanceof ne) {
|
|
1428
|
+
this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0, o = !1, l = !0, a("warn", `Rate limited, skipping retries${this.integrationId ? ` [${this.integrationId}]` : ""}`, {
|
|
1429
|
+
data: { events: e.events.length, attempt: c }
|
|
1430
|
+
});
|
|
1431
|
+
break;
|
|
1432
|
+
}
|
|
1433
|
+
if (u instanceof P || (o = !1), u instanceof TypeError || (l = !0), a(
|
|
1421
1434
|
g ? "error" : "warn",
|
|
1422
1435
|
`Send attempt ${c} failed${this.integrationId ? ` [${this.integrationId}]` : ""}${g ? " (all retries exhausted)" : ", will retry"}`,
|
|
1423
1436
|
{
|
|
@@ -1434,7 +1447,7 @@ class Je extends w {
|
|
|
1434
1447
|
continue;
|
|
1435
1448
|
}
|
|
1436
1449
|
if (o)
|
|
1437
|
-
throw new
|
|
1450
|
+
throw new P("All retry attempts timed out (server likely received the request)");
|
|
1438
1451
|
return l ? (this.consecutiveNetworkFailures = 0, this.circuitOpenedAt = 0) : (this.consecutiveNetworkFailures = Math.min(
|
|
1439
1452
|
this.consecutiveNetworkFailures + 1,
|
|
1440
1453
|
3
|
|
@@ -1466,11 +1479,11 @@ class Je extends w {
|
|
|
1466
1479
|
* @private
|
|
1467
1480
|
*/
|
|
1468
1481
|
async sendWithTimeout(e, t) {
|
|
1469
|
-
const
|
|
1470
|
-
this.pendingControllers.add(
|
|
1482
|
+
const s = new AbortController();
|
|
1483
|
+
this.pendingControllers.add(s);
|
|
1471
1484
|
let n = !1;
|
|
1472
1485
|
const i = setTimeout(() => {
|
|
1473
|
-
n = !0,
|
|
1486
|
+
n = !0, s.abort();
|
|
1474
1487
|
}, 15e3);
|
|
1475
1488
|
try {
|
|
1476
1489
|
const o = this.getCustomHeaders(), l = await fetch(e, {
|
|
@@ -1478,19 +1491,19 @@ class Je extends w {
|
|
|
1478
1491
|
body: t,
|
|
1479
1492
|
keepalive: !0,
|
|
1480
1493
|
credentials: this.fetchCredentials,
|
|
1481
|
-
signal:
|
|
1494
|
+
signal: s.signal,
|
|
1482
1495
|
headers: {
|
|
1483
1496
|
...o,
|
|
1484
1497
|
"Content-Type": "application/json"
|
|
1485
1498
|
}
|
|
1486
1499
|
});
|
|
1487
1500
|
if (!l.ok)
|
|
1488
|
-
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}`);
|
|
1489
1502
|
return l;
|
|
1490
1503
|
} catch (o) {
|
|
1491
|
-
throw o instanceof
|
|
1504
|
+
throw o instanceof O ? o : n ? new P("Request timed out (server likely received the request)") : o;
|
|
1492
1505
|
} finally {
|
|
1493
|
-
clearTimeout(i), this.pendingControllers.delete(
|
|
1506
|
+
clearTimeout(i), this.pendingControllers.delete(s);
|
|
1494
1507
|
}
|
|
1495
1508
|
}
|
|
1496
1509
|
/**
|
|
@@ -1517,10 +1530,10 @@ class Je extends w {
|
|
|
1517
1530
|
const t = this.applyBeforeSendTransformer(e);
|
|
1518
1531
|
if (!t)
|
|
1519
1532
|
return !0;
|
|
1520
|
-
const
|
|
1521
|
-
if (!
|
|
1533
|
+
const s = this.applyBeforeBatchTransformer(t);
|
|
1534
|
+
if (!s)
|
|
1522
1535
|
return !0;
|
|
1523
|
-
const { url: n, payload: i } = this.prepareRequest(
|
|
1536
|
+
const { url: n, payload: i } = this.prepareRequest(s);
|
|
1524
1537
|
if (i.length > 65536)
|
|
1525
1538
|
return a(
|
|
1526
1539
|
"warn",
|
|
@@ -1529,21 +1542,21 @@ class Je extends w {
|
|
|
1529
1542
|
data: {
|
|
1530
1543
|
size: i.length,
|
|
1531
1544
|
limit: 65536,
|
|
1532
|
-
events:
|
|
1545
|
+
events: s.events.length
|
|
1533
1546
|
}
|
|
1534
1547
|
}
|
|
1535
|
-
), this.persistEvents(
|
|
1548
|
+
), this.persistEvents(s), !1;
|
|
1536
1549
|
const o = new Blob([i], { type: "application/json" });
|
|
1537
1550
|
if (!this.isSendBeaconAvailable())
|
|
1538
1551
|
return a(
|
|
1539
1552
|
"warn",
|
|
1540
1553
|
`sendBeacon not available, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1541
|
-
), this.persistEvents(
|
|
1554
|
+
), this.persistEvents(s), !1;
|
|
1542
1555
|
const l = navigator.sendBeacon(n, o);
|
|
1543
1556
|
return l || (a(
|
|
1544
1557
|
"warn",
|
|
1545
1558
|
`sendBeacon rejected request, persisting events for recovery${this.integrationId ? ` [${this.integrationId}]` : ""}`
|
|
1546
|
-
), this.persistEvents(
|
|
1559
|
+
), this.persistEvents(s)), l;
|
|
1547
1560
|
}
|
|
1548
1561
|
/**
|
|
1549
1562
|
* Prepares request by enriching payload with metadata and serializing to JSON.
|
|
@@ -1566,17 +1579,17 @@ class Je extends w {
|
|
|
1566
1579
|
prepareRequest(e) {
|
|
1567
1580
|
let t = Date.now();
|
|
1568
1581
|
t < this.lastMetadataTimestamp && (t = this.lastMetadataTimestamp), this.lastMetadataTimestamp = t;
|
|
1569
|
-
const
|
|
1582
|
+
const s = {
|
|
1570
1583
|
...e,
|
|
1571
1584
|
_metadata: {
|
|
1572
1585
|
referer: typeof window < "u" ? window.location.href : void 0,
|
|
1573
1586
|
timestamp: t,
|
|
1574
|
-
client_version:
|
|
1587
|
+
client_version: Jt
|
|
1575
1588
|
}
|
|
1576
1589
|
};
|
|
1577
1590
|
return {
|
|
1578
1591
|
url: this.apiUrl || "",
|
|
1579
|
-
payload: JSON.stringify(
|
|
1592
|
+
payload: JSON.stringify(s)
|
|
1580
1593
|
};
|
|
1581
1594
|
}
|
|
1582
1595
|
/**
|
|
@@ -1627,7 +1640,7 @@ class Je extends w {
|
|
|
1627
1640
|
* @private
|
|
1628
1641
|
*/
|
|
1629
1642
|
createRecoveryBody(e) {
|
|
1630
|
-
const { timestamp: t, recoveryFailures:
|
|
1643
|
+
const { timestamp: t, recoveryFailures: s, ...n } = e;
|
|
1631
1644
|
return n;
|
|
1632
1645
|
}
|
|
1633
1646
|
/**
|
|
@@ -1664,10 +1677,10 @@ class Je extends w {
|
|
|
1664
1677
|
* @returns `true` on successful persistence or throttled write, `false` on error
|
|
1665
1678
|
* @private
|
|
1666
1679
|
*/
|
|
1667
|
-
persistEventsWithFailureCount(e, t,
|
|
1680
|
+
persistEventsWithFailureCount(e, t, s = !1) {
|
|
1668
1681
|
try {
|
|
1669
1682
|
const n = this.getPersistedData();
|
|
1670
|
-
if (!
|
|
1683
|
+
if (!s && n && n.timestamp) {
|
|
1671
1684
|
const l = Date.now() - n.timestamp;
|
|
1672
1685
|
if (l < 1e3)
|
|
1673
1686
|
return a(
|
|
@@ -1709,13 +1722,13 @@ class Je extends w {
|
|
|
1709
1722
|
return typeof navigator < "u" && typeof navigator.sendBeacon == "function";
|
|
1710
1723
|
}
|
|
1711
1724
|
logPermanentError(e, t) {
|
|
1712
|
-
const
|
|
1713
|
-
(!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}]` : ""}`, {
|
|
1714
1727
|
data: { status: t.statusCode, message: t.message }
|
|
1715
|
-
}), this.lastPermanentErrorLog = { statusCode: t.statusCode, timestamp:
|
|
1728
|
+
}), this.lastPermanentErrorLog = { statusCode: t.statusCode, timestamp: s });
|
|
1716
1729
|
}
|
|
1717
1730
|
}
|
|
1718
|
-
class
|
|
1731
|
+
class Ss extends _ {
|
|
1719
1732
|
bootTime;
|
|
1720
1733
|
bootTimestamp;
|
|
1721
1734
|
hasPerformanceNow;
|
|
@@ -1807,13 +1820,13 @@ class Er extends w {
|
|
|
1807
1820
|
if (e - this.lastClockSkewCheck < 5e3)
|
|
1808
1821
|
return this.detectedSkew;
|
|
1809
1822
|
this.lastClockSkewCheck = e;
|
|
1810
|
-
const t = this.now(),
|
|
1811
|
-
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", {
|
|
1812
1825
|
data: {
|
|
1813
1826
|
skewMs: this.detectedSkew,
|
|
1814
1827
|
skewMinutes: (this.detectedSkew / 1e3 / 60).toFixed(2),
|
|
1815
1828
|
monotonicTime: new Date(t).toISOString(),
|
|
1816
|
-
systemTime: new Date(
|
|
1829
|
+
systemTime: new Date(s).toISOString()
|
|
1817
1830
|
}
|
|
1818
1831
|
}), this.detectedSkew;
|
|
1819
1832
|
}
|
|
@@ -1842,7 +1855,7 @@ class Er extends w {
|
|
|
1842
1855
|
* ```
|
|
1843
1856
|
*/
|
|
1844
1857
|
validateTimestamp(e) {
|
|
1845
|
-
const
|
|
1858
|
+
const s = this.now(), n = e - s;
|
|
1846
1859
|
return n > 12e4 ? {
|
|
1847
1860
|
valid: !1,
|
|
1848
1861
|
error: `Timestamp is ${(n / 1e3 / 60).toFixed(2)} minutes in the future (max allowed: 2 minutes)`
|
|
@@ -1864,8 +1877,8 @@ class Er extends w {
|
|
|
1864
1877
|
};
|
|
1865
1878
|
}
|
|
1866
1879
|
}
|
|
1867
|
-
const
|
|
1868
|
-
class
|
|
1880
|
+
const ps = new Set(Object.values(d));
|
|
1881
|
+
class Ts extends _ {
|
|
1869
1882
|
dataSenders;
|
|
1870
1883
|
emitter;
|
|
1871
1884
|
transformers;
|
|
@@ -1903,15 +1916,15 @@ class pr extends w {
|
|
|
1903
1916
|
* @param customHeadersProvider - Optional callback for dynamic headers
|
|
1904
1917
|
* @param fetchCredentials - Fetch credentials mode for custom backend. @default 'include'
|
|
1905
1918
|
*/
|
|
1906
|
-
constructor(e, t = null,
|
|
1907
|
-
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 = [];
|
|
1908
1921
|
const l = this.get("collectApiUrls");
|
|
1909
|
-
l?.saas && this.dataSenders.push(new
|
|
1910
|
-
new
|
|
1922
|
+
l?.saas && this.dataSenders.push(new Ze(e, "saas", l.saas, s)), l?.custom && this.dataSenders.push(
|
|
1923
|
+
new Ze(
|
|
1911
1924
|
e,
|
|
1912
1925
|
"custom",
|
|
1913
1926
|
l.custom,
|
|
1914
|
-
|
|
1927
|
+
s,
|
|
1915
1928
|
n,
|
|
1916
1929
|
i,
|
|
1917
1930
|
o
|
|
@@ -1947,7 +1960,7 @@ class pr extends w {
|
|
|
1947
1960
|
async recoverPersistedEvents() {
|
|
1948
1961
|
const e = this.dataSenders.map(
|
|
1949
1962
|
async (t) => t.recoverPersistedEvents({
|
|
1950
|
-
onSuccess: (
|
|
1963
|
+
onSuccess: (s, n, i) => {
|
|
1951
1964
|
if (n && n.length > 0) {
|
|
1952
1965
|
const o = n.map((l) => l.id);
|
|
1953
1966
|
this.removeProcessedEvents(o), i && this.emitEventsQueue(i);
|
|
@@ -2022,7 +2035,7 @@ class pr extends w {
|
|
|
2022
2035
|
track({
|
|
2023
2036
|
type: e,
|
|
2024
2037
|
page_url: t,
|
|
2025
|
-
from_page_url:
|
|
2038
|
+
from_page_url: s,
|
|
2026
2039
|
scroll_data: n,
|
|
2027
2040
|
click_data: i,
|
|
2028
2041
|
custom_event: o,
|
|
@@ -2035,7 +2048,7 @@ class pr extends w {
|
|
|
2035
2048
|
a("error", "Event type is required - event will be ignored");
|
|
2036
2049
|
return;
|
|
2037
2050
|
}
|
|
2038
|
-
if (!
|
|
2051
|
+
if (!ps.has(e)) {
|
|
2039
2052
|
a("error", "Invalid event type - event will be ignored", {
|
|
2040
2053
|
data: { type: e }
|
|
2041
2054
|
});
|
|
@@ -2048,7 +2061,7 @@ class pr extends w {
|
|
|
2048
2061
|
})), this.pendingEventsBuffer.push({
|
|
2049
2062
|
type: e,
|
|
2050
2063
|
page_url: t,
|
|
2051
|
-
from_page_url:
|
|
2064
|
+
from_page_url: s,
|
|
2052
2065
|
scroll_data: n,
|
|
2053
2066
|
click_data: i,
|
|
2054
2067
|
custom_event: o,
|
|
@@ -2079,12 +2092,12 @@ class pr extends w {
|
|
|
2079
2092
|
}
|
|
2080
2093
|
const v = this.getTypeLimitForEvent(S);
|
|
2081
2094
|
if (v) {
|
|
2082
|
-
const
|
|
2083
|
-
if (
|
|
2095
|
+
const he = this.sessionEventCounts[S];
|
|
2096
|
+
if (he !== void 0 && he >= v) {
|
|
2084
2097
|
a("warn", "Session event type limit reached", {
|
|
2085
2098
|
data: {
|
|
2086
2099
|
type: S,
|
|
2087
|
-
count:
|
|
2100
|
+
count: he,
|
|
2088
2101
|
limit: v
|
|
2089
2102
|
}
|
|
2090
2103
|
});
|
|
@@ -2097,10 +2110,10 @@ class pr extends w {
|
|
|
2097
2110
|
if (!this.checkPerEventRateLimit(o.name, v))
|
|
2098
2111
|
return;
|
|
2099
2112
|
}
|
|
2100
|
-
const
|
|
2113
|
+
const Ve = S === d.SESSION_START, Y = t || this.get("pageUrl"), $ = this.buildEventPayload({
|
|
2101
2114
|
type: S,
|
|
2102
2115
|
page_url: Y,
|
|
2103
|
-
from_page_url:
|
|
2116
|
+
from_page_url: s,
|
|
2104
2117
|
scroll_data: n,
|
|
2105
2118
|
click_data: i,
|
|
2106
2119
|
custom_event: o,
|
|
@@ -2110,7 +2123,7 @@ class pr extends w {
|
|
|
2110
2123
|
page_view: g
|
|
2111
2124
|
});
|
|
2112
2125
|
if ($ && !(!T && !this.shouldSample())) {
|
|
2113
|
-
if (
|
|
2126
|
+
if (Ve) {
|
|
2114
2127
|
const v = this.get("sessionId");
|
|
2115
2128
|
if (!v) {
|
|
2116
2129
|
a("error", "Session start event requires sessionId - event will be ignored");
|
|
@@ -2125,7 +2138,7 @@ class pr extends w {
|
|
|
2125
2138
|
this.set("hasStartSession", !0);
|
|
2126
2139
|
}
|
|
2127
2140
|
if (!this.isDuplicateEvent($)) {
|
|
2128
|
-
if (this.get("mode") ===
|
|
2141
|
+
if (this.get("mode") === ie.QA) {
|
|
2129
2142
|
if (S === d.CUSTOM && o) {
|
|
2130
2143
|
a("info", `Custom Event: ${o.name}`, {
|
|
2131
2144
|
visibility: "qa",
|
|
@@ -2403,8 +2416,8 @@ class pr extends w {
|
|
|
2403
2416
|
return;
|
|
2404
2417
|
}
|
|
2405
2418
|
const t = [...this.pendingEventsBuffer];
|
|
2406
|
-
this.pendingEventsBuffer = [], t.forEach((
|
|
2407
|
-
this.track(
|
|
2419
|
+
this.pendingEventsBuffer = [], t.forEach((s) => {
|
|
2420
|
+
this.track(s);
|
|
2408
2421
|
});
|
|
2409
2422
|
}
|
|
2410
2423
|
clearSendTimeout() {
|
|
@@ -2418,7 +2431,7 @@ class pr extends w {
|
|
|
2418
2431
|
return e ? !0 : Promise.resolve(!0);
|
|
2419
2432
|
if (!e && this.sendInProgress)
|
|
2420
2433
|
return a("debug", "Async flush skipped: send already in progress"), Promise.resolve(!1);
|
|
2421
|
-
const t = this.buildEventsPayload(),
|
|
2434
|
+
const t = this.buildEventsPayload(), s = [...this.eventsQueue], n = s.map((i) => i.id);
|
|
2422
2435
|
if (this.dataSenders.length === 0)
|
|
2423
2436
|
return this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t), e ? !0 : Promise.resolve(!0);
|
|
2424
2437
|
if (e) {
|
|
@@ -2438,7 +2451,7 @@ class pr extends w {
|
|
|
2438
2451
|
return Promise.allSettled(i).then((o) => {
|
|
2439
2452
|
const l = o.some((c) => this.isSuccessfulResult(c));
|
|
2440
2453
|
return l ? (this.removeProcessedEvents(n), this.clearSendTimeout(), this.emitEventsQueue(t)) : a("debug", "Async flush complete failure, events kept in queue for retry", {
|
|
2441
|
-
data: { eventCount:
|
|
2454
|
+
data: { eventCount: s.length }
|
|
2442
2455
|
}), l;
|
|
2443
2456
|
});
|
|
2444
2457
|
}
|
|
@@ -2452,7 +2465,7 @@ class pr extends w {
|
|
|
2452
2465
|
this.emitEventsQueue(e);
|
|
2453
2466
|
return;
|
|
2454
2467
|
}
|
|
2455
|
-
const t = [...this.eventsQueue],
|
|
2468
|
+
const t = [...this.eventsQueue], s = t.map((l) => l.id), n = this.dataSenders.map(
|
|
2456
2469
|
async (l) => l.sendEventsQueue(e, {
|
|
2457
2470
|
onSuccess: () => {
|
|
2458
2471
|
},
|
|
@@ -2461,7 +2474,7 @@ class pr extends w {
|
|
|
2461
2474
|
})
|
|
2462
2475
|
), i = await Promise.allSettled(n);
|
|
2463
2476
|
if (i.some((l) => this.isSuccessfulResult(l))) {
|
|
2464
|
-
this.consecutiveSendFailures = 0, this.removeProcessedEvents(
|
|
2477
|
+
this.consecutiveSendFailures = 0, this.removeProcessedEvents(s), this.emitEventsQueue(e);
|
|
2465
2478
|
const l = i.filter((c) => !this.isSuccessfulResult(c)).length;
|
|
2466
2479
|
l > 0 && a("debug", "Periodic send completed with some failures, removed from queue and persisted per-integration", {
|
|
2467
2480
|
data: { eventCount: t.length, failedCount: l }
|
|
@@ -2482,33 +2495,33 @@ class pr extends w {
|
|
|
2482
2495
|
const u = this.createEventSignature(c);
|
|
2483
2496
|
e.has(u) || t.push(u), e.set(u, c);
|
|
2484
2497
|
}
|
|
2485
|
-
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);
|
|
2486
2499
|
let n = {
|
|
2487
2500
|
user_id: this.get("userId"),
|
|
2488
2501
|
session_id: this.get("sessionId"),
|
|
2489
2502
|
device: this.get("device"),
|
|
2490
|
-
events:
|
|
2503
|
+
events: s,
|
|
2491
2504
|
...this.get("config")?.globalMetadata && { global_metadata: this.get("config")?.globalMetadata },
|
|
2492
2505
|
...this.get("identity") && { identify: this.get("identity") }
|
|
2493
2506
|
};
|
|
2494
2507
|
const i = this.get("collectApiUrls"), o = !!(i?.custom || i?.saas), l = this.transformers.beforeBatch;
|
|
2495
2508
|
if (!o && l) {
|
|
2496
|
-
const c =
|
|
2509
|
+
const c = gt(n, l, "EventManager");
|
|
2497
2510
|
c !== null && (n = c);
|
|
2498
2511
|
}
|
|
2499
2512
|
return n;
|
|
2500
2513
|
}
|
|
2501
2514
|
buildEventPayload(e) {
|
|
2502
|
-
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);
|
|
2503
2516
|
n.valid || a("warn", "Event timestamp validation failed", {
|
|
2504
2517
|
data: { type: e.type, error: n.error }
|
|
2505
2518
|
});
|
|
2506
2519
|
const i = this.get("sessionReferrer"), o = this.get("sessionUtm");
|
|
2507
2520
|
let l = {
|
|
2508
|
-
id:
|
|
2521
|
+
id: ns(),
|
|
2509
2522
|
type: e.type,
|
|
2510
2523
|
page_url: t,
|
|
2511
|
-
timestamp:
|
|
2524
|
+
timestamp: s,
|
|
2512
2525
|
...i && { referrer: i },
|
|
2513
2526
|
...e.from_page_url && { from_page_url: e.from_page_url },
|
|
2514
2527
|
...e.scroll_data && { scroll_data: e.scroll_data },
|
|
@@ -2522,7 +2535,7 @@ class pr extends w {
|
|
|
2522
2535
|
};
|
|
2523
2536
|
const c = this.get("collectApiUrls"), u = !!c?.custom, g = !!c?.saas, E = u || g, T = u && g, S = this.transformers.beforeSend;
|
|
2524
2537
|
if (S && (!E || u && !T)) {
|
|
2525
|
-
const Y =
|
|
2538
|
+
const Y = mt(l, S, "EventManager");
|
|
2526
2539
|
if (Y === null)
|
|
2527
2540
|
return null;
|
|
2528
2541
|
l = Y;
|
|
@@ -2530,15 +2543,15 @@ class pr extends w {
|
|
|
2530
2543
|
return l;
|
|
2531
2544
|
}
|
|
2532
2545
|
isDuplicateEvent(e) {
|
|
2533
|
-
const t = Date.now(),
|
|
2534
|
-
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", {
|
|
2535
2548
|
data: { hardLimit: 3e3 }
|
|
2536
2549
|
})), !1);
|
|
2537
2550
|
}
|
|
2538
2551
|
pruneOldFingerprints() {
|
|
2539
2552
|
const e = Date.now(), t = 1e3 * 10;
|
|
2540
|
-
for (const [
|
|
2541
|
-
e - n > t && this.recentEventFingerprints.delete(
|
|
2553
|
+
for (const [s, n] of this.recentEventFingerprints.entries())
|
|
2554
|
+
e - n > t && this.recentEventFingerprints.delete(s);
|
|
2542
2555
|
a("debug", "Pruned old event fingerprints", {
|
|
2543
2556
|
data: {
|
|
2544
2557
|
remaining: this.recentEventFingerprints.size,
|
|
@@ -2549,8 +2562,8 @@ class pr extends w {
|
|
|
2549
2562
|
createEventFingerprint(e) {
|
|
2550
2563
|
let t = `${e.type}_${e.page_url}`;
|
|
2551
2564
|
if (e.click_data) {
|
|
2552
|
-
const
|
|
2553
|
-
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}`;
|
|
2554
2567
|
}
|
|
2555
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;
|
|
2556
2569
|
}
|
|
@@ -2559,17 +2572,17 @@ class pr extends w {
|
|
|
2559
2572
|
}
|
|
2560
2573
|
/** Deterministic JSON string with sorted keys to ensure consistent fingerprints regardless of property insertion order */
|
|
2561
2574
|
stableStringify(e) {
|
|
2562
|
-
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);
|
|
2563
2576
|
}
|
|
2564
2577
|
addToQueue(e) {
|
|
2565
2578
|
if (this.emitEvent(e), this.eventsQueue.push(e), this.eventsQueue.length > 100) {
|
|
2566
|
-
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();
|
|
2567
2580
|
a("warn", "Event queue overflow, oldest non-critical event removed", {
|
|
2568
2581
|
data: {
|
|
2569
2582
|
maxLength: 100,
|
|
2570
2583
|
currentLength: this.eventsQueue.length,
|
|
2571
|
-
removedEventType:
|
|
2572
|
-
wasCritical:
|
|
2584
|
+
removedEventType: s?.type,
|
|
2585
|
+
wasCritical: s?.type === d.SESSION_START
|
|
2573
2586
|
}
|
|
2574
2587
|
});
|
|
2575
2588
|
}
|
|
@@ -2597,14 +2610,14 @@ class pr extends w {
|
|
|
2597
2610
|
return e - this.rateLimitWindowStart > 1e3 && (this.rateLimitCounter = 0, this.rateLimitWindowStart = e), this.rateLimitCounter >= 50 ? !1 : (this.rateLimitCounter++, !0);
|
|
2598
2611
|
}
|
|
2599
2612
|
checkPerEventRateLimit(e, t) {
|
|
2600
|
-
const
|
|
2613
|
+
const s = Date.now(), i = (this.perEventRateLimits.get(e) ?? []).filter((o) => s - o < 6e4);
|
|
2601
2614
|
return i.length >= t ? (a("warn", "Per-event rate limit exceeded for custom event", {
|
|
2602
2615
|
data: {
|
|
2603
2616
|
eventName: e,
|
|
2604
2617
|
limit: t,
|
|
2605
2618
|
window: `${6e4 / 1e3}s`
|
|
2606
2619
|
}
|
|
2607
|
-
}), !1) : (i.push(
|
|
2620
|
+
}), !1) : (i.push(s), this.perEventRateLimits.set(e, i), !0);
|
|
2608
2621
|
}
|
|
2609
2622
|
getTypeLimitForEvent(e) {
|
|
2610
2623
|
return {
|
|
@@ -2617,13 +2630,13 @@ class pr extends w {
|
|
|
2617
2630
|
}
|
|
2618
2631
|
removeProcessedEvents(e) {
|
|
2619
2632
|
const t = new Set(e);
|
|
2620
|
-
this.eventsQueue = this.eventsQueue.filter((
|
|
2633
|
+
this.eventsQueue = this.eventsQueue.filter((s) => !t.has(s.id));
|
|
2621
2634
|
}
|
|
2622
2635
|
emitEvent(e) {
|
|
2623
|
-
this.emitter && this.emitter.emit(
|
|
2636
|
+
this.emitter && this.emitter.emit(re.EVENT, e);
|
|
2624
2637
|
}
|
|
2625
2638
|
emitEventsQueue(e) {
|
|
2626
|
-
this.emitter && this.emitter.emit(
|
|
2639
|
+
this.emitter && this.emitter.emit(re.QUEUE, e);
|
|
2627
2640
|
}
|
|
2628
2641
|
/**
|
|
2629
2642
|
* Creates a debounced version of a function that delays execution until after
|
|
@@ -2646,10 +2659,10 @@ class pr extends w {
|
|
|
2646
2659
|
* @internal
|
|
2647
2660
|
*/
|
|
2648
2661
|
debounce(e, t) {
|
|
2649
|
-
let
|
|
2662
|
+
let s = null;
|
|
2650
2663
|
return ((...n) => {
|
|
2651
|
-
|
|
2652
|
-
e(...n),
|
|
2664
|
+
s !== null && clearTimeout(s), s = setTimeout(() => {
|
|
2665
|
+
e(...n), s = null;
|
|
2653
2666
|
}, t);
|
|
2654
2667
|
});
|
|
2655
2668
|
}
|
|
@@ -2699,15 +2712,15 @@ class pr extends w {
|
|
|
2699
2712
|
loadSessionCounts(e) {
|
|
2700
2713
|
if (typeof window > "u" || typeof localStorage > "u")
|
|
2701
2714
|
return this.getInitialCounts();
|
|
2702
|
-
const t = this.get("userId") || "anonymous",
|
|
2715
|
+
const t = this.get("userId") || "anonymous", s = Fe(t, e);
|
|
2703
2716
|
try {
|
|
2704
|
-
const n = localStorage.getItem(
|
|
2717
|
+
const n = localStorage.getItem(s);
|
|
2705
2718
|
if (!n)
|
|
2706
2719
|
return this.getInitialCounts();
|
|
2707
2720
|
const i = JSON.parse(n);
|
|
2708
|
-
return i._timestamp && Date.now() - i._timestamp >
|
|
2721
|
+
return i._timestamp && Date.now() - i._timestamp > xe ? (a("debug", "Session counts expired, clearing", {
|
|
2709
2722
|
data: { sessionId: e, age: Date.now() - i._timestamp }
|
|
2710
|
-
}), 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" ? {
|
|
2711
2724
|
total: i.total,
|
|
2712
2725
|
[d.CLICK]: i[d.CLICK],
|
|
2713
2726
|
[d.PAGE_VIEW]: i[d.PAGE_VIEW],
|
|
@@ -2716,7 +2729,7 @@ class pr extends w {
|
|
|
2716
2729
|
[d.SCROLL]: i[d.SCROLL]
|
|
2717
2730
|
} : (a("warn", "Invalid session counts structure in localStorage, resetting", {
|
|
2718
2731
|
data: { sessionId: e, parsed: i }
|
|
2719
|
-
}), localStorage.removeItem(
|
|
2732
|
+
}), localStorage.removeItem(s), a("debug", "Session counts removed due to invalid/corrupted data", {
|
|
2720
2733
|
data: { sessionId: e, parsed: i }
|
|
2721
2734
|
}), this.getInitialCounts());
|
|
2722
2735
|
} catch (n) {
|
|
@@ -2750,32 +2763,32 @@ class pr extends w {
|
|
|
2750
2763
|
cleanupExpiredSessionCounts() {
|
|
2751
2764
|
if (!(typeof window > "u" || typeof localStorage > "u"))
|
|
2752
2765
|
try {
|
|
2753
|
-
const e = localStorage.getItem(
|
|
2766
|
+
const e = localStorage.getItem($e);
|
|
2754
2767
|
if (e) {
|
|
2755
2768
|
const i = Date.now() - parseInt(e, 10);
|
|
2756
|
-
if (i <
|
|
2769
|
+
if (i < Be) {
|
|
2757
2770
|
a("debug", "Skipping session counts cleanup (throttled)", {
|
|
2758
|
-
data: { timeSinceLastCleanup: i, throttleMs:
|
|
2771
|
+
data: { timeSinceLastCleanup: i, throttleMs: Be }
|
|
2759
2772
|
});
|
|
2760
2773
|
return;
|
|
2761
2774
|
}
|
|
2762
2775
|
}
|
|
2763
|
-
const t = this.get("userId") || "anonymous",
|
|
2776
|
+
const t = this.get("userId") || "anonymous", s = `${I}:${t}:session_counts:`, n = [];
|
|
2764
2777
|
for (let i = 0; i < localStorage.length; i++) {
|
|
2765
2778
|
const o = localStorage.key(i);
|
|
2766
|
-
if (o?.startsWith(
|
|
2779
|
+
if (o?.startsWith(s))
|
|
2767
2780
|
try {
|
|
2768
2781
|
const l = localStorage.getItem(o);
|
|
2769
2782
|
if (l) {
|
|
2770
2783
|
const c = JSON.parse(l);
|
|
2771
|
-
c._timestamp && Date.now() - c._timestamp >
|
|
2784
|
+
c._timestamp && Date.now() - c._timestamp > xe && n.push(o);
|
|
2772
2785
|
}
|
|
2773
2786
|
} catch {
|
|
2774
2787
|
}
|
|
2775
2788
|
}
|
|
2776
2789
|
n.forEach((i) => {
|
|
2777
2790
|
localStorage.removeItem(i), a("debug", "Cleaned up expired session counts", { data: { key: i } });
|
|
2778
|
-
}), n.length > 0 && a("info", `Cleaned up ${n.length} expired session counts entries`), localStorage.setItem(
|
|
2791
|
+
}), n.length > 0 && a("info", `Cleaned up ${n.length} expired session counts entries`), localStorage.setItem($e, Date.now().toString());
|
|
2779
2792
|
} catch (e) {
|
|
2780
2793
|
a("warn", "Failed to cleanup expired session counts", { error: e });
|
|
2781
2794
|
}
|
|
@@ -2809,14 +2822,14 @@ class pr extends w {
|
|
|
2809
2822
|
* @internal
|
|
2810
2823
|
*/
|
|
2811
2824
|
saveSessionCounts(e) {
|
|
2812
|
-
const t = this.get("userId") || "anonymous",
|
|
2825
|
+
const t = this.get("userId") || "anonymous", s = Fe(t, e);
|
|
2813
2826
|
try {
|
|
2814
2827
|
const n = {
|
|
2815
2828
|
...this.sessionEventCounts,
|
|
2816
2829
|
_timestamp: Date.now(),
|
|
2817
2830
|
_version: 1
|
|
2818
2831
|
};
|
|
2819
|
-
localStorage.setItem(
|
|
2832
|
+
localStorage.setItem(s, JSON.stringify(n));
|
|
2820
2833
|
} catch (n) {
|
|
2821
2834
|
a("warn", "Failed to persist session counts to localStorage", {
|
|
2822
2835
|
error: n,
|
|
@@ -2825,7 +2838,7 @@ class pr extends w {
|
|
|
2825
2838
|
}
|
|
2826
2839
|
}
|
|
2827
2840
|
}
|
|
2828
|
-
class
|
|
2841
|
+
class Is {
|
|
2829
2842
|
/**
|
|
2830
2843
|
* Gets or creates a unique user ID.
|
|
2831
2844
|
*
|
|
@@ -2843,15 +2856,15 @@ class Tr {
|
|
|
2843
2856
|
* @returns Persistent unique user ID (UUID v4 format)
|
|
2844
2857
|
*/
|
|
2845
2858
|
static getId(e) {
|
|
2846
|
-
const t = e.getItem(
|
|
2859
|
+
const t = e.getItem(Te);
|
|
2847
2860
|
if (t)
|
|
2848
2861
|
return t;
|
|
2849
|
-
const
|
|
2850
|
-
return e.setItem(
|
|
2862
|
+
const s = ut();
|
|
2863
|
+
return e.setItem(Te, s), s;
|
|
2851
2864
|
}
|
|
2852
2865
|
}
|
|
2853
|
-
const
|
|
2854
|
-
class
|
|
2866
|
+
const vs = /^\d{13}-[a-z0-9]{9}$/;
|
|
2867
|
+
class _s extends _ {
|
|
2855
2868
|
storageManager;
|
|
2856
2869
|
eventManager;
|
|
2857
2870
|
projectId;
|
|
@@ -2868,8 +2881,8 @@ class vr extends w {
|
|
|
2868
2881
|
* @param eventManager - Event manager for SESSION_START events
|
|
2869
2882
|
* @param projectId - Project identifier for namespacing session storage
|
|
2870
2883
|
*/
|
|
2871
|
-
constructor(e, t,
|
|
2872
|
-
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;
|
|
2873
2886
|
}
|
|
2874
2887
|
initCrossTabSync() {
|
|
2875
2888
|
if (typeof BroadcastChannel > "u") {
|
|
@@ -2877,9 +2890,9 @@ class vr extends w {
|
|
|
2877
2890
|
return;
|
|
2878
2891
|
}
|
|
2879
2892
|
const e = this.getProjectId();
|
|
2880
|
-
this.broadcastChannel = new BroadcastChannel(
|
|
2881
|
-
const { action:
|
|
2882
|
-
o === e && (
|
|
2893
|
+
this.broadcastChannel = new BroadcastChannel(Nt(e)), this.broadcastChannel.onmessage = (t) => {
|
|
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 } }));
|
|
2883
2896
|
};
|
|
2884
2897
|
}
|
|
2885
2898
|
shareSession(e) {
|
|
@@ -2897,18 +2910,18 @@ class vr extends w {
|
|
|
2897
2910
|
const e = this.loadStoredSession();
|
|
2898
2911
|
if (!e)
|
|
2899
2912
|
return null;
|
|
2900
|
-
if (!
|
|
2913
|
+
if (!vs.test(e.id))
|
|
2901
2914
|
return a("warn", "Invalid session ID format recovered from storage, clearing", {
|
|
2902
2915
|
data: { sessionId: e.id }
|
|
2903
2916
|
}), this.clearStoredSession(), null;
|
|
2904
2917
|
const t = this.get("config")?.sessionTimeout ?? 9e5;
|
|
2905
2918
|
return Date.now() - e.lastActivity > t ? (this.clearStoredSession(), null) : e.id;
|
|
2906
2919
|
}
|
|
2907
|
-
persistSession(e, t = Date.now(),
|
|
2920
|
+
persistSession(e, t = Date.now(), s, n) {
|
|
2908
2921
|
this.saveStoredSession({
|
|
2909
2922
|
id: e,
|
|
2910
2923
|
lastActivity: t,
|
|
2911
|
-
...
|
|
2924
|
+
...s && { referrer: s },
|
|
2912
2925
|
...n && { utm: n }
|
|
2913
2926
|
});
|
|
2914
2927
|
}
|
|
@@ -2926,10 +2939,10 @@ class vr extends w {
|
|
|
2926
2939
|
} catch {
|
|
2927
2940
|
this.storageManager.removeItem(e);
|
|
2928
2941
|
}
|
|
2929
|
-
const
|
|
2930
|
-
if (
|
|
2942
|
+
const s = this.storageManager.getSessionItem(e);
|
|
2943
|
+
if (s !== null)
|
|
2931
2944
|
try {
|
|
2932
|
-
const n = JSON.parse(
|
|
2945
|
+
const n = JSON.parse(s);
|
|
2933
2946
|
if (n.id && typeof n.lastActivity == "number")
|
|
2934
2947
|
return n;
|
|
2935
2948
|
} catch {
|
|
@@ -2938,11 +2951,11 @@ class vr extends w {
|
|
|
2938
2951
|
return null;
|
|
2939
2952
|
}
|
|
2940
2953
|
saveStoredSession(e) {
|
|
2941
|
-
const t = this.getSessionStorageKey(),
|
|
2942
|
-
this.storageManager.setItem(t,
|
|
2954
|
+
const t = this.getSessionStorageKey(), s = JSON.stringify(e);
|
|
2955
|
+
this.storageManager.setItem(t, s), this.storageManager.setSessionItem(t, s);
|
|
2943
2956
|
}
|
|
2944
2957
|
getSessionStorageKey() {
|
|
2945
|
-
return
|
|
2958
|
+
return Rt(this.getProjectId());
|
|
2946
2959
|
}
|
|
2947
2960
|
getProjectId() {
|
|
2948
2961
|
return this.projectId;
|
|
@@ -3005,23 +3018,23 @@ class vr extends w {
|
|
|
3005
3018
|
return;
|
|
3006
3019
|
}
|
|
3007
3020
|
const e = this.recoverSession(), t = e ?? this.generateSessionId();
|
|
3008
|
-
let
|
|
3021
|
+
let s, n;
|
|
3009
3022
|
if (e) {
|
|
3010
3023
|
const i = this.loadStoredSession();
|
|
3011
|
-
|
|
3024
|
+
s = i?.referrer ?? me(), n = i?.utm ?? ge();
|
|
3012
3025
|
} else
|
|
3013
|
-
|
|
3026
|
+
s = me(), n = ge();
|
|
3014
3027
|
a("debug", "Session tracking initialized", {
|
|
3015
3028
|
data: {
|
|
3016
3029
|
sessionId: t,
|
|
3017
3030
|
wasRecovered: !!e,
|
|
3018
3031
|
willEmitSessionStart: !e,
|
|
3019
|
-
sessionReferrer:
|
|
3032
|
+
sessionReferrer: s,
|
|
3020
3033
|
hasUtm: !!n
|
|
3021
3034
|
}
|
|
3022
3035
|
}), this.isTracking = !0;
|
|
3023
3036
|
try {
|
|
3024
|
-
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", {
|
|
3025
3038
|
data: { sessionId: t }
|
|
3026
3039
|
}) : (a("debug", "Emitting SESSION_START event", {
|
|
3027
3040
|
data: { sessionId: t }
|
|
@@ -3061,10 +3074,10 @@ class vr extends w {
|
|
|
3061
3074
|
*/
|
|
3062
3075
|
renewSession() {
|
|
3063
3076
|
this.needsRenewal = !1;
|
|
3064
|
-
const e = this.generateSessionId(), t =
|
|
3077
|
+
const e = this.generateSessionId(), t = me(), s = ge();
|
|
3065
3078
|
a("debug", "Renewing session after timeout", {
|
|
3066
3079
|
data: { newSessionId: e }
|
|
3067
|
-
}), 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({
|
|
3068
3081
|
type: d.SESSION_START
|
|
3069
3082
|
}), this.eventManager.flushPendingEvents(), this.setupSessionTimeout();
|
|
3070
3083
|
}
|
|
@@ -3094,8 +3107,8 @@ class vr extends w {
|
|
|
3094
3107
|
const t = this.loadStoredSession();
|
|
3095
3108
|
if (!t)
|
|
3096
3109
|
return !1;
|
|
3097
|
-
const
|
|
3098
|
-
return Date.now() - t.lastActivity >
|
|
3110
|
+
const s = this.get("config")?.sessionTimeout ?? 9e5;
|
|
3111
|
+
return Date.now() - t.lastActivity > s;
|
|
3099
3112
|
}
|
|
3100
3113
|
cleanupLifecycleListeners() {
|
|
3101
3114
|
this.visibilityChangeHandler && (document.removeEventListener("visibilitychange", this.visibilityChangeHandler), this.visibilityChangeHandler = null);
|
|
@@ -3182,7 +3195,7 @@ class vr extends w {
|
|
|
3182
3195
|
this.clearSessionTimeout(), this.cleanupActivityListeners(), this.cleanupCrossTabSync(), this.cleanupLifecycleListeners(), this.isTracking = !1, this.needsRenewal = !1, this.set("hasStartSession", !1);
|
|
3183
3196
|
}
|
|
3184
3197
|
}
|
|
3185
|
-
class
|
|
3198
|
+
class ys extends _ {
|
|
3186
3199
|
eventManager;
|
|
3187
3200
|
storageManager;
|
|
3188
3201
|
sessionManager = null;
|
|
@@ -3217,8 +3230,8 @@ class _r extends w {
|
|
|
3217
3230
|
}
|
|
3218
3231
|
const t = this.get("config")?.integrations?.tracelog?.projectId ?? "custom";
|
|
3219
3232
|
try {
|
|
3220
|
-
this.sessionManager = new
|
|
3221
|
-
} catch (
|
|
3233
|
+
this.sessionManager = new _s(this.storageManager, this.eventManager, t), this.sessionManager.startTracking(), this.eventManager.flushPendingEvents();
|
|
3234
|
+
} catch (s) {
|
|
3222
3235
|
if (this.sessionManager) {
|
|
3223
3236
|
try {
|
|
3224
3237
|
this.sessionManager.destroy();
|
|
@@ -3226,7 +3239,7 @@ class _r extends w {
|
|
|
3226
3239
|
}
|
|
3227
3240
|
this.sessionManager = null;
|
|
3228
3241
|
}
|
|
3229
|
-
throw a("error", "Failed to start session tracking", { error:
|
|
3242
|
+
throw a("error", "Failed to start session tracking", { error: s }), s;
|
|
3230
3243
|
}
|
|
3231
3244
|
}
|
|
3232
3245
|
isActive() {
|
|
@@ -3270,7 +3283,7 @@ class _r extends w {
|
|
|
3270
3283
|
this.destroyed || (this.sessionManager && (this.sessionManager.destroy(), this.sessionManager = null), this.destroyed = !0);
|
|
3271
3284
|
}
|
|
3272
3285
|
}
|
|
3273
|
-
class
|
|
3286
|
+
class ws extends _ {
|
|
3274
3287
|
eventManager;
|
|
3275
3288
|
onTrack;
|
|
3276
3289
|
originalPushState;
|
|
@@ -3305,18 +3318,18 @@ class yr extends w {
|
|
|
3305
3318
|
}
|
|
3306
3319
|
patchHistory(e) {
|
|
3307
3320
|
const t = window.history[e];
|
|
3308
|
-
e === "pushState" && !this.originalPushState ? this.originalPushState = t : e === "replaceState" && !this.originalReplaceState && (this.originalReplaceState = t), window.history[e] = (...
|
|
3309
|
-
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();
|
|
3310
3323
|
};
|
|
3311
3324
|
}
|
|
3312
3325
|
trackCurrentPage = () => {
|
|
3313
|
-
const e = window.location.href, t =
|
|
3326
|
+
const e = window.location.href, t = ye(e, this.get("config").sensitiveQueryParams);
|
|
3314
3327
|
if (this.get("pageUrl") === t)
|
|
3315
3328
|
return;
|
|
3316
|
-
const
|
|
3317
|
-
if (
|
|
3329
|
+
const s = Date.now(), n = this.get("config").pageViewThrottleMs ?? 1e3;
|
|
3330
|
+
if (s - this.lastPageViewTime < n)
|
|
3318
3331
|
return;
|
|
3319
|
-
this.lastPageViewTime =
|
|
3332
|
+
this.lastPageViewTime = s, this.onTrack();
|
|
3320
3333
|
const i = this.get("pageUrl");
|
|
3321
3334
|
this.set("pageUrl", t);
|
|
3322
3335
|
const o = this.extractPageViewData();
|
|
@@ -3328,7 +3341,7 @@ class yr extends w {
|
|
|
3328
3341
|
});
|
|
3329
3342
|
};
|
|
3330
3343
|
trackInitialPageView() {
|
|
3331
|
-
const e =
|
|
3344
|
+
const e = ye(window.location.href, this.get("config").sensitiveQueryParams), t = this.extractPageViewData();
|
|
3332
3345
|
this.lastPageViewTime = Date.now(), this.eventManager.track({
|
|
3333
3346
|
type: d.PAGE_VIEW,
|
|
3334
3347
|
page_url: e,
|
|
@@ -3336,17 +3349,17 @@ class yr extends w {
|
|
|
3336
3349
|
}), this.onTrack();
|
|
3337
3350
|
}
|
|
3338
3351
|
extractPageViewData() {
|
|
3339
|
-
const { pathname: e, search: t, hash:
|
|
3340
|
-
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 : {
|
|
3341
3354
|
...n && { referrer: n },
|
|
3342
3355
|
...i && { title: i },
|
|
3343
3356
|
...e && { pathname: e },
|
|
3344
3357
|
...t && { search: t },
|
|
3345
|
-
...
|
|
3358
|
+
...s && { hash: s }
|
|
3346
3359
|
};
|
|
3347
3360
|
}
|
|
3348
3361
|
}
|
|
3349
|
-
class
|
|
3362
|
+
class bs extends _ {
|
|
3350
3363
|
eventManager;
|
|
3351
3364
|
lastClickTimes = /* @__PURE__ */ new Map();
|
|
3352
3365
|
clickHandler;
|
|
@@ -3369,7 +3382,7 @@ class wr extends w {
|
|
|
3369
3382
|
*/
|
|
3370
3383
|
startTracking() {
|
|
3371
3384
|
this.clickHandler || (this.clickHandler = (e) => {
|
|
3372
|
-
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;
|
|
3373
3386
|
if (!n) {
|
|
3374
3387
|
a("debug", "Click target not found or not an element");
|
|
3375
3388
|
return;
|
|
@@ -3417,15 +3430,15 @@ class wr extends w {
|
|
|
3417
3430
|
* Returns true if the click should be tracked, false if throttled
|
|
3418
3431
|
*/
|
|
3419
3432
|
checkClickThrottle(e, t) {
|
|
3420
|
-
const
|
|
3433
|
+
const s = this.getElementSignature(e), n = Date.now();
|
|
3421
3434
|
this.pruneThrottleCache(n);
|
|
3422
|
-
const i = this.lastClickTimes.get(
|
|
3435
|
+
const i = this.lastClickTimes.get(s);
|
|
3423
3436
|
return i !== void 0 && n - i < t ? (a("debug", "ClickHandler: Click suppressed by throttle", {
|
|
3424
3437
|
data: {
|
|
3425
|
-
signature:
|
|
3438
|
+
signature: s,
|
|
3426
3439
|
throttleRemaining: t - (n - i)
|
|
3427
3440
|
}
|
|
3428
|
-
}), !1) : (this.lastClickTimes.set(
|
|
3441
|
+
}), !1) : (this.lastClickTimes.set(s, n), !0);
|
|
3429
3442
|
}
|
|
3430
3443
|
/**
|
|
3431
3444
|
* Prunes stale entries from the throttle cache to prevent memory leaks
|
|
@@ -3437,10 +3450,10 @@ class wr extends w {
|
|
|
3437
3450
|
return;
|
|
3438
3451
|
this.lastPruneTime = e;
|
|
3439
3452
|
const t = e - 3e5;
|
|
3440
|
-
for (const [
|
|
3441
|
-
n < t && this.lastClickTimes.delete(
|
|
3453
|
+
for (const [s, n] of this.lastClickTimes.entries())
|
|
3454
|
+
n < t && this.lastClickTimes.delete(s);
|
|
3442
3455
|
if (this.lastClickTimes.size > 1e3) {
|
|
3443
|
-
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);
|
|
3444
3457
|
for (const [o] of i)
|
|
3445
3458
|
this.lastClickTimes.delete(o);
|
|
3446
3459
|
a("debug", "ClickHandler: Pruned throttle cache", {
|
|
@@ -3461,22 +3474,22 @@ class wr extends w {
|
|
|
3461
3474
|
const t = e.getAttribute("data-testid");
|
|
3462
3475
|
if (t)
|
|
3463
3476
|
return `[data-testid="${t}"]`;
|
|
3464
|
-
const
|
|
3465
|
-
return
|
|
3477
|
+
const s = e.getAttribute(`${b}-name`);
|
|
3478
|
+
return s ? `[${b}-name="${s}"]` : this.getElementPath(e);
|
|
3466
3479
|
}
|
|
3467
3480
|
/**
|
|
3468
3481
|
* Generates a DOM path for an element (e.g., "body>div>button")
|
|
3469
3482
|
*/
|
|
3470
3483
|
getElementPath(e) {
|
|
3471
3484
|
const t = [];
|
|
3472
|
-
let
|
|
3473
|
-
for (;
|
|
3474
|
-
let n =
|
|
3475
|
-
if (
|
|
3476
|
-
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];
|
|
3477
3490
|
i && (n += `.${i}`);
|
|
3478
3491
|
}
|
|
3479
|
-
t.unshift(n),
|
|
3492
|
+
t.unshift(n), s = s.parentElement;
|
|
3480
3493
|
}
|
|
3481
3494
|
return t.join(">") || "unknown";
|
|
3482
3495
|
}
|
|
@@ -3484,15 +3497,15 @@ class wr extends w {
|
|
|
3484
3497
|
return e.hasAttribute(`${b}-name`) ? e : e.closest(`[${b}-name]`);
|
|
3485
3498
|
}
|
|
3486
3499
|
getRelevantClickElement(e) {
|
|
3487
|
-
for (const t of
|
|
3500
|
+
for (const t of bt)
|
|
3488
3501
|
try {
|
|
3489
3502
|
if (e.matches(t))
|
|
3490
3503
|
return e;
|
|
3491
|
-
const
|
|
3492
|
-
if (
|
|
3493
|
-
return
|
|
3494
|
-
} catch (
|
|
3495
|
-
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 } });
|
|
3496
3509
|
continue;
|
|
3497
3510
|
}
|
|
3498
3511
|
return e;
|
|
@@ -3512,20 +3525,20 @@ class wr extends w {
|
|
|
3512
3525
|
return Math.max(0, Math.min(1, Number(e.toFixed(3))));
|
|
3513
3526
|
}
|
|
3514
3527
|
calculateClickCoordinates(e, t) {
|
|
3515
|
-
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;
|
|
3516
3529
|
return { x: n, y: i, relativeX: o, relativeY: l };
|
|
3517
3530
|
}
|
|
3518
3531
|
extractTrackingData(e) {
|
|
3519
|
-
const t = e.getAttribute(`${b}-name`),
|
|
3532
|
+
const t = e.getAttribute(`${b}-name`), s = e.getAttribute(`${b}-value`);
|
|
3520
3533
|
if (t)
|
|
3521
3534
|
return {
|
|
3522
3535
|
element: e,
|
|
3523
3536
|
name: t,
|
|
3524
|
-
...
|
|
3537
|
+
...s && { value: s }
|
|
3525
3538
|
};
|
|
3526
3539
|
}
|
|
3527
|
-
generateClickData(e, t,
|
|
3528
|
-
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);
|
|
3529
3542
|
return {
|
|
3530
3543
|
x: n,
|
|
3531
3544
|
y: i,
|
|
@@ -3564,18 +3577,18 @@ class wr extends w {
|
|
|
3564
3577
|
*/
|
|
3565
3578
|
sanitizeText(e) {
|
|
3566
3579
|
let t = e;
|
|
3567
|
-
for (const
|
|
3568
|
-
const n = new RegExp(
|
|
3580
|
+
for (const s of at) {
|
|
3581
|
+
const n = new RegExp(s.source, s.flags);
|
|
3569
3582
|
t = t.replace(n, "[REDACTED]");
|
|
3570
3583
|
}
|
|
3571
3584
|
return t;
|
|
3572
3585
|
}
|
|
3573
3586
|
getRelevantText(e, t) {
|
|
3574
|
-
const
|
|
3575
|
-
if (!
|
|
3587
|
+
const s = e.textContent?.trim() ?? "", n = t.textContent?.trim() ?? "";
|
|
3588
|
+
if (!s && !n)
|
|
3576
3589
|
return "";
|
|
3577
3590
|
let i = "";
|
|
3578
|
-
return
|
|
3591
|
+
return s && s.length <= 255 ? i = s : n.length <= 255 ? i = n : i = n.slice(0, 252) + "...", this.sanitizeText(i);
|
|
3579
3592
|
}
|
|
3580
3593
|
extractElementAttributes(e) {
|
|
3581
3594
|
const t = [
|
|
@@ -3589,12 +3602,12 @@ class wr extends w {
|
|
|
3589
3602
|
"name",
|
|
3590
3603
|
"alt",
|
|
3591
3604
|
"role"
|
|
3592
|
-
],
|
|
3605
|
+
], s = {};
|
|
3593
3606
|
for (const n of t) {
|
|
3594
3607
|
const i = e.getAttribute(n);
|
|
3595
|
-
i && (
|
|
3608
|
+
i && (s[n] = i);
|
|
3596
3609
|
}
|
|
3597
|
-
return
|
|
3610
|
+
return s;
|
|
3598
3611
|
}
|
|
3599
3612
|
createCustomEventData(e) {
|
|
3600
3613
|
return {
|
|
@@ -3603,7 +3616,7 @@ class wr extends w {
|
|
|
3603
3616
|
};
|
|
3604
3617
|
}
|
|
3605
3618
|
}
|
|
3606
|
-
class
|
|
3619
|
+
class As extends _ {
|
|
3607
3620
|
eventManager;
|
|
3608
3621
|
containers = [];
|
|
3609
3622
|
limitWarningLogged = !1;
|
|
@@ -3649,9 +3662,9 @@ class br extends w {
|
|
|
3649
3662
|
tryDetectScrollContainers(e) {
|
|
3650
3663
|
const t = this.findScrollableElements();
|
|
3651
3664
|
if (this.isWindowScrollable() && this.setupScrollContainer(window, "window"), t.length > 0) {
|
|
3652
|
-
for (const
|
|
3653
|
-
const n = this.getElementSelector(
|
|
3654
|
-
this.setupScrollContainer(
|
|
3665
|
+
for (const s of t) {
|
|
3666
|
+
const n = this.getElementSelector(s);
|
|
3667
|
+
this.setupScrollContainer(s, n);
|
|
3655
3668
|
}
|
|
3656
3669
|
this.applyPrimaryScrollSelectorIfConfigured();
|
|
3657
3670
|
return;
|
|
@@ -3680,9 +3693,9 @@ class br extends w {
|
|
|
3680
3693
|
return o.overflowY === "auto" || o.overflowY === "scroll" || o.overflow === "auto" || o.overflow === "scroll" ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
3681
3694
|
}
|
|
3682
3695
|
});
|
|
3683
|
-
let
|
|
3684
|
-
for (; (
|
|
3685
|
-
const n =
|
|
3696
|
+
let s;
|
|
3697
|
+
for (; (s = t.nextNode()) && e.length < 10; ) {
|
|
3698
|
+
const n = s;
|
|
3686
3699
|
this.isElementScrollable(n) && e.push(n);
|
|
3687
3700
|
}
|
|
3688
3701
|
return e;
|
|
@@ -3694,9 +3707,9 @@ class br extends w {
|
|
|
3694
3707
|
if (t.id)
|
|
3695
3708
|
return `#${t.id}`;
|
|
3696
3709
|
if (t.className && typeof t.className == "string") {
|
|
3697
|
-
const
|
|
3698
|
-
if (
|
|
3699
|
-
return `.${
|
|
3710
|
+
const s = t.className.split(" ").filter((n) => n.trim())[0];
|
|
3711
|
+
if (s)
|
|
3712
|
+
return `.${s}`;
|
|
3700
3713
|
}
|
|
3701
3714
|
return t.tagName.toLowerCase();
|
|
3702
3715
|
}
|
|
@@ -3734,10 +3747,10 @@ class br extends w {
|
|
|
3734
3747
|
};
|
|
3735
3748
|
l.listener = c, this.containers.push(l), e === window ? window.addEventListener("scroll", c, { passive: !0 }) : e.addEventListener("scroll", c, { passive: !0 });
|
|
3736
3749
|
}
|
|
3737
|
-
processScrollEvent(e, t,
|
|
3738
|
-
if (!this.shouldEmitScrollEvent(e, t,
|
|
3750
|
+
processScrollEvent(e, t, s) {
|
|
3751
|
+
if (!this.shouldEmitScrollEvent(e, t, s))
|
|
3739
3752
|
return;
|
|
3740
|
-
e.lastEventTime =
|
|
3753
|
+
e.lastEventTime = s, e.lastDepth = t.depth, e.lastDirection = t.direction;
|
|
3741
3754
|
const n = this.get("scrollEventCount") ?? 0;
|
|
3742
3755
|
this.set("scrollEventCount", n + 1), this.eventManager.track({
|
|
3743
3756
|
type: d.SCROLL,
|
|
@@ -3748,8 +3761,8 @@ class br extends w {
|
|
|
3748
3761
|
}
|
|
3749
3762
|
});
|
|
3750
3763
|
}
|
|
3751
|
-
shouldEmitScrollEvent(e, t,
|
|
3752
|
-
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));
|
|
3753
3766
|
}
|
|
3754
3767
|
hasReachedSessionLimit() {
|
|
3755
3768
|
return (this.get("scrollEventCount") ?? 0) >= this.maxEventsPerSession;
|
|
@@ -3777,17 +3790,17 @@ class br extends w {
|
|
|
3777
3790
|
getScrollDirection(e, t) {
|
|
3778
3791
|
return e > t ? ee.DOWN : ee.UP;
|
|
3779
3792
|
}
|
|
3780
|
-
calculateScrollDepth(e, t,
|
|
3781
|
-
if (t <=
|
|
3793
|
+
calculateScrollDepth(e, t, s) {
|
|
3794
|
+
if (t <= s)
|
|
3782
3795
|
return 0;
|
|
3783
|
-
const n = t -
|
|
3796
|
+
const n = t - s;
|
|
3784
3797
|
return Math.min(100, Math.max(0, Math.floor(e / n * 100)));
|
|
3785
3798
|
}
|
|
3786
3799
|
calculateScrollData(e) {
|
|
3787
|
-
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);
|
|
3788
3801
|
if (l < 10 || t === window && !this.isWindowScrollable())
|
|
3789
3802
|
return null;
|
|
3790
|
-
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);
|
|
3791
3804
|
let T;
|
|
3792
3805
|
n > 0 ? T = o - n : e.firstScrollEventTime !== null ? T = o - e.firstScrollEventTime : T = 250;
|
|
3793
3806
|
const S = Math.round(l / T * 1e3);
|
|
@@ -3808,8 +3821,8 @@ class br extends w {
|
|
|
3808
3821
|
return e === window ? document.documentElement.scrollHeight : e.scrollHeight;
|
|
3809
3822
|
}
|
|
3810
3823
|
isElementScrollable(e) {
|
|
3811
|
-
const t = getComputedStyle(e),
|
|
3812
|
-
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;
|
|
3813
3826
|
}
|
|
3814
3827
|
applyPrimaryScrollSelector(e) {
|
|
3815
3828
|
let t;
|
|
@@ -3831,7 +3844,7 @@ class br extends w {
|
|
|
3831
3844
|
e.isPrimary = t;
|
|
3832
3845
|
}
|
|
3833
3846
|
}
|
|
3834
|
-
class
|
|
3847
|
+
class Ls extends _ {
|
|
3835
3848
|
eventManager;
|
|
3836
3849
|
trackedElements = /* @__PURE__ */ new Map();
|
|
3837
3850
|
observer = null;
|
|
@@ -3848,12 +3861,12 @@ class Ar extends w {
|
|
|
3848
3861
|
const e = this.get("config");
|
|
3849
3862
|
if (this.config = e.viewport ?? null, !this.config?.elements || this.config.elements.length === 0)
|
|
3850
3863
|
return;
|
|
3851
|
-
const t = this.config.threshold ?? 0.5,
|
|
3864
|
+
const t = this.config.threshold ?? 0.5, s = this.config.minDwellTime ?? 1e3;
|
|
3852
3865
|
if (t < 0 || t > 1) {
|
|
3853
3866
|
a("debug", "ViewportHandler: Invalid threshold, must be between 0 and 1");
|
|
3854
3867
|
return;
|
|
3855
3868
|
}
|
|
3856
|
-
if (
|
|
3869
|
+
if (s < 0) {
|
|
3857
3870
|
a("debug", "ViewportHandler: Invalid minDwellTime, must be non-negative");
|
|
3858
3871
|
return;
|
|
3859
3872
|
}
|
|
@@ -3881,15 +3894,15 @@ class Ar extends w {
|
|
|
3881
3894
|
if (!this.config || !this.observer) return;
|
|
3882
3895
|
const e = this.config.maxTrackedElements ?? 100;
|
|
3883
3896
|
let t = this.trackedElements.size;
|
|
3884
|
-
for (const
|
|
3897
|
+
for (const s of this.config.elements)
|
|
3885
3898
|
try {
|
|
3886
|
-
const n = document.querySelectorAll(
|
|
3899
|
+
const n = document.querySelectorAll(s.selector);
|
|
3887
3900
|
for (const i of Array.from(n)) {
|
|
3888
3901
|
if (t >= e) {
|
|
3889
3902
|
a("debug", "ViewportHandler: Maximum tracked elements reached", {
|
|
3890
3903
|
data: {
|
|
3891
3904
|
limit: e,
|
|
3892
|
-
selector:
|
|
3905
|
+
selector: s.selector,
|
|
3893
3906
|
message: "Some elements will not be tracked. Consider more specific selectors."
|
|
3894
3907
|
}
|
|
3895
3908
|
});
|
|
@@ -3897,16 +3910,16 @@ class Ar extends w {
|
|
|
3897
3910
|
}
|
|
3898
3911
|
i.hasAttribute(`${b}-ignore`) || this.trackedElements.has(i) || (this.trackedElements.set(i, {
|
|
3899
3912
|
element: i,
|
|
3900
|
-
selector:
|
|
3901
|
-
id:
|
|
3902
|
-
name:
|
|
3913
|
+
selector: s.selector,
|
|
3914
|
+
id: s.id,
|
|
3915
|
+
name: s.name,
|
|
3903
3916
|
startTime: null,
|
|
3904
3917
|
timeoutId: null,
|
|
3905
3918
|
lastFiredTime: null
|
|
3906
3919
|
}), this.observer?.observe(i), t++);
|
|
3907
3920
|
}
|
|
3908
3921
|
} catch (n) {
|
|
3909
|
-
a("debug", `ViewportHandler: Invalid selector "${
|
|
3922
|
+
a("debug", `ViewportHandler: Invalid selector "${s.selector}"`, { error: n });
|
|
3910
3923
|
}
|
|
3911
3924
|
a("debug", "ViewportHandler: Elements tracked", {
|
|
3912
3925
|
data: { count: t, limit: e }
|
|
@@ -3918,10 +3931,10 @@ class Ar extends w {
|
|
|
3918
3931
|
handleIntersection = (e) => {
|
|
3919
3932
|
if (!this.config) return;
|
|
3920
3933
|
const t = this.config.minDwellTime ?? 1e3;
|
|
3921
|
-
for (const
|
|
3922
|
-
const n = this.trackedElements.get(
|
|
3923
|
-
n && (
|
|
3924
|
-
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;
|
|
3925
3938
|
this.fireViewportEvent(n, i);
|
|
3926
3939
|
}, t)) : n.startTime !== null && (n.timeoutId !== null && (window.clearTimeout(n.timeoutId), n.timeoutId = null), n.startTime = null));
|
|
3927
3940
|
}
|
|
@@ -3931,7 +3944,7 @@ class Ar extends w {
|
|
|
3931
3944
|
*/
|
|
3932
3945
|
fireViewportEvent(e, t) {
|
|
3933
3946
|
if (e.startTime === null) return;
|
|
3934
|
-
const
|
|
3947
|
+
const s = Math.round(performance.now() - e.startTime);
|
|
3935
3948
|
if (e.element.hasAttribute(`${b}-ignore`))
|
|
3936
3949
|
return;
|
|
3937
3950
|
const n = this.config?.cooldownPeriod ?? 6e4, i = Date.now();
|
|
@@ -3946,7 +3959,7 @@ class Ar extends w {
|
|
|
3946
3959
|
}
|
|
3947
3960
|
const o = {
|
|
3948
3961
|
selector: e.selector,
|
|
3949
|
-
dwellTime:
|
|
3962
|
+
dwellTime: s,
|
|
3950
3963
|
visibilityRatio: t,
|
|
3951
3964
|
...e.id !== void 0 && { id: e.id },
|
|
3952
3965
|
...e.name !== void 0 && { name: e.name }
|
|
@@ -3967,8 +3980,8 @@ class Ar extends w {
|
|
|
3967
3980
|
}
|
|
3968
3981
|
this.mutationObserver = new MutationObserver((e) => {
|
|
3969
3982
|
let t = !1;
|
|
3970
|
-
for (const
|
|
3971
|
-
|
|
3983
|
+
for (const s of e)
|
|
3984
|
+
s.type === "childList" && (s.addedNodes.length > 0 && (t = !0), s.removedNodes.length > 0 && this.cleanupRemovedNodes(s.removedNodes));
|
|
3972
3985
|
t && (this.mutationDebounceTimer !== null && window.clearTimeout(this.mutationDebounceTimer), this.mutationDebounceTimer = window.setTimeout(() => {
|
|
3973
3986
|
this.observeElements(), this.mutationDebounceTimer = null;
|
|
3974
3987
|
}, 100));
|
|
@@ -3984,15 +3997,56 @@ class Ar extends w {
|
|
|
3984
3997
|
cleanupRemovedNodes(e) {
|
|
3985
3998
|
e.forEach((t) => {
|
|
3986
3999
|
if (t.nodeType !== 1) return;
|
|
3987
|
-
const
|
|
3988
|
-
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) => {
|
|
3989
4002
|
const l = this.trackedElements.get(o);
|
|
3990
4003
|
l && l.timeoutId !== null && window.clearTimeout(l.timeoutId), this.observer?.unobserve(o), this.trackedElements.delete(o);
|
|
3991
4004
|
});
|
|
3992
4005
|
});
|
|
3993
4006
|
}
|
|
3994
4007
|
}
|
|
3995
|
-
|
|
4008
|
+
const Ms = "tracelog_session_id";
|
|
4009
|
+
class Cs extends _ {
|
|
4010
|
+
visibilityHandler = null;
|
|
4011
|
+
lastSyncedSessionId = null;
|
|
4012
|
+
activate() {
|
|
4013
|
+
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
|
+
}).catch(() => {
|
|
4034
|
+
a("debug", "Shopify cart attribute update failed");
|
|
4035
|
+
});
|
|
4036
|
+
} catch {
|
|
4037
|
+
a("debug", "Shopify cart attribute update failed");
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
setupVisibilityListener() {
|
|
4041
|
+
this.visibilityHandler = () => {
|
|
4042
|
+
document.hidden || this.syncCartAttribute();
|
|
4043
|
+
}, document.addEventListener("visibilitychange", this.visibilityHandler);
|
|
4044
|
+
}
|
|
4045
|
+
cleanupVisibilityListener() {
|
|
4046
|
+
this.visibilityHandler && (document.removeEventListener("visibilitychange", this.visibilityHandler), this.visibilityHandler = null);
|
|
4047
|
+
}
|
|
4048
|
+
}
|
|
4049
|
+
class Rs {
|
|
3996
4050
|
storage;
|
|
3997
4051
|
sessionStorageRef;
|
|
3998
4052
|
fallbackStorage = /* @__PURE__ */ new Map();
|
|
@@ -4040,8 +4094,8 @@ class Lr {
|
|
|
4040
4094
|
this.storage.setItem(e, t);
|
|
4041
4095
|
return;
|
|
4042
4096
|
}
|
|
4043
|
-
} catch (
|
|
4044
|
-
if (
|
|
4097
|
+
} catch (s) {
|
|
4098
|
+
if (s instanceof DOMException && s.name === "QuotaExceededError" || s instanceof Error && s.name === "QuotaExceededError")
|
|
4045
4099
|
if (this.hasQuotaExceededError = !0, a("warn", "localStorage quota exceeded, attempting cleanup", {
|
|
4046
4100
|
data: { key: e, valueSize: t.length }
|
|
4047
4101
|
}), this.cleanupOldData())
|
|
@@ -4058,7 +4112,7 @@ class Lr {
|
|
|
4058
4112
|
}
|
|
4059
4113
|
else
|
|
4060
4114
|
a("error", "localStorage quota exceeded and no data to cleanup - data will not persist", {
|
|
4061
|
-
error:
|
|
4115
|
+
error: s,
|
|
4062
4116
|
data: { key: e, valueSize: t.length }
|
|
4063
4117
|
});
|
|
4064
4118
|
}
|
|
@@ -4096,8 +4150,8 @@ class Lr {
|
|
|
4096
4150
|
try {
|
|
4097
4151
|
const e = [];
|
|
4098
4152
|
for (let t = 0; t < this.storage.length; t++) {
|
|
4099
|
-
const
|
|
4100
|
-
|
|
4153
|
+
const s = this.storage.key(t);
|
|
4154
|
+
s?.startsWith("tracelog_") && e.push(s);
|
|
4101
4155
|
}
|
|
4102
4156
|
e.forEach((t) => {
|
|
4103
4157
|
this.storage.removeItem(t);
|
|
@@ -4172,7 +4226,7 @@ class Lr {
|
|
|
4172
4226
|
} catch {
|
|
4173
4227
|
}
|
|
4174
4228
|
}), !0;
|
|
4175
|
-
const
|
|
4229
|
+
const s = ["tracelog_session_", "tracelog_user_id", "tracelog_device_id", "tracelog_config"], n = e.filter((i) => !s.some((o) => i.startsWith(o)));
|
|
4176
4230
|
return n.length > 0 ? (n.slice(0, 5).forEach((o) => {
|
|
4177
4231
|
try {
|
|
4178
4232
|
this.storage.removeItem(o);
|
|
@@ -4211,8 +4265,8 @@ class Lr {
|
|
|
4211
4265
|
if (typeof window > "u")
|
|
4212
4266
|
return null;
|
|
4213
4267
|
try {
|
|
4214
|
-
const t = e === "localStorage" ? window.localStorage : window.sessionStorage,
|
|
4215
|
-
return t.setItem(
|
|
4268
|
+
const t = e === "localStorage" ? window.localStorage : window.sessionStorage, s = "__tracelog_test__";
|
|
4269
|
+
return t.setItem(s, "test"), t.removeItem(s), t;
|
|
4216
4270
|
} catch {
|
|
4217
4271
|
return null;
|
|
4218
4272
|
}
|
|
@@ -4253,9 +4307,9 @@ class Lr {
|
|
|
4253
4307
|
this.sessionStorageRef.setItem(e, t);
|
|
4254
4308
|
return;
|
|
4255
4309
|
}
|
|
4256
|
-
} catch (
|
|
4257
|
-
(
|
|
4258
|
-
error:
|
|
4310
|
+
} catch (s) {
|
|
4311
|
+
(s instanceof DOMException && s.name === "QuotaExceededError" || s instanceof Error && s.name === "QuotaExceededError") && a("error", "sessionStorage quota exceeded - data will not persist", {
|
|
4312
|
+
error: s,
|
|
4259
4313
|
data: { key: e, valueSize: t.length }
|
|
4260
4314
|
});
|
|
4261
4315
|
}
|
|
@@ -4275,7 +4329,7 @@ class Lr {
|
|
|
4275
4329
|
this.fallbackSessionStorage.delete(e);
|
|
4276
4330
|
}
|
|
4277
4331
|
}
|
|
4278
|
-
class
|
|
4332
|
+
class Ns extends _ {
|
|
4279
4333
|
eventManager;
|
|
4280
4334
|
reportedByNav = /* @__PURE__ */ new Map();
|
|
4281
4335
|
navigationHistory = [];
|
|
@@ -4286,7 +4340,7 @@ class Mr extends w {
|
|
|
4286
4340
|
navigationCounter = 0;
|
|
4287
4341
|
// Counter for handling simultaneous navigations edge case
|
|
4288
4342
|
constructor(e) {
|
|
4289
|
-
super(), this.eventManager = e, this.vitalThresholds =
|
|
4343
|
+
super(), this.eventManager = e, this.vitalThresholds = Ke(_e);
|
|
4290
4344
|
}
|
|
4291
4345
|
/**
|
|
4292
4346
|
* Starts tracking Web Vitals and performance metrics.
|
|
@@ -4303,8 +4357,8 @@ class Mr extends w {
|
|
|
4303
4357
|
* @returns Promise that resolves when tracking is initialized
|
|
4304
4358
|
*/
|
|
4305
4359
|
async startTracking() {
|
|
4306
|
-
const e = this.get("config"), t = e?.webVitalsMode ??
|
|
4307
|
-
this.vitalThresholds =
|
|
4360
|
+
const e = this.get("config"), t = e?.webVitalsMode ?? _e;
|
|
4361
|
+
this.vitalThresholds = Ke(t), e?.webVitalsThresholds && (this.vitalThresholds = { ...this.vitalThresholds, ...e.webVitalsThresholds }), await this.initWebVitals(), this.observeLongTasks();
|
|
4308
4362
|
}
|
|
4309
4363
|
/**
|
|
4310
4364
|
* Stops tracking Web Vitals and cleans up resources.
|
|
@@ -4319,16 +4373,16 @@ class Mr extends w {
|
|
|
4319
4373
|
this.observers.forEach((e, t) => {
|
|
4320
4374
|
try {
|
|
4321
4375
|
e.disconnect();
|
|
4322
|
-
} catch (
|
|
4323
|
-
a("debug", "Failed to disconnect performance observer", { error:
|
|
4376
|
+
} catch (s) {
|
|
4377
|
+
a("debug", "Failed to disconnect performance observer", { error: s, data: { observerIndex: t } });
|
|
4324
4378
|
}
|
|
4325
4379
|
}), this.observers.length = 0, this.reportedByNav.clear(), this.navigationHistory.length = 0;
|
|
4326
4380
|
}
|
|
4327
4381
|
observeWebVitalsFallback() {
|
|
4328
4382
|
this.reportTTFB(), this.safeObserve(
|
|
4329
4383
|
"largest-contentful-paint",
|
|
4330
|
-
(
|
|
4331
|
-
const n =
|
|
4384
|
+
(s) => {
|
|
4385
|
+
const n = s.getEntries(), i = n[n.length - 1];
|
|
4332
4386
|
i && this.sendVital({ type: "LCP", value: Number(i.startTime.toFixed(2)) });
|
|
4333
4387
|
},
|
|
4334
4388
|
{ type: "largest-contentful-paint", buffered: !0 },
|
|
@@ -4337,10 +4391,10 @@ class Mr extends w {
|
|
|
4337
4391
|
let e = 0, t = this.getNavigationId();
|
|
4338
4392
|
this.safeObserve(
|
|
4339
4393
|
"layout-shift",
|
|
4340
|
-
(
|
|
4394
|
+
(s) => {
|
|
4341
4395
|
const n = this.getNavigationId();
|
|
4342
4396
|
n !== t && (e = 0, t = n);
|
|
4343
|
-
const i =
|
|
4397
|
+
const i = s.getEntries();
|
|
4344
4398
|
for (const o of i) {
|
|
4345
4399
|
if (o.hadRecentInput === !0)
|
|
4346
4400
|
continue;
|
|
@@ -4352,17 +4406,17 @@ class Mr extends w {
|
|
|
4352
4406
|
{ type: "layout-shift", buffered: !0 }
|
|
4353
4407
|
), this.safeObserve(
|
|
4354
4408
|
"paint",
|
|
4355
|
-
(
|
|
4356
|
-
for (const n of
|
|
4409
|
+
(s) => {
|
|
4410
|
+
for (const n of s.getEntries())
|
|
4357
4411
|
n.name === "first-contentful-paint" && this.sendVital({ type: "FCP", value: Number(n.startTime.toFixed(2)) });
|
|
4358
4412
|
},
|
|
4359
4413
|
{ type: "paint", buffered: !0 },
|
|
4360
4414
|
!0
|
|
4361
4415
|
), this.safeObserve(
|
|
4362
4416
|
"event",
|
|
4363
|
-
(
|
|
4417
|
+
(s) => {
|
|
4364
4418
|
let n = 0;
|
|
4365
|
-
const i =
|
|
4419
|
+
const i = s.getEntries();
|
|
4366
4420
|
for (const o of i) {
|
|
4367
4421
|
const l = (o.processingEnd ?? 0) - (o.startTime ?? 0);
|
|
4368
4422
|
n = Math.max(n, l);
|
|
@@ -4374,11 +4428,11 @@ class Mr extends w {
|
|
|
4374
4428
|
}
|
|
4375
4429
|
async initWebVitals() {
|
|
4376
4430
|
try {
|
|
4377
|
-
const { onLCP: e, onCLS: t, onFCP:
|
|
4431
|
+
const { onLCP: e, onCLS: t, onFCP: s, onTTFB: n, onINP: i } = await Promise.resolve().then(() => cr), o = (l) => (c) => {
|
|
4378
4432
|
const u = Number(c.value.toFixed(2));
|
|
4379
4433
|
this.sendVital({ type: l, value: u });
|
|
4380
4434
|
};
|
|
4381
|
-
e(o("LCP"), { reportAllChanges: !1 }), t(o("CLS"), { reportAllChanges: !1 }),
|
|
4435
|
+
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 });
|
|
4382
4436
|
} catch (e) {
|
|
4383
4437
|
a("debug", "Failed to load web-vitals library, using fallback", { error: e }), this.observeWebVitalsFallback();
|
|
4384
4438
|
}
|
|
@@ -4399,9 +4453,9 @@ class Mr extends w {
|
|
|
4399
4453
|
"longtask",
|
|
4400
4454
|
(e) => {
|
|
4401
4455
|
const t = e.getEntries();
|
|
4402
|
-
for (const
|
|
4403
|
-
const n = Number(
|
|
4404
|
-
i - this.lastLongTaskSentAt >=
|
|
4456
|
+
for (const s of t) {
|
|
4457
|
+
const n = Number(s.duration.toFixed(2)), i = Date.now();
|
|
4458
|
+
i - this.lastLongTaskSentAt >= Kt && (this.shouldSendVital("LONG_TASK", n) && this.trackWebVital("LONG_TASK", n), this.lastLongTaskSentAt = i);
|
|
4405
4459
|
}
|
|
4406
4460
|
},
|
|
4407
4461
|
{ type: "longtask", buffered: !0 }
|
|
@@ -4412,12 +4466,12 @@ class Mr extends w {
|
|
|
4412
4466
|
return;
|
|
4413
4467
|
const t = this.getNavigationId();
|
|
4414
4468
|
if (t) {
|
|
4415
|
-
const
|
|
4416
|
-
if (
|
|
4469
|
+
const s = this.reportedByNav.get(t);
|
|
4470
|
+
if (s?.has(e.type))
|
|
4417
4471
|
return;
|
|
4418
|
-
if (
|
|
4419
|
-
|
|
4420
|
-
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length >
|
|
4472
|
+
if (s)
|
|
4473
|
+
s.add(e.type);
|
|
4474
|
+
else if (this.reportedByNav.set(t, /* @__PURE__ */ new Set([e.type])), this.navigationHistory.push(t), this.navigationHistory.length > Yt) {
|
|
4421
4475
|
const i = this.navigationHistory.shift();
|
|
4422
4476
|
i && this.reportedByNav.delete(i);
|
|
4423
4477
|
}
|
|
@@ -4463,8 +4517,8 @@ class Mr extends w {
|
|
|
4463
4517
|
const e = performance.getEntriesByType("navigation")[0];
|
|
4464
4518
|
if (!e)
|
|
4465
4519
|
return null;
|
|
4466
|
-
const t = e.startTime || performance.now(),
|
|
4467
|
-
return
|
|
4520
|
+
const t = e.startTime || performance.now(), s = ++this.navigationCounter, n = `${t.toFixed(2)}_${window.location.pathname}`;
|
|
4521
|
+
return s > 1 ? `${n}_${s}` : n;
|
|
4468
4522
|
} catch (e) {
|
|
4469
4523
|
return a("debug", "Failed to get navigation ID", { error: e }), null;
|
|
4470
4524
|
}
|
|
@@ -4474,7 +4528,7 @@ class Mr extends w {
|
|
|
4474
4528
|
const t = PerformanceObserver.supportedEntryTypes;
|
|
4475
4529
|
return !t || t.includes(e);
|
|
4476
4530
|
}
|
|
4477
|
-
safeObserve(e, t,
|
|
4531
|
+
safeObserve(e, t, s, n = !1) {
|
|
4478
4532
|
try {
|
|
4479
4533
|
if (!this.isObserverSupported(e))
|
|
4480
4534
|
return !1;
|
|
@@ -4493,7 +4547,7 @@ class Mr extends w {
|
|
|
4493
4547
|
} catch {
|
|
4494
4548
|
}
|
|
4495
4549
|
});
|
|
4496
|
-
return i.observe(
|
|
4550
|
+
return i.observe(s ?? { type: e, buffered: !0 }), n || this.observers.push(i), !0;
|
|
4497
4551
|
} catch (i) {
|
|
4498
4552
|
return a("debug", "Failed to create performance observer", {
|
|
4499
4553
|
error: i,
|
|
@@ -4504,11 +4558,11 @@ class Mr extends w {
|
|
|
4504
4558
|
shouldSendVital(e, t) {
|
|
4505
4559
|
if (typeof t != "number" || !Number.isFinite(t))
|
|
4506
4560
|
return a("debug", "Invalid web vital value", { data: { type: e, value: t } }), !1;
|
|
4507
|
-
const
|
|
4508
|
-
return !(typeof
|
|
4561
|
+
const s = this.vitalThresholds[e];
|
|
4562
|
+
return !(typeof s == "number" && t <= s);
|
|
4509
4563
|
}
|
|
4510
4564
|
}
|
|
4511
|
-
class
|
|
4565
|
+
class ae extends _ {
|
|
4512
4566
|
eventManager;
|
|
4513
4567
|
recentErrors = /* @__PURE__ */ new Map();
|
|
4514
4568
|
errorBurstCounter = 0;
|
|
@@ -4544,15 +4598,15 @@ class ie extends w {
|
|
|
4544
4598
|
const e = Date.now();
|
|
4545
4599
|
if (e < this.burstBackoffUntil)
|
|
4546
4600
|
return !1;
|
|
4547
|
-
if (e - this.burstWindowStart >
|
|
4548
|
-
return this.burstBackoffUntil = e +
|
|
4601
|
+
if (e - this.burstWindowStart > Gt && (this.errorBurstCounter = 0, this.burstWindowStart = e), this.errorBurstCounter++, this.errorBurstCounter > jt)
|
|
4602
|
+
return this.burstBackoffUntil = e + ze, a("debug", "Error burst detected - entering cooldown", {
|
|
4549
4603
|
data: {
|
|
4550
4604
|
errorsInWindow: this.errorBurstCounter,
|
|
4551
|
-
cooldownMs:
|
|
4605
|
+
cooldownMs: ze
|
|
4552
4606
|
}
|
|
4553
4607
|
}), !1;
|
|
4554
|
-
const
|
|
4555
|
-
return Math.random() <
|
|
4608
|
+
const s = this.get("config").errorSampling ?? lt;
|
|
4609
|
+
return Math.random() < s;
|
|
4556
4610
|
}
|
|
4557
4611
|
handleError = (e) => {
|
|
4558
4612
|
if (!this.shouldSample())
|
|
@@ -4560,7 +4614,7 @@ class ie extends w {
|
|
|
4560
4614
|
const t = this.sanitize(e.message || "Unknown error");
|
|
4561
4615
|
if (this.shouldSuppressError(W.JS_ERROR, t))
|
|
4562
4616
|
return;
|
|
4563
|
-
const
|
|
4617
|
+
const s = typeof e.error?.stack == "string" ? this.truncateStack(e.error.stack) : void 0;
|
|
4564
4618
|
this.eventManager.track({
|
|
4565
4619
|
type: d.ERROR,
|
|
4566
4620
|
error_data: {
|
|
@@ -4569,22 +4623,22 @@ class ie extends w {
|
|
|
4569
4623
|
...e.filename !== "" && { filename: e.filename },
|
|
4570
4624
|
...e.lineno !== 0 && { line: e.lineno },
|
|
4571
4625
|
...e.colno !== 0 && { column: e.colno },
|
|
4572
|
-
...
|
|
4626
|
+
...s !== void 0 && { stack: s }
|
|
4573
4627
|
}
|
|
4574
4628
|
});
|
|
4575
4629
|
};
|
|
4576
4630
|
handleRejection = (e) => {
|
|
4577
4631
|
if (!this.shouldSample())
|
|
4578
4632
|
return;
|
|
4579
|
-
const t = this.extractRejectionMessage(e.reason),
|
|
4580
|
-
if (this.shouldSuppressError(W.PROMISE_REJECTION,
|
|
4633
|
+
const t = this.extractRejectionMessage(e.reason), s = this.sanitize(t);
|
|
4634
|
+
if (this.shouldSuppressError(W.PROMISE_REJECTION, s))
|
|
4581
4635
|
return;
|
|
4582
4636
|
const n = e.reason instanceof Error && typeof e.reason.stack == "string" ? this.truncateStack(e.reason.stack) : void 0;
|
|
4583
4637
|
this.eventManager.track({
|
|
4584
4638
|
type: d.ERROR,
|
|
4585
4639
|
error_data: {
|
|
4586
4640
|
type: W.PROMISE_REJECTION,
|
|
4587
|
-
message:
|
|
4641
|
+
message: s,
|
|
4588
4642
|
...n !== void 0 && { stack: n }
|
|
4589
4643
|
}
|
|
4590
4644
|
});
|
|
@@ -4603,50 +4657,51 @@ class ie extends w {
|
|
|
4603
4657
|
}
|
|
4604
4658
|
}
|
|
4605
4659
|
sanitize(e) {
|
|
4606
|
-
const t = e.length >
|
|
4660
|
+
const t = e.length > Xe ? e.slice(0, Xe) + "..." : e;
|
|
4607
4661
|
return this.sanitizePii(t);
|
|
4608
4662
|
}
|
|
4609
4663
|
sanitizePii(e) {
|
|
4610
4664
|
let t = e;
|
|
4611
|
-
for (const
|
|
4612
|
-
const n = new RegExp(
|
|
4665
|
+
for (const s of at) {
|
|
4666
|
+
const n = new RegExp(s.source, s.flags);
|
|
4613
4667
|
t = t.replace(n, "[REDACTED]");
|
|
4614
4668
|
}
|
|
4615
4669
|
return t;
|
|
4616
4670
|
}
|
|
4617
4671
|
shouldSuppressError(e, t) {
|
|
4618
|
-
const
|
|
4619
|
-
return i !== void 0 &&
|
|
4672
|
+
const s = Date.now(), n = `${e}:${t}`, i = this.recentErrors.get(n);
|
|
4673
|
+
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));
|
|
4620
4674
|
}
|
|
4621
4675
|
static TRUNCATION_SUFFIX = `
|
|
4622
4676
|
...truncated`;
|
|
4623
4677
|
truncateStack(e) {
|
|
4624
|
-
if (e.length <=
|
|
4625
|
-
const t =
|
|
4626
|
-
return this.sanitizePii(
|
|
4678
|
+
if (e.length <= Ge) return this.sanitizePii(e);
|
|
4679
|
+
const t = Ge - ae.TRUNCATION_SUFFIX.length, s = e.slice(0, t) + ae.TRUNCATION_SUFFIX;
|
|
4680
|
+
return this.sanitizePii(s);
|
|
4627
4681
|
}
|
|
4628
4682
|
pruneOldErrors() {
|
|
4629
4683
|
const e = Date.now();
|
|
4630
4684
|
for (const [n, i] of this.recentErrors.entries())
|
|
4631
|
-
e - i >
|
|
4685
|
+
e - i > je && this.recentErrors.delete(n);
|
|
4632
4686
|
if (this.recentErrors.size <= te)
|
|
4633
4687
|
return;
|
|
4634
|
-
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]),
|
|
4635
|
-
for (let n = 0; n <
|
|
4688
|
+
const t = Array.from(this.recentErrors.entries()).sort((n, i) => n[1] - i[1]), s = this.recentErrors.size - te;
|
|
4689
|
+
for (let n = 0; n < s; n += 1) {
|
|
4636
4690
|
const i = t[n];
|
|
4637
4691
|
i && this.recentErrors.delete(i[0]);
|
|
4638
4692
|
}
|
|
4639
4693
|
}
|
|
4640
4694
|
}
|
|
4641
|
-
class
|
|
4695
|
+
class Os extends _ {
|
|
4642
4696
|
isInitialized = !1;
|
|
4643
4697
|
suppressNextScrollTimer = null;
|
|
4644
4698
|
pageUnloadHandler = null;
|
|
4645
|
-
emitter = new
|
|
4699
|
+
emitter = new gs();
|
|
4646
4700
|
transformers = {};
|
|
4647
4701
|
customHeadersProvider;
|
|
4648
4702
|
managers = {};
|
|
4649
4703
|
handlers = {};
|
|
4704
|
+
integrationInstances = {};
|
|
4650
4705
|
get initialized() {
|
|
4651
4706
|
return this.isInitialized;
|
|
4652
4707
|
}
|
|
@@ -4660,24 +4715,24 @@ class Cr extends w {
|
|
|
4660
4715
|
async init(e = {}) {
|
|
4661
4716
|
if (this.isInitialized)
|
|
4662
4717
|
return { sessionId: this.get("sessionId") ?? "" };
|
|
4663
|
-
this.managers.storage = new
|
|
4718
|
+
this.managers.storage = new Rs();
|
|
4664
4719
|
try {
|
|
4665
4720
|
this.setupState(e);
|
|
4666
|
-
const t = e.integrations?.custom?.headers ?? {},
|
|
4667
|
-
return this.managers.event = new
|
|
4721
|
+
const t = e.integrations?.custom?.headers ?? {}, s = e.integrations?.custom?.fetchCredentials ?? "include";
|
|
4722
|
+
return this.managers.event = new Ts(
|
|
4668
4723
|
this.managers.storage,
|
|
4669
4724
|
this.emitter,
|
|
4670
4725
|
this.transformers,
|
|
4671
4726
|
t,
|
|
4672
4727
|
this.customHeadersProvider,
|
|
4673
|
-
|
|
4728
|
+
s
|
|
4674
4729
|
), this.loadPersistedIdentity(), this.initializeHandlers(), this.setupPageLifecycleListeners(), await this.managers.event.recoverPersistedEvents().catch((n) => {
|
|
4675
4730
|
a("warn", "Failed to recover persisted events", { error: n });
|
|
4676
4731
|
}), this.isInitialized = !0, { sessionId: this.get("sessionId") ?? "" };
|
|
4677
4732
|
} catch (t) {
|
|
4678
4733
|
this.destroy(!0);
|
|
4679
|
-
const
|
|
4680
|
-
throw new Error(`[TraceLog] TraceLog initialization failed: ${
|
|
4734
|
+
const s = t instanceof Error ? t.message : String(t);
|
|
4735
|
+
throw new Error(`[TraceLog] TraceLog initialization failed: ${s}`);
|
|
4681
4736
|
}
|
|
4682
4737
|
}
|
|
4683
4738
|
/**
|
|
@@ -4692,11 +4747,11 @@ class Cr extends w {
|
|
|
4692
4747
|
a("warn", "Cannot send custom event: TraceLog not initialized", { data: { name: e } });
|
|
4693
4748
|
return;
|
|
4694
4749
|
}
|
|
4695
|
-
let
|
|
4696
|
-
t && typeof t == "object" && !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && (
|
|
4697
|
-
const { valid: n, error: i, sanitizedMetadata: o } =
|
|
4750
|
+
let s = t;
|
|
4751
|
+
t && typeof t == "object" && !Array.isArray(t) && Object.getPrototypeOf(t) !== Object.prototype && (s = Object.assign({}, t));
|
|
4752
|
+
const { valid: n, error: i, sanitizedMetadata: o } = ms(e, s);
|
|
4698
4753
|
if (!n) {
|
|
4699
|
-
if (this.get("mode") ===
|
|
4754
|
+
if (this.get("mode") === ie.QA)
|
|
4700
4755
|
throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${i}`);
|
|
4701
4756
|
a("warn", `Custom event "${e}" dropped: ${i}`);
|
|
4702
4757
|
return;
|
|
@@ -4757,21 +4812,21 @@ class Cr extends w {
|
|
|
4757
4812
|
!this.isInitialized && !e || (Object.values(this.handlers).filter(Boolean).forEach((t) => {
|
|
4758
4813
|
try {
|
|
4759
4814
|
t.stopTracking();
|
|
4760
|
-
} catch (
|
|
4761
|
-
a("warn", "Failed to stop tracking", { error:
|
|
4815
|
+
} catch (s) {
|
|
4816
|
+
a("warn", "Failed to stop tracking", { error: s });
|
|
4762
4817
|
}
|
|
4763
|
-
}), 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 = {});
|
|
4818
|
+
}), 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 = {});
|
|
4764
4819
|
}
|
|
4765
4820
|
setupState(e = {}) {
|
|
4766
4821
|
this.set("config", e);
|
|
4767
|
-
const t =
|
|
4822
|
+
const t = Is.getId(this.managers.storage);
|
|
4768
4823
|
this.set("userId", t);
|
|
4769
|
-
const
|
|
4770
|
-
this.set("collectApiUrls",
|
|
4771
|
-
const n =
|
|
4824
|
+
const s = os(e);
|
|
4825
|
+
this.set("collectApiUrls", s);
|
|
4826
|
+
const n = Wt();
|
|
4772
4827
|
this.set("device", n);
|
|
4773
|
-
const i =
|
|
4774
|
-
this.set("pageUrl", i),
|
|
4828
|
+
const i = ye(window.location.href, e.sensitiveQueryParams);
|
|
4829
|
+
this.set("pageUrl", i), es() && this.set("mode", ie.QA);
|
|
4775
4830
|
}
|
|
4776
4831
|
/**
|
|
4777
4832
|
* Returns the current configuration object.
|
|
@@ -4822,7 +4877,7 @@ class Cr extends w {
|
|
|
4822
4877
|
valid: !1,
|
|
4823
4878
|
error: "Global metadata must be a plain object"
|
|
4824
4879
|
};
|
|
4825
|
-
const t =
|
|
4880
|
+
const t = ft("Global", e, "globalMetadata");
|
|
4826
4881
|
return t.valid ? { valid: !0 } : {
|
|
4827
4882
|
valid: !1,
|
|
4828
4883
|
error: t.error
|
|
@@ -4856,11 +4911,11 @@ class Cr extends w {
|
|
|
4856
4911
|
const t = this.validateGlobalMetadata(e);
|
|
4857
4912
|
if (!t.valid)
|
|
4858
4913
|
throw new Error(`[TraceLog] Invalid global metadata: ${t.error}`);
|
|
4859
|
-
const
|
|
4860
|
-
...
|
|
4914
|
+
const s = this.get("config"), i = {
|
|
4915
|
+
...s.globalMetadata ?? {},
|
|
4861
4916
|
...e
|
|
4862
4917
|
}, o = {
|
|
4863
|
-
...
|
|
4918
|
+
...s,
|
|
4864
4919
|
globalMetadata: i
|
|
4865
4920
|
};
|
|
4866
4921
|
this.set("config", o), a("debug", "Global metadata updated (merged)", { data: { keys: Object.keys(e) } });
|
|
@@ -4889,12 +4944,12 @@ class Cr extends w {
|
|
|
4889
4944
|
a("warn", "identify() userId exceeds 256 characters", { data: { length: e.trim().length } });
|
|
4890
4945
|
return;
|
|
4891
4946
|
}
|
|
4892
|
-
const
|
|
4893
|
-
userId:
|
|
4947
|
+
const s = e.trim(), n = ht(t), i = {
|
|
4948
|
+
userId: s,
|
|
4894
4949
|
...n ? { traits: n } : {}
|
|
4895
4950
|
};
|
|
4896
4951
|
this.set("identity", i), this.persistIdentity(i), a("debug", "Visitor identified", {
|
|
4897
|
-
data: { userIdLength:
|
|
4952
|
+
data: { userIdLength: s.length, traitKeys: n ? Object.keys(n) : [] }
|
|
4898
4953
|
});
|
|
4899
4954
|
}
|
|
4900
4955
|
/**
|
|
@@ -4908,8 +4963,8 @@ class Cr extends w {
|
|
|
4908
4963
|
*/
|
|
4909
4964
|
async resetIdentity() {
|
|
4910
4965
|
await this.managers.event?.flushImmediately(), this.set("identity", void 0), this.clearPersistedIdentity();
|
|
4911
|
-
const e =
|
|
4912
|
-
this.managers.storage.setItem(
|
|
4966
|
+
const e = ut();
|
|
4967
|
+
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");
|
|
4913
4968
|
}
|
|
4914
4969
|
/**
|
|
4915
4970
|
* Returns the project ID used for identity storage scoping.
|
|
@@ -4923,8 +4978,8 @@ class Cr extends w {
|
|
|
4923
4978
|
*/
|
|
4924
4979
|
persistIdentity(e) {
|
|
4925
4980
|
try {
|
|
4926
|
-
const t = this.getProjectId(),
|
|
4927
|
-
this.managers.storage.setItem(
|
|
4981
|
+
const t = this.getProjectId(), s = fe(t);
|
|
4982
|
+
this.managers.storage.setItem(s, JSON.stringify(e));
|
|
4928
4983
|
} catch {
|
|
4929
4984
|
a("debug", "Failed to persist identity to localStorage");
|
|
4930
4985
|
}
|
|
@@ -4934,7 +4989,7 @@ class Cr extends w {
|
|
|
4934
4989
|
* Also migrates pending identity (set before init) to the project-scoped key.
|
|
4935
4990
|
*/
|
|
4936
4991
|
loadPersistedIdentity() {
|
|
4937
|
-
const e = this.managers.storage, t = this.getProjectId(),
|
|
4992
|
+
const e = this.managers.storage, t = this.getProjectId(), s = fe(t);
|
|
4938
4993
|
try {
|
|
4939
4994
|
const n = e.getItem(H);
|
|
4940
4995
|
if (n) {
|
|
@@ -4944,18 +4999,18 @@ class Cr extends w {
|
|
|
4944
4999
|
return;
|
|
4945
5000
|
}
|
|
4946
5001
|
const o = { ...i, userId: i.userId.trim() };
|
|
4947
|
-
e.setItem(
|
|
5002
|
+
e.setItem(s, JSON.stringify(o)), this.set("identity", o), a("debug", "Migrated pending identity to project-scoped key");
|
|
4948
5003
|
return;
|
|
4949
5004
|
}
|
|
4950
5005
|
} catch {
|
|
4951
5006
|
e.removeItem(H);
|
|
4952
5007
|
}
|
|
4953
5008
|
try {
|
|
4954
|
-
const n = e.getItem(
|
|
5009
|
+
const n = e.getItem(s);
|
|
4955
5010
|
if (n) {
|
|
4956
5011
|
const i = JSON.parse(n);
|
|
4957
5012
|
if (!this.isValidIdentityData(i)) {
|
|
4958
|
-
e.removeItem(
|
|
5013
|
+
e.removeItem(s), a("debug", "Invalid persisted identity in localStorage, discarded");
|
|
4959
5014
|
return;
|
|
4960
5015
|
}
|
|
4961
5016
|
const o = { ...i, userId: i.userId.trim() };
|
|
@@ -4971,11 +5026,11 @@ class Cr extends w {
|
|
|
4971
5026
|
*/
|
|
4972
5027
|
isValidIdentityData(e) {
|
|
4973
5028
|
if (!e || typeof e != "object") return !1;
|
|
4974
|
-
const { userId: t, traits:
|
|
5029
|
+
const { userId: t, traits: s } = e;
|
|
4975
5030
|
if (typeof t != "string" || t.trim().length === 0 || t.trim().length > 256) return !1;
|
|
4976
|
-
if (
|
|
4977
|
-
if (typeof
|
|
4978
|
-
for (const n of Object.values(
|
|
5031
|
+
if (s !== void 0) {
|
|
5032
|
+
if (typeof s != "object" || s === null || Array.isArray(s)) return !1;
|
|
5033
|
+
for (const n of Object.values(s))
|
|
4979
5034
|
if (typeof n != "string") return !1;
|
|
4980
5035
|
}
|
|
4981
5036
|
return !0;
|
|
@@ -4986,7 +5041,7 @@ class Cr extends w {
|
|
|
4986
5041
|
clearPersistedIdentity() {
|
|
4987
5042
|
try {
|
|
4988
5043
|
const e = this.managers.storage, t = this.getProjectId();
|
|
4989
|
-
e.removeItem(
|
|
5044
|
+
e.removeItem(fe(t)), e.removeItem(H);
|
|
4990
5045
|
} catch {
|
|
4991
5046
|
a("debug", "Failed to clear persisted identity");
|
|
4992
5047
|
}
|
|
@@ -4998,7 +5053,7 @@ class Cr extends w {
|
|
|
4998
5053
|
}
|
|
4999
5054
|
initializeHandlers() {
|
|
5000
5055
|
const e = this.get("config");
|
|
5001
|
-
this.handlers.session = new
|
|
5056
|
+
this.handlers.session = new ys(
|
|
5002
5057
|
this.managers.storage,
|
|
5003
5058
|
this.managers.event
|
|
5004
5059
|
), this.handlers.session.startTracking();
|
|
@@ -5007,115 +5062,120 @@ class Cr extends w {
|
|
|
5007
5062
|
this.set("suppressNextScroll", !1);
|
|
5008
5063
|
}, 500);
|
|
5009
5064
|
};
|
|
5010
|
-
this.handlers.pageView = new
|
|
5011
|
-
a("warn", "Failed to start performance tracking", { error:
|
|
5012
|
-
}), this.handlers.error = new
|
|
5065
|
+
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) => {
|
|
5066
|
+
a("warn", "Failed to start performance tracking", { error: s });
|
|
5067
|
+
}), 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) {
|
|
5068
|
+
const s = new Cs();
|
|
5069
|
+
s.activate(), this.integrationInstances.shopifyCartLinker = s, this.emitter.on(re.EVENT, (n) => {
|
|
5070
|
+
n.type === d.SESSION_START && s.onSessionChange();
|
|
5071
|
+
});
|
|
5072
|
+
}
|
|
5013
5073
|
}
|
|
5014
5074
|
}
|
|
5015
|
-
const
|
|
5016
|
-
let
|
|
5017
|
-
const
|
|
5075
|
+
const V = [], M = [];
|
|
5076
|
+
let k = null, h = null, R = !1, p = !1, D = null;
|
|
5077
|
+
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 () => {
|
|
5018
5078
|
try {
|
|
5019
|
-
const e =
|
|
5079
|
+
const e = ds(r ?? {}), t = new Os();
|
|
5020
5080
|
try {
|
|
5021
|
-
|
|
5081
|
+
V.forEach(({ event: o, callback: l }) => {
|
|
5022
5082
|
t.on(o, l);
|
|
5023
|
-
}),
|
|
5083
|
+
}), V.length = 0, M.forEach(({ hook: o, fn: l }) => {
|
|
5024
5084
|
o === "beforeSend" ? t.setTransformer("beforeSend", l) : t.setTransformer("beforeBatch", l);
|
|
5025
|
-
}), M.length = 0,
|
|
5026
|
-
const
|
|
5085
|
+
}), M.length = 0, k && (t.setCustomHeaders(k), k = null);
|
|
5086
|
+
const s = t.init(e), n = new Promise((o, l) => {
|
|
5027
5087
|
setTimeout(() => {
|
|
5028
5088
|
l(new Error("[TraceLog] Initialization timeout after 10000ms"));
|
|
5029
5089
|
}, 1e4);
|
|
5030
|
-
}), i = await Promise.race([
|
|
5090
|
+
}), i = await Promise.race([s, n]);
|
|
5031
5091
|
return h = t, i;
|
|
5032
|
-
} catch (
|
|
5092
|
+
} catch (s) {
|
|
5033
5093
|
try {
|
|
5034
5094
|
t.destroy(!0);
|
|
5035
5095
|
} catch (n) {
|
|
5036
5096
|
a("error", "Failed to cleanup partially initialized app", { error: n });
|
|
5037
5097
|
}
|
|
5038
|
-
throw
|
|
5098
|
+
throw s;
|
|
5039
5099
|
}
|
|
5040
5100
|
} catch (e) {
|
|
5041
5101
|
throw h = null, e;
|
|
5042
5102
|
} finally {
|
|
5043
|
-
R = !1,
|
|
5103
|
+
R = !1, D = null;
|
|
5044
5104
|
}
|
|
5045
|
-
})()),
|
|
5105
|
+
})()), D)), Ds = (r, e) => {
|
|
5046
5106
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5047
5107
|
if (!h)
|
|
5048
5108
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
5049
5109
|
if (p)
|
|
5050
5110
|
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
5051
|
-
h.sendCustomEvent(
|
|
5111
|
+
h.sendCustomEvent(r, e);
|
|
5052
5112
|
}
|
|
5053
|
-
},
|
|
5113
|
+
}, ks = (r, e) => {
|
|
5054
5114
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5055
5115
|
if (!h || R) {
|
|
5056
|
-
|
|
5116
|
+
V.push({ event: r, callback: e });
|
|
5057
5117
|
return;
|
|
5058
5118
|
}
|
|
5059
|
-
h.on(
|
|
5119
|
+
h.on(r, e);
|
|
5060
5120
|
}
|
|
5061
|
-
},
|
|
5121
|
+
}, Vs = (r, e) => {
|
|
5062
5122
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5063
5123
|
if (!h) {
|
|
5064
|
-
const t =
|
|
5065
|
-
t !== -1 &&
|
|
5124
|
+
const t = V.findIndex((s) => s.event === r && s.callback === e);
|
|
5125
|
+
t !== -1 && V.splice(t, 1);
|
|
5066
5126
|
return;
|
|
5067
5127
|
}
|
|
5068
|
-
h.off(
|
|
5128
|
+
h.off(r, e);
|
|
5069
5129
|
}
|
|
5070
5130
|
};
|
|
5071
|
-
function
|
|
5131
|
+
function Us(r, e) {
|
|
5072
5132
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5073
5133
|
if (typeof e != "function")
|
|
5074
5134
|
throw new Error(`[TraceLog] Transformer must be a function, received: ${typeof e}`);
|
|
5075
5135
|
if (!h || R) {
|
|
5076
|
-
const t = M.findIndex((
|
|
5077
|
-
t !== -1 && M.splice(t, 1), M.push({ hook:
|
|
5136
|
+
const t = M.findIndex((s) => s.hook === r);
|
|
5137
|
+
t !== -1 && M.splice(t, 1), M.push({ hook: r, fn: e });
|
|
5078
5138
|
return;
|
|
5079
5139
|
}
|
|
5080
5140
|
if (p)
|
|
5081
5141
|
throw new Error("[TraceLog] Cannot set transformers while TraceLog is being destroyed");
|
|
5082
|
-
|
|
5142
|
+
r === "beforeSend" ? h.setTransformer("beforeSend", e) : h.setTransformer("beforeBatch", e);
|
|
5083
5143
|
}
|
|
5084
5144
|
}
|
|
5085
|
-
const
|
|
5145
|
+
const Hs = (r) => {
|
|
5086
5146
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5087
5147
|
if (!h) {
|
|
5088
|
-
const e = M.findIndex((t) => t.hook ===
|
|
5148
|
+
const e = M.findIndex((t) => t.hook === r);
|
|
5089
5149
|
e !== -1 && M.splice(e, 1);
|
|
5090
5150
|
return;
|
|
5091
5151
|
}
|
|
5092
5152
|
if (p)
|
|
5093
5153
|
throw new Error("[TraceLog] Cannot remove transformers while TraceLog is being destroyed");
|
|
5094
|
-
h.removeTransformer(
|
|
5154
|
+
h.removeTransformer(r);
|
|
5095
5155
|
}
|
|
5096
|
-
},
|
|
5156
|
+
}, Fs = (r) => {
|
|
5097
5157
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5098
|
-
if (typeof
|
|
5099
|
-
throw new Error(`[TraceLog] Custom headers provider must be a function, received: ${typeof
|
|
5158
|
+
if (typeof r != "function")
|
|
5159
|
+
throw new Error(`[TraceLog] Custom headers provider must be a function, received: ${typeof r}`);
|
|
5100
5160
|
if (!h || R) {
|
|
5101
|
-
|
|
5161
|
+
k = r;
|
|
5102
5162
|
return;
|
|
5103
5163
|
}
|
|
5104
5164
|
if (p)
|
|
5105
5165
|
throw new Error("[TraceLog] Cannot set custom headers while TraceLog is being destroyed");
|
|
5106
|
-
h.setCustomHeaders(
|
|
5166
|
+
h.setCustomHeaders(r);
|
|
5107
5167
|
}
|
|
5108
|
-
},
|
|
5168
|
+
}, xs = () => {
|
|
5109
5169
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5110
5170
|
if (!h) {
|
|
5111
|
-
|
|
5171
|
+
k = null;
|
|
5112
5172
|
return;
|
|
5113
5173
|
}
|
|
5114
5174
|
if (p)
|
|
5115
5175
|
throw new Error("[TraceLog] Cannot remove custom headers while TraceLog is being destroyed");
|
|
5116
5176
|
h.removeCustomHeaders();
|
|
5117
5177
|
}
|
|
5118
|
-
},
|
|
5178
|
+
}, $s = () => typeof window > "u" || typeof document > "u" ? !1 : h !== null, Bs = () => typeof window > "u" || typeof document > "u" || !h ? null : h.getSessionId(), Ws = () => {
|
|
5119
5179
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5120
5180
|
if (p)
|
|
5121
5181
|
throw new Error("[TraceLog] Destroy operation already in progress");
|
|
@@ -5125,36 +5185,36 @@ const kr = (s) => {
|
|
|
5125
5185
|
}
|
|
5126
5186
|
p = !0;
|
|
5127
5187
|
try {
|
|
5128
|
-
h.destroy(), h = null, R = !1,
|
|
5129
|
-
} catch (
|
|
5130
|
-
h = null, R = !1,
|
|
5188
|
+
h.destroy(), h = null, R = !1, D = null, V.length = 0, M.length = 0, k = null, p = !1;
|
|
5189
|
+
} catch (r) {
|
|
5190
|
+
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 });
|
|
5131
5191
|
}
|
|
5132
5192
|
}
|
|
5133
|
-
},
|
|
5134
|
-
typeof window > "u" || typeof document > "u" ||
|
|
5135
|
-
},
|
|
5193
|
+
}, Xs = (r) => {
|
|
5194
|
+
typeof window > "u" || typeof document > "u" || ts(r);
|
|
5195
|
+
}, Gs = (r) => {
|
|
5136
5196
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5137
5197
|
if (!h)
|
|
5138
5198
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
5139
5199
|
if (p)
|
|
5140
5200
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
5141
|
-
h.updateGlobalMetadata(
|
|
5201
|
+
h.updateGlobalMetadata(r);
|
|
5142
5202
|
}
|
|
5143
|
-
},
|
|
5203
|
+
}, js = (r) => {
|
|
5144
5204
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5145
5205
|
if (!h)
|
|
5146
5206
|
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
5147
5207
|
if (p)
|
|
5148
5208
|
throw new Error("[TraceLog] Cannot update metadata while TraceLog is being destroyed");
|
|
5149
|
-
h.mergeGlobalMetadata(
|
|
5209
|
+
h.mergeGlobalMetadata(r);
|
|
5150
5210
|
}
|
|
5151
|
-
},
|
|
5211
|
+
}, zs = (r, e) => {
|
|
5152
5212
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5153
|
-
if (!
|
|
5213
|
+
if (!r || typeof r != "string" || r.trim().length === 0) {
|
|
5154
5214
|
a("warn", "identify() called with invalid userId");
|
|
5155
5215
|
return;
|
|
5156
5216
|
}
|
|
5157
|
-
if (
|
|
5217
|
+
if (r.trim().length > 256) {
|
|
5158
5218
|
a("warn", "identify() userId exceeds 256 characters");
|
|
5159
5219
|
return;
|
|
5160
5220
|
}
|
|
@@ -5163,20 +5223,20 @@ const kr = (s) => {
|
|
|
5163
5223
|
return;
|
|
5164
5224
|
}
|
|
5165
5225
|
if (h) {
|
|
5166
|
-
h.identify(
|
|
5226
|
+
h.identify(r, e);
|
|
5167
5227
|
return;
|
|
5168
5228
|
}
|
|
5169
5229
|
try {
|
|
5170
|
-
const t =
|
|
5171
|
-
userId:
|
|
5230
|
+
const t = ht(e), s = {
|
|
5231
|
+
userId: r.trim(),
|
|
5172
5232
|
...t ? { traits: t } : {}
|
|
5173
5233
|
};
|
|
5174
|
-
localStorage.setItem(H, JSON.stringify(
|
|
5234
|
+
localStorage.setItem(H, JSON.stringify(s)), a("debug", "Identity persisted pre-init (will be applied on init)");
|
|
5175
5235
|
} catch {
|
|
5176
5236
|
a("debug", "Failed to persist pre-init identity");
|
|
5177
5237
|
}
|
|
5178
5238
|
}
|
|
5179
|
-
},
|
|
5239
|
+
}, Qs = async () => {
|
|
5180
5240
|
if (!(typeof window > "u" || typeof document > "u")) {
|
|
5181
5241
|
if (!h) {
|
|
5182
5242
|
try {
|
|
@@ -5189,298 +5249,299 @@ const kr = (s) => {
|
|
|
5189
5249
|
throw new Error("[TraceLog] Cannot reset identity while TraceLog is being destroyed");
|
|
5190
5250
|
await h.resetIdentity();
|
|
5191
5251
|
}
|
|
5192
|
-
},
|
|
5193
|
-
init:
|
|
5194
|
-
event:
|
|
5195
|
-
on:
|
|
5196
|
-
off:
|
|
5197
|
-
setTransformer:
|
|
5198
|
-
removeTransformer:
|
|
5199
|
-
setCustomHeaders:
|
|
5200
|
-
removeCustomHeaders:
|
|
5201
|
-
isInitialized:
|
|
5202
|
-
getSessionId:
|
|
5203
|
-
destroy:
|
|
5204
|
-
setQaMode:
|
|
5205
|
-
updateGlobalMetadata:
|
|
5206
|
-
mergeGlobalMetadata:
|
|
5207
|
-
identify:
|
|
5208
|
-
resetIdentity:
|
|
5252
|
+
}, yr = {
|
|
5253
|
+
init: Ps,
|
|
5254
|
+
event: Ds,
|
|
5255
|
+
on: ks,
|
|
5256
|
+
off: Vs,
|
|
5257
|
+
setTransformer: Us,
|
|
5258
|
+
removeTransformer: Hs,
|
|
5259
|
+
setCustomHeaders: Fs,
|
|
5260
|
+
removeCustomHeaders: xs,
|
|
5261
|
+
isInitialized: $s,
|
|
5262
|
+
getSessionId: Bs,
|
|
5263
|
+
destroy: Ws,
|
|
5264
|
+
setQaMode: Xs,
|
|
5265
|
+
updateGlobalMetadata: Gs,
|
|
5266
|
+
mergeGlobalMetadata: js,
|
|
5267
|
+
identify: zs,
|
|
5268
|
+
resetIdentity: Qs
|
|
5209
5269
|
};
|
|
5210
|
-
var
|
|
5270
|
+
var Ae, C, j, Et, le, St = -1, U = function(r) {
|
|
5211
5271
|
addEventListener("pageshow", (function(e) {
|
|
5212
|
-
e.persisted && (
|
|
5272
|
+
e.persisted && (St = e.timeStamp, r(e));
|
|
5213
5273
|
}), !0);
|
|
5214
|
-
},
|
|
5215
|
-
var
|
|
5216
|
-
if (
|
|
5217
|
-
},
|
|
5218
|
-
var
|
|
5219
|
-
return
|
|
5220
|
-
},
|
|
5221
|
-
var t =
|
|
5222
|
-
return
|
|
5223
|
-
}, x = function(
|
|
5274
|
+
}, Pe = function() {
|
|
5275
|
+
var r = self.performance && performance.getEntriesByType && performance.getEntriesByType("navigation")[0];
|
|
5276
|
+
if (r && r.responseStart > 0 && r.responseStart < performance.now()) return r;
|
|
5277
|
+
}, ue = function() {
|
|
5278
|
+
var r = Pe();
|
|
5279
|
+
return r && r.activationStart || 0;
|
|
5280
|
+
}, y = function(r, e) {
|
|
5281
|
+
var t = Pe(), s = "navigate";
|
|
5282
|
+
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 };
|
|
5283
|
+
}, x = function(r, e, t) {
|
|
5224
5284
|
try {
|
|
5225
|
-
if (PerformanceObserver.supportedEntryTypes.includes(
|
|
5226
|
-
var
|
|
5285
|
+
if (PerformanceObserver.supportedEntryTypes.includes(r)) {
|
|
5286
|
+
var s = new PerformanceObserver((function(n) {
|
|
5227
5287
|
Promise.resolve().then((function() {
|
|
5228
5288
|
e(n.getEntries());
|
|
5229
5289
|
}));
|
|
5230
5290
|
}));
|
|
5231
|
-
return
|
|
5291
|
+
return s.observe(Object.assign({ type: r, buffered: !0 }, t || {})), s;
|
|
5232
5292
|
}
|
|
5233
5293
|
} catch {
|
|
5234
5294
|
}
|
|
5235
|
-
},
|
|
5295
|
+
}, w = function(r, e, t, s) {
|
|
5236
5296
|
var n, i;
|
|
5237
5297
|
return function(o) {
|
|
5238
|
-
e.value >= 0 && (o ||
|
|
5298
|
+
e.value >= 0 && (o || s) && ((i = e.value - (n || 0)) || n === void 0) && (n = e.value, e.delta = i, e.rating = (function(l, c) {
|
|
5239
5299
|
return l > c[1] ? "poor" : l > c[0] ? "needs-improvement" : "good";
|
|
5240
|
-
})(e.value, t),
|
|
5300
|
+
})(e.value, t), r(e));
|
|
5241
5301
|
};
|
|
5242
|
-
},
|
|
5302
|
+
}, De = function(r) {
|
|
5243
5303
|
requestAnimationFrame((function() {
|
|
5244
5304
|
return requestAnimationFrame((function() {
|
|
5245
|
-
return
|
|
5305
|
+
return r();
|
|
5246
5306
|
}));
|
|
5247
5307
|
}));
|
|
5248
|
-
}, Q = function(
|
|
5308
|
+
}, Q = function(r) {
|
|
5249
5309
|
document.addEventListener("visibilitychange", (function() {
|
|
5250
|
-
document.visibilityState === "hidden" &&
|
|
5310
|
+
document.visibilityState === "hidden" && r();
|
|
5251
5311
|
}));
|
|
5252
|
-
},
|
|
5312
|
+
}, de = function(r) {
|
|
5253
5313
|
var e = !1;
|
|
5254
5314
|
return function() {
|
|
5255
|
-
e || (
|
|
5315
|
+
e || (r(), e = !0);
|
|
5256
5316
|
};
|
|
5257
|
-
}, F = -1,
|
|
5317
|
+
}, F = -1, et = function() {
|
|
5258
5318
|
return document.visibilityState !== "hidden" || document.prerendering ? 1 / 0 : 0;
|
|
5259
|
-
},
|
|
5260
|
-
document.visibilityState === "hidden" && F > -1 && (F =
|
|
5261
|
-
},
|
|
5262
|
-
addEventListener("visibilitychange",
|
|
5263
|
-
},
|
|
5264
|
-
removeEventListener("visibilitychange",
|
|
5265
|
-
},
|
|
5266
|
-
return F < 0 && (F =
|
|
5319
|
+
}, ce = function(r) {
|
|
5320
|
+
document.visibilityState === "hidden" && F > -1 && (F = r.type === "visibilitychange" ? r.timeStamp : 0, Ks());
|
|
5321
|
+
}, tt = function() {
|
|
5322
|
+
addEventListener("visibilitychange", ce, !0), addEventListener("prerenderingchange", ce, !0);
|
|
5323
|
+
}, Ks = function() {
|
|
5324
|
+
removeEventListener("visibilitychange", ce, !0), removeEventListener("prerenderingchange", ce, !0);
|
|
5325
|
+
}, ke = function() {
|
|
5326
|
+
return F < 0 && (F = et(), tt(), U((function() {
|
|
5267
5327
|
setTimeout((function() {
|
|
5268
|
-
F =
|
|
5328
|
+
F = et(), tt();
|
|
5269
5329
|
}), 0);
|
|
5270
5330
|
}))), { get firstHiddenTime() {
|
|
5271
5331
|
return F;
|
|
5272
5332
|
} };
|
|
5273
|
-
}, K = function(
|
|
5333
|
+
}, K = function(r) {
|
|
5274
5334
|
document.prerendering ? addEventListener("prerenderingchange", (function() {
|
|
5275
|
-
return
|
|
5276
|
-
}), !0) :
|
|
5277
|
-
},
|
|
5335
|
+
return r();
|
|
5336
|
+
}), !0) : r();
|
|
5337
|
+
}, Le = [1800, 3e3], pt = function(r, e) {
|
|
5278
5338
|
e = e || {}, K((function() {
|
|
5279
|
-
var t,
|
|
5339
|
+
var t, s = ke(), n = y("FCP"), i = x("paint", (function(o) {
|
|
5280
5340
|
o.forEach((function(l) {
|
|
5281
|
-
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime <
|
|
5341
|
+
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)));
|
|
5282
5342
|
}));
|
|
5283
5343
|
}));
|
|
5284
|
-
i && (t =
|
|
5285
|
-
n =
|
|
5344
|
+
i && (t = w(r, n, Le, e.reportAllChanges), U((function(o) {
|
|
5345
|
+
n = y("FCP"), t = w(r, n, Le, e.reportAllChanges), De((function() {
|
|
5286
5346
|
n.value = performance.now() - o.timeStamp, t(!0);
|
|
5287
5347
|
}));
|
|
5288
5348
|
})));
|
|
5289
5349
|
}));
|
|
5290
|
-
},
|
|
5291
|
-
e = e || {},
|
|
5292
|
-
var t,
|
|
5350
|
+
}, Me = [0.1, 0.25], Ys = function(r, e) {
|
|
5351
|
+
e = e || {}, pt(de((function() {
|
|
5352
|
+
var t, s = y("CLS", 0), n = 0, i = [], o = function(c) {
|
|
5293
5353
|
c.forEach((function(u) {
|
|
5294
5354
|
if (!u.hadRecentInput) {
|
|
5295
5355
|
var g = i[0], E = i[i.length - 1];
|
|
5296
5356
|
n && u.startTime - E.startTime < 1e3 && u.startTime - g.startTime < 5e3 ? (n += u.value, i.push(u)) : (n = u.value, i = [u]);
|
|
5297
5357
|
}
|
|
5298
|
-
})), n >
|
|
5358
|
+
})), n > s.value && (s.value = n, s.entries = i, t());
|
|
5299
5359
|
}, l = x("layout-shift", o);
|
|
5300
|
-
l && (t =
|
|
5360
|
+
l && (t = w(r, s, Me, e.reportAllChanges), Q((function() {
|
|
5301
5361
|
o(l.takeRecords()), t(!0);
|
|
5302
|
-
})),
|
|
5303
|
-
n = 0,
|
|
5362
|
+
})), U((function() {
|
|
5363
|
+
n = 0, s = y("CLS", 0), t = w(r, s, Me, e.reportAllChanges), De((function() {
|
|
5304
5364
|
return t();
|
|
5305
5365
|
}));
|
|
5306
5366
|
})), setTimeout(t, 0));
|
|
5307
5367
|
})));
|
|
5308
|
-
},
|
|
5309
|
-
|
|
5310
|
-
e.interactionId && (
|
|
5368
|
+
}, Tt = 0, Se = 1 / 0, Z = 0, qs = function(r) {
|
|
5369
|
+
r.forEach((function(e) {
|
|
5370
|
+
e.interactionId && (Se = Math.min(Se, e.interactionId), Z = Math.max(Z, e.interactionId), Tt = Z ? (Z - Se) / 7 + 1 : 0);
|
|
5311
5371
|
}));
|
|
5312
|
-
},
|
|
5313
|
-
return
|
|
5314
|
-
},
|
|
5315
|
-
"interactionCount" in performance ||
|
|
5316
|
-
}, A = [],
|
|
5317
|
-
var
|
|
5318
|
-
return A[
|
|
5319
|
-
},
|
|
5320
|
-
if (
|
|
5321
|
-
return n(
|
|
5322
|
-
})),
|
|
5323
|
-
var e = A[A.length - 1], t =
|
|
5324
|
-
if (t || A.length < 10 ||
|
|
5325
|
-
if (t)
|
|
5372
|
+
}, It = function() {
|
|
5373
|
+
return Ae ? Tt : performance.interactionCount || 0;
|
|
5374
|
+
}, Js = function() {
|
|
5375
|
+
"interactionCount" in performance || Ae || (Ae = x("event", qs, { type: "event", buffered: !0, durationThreshold: 0 }));
|
|
5376
|
+
}, A = [], se = /* @__PURE__ */ new Map(), vt = 0, Zs = function() {
|
|
5377
|
+
var r = Math.min(A.length - 1, Math.floor((It() - vt) / 50));
|
|
5378
|
+
return A[r];
|
|
5379
|
+
}, er = [], tr = function(r) {
|
|
5380
|
+
if (er.forEach((function(n) {
|
|
5381
|
+
return n(r);
|
|
5382
|
+
})), r.interactionId || r.entryType === "first-input") {
|
|
5383
|
+
var e = A[A.length - 1], t = se.get(r.interactionId);
|
|
5384
|
+
if (t || A.length < 10 || r.duration > e.latency) {
|
|
5385
|
+
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);
|
|
5326
5386
|
else {
|
|
5327
|
-
var
|
|
5328
|
-
|
|
5387
|
+
var s = { id: r.interactionId, latency: r.duration, entries: [r] };
|
|
5388
|
+
se.set(s.id, s), A.push(s);
|
|
5329
5389
|
}
|
|
5330
5390
|
A.sort((function(n, i) {
|
|
5331
5391
|
return i.latency - n.latency;
|
|
5332
5392
|
})), A.length > 10 && A.splice(10).forEach((function(n) {
|
|
5333
|
-
return
|
|
5393
|
+
return se.delete(n.id);
|
|
5334
5394
|
}));
|
|
5335
5395
|
}
|
|
5336
5396
|
}
|
|
5337
|
-
},
|
|
5397
|
+
}, _t = function(r) {
|
|
5338
5398
|
var e = self.requestIdleCallback || self.setTimeout, t = -1;
|
|
5339
|
-
return
|
|
5340
|
-
},
|
|
5399
|
+
return r = de(r), document.visibilityState === "hidden" ? r() : (t = e(r), Q(r)), t;
|
|
5400
|
+
}, Ce = [200, 500], sr = function(r, e) {
|
|
5341
5401
|
"PerformanceEventTiming" in self && "interactionId" in PerformanceEventTiming.prototype && (e = e || {}, K((function() {
|
|
5342
5402
|
var t;
|
|
5343
|
-
|
|
5344
|
-
var
|
|
5345
|
-
|
|
5346
|
-
l.forEach(
|
|
5347
|
-
var c =
|
|
5348
|
-
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries,
|
|
5403
|
+
Js();
|
|
5404
|
+
var s, n = y("INP"), i = function(l) {
|
|
5405
|
+
_t((function() {
|
|
5406
|
+
l.forEach(tr);
|
|
5407
|
+
var c = Zs();
|
|
5408
|
+
c && c.latency !== n.value && (n.value = c.latency, n.entries = c.entries, s());
|
|
5349
5409
|
}));
|
|
5350
5410
|
}, o = x("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
|
|
5351
|
-
|
|
5352
|
-
i(o.takeRecords()),
|
|
5353
|
-
})),
|
|
5354
|
-
|
|
5411
|
+
s = w(r, n, Ce, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), Q((function() {
|
|
5412
|
+
i(o.takeRecords()), s(!0);
|
|
5413
|
+
})), U((function() {
|
|
5414
|
+
vt = It(), A.length = 0, se.clear(), n = y("INP"), s = w(r, n, Ce, e.reportAllChanges);
|
|
5355
5415
|
})));
|
|
5356
5416
|
})));
|
|
5357
|
-
},
|
|
5417
|
+
}, Re = [2500, 4e3], pe = {}, rr = function(r, e) {
|
|
5358
5418
|
e = e || {}, K((function() {
|
|
5359
|
-
var t,
|
|
5419
|
+
var t, s = ke(), n = y("LCP"), i = function(c) {
|
|
5360
5420
|
e.reportAllChanges || (c = c.slice(-1)), c.forEach((function(u) {
|
|
5361
|
-
u.startTime <
|
|
5421
|
+
u.startTime < s.firstHiddenTime && (n.value = Math.max(u.startTime - ue(), 0), n.entries = [u], t());
|
|
5362
5422
|
}));
|
|
5363
5423
|
}, o = x("largest-contentful-paint", i);
|
|
5364
5424
|
if (o) {
|
|
5365
|
-
t =
|
|
5366
|
-
var l =
|
|
5367
|
-
|
|
5425
|
+
t = w(r, n, Re, e.reportAllChanges);
|
|
5426
|
+
var l = de((function() {
|
|
5427
|
+
pe[n.id] || (i(o.takeRecords()), o.disconnect(), pe[n.id] = !0, t(!0));
|
|
5368
5428
|
}));
|
|
5369
5429
|
["keydown", "click"].forEach((function(c) {
|
|
5370
5430
|
addEventListener(c, (function() {
|
|
5371
|
-
return
|
|
5431
|
+
return _t(l);
|
|
5372
5432
|
}), { once: !0, capture: !0 });
|
|
5373
|
-
})), Q(l),
|
|
5374
|
-
n =
|
|
5375
|
-
n.value = performance.now() - c.timeStamp,
|
|
5433
|
+
})), Q(l), U((function(c) {
|
|
5434
|
+
n = y("LCP"), t = w(r, n, Re, e.reportAllChanges), De((function() {
|
|
5435
|
+
n.value = performance.now() - c.timeStamp, pe[n.id] = !0, t(!0);
|
|
5376
5436
|
}));
|
|
5377
5437
|
}));
|
|
5378
5438
|
}
|
|
5379
5439
|
}));
|
|
5380
|
-
},
|
|
5440
|
+
}, Ne = [800, 1800], nr = function r(e) {
|
|
5381
5441
|
document.prerendering ? K((function() {
|
|
5382
|
-
return
|
|
5442
|
+
return r(e);
|
|
5383
5443
|
})) : document.readyState !== "complete" ? addEventListener("load", (function() {
|
|
5384
|
-
return
|
|
5444
|
+
return r(e);
|
|
5385
5445
|
}), !0) : setTimeout(e, 0);
|
|
5386
|
-
},
|
|
5446
|
+
}, ir = function(r, e) {
|
|
5387
5447
|
e = e || {};
|
|
5388
|
-
var t =
|
|
5389
|
-
|
|
5390
|
-
var n =
|
|
5391
|
-
n && (t.value = Math.max(n.responseStart -
|
|
5392
|
-
t =
|
|
5448
|
+
var t = y("TTFB"), s = w(r, t, Ne, e.reportAllChanges);
|
|
5449
|
+
nr((function() {
|
|
5450
|
+
var n = Pe();
|
|
5451
|
+
n && (t.value = Math.max(n.responseStart - ue(), 0), t.entries = [n], s(!0), U((function() {
|
|
5452
|
+
t = y("TTFB", 0), (s = w(r, t, Ne, e.reportAllChanges))(!0);
|
|
5393
5453
|
})));
|
|
5394
5454
|
}));
|
|
5395
|
-
}, X = { passive: !0, capture: !0 },
|
|
5396
|
-
C || (C = e, j =
|
|
5397
|
-
},
|
|
5398
|
-
if (j >= 0 && j <
|
|
5399
|
-
var
|
|
5400
|
-
|
|
5401
|
-
e(
|
|
5402
|
-
})),
|
|
5403
|
-
}
|
|
5404
|
-
},
|
|
5405
|
-
if (
|
|
5406
|
-
var e = (
|
|
5407
|
-
|
|
5455
|
+
}, X = { passive: !0, capture: !0 }, or = /* @__PURE__ */ new Date(), st = function(r, e) {
|
|
5456
|
+
C || (C = e, j = r, Et = /* @__PURE__ */ new Date(), wt(removeEventListener), yt());
|
|
5457
|
+
}, yt = function() {
|
|
5458
|
+
if (j >= 0 && j < Et - or) {
|
|
5459
|
+
var r = { entryType: "first-input", name: C.type, target: C.target, cancelable: C.cancelable, startTime: C.timeStamp, processingStart: C.timeStamp + j };
|
|
5460
|
+
le.forEach((function(e) {
|
|
5461
|
+
e(r);
|
|
5462
|
+
})), le = [];
|
|
5463
|
+
}
|
|
5464
|
+
}, ar = function(r) {
|
|
5465
|
+
if (r.cancelable) {
|
|
5466
|
+
var e = (r.timeStamp > 1e12 ? /* @__PURE__ */ new Date() : performance.now()) - r.timeStamp;
|
|
5467
|
+
r.type == "pointerdown" ? (function(t, s) {
|
|
5408
5468
|
var n = function() {
|
|
5409
|
-
|
|
5469
|
+
st(t, s), o();
|
|
5410
5470
|
}, i = function() {
|
|
5411
5471
|
o();
|
|
5412
5472
|
}, o = function() {
|
|
5413
5473
|
removeEventListener("pointerup", n, X), removeEventListener("pointercancel", i, X);
|
|
5414
5474
|
};
|
|
5415
5475
|
addEventListener("pointerup", n, X), addEventListener("pointercancel", i, X);
|
|
5416
|
-
})(e,
|
|
5476
|
+
})(e, r) : st(e, r);
|
|
5417
5477
|
}
|
|
5418
|
-
},
|
|
5478
|
+
}, wt = function(r) {
|
|
5419
5479
|
["mousedown", "keydown", "touchstart", "pointerdown"].forEach((function(e) {
|
|
5420
|
-
return
|
|
5480
|
+
return r(e, ar, X);
|
|
5421
5481
|
}));
|
|
5422
|
-
},
|
|
5482
|
+
}, Oe = [100, 300], lr = function(r, e) {
|
|
5423
5483
|
e = e || {}, K((function() {
|
|
5424
|
-
var t,
|
|
5425
|
-
c.startTime <
|
|
5484
|
+
var t, s = ke(), n = y("FID"), i = function(c) {
|
|
5485
|
+
c.startTime < s.firstHiddenTime && (n.value = c.processingStart - c.startTime, n.entries.push(c), t(!0));
|
|
5426
5486
|
}, o = function(c) {
|
|
5427
5487
|
c.forEach(i);
|
|
5428
5488
|
}, l = x("first-input", o);
|
|
5429
|
-
t =
|
|
5489
|
+
t = w(r, n, Oe, e.reportAllChanges), l && (Q(de((function() {
|
|
5430
5490
|
o(l.takeRecords()), l.disconnect();
|
|
5431
|
-
}))),
|
|
5491
|
+
}))), U((function() {
|
|
5432
5492
|
var c;
|
|
5433
|
-
n =
|
|
5493
|
+
n = y("FID"), t = w(r, n, Oe, e.reportAllChanges), le = [], j = -1, C = null, wt(addEventListener), c = i, le.push(c), yt();
|
|
5434
5494
|
})));
|
|
5435
5495
|
}));
|
|
5436
5496
|
};
|
|
5437
|
-
const
|
|
5497
|
+
const cr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5438
5498
|
__proto__: null,
|
|
5439
|
-
CLSThresholds:
|
|
5440
|
-
FCPThresholds:
|
|
5441
|
-
FIDThresholds:
|
|
5442
|
-
INPThresholds:
|
|
5443
|
-
LCPThresholds:
|
|
5444
|
-
TTFBThresholds:
|
|
5445
|
-
onCLS:
|
|
5446
|
-
onFCP:
|
|
5447
|
-
onFID:
|
|
5448
|
-
onINP:
|
|
5449
|
-
onLCP:
|
|
5450
|
-
onTTFB:
|
|
5499
|
+
CLSThresholds: Me,
|
|
5500
|
+
FCPThresholds: Le,
|
|
5501
|
+
FIDThresholds: Oe,
|
|
5502
|
+
INPThresholds: Ce,
|
|
5503
|
+
LCPThresholds: Re,
|
|
5504
|
+
TTFBThresholds: Ne,
|
|
5505
|
+
onCLS: Ys,
|
|
5506
|
+
onFCP: pt,
|
|
5507
|
+
onFID: lr,
|
|
5508
|
+
onINP: sr,
|
|
5509
|
+
onLCP: rr,
|
|
5510
|
+
onTTFB: ir
|
|
5451
5511
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
5452
5512
|
export {
|
|
5453
5513
|
f as AppConfigValidationError,
|
|
5454
|
-
|
|
5455
|
-
|
|
5514
|
+
ur as DEFAULT_SESSION_TIMEOUT,
|
|
5515
|
+
_e as DEFAULT_WEB_VITALS_MODE,
|
|
5456
5516
|
L as DeviceType,
|
|
5457
|
-
|
|
5517
|
+
re as EmitterEvent,
|
|
5458
5518
|
W as ErrorType,
|
|
5459
5519
|
d as EventType,
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5520
|
+
vr as InitializationTimeoutError,
|
|
5521
|
+
N as IntegrationValidationError,
|
|
5522
|
+
pr as MAX_ARRAY_LENGTH,
|
|
5523
|
+
mr as MAX_CUSTOM_EVENT_ARRAY_SIZE,
|
|
5524
|
+
fr as MAX_CUSTOM_EVENT_KEYS,
|
|
5525
|
+
dr as MAX_CUSTOM_EVENT_NAME_LENGTH,
|
|
5526
|
+
hr as MAX_CUSTOM_EVENT_STRING_SIZE,
|
|
5527
|
+
gr as MAX_NESTED_OBJECT_KEYS,
|
|
5528
|
+
Er as MAX_STRING_LENGTH,
|
|
5529
|
+
Sr as MAX_STRING_LENGTH_IN_ARRAY,
|
|
5530
|
+
ie as Mode,
|
|
5531
|
+
at as PII_PATTERNS,
|
|
5532
|
+
O as PermanentError,
|
|
5533
|
+
ne as RateLimitError,
|
|
5534
|
+
We as SamplingRateValidationError,
|
|
5474
5535
|
ee as ScrollDirection,
|
|
5475
|
-
|
|
5536
|
+
Ot as SessionTimeoutValidationError,
|
|
5476
5537
|
B as SpecialApiUrl,
|
|
5477
|
-
|
|
5538
|
+
P as TimeoutError,
|
|
5478
5539
|
z as TraceLogValidationError,
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5540
|
+
_r as WEB_VITALS_GOOD_THRESHOLDS,
|
|
5541
|
+
Qe as WEB_VITALS_NEEDS_IMPROVEMENT_THRESHOLDS,
|
|
5542
|
+
Qt as WEB_VITALS_POOR_THRESHOLDS,
|
|
5543
|
+
Ke as getWebVitalsThresholds,
|
|
5544
|
+
Tr as isPrimaryScrollEvent,
|
|
5545
|
+
Ir as isSecondaryScrollEvent,
|
|
5546
|
+
yr as tracelog
|
|
5486
5547
|
};
|