@tracelog/lib 0.11.0 → 0.11.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 -0
- package/dist/browser/tracelog.esm.js +119 -114
- 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/cjs/api.d.ts.map +1 -1
- package/dist/cjs/api.js +17 -2
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/handlers/viewport.handler.d.ts.map +1 -1
- package/dist/cjs/handlers/viewport.handler.js.map +1 -1
- package/dist/cjs/types/event.types.d.ts +137 -16
- package/dist/cjs/types/event.types.d.ts.map +1 -1
- package/dist/cjs/types/event.types.js +22 -9
- package/dist/cjs/types/event.types.js.map +1 -1
- package/dist/cjs/types/index.d.ts +2 -0
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +2 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/scroll.types.d.ts +16 -0
- package/dist/cjs/types/scroll.types.d.ts.map +1 -0
- package/dist/cjs/types/scroll.types.js +12 -0
- package/dist/cjs/types/scroll.types.js.map +1 -0
- package/dist/cjs/types/viewport.types.d.ts +0 -27
- package/dist/cjs/types/viewport.types.d.ts.map +1 -1
- package/dist/esm/api.d.ts.map +1 -1
- package/dist/esm/api.js +17 -2
- package/dist/esm/api.js.map +1 -1
- package/dist/esm/handlers/viewport.handler.d.ts.map +1 -1
- package/dist/esm/handlers/viewport.handler.js.map +1 -1
- package/dist/esm/types/event.types.d.ts +137 -16
- package/dist/esm/types/event.types.d.ts.map +1 -1
- package/dist/esm/types/event.types.js +22 -7
- package/dist/esm/types/event.types.js.map +1 -1
- package/dist/esm/types/index.d.ts +2 -0
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/scroll.types.d.ts +16 -0
- package/dist/esm/types/scroll.types.d.ts.map +1 -0
- package/dist/esm/types/scroll.types.js +8 -0
- package/dist/esm/types/scroll.types.js.map +1 -0
- package/dist/esm/types/viewport.types.d.ts +0 -27
- package/dist/esm/types/viewport.types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -213,6 +213,13 @@ npm run test:coverage # With coverage
|
|
|
213
213
|
|
|
214
214
|
Chrome 60+, Firefox 55+, Safari 12+, Edge 79+
|
|
215
215
|
|
|
216
|
+
## SSR/SSG Support
|
|
217
|
+
|
|
218
|
+
Safe to import in SSR frameworks (Angular Universal, Next.js, Nuxt, SvelteKit). All methods silently no-op in Node.js environments.
|
|
219
|
+
|
|
220
|
+
**Best practice**
|
|
221
|
+
Register listeners AFTER init() in browser-only lifecycle hooks.
|
|
222
|
+
|
|
216
223
|
## Documentation
|
|
217
224
|
|
|
218
225
|
- [Handlers](./src/handlers/README.md) - Event capture implementation
|
|
@@ -85,20 +85,19 @@ class R extends Error {
|
|
|
85
85
|
super(e), this.statusCode = t, this.name = "PermanentError", Error.captureStackTrace && Error.captureStackTrace(this, R);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
var u = /* @__PURE__ */ ((n) => (n.PAGE_VIEW = "page_view", n.CLICK = "click", n.SCROLL = "scroll", n.SESSION_START = "session_start", n.SESSION_END = "session_end", n.CUSTOM = "custom", n.WEB_VITALS = "web_vitals", n.ERROR = "error", n.VIEWPORT_VISIBLE = "viewport_visible", n))(u || {}), H = /* @__PURE__ */ ((n) => (n.UP = "up", n.DOWN = "down", n))(H || {}), P = /* @__PURE__ */ ((n) => (n.JS_ERROR = "js_error", n.PROMISE_REJECTION = "promise_rejection", n))(P || {});
|
|
88
|
+
var u = /* @__PURE__ */ ((n) => (n.PAGE_VIEW = "page_view", n.CLICK = "click", n.SCROLL = "scroll", n.SESSION_START = "session_start", n.SESSION_END = "session_end", n.CUSTOM = "custom", n.WEB_VITALS = "web_vitals", n.ERROR = "error", n.VIEWPORT_VISIBLE = "viewport_visible", n))(u || {}), H = /* @__PURE__ */ ((n) => (n.UP = "up", n.DOWN = "down", n))(H || {}), P = /* @__PURE__ */ ((n) => (n.JS_ERROR = "js_error", n.PROMISE_REJECTION = "promise_rejection", n))(P || {}), D = /* @__PURE__ */ ((n) => (n.QA = "qa", n))(D || {});
|
|
89
89
|
function nr(n) {
|
|
90
|
-
return n.type ===
|
|
90
|
+
return n.type === u.SCROLL && "scroll_data" in n && n.scroll_data.is_primary === !0;
|
|
91
91
|
}
|
|
92
92
|
function sr(n) {
|
|
93
|
-
return n.type ===
|
|
93
|
+
return n.type === u.SCROLL && "scroll_data" in n && n.scroll_data.is_primary === !1;
|
|
94
94
|
}
|
|
95
|
-
var D = /* @__PURE__ */ ((n) => (n.QA = "qa", n))(D || {});
|
|
96
95
|
class V extends Error {
|
|
97
96
|
constructor(e, t, r) {
|
|
98
97
|
super(e), this.errorCode = t, this.layer = r, this.name = this.constructor.name, Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
|
|
99
98
|
}
|
|
100
99
|
}
|
|
101
|
-
class
|
|
100
|
+
class f extends V {
|
|
102
101
|
constructor(e, t = "config") {
|
|
103
102
|
super(e, "APP_CONFIG_INVALID", t);
|
|
104
103
|
}
|
|
@@ -113,7 +112,7 @@ class he extends V {
|
|
|
113
112
|
super(e, "SAMPLING_RATE_INVALID", t);
|
|
114
113
|
}
|
|
115
114
|
}
|
|
116
|
-
class
|
|
115
|
+
class M extends V {
|
|
117
116
|
constructor(e, t = "config") {
|
|
118
117
|
super(e, "INTEGRATION_INVALID", t);
|
|
119
118
|
}
|
|
@@ -161,7 +160,7 @@ const Xe = () => {
|
|
|
161
160
|
} catch (n) {
|
|
162
161
|
return a("warn", "Device detection failed, defaulting to desktop", { error: n }), w.Desktop;
|
|
163
162
|
}
|
|
164
|
-
}, y = "tlog",
|
|
163
|
+
}, y = "tlog", fe = `${y}:qa_mode`, ze = `${y}:uid`, Qe = (n) => n ? `${y}:${n}:queue` : `${y}:queue`, je = (n) => n ? `${y}:${n}:session` : `${y}:session`, Ye = (n) => n ? `${y}:${n}:broadcast` : `${y}:broadcast`, ye = {
|
|
165
164
|
LCP: 4e3,
|
|
166
165
|
FCP: 1800,
|
|
167
166
|
CLS: 0.25,
|
|
@@ -183,12 +182,12 @@ const Xe = () => {
|
|
|
183
182
|
/Bearer\s+[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)?(?:\.[A-Za-z0-9_-]+)?/gi,
|
|
184
183
|
// Passwords in connection strings (protocol://user:password@host)
|
|
185
184
|
/:\/\/[^:/]+:([^@]+)@/gi
|
|
186
|
-
],
|
|
187
|
-
if (sessionStorage.getItem(
|
|
185
|
+
], Ee = 500, ge = 5e3, x = 50, qe = x * 2, Le = 1, Ze = 1e3, Je = 10, me = 5e3, et = 6e4, Se = "tlog_mode", tt = "qa", rt = () => {
|
|
186
|
+
if (sessionStorage.getItem(fe) === "true")
|
|
188
187
|
return !0;
|
|
189
188
|
const e = new URLSearchParams(window.location.search), r = e.get(Se) === tt;
|
|
190
189
|
if (r) {
|
|
191
|
-
sessionStorage.setItem(
|
|
190
|
+
sessionStorage.setItem(fe, "true"), e.delete(Se);
|
|
192
191
|
const s = e.toString(), i = `${window.location.pathname}${s ? "?" + s : ""}${window.location.hash}`;
|
|
193
192
|
try {
|
|
194
193
|
window.history.replaceState({}, "", i);
|
|
@@ -311,18 +310,18 @@ const Xe = () => {
|
|
|
311
310
|
}
|
|
312
311
|
}, at = (n) => {
|
|
313
312
|
if (n !== void 0 && (n === null || typeof n != "object"))
|
|
314
|
-
throw new
|
|
313
|
+
throw new f("Configuration must be an object", "config");
|
|
315
314
|
if (n) {
|
|
316
315
|
if (n.sessionTimeout !== void 0 && (typeof n.sessionTimeout != "number" || n.sessionTimeout < 3e4 || n.sessionTimeout > 864e5))
|
|
317
316
|
throw new Ge(h.INVALID_SESSION_TIMEOUT, "config");
|
|
318
317
|
if (n.globalMetadata !== void 0 && (typeof n.globalMetadata != "object" || n.globalMetadata === null))
|
|
319
|
-
throw new
|
|
318
|
+
throw new f(h.INVALID_GLOBAL_METADATA, "config");
|
|
320
319
|
if (n.integrations && ct(n.integrations), n.sensitiveQueryParams !== void 0) {
|
|
321
320
|
if (!Array.isArray(n.sensitiveQueryParams))
|
|
322
|
-
throw new
|
|
321
|
+
throw new f(h.INVALID_SENSITIVE_QUERY_PARAMS, "config");
|
|
323
322
|
for (const e of n.sensitiveQueryParams)
|
|
324
323
|
if (typeof e != "string")
|
|
325
|
-
throw new
|
|
324
|
+
throw new f("All sensitive query params must be strings", "config");
|
|
326
325
|
}
|
|
327
326
|
if (n.errorSampling !== void 0 && (typeof n.errorSampling != "number" || n.errorSampling < 0 || n.errorSampling > 1))
|
|
328
327
|
throw new he(h.INVALID_ERROR_SAMPLING_RATE, "config");
|
|
@@ -330,78 +329,78 @@ const Xe = () => {
|
|
|
330
329
|
throw new he(h.INVALID_SAMPLING_RATE, "config");
|
|
331
330
|
if (n.primaryScrollSelector !== void 0) {
|
|
332
331
|
if (typeof n.primaryScrollSelector != "string" || !n.primaryScrollSelector.trim())
|
|
333
|
-
throw new
|
|
332
|
+
throw new f(h.INVALID_PRIMARY_SCROLL_SELECTOR, "config");
|
|
334
333
|
if (n.primaryScrollSelector !== "window")
|
|
335
334
|
try {
|
|
336
335
|
document.querySelector(n.primaryScrollSelector);
|
|
337
336
|
} catch {
|
|
338
|
-
throw new
|
|
337
|
+
throw new f(
|
|
339
338
|
`${h.INVALID_PRIMARY_SCROLL_SELECTOR_SYNTAX}: "${n.primaryScrollSelector}"`,
|
|
340
339
|
"config"
|
|
341
340
|
);
|
|
342
341
|
}
|
|
343
342
|
}
|
|
344
343
|
if (n.pageViewThrottleMs !== void 0 && (typeof n.pageViewThrottleMs != "number" || n.pageViewThrottleMs < 0))
|
|
345
|
-
throw new
|
|
344
|
+
throw new f(h.INVALID_PAGE_VIEW_THROTTLE, "config");
|
|
346
345
|
if (n.clickThrottleMs !== void 0 && (typeof n.clickThrottleMs != "number" || n.clickThrottleMs < 0))
|
|
347
|
-
throw new
|
|
346
|
+
throw new f(h.INVALID_CLICK_THROTTLE, "config");
|
|
348
347
|
if (n.maxSameEventPerMinute !== void 0 && (typeof n.maxSameEventPerMinute != "number" || n.maxSameEventPerMinute <= 0))
|
|
349
|
-
throw new
|
|
348
|
+
throw new f(h.INVALID_MAX_SAME_EVENT_PER_MINUTE, "config");
|
|
350
349
|
n.viewport !== void 0 && lt(n.viewport);
|
|
351
350
|
}
|
|
352
351
|
}, lt = (n) => {
|
|
353
352
|
if (typeof n != "object" || n === null)
|
|
354
|
-
throw new
|
|
353
|
+
throw new f(h.INVALID_VIEWPORT_CONFIG, "config");
|
|
355
354
|
if (!n.elements || !Array.isArray(n.elements))
|
|
356
|
-
throw new
|
|
355
|
+
throw new f(h.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
357
356
|
if (n.elements.length === 0)
|
|
358
|
-
throw new
|
|
357
|
+
throw new f(h.INVALID_VIEWPORT_ELEMENTS, "config");
|
|
359
358
|
const e = /* @__PURE__ */ new Set();
|
|
360
359
|
for (const t of n.elements) {
|
|
361
360
|
if (!t.selector || typeof t.selector != "string" || !t.selector.trim())
|
|
362
|
-
throw new
|
|
361
|
+
throw new f(h.INVALID_VIEWPORT_ELEMENT, "config");
|
|
363
362
|
const r = t.selector.trim();
|
|
364
363
|
if (e.has(r))
|
|
365
|
-
throw new
|
|
364
|
+
throw new f(
|
|
366
365
|
`Duplicate viewport selector found: "${r}". Each selector should appear only once.`,
|
|
367
366
|
"config"
|
|
368
367
|
);
|
|
369
368
|
if (e.add(r), t.id !== void 0 && (typeof t.id != "string" || !t.id.trim()))
|
|
370
|
-
throw new
|
|
369
|
+
throw new f(h.INVALID_VIEWPORT_ELEMENT_ID, "config");
|
|
371
370
|
if (t.name !== void 0 && (typeof t.name != "string" || !t.name.trim()))
|
|
372
|
-
throw new
|
|
371
|
+
throw new f(h.INVALID_VIEWPORT_ELEMENT_NAME, "config");
|
|
373
372
|
}
|
|
374
373
|
if (n.threshold !== void 0 && (typeof n.threshold != "number" || n.threshold < 0 || n.threshold > 1))
|
|
375
|
-
throw new
|
|
374
|
+
throw new f(h.INVALID_VIEWPORT_THRESHOLD, "config");
|
|
376
375
|
if (n.minDwellTime !== void 0 && (typeof n.minDwellTime != "number" || n.minDwellTime < 0))
|
|
377
|
-
throw new
|
|
376
|
+
throw new f(h.INVALID_VIEWPORT_MIN_DWELL_TIME, "config");
|
|
378
377
|
if (n.cooldownPeriod !== void 0 && (typeof n.cooldownPeriod != "number" || n.cooldownPeriod < 0))
|
|
379
|
-
throw new
|
|
378
|
+
throw new f(h.INVALID_VIEWPORT_COOLDOWN_PERIOD, "config");
|
|
380
379
|
if (n.maxTrackedElements !== void 0 && (typeof n.maxTrackedElements != "number" || n.maxTrackedElements <= 0))
|
|
381
|
-
throw new
|
|
380
|
+
throw new f(h.INVALID_VIEWPORT_MAX_TRACKED_ELEMENTS, "config");
|
|
382
381
|
}, ct = (n) => {
|
|
383
382
|
if (n) {
|
|
384
383
|
if (n.tracelog && (!n.tracelog.projectId || typeof n.tracelog.projectId != "string" || n.tracelog.projectId.trim() === ""))
|
|
385
|
-
throw new
|
|
384
|
+
throw new M(h.INVALID_TRACELOG_PROJECT_ID, "config");
|
|
386
385
|
if (n.custom) {
|
|
387
386
|
if (!n.custom.collectApiUrl || typeof n.custom.collectApiUrl != "string" || n.custom.collectApiUrl.trim() === "")
|
|
388
|
-
throw new
|
|
387
|
+
throw new M(h.INVALID_CUSTOM_API_URL, "config");
|
|
389
388
|
if (n.custom.allowHttp !== void 0 && typeof n.custom.allowHttp != "boolean")
|
|
390
|
-
throw new
|
|
389
|
+
throw new M("allowHttp must be a boolean", "config");
|
|
391
390
|
const e = n.custom.collectApiUrl.trim();
|
|
392
391
|
if (!e.startsWith("http://") && !e.startsWith("https://"))
|
|
393
|
-
throw new
|
|
392
|
+
throw new M('Custom API URL must start with "http://" or "https://"', "config");
|
|
394
393
|
if (!(n.custom.allowHttp ?? !1) && e.startsWith("http://"))
|
|
395
|
-
throw new
|
|
394
|
+
throw new M(
|
|
396
395
|
"Custom API URL must use HTTPS in production. Set allowHttp: true in integration config to allow HTTP (not recommended)",
|
|
397
396
|
"config"
|
|
398
397
|
);
|
|
399
398
|
}
|
|
400
399
|
if (n.googleAnalytics) {
|
|
401
400
|
if (!n.googleAnalytics.measurementId || typeof n.googleAnalytics.measurementId != "string" || n.googleAnalytics.measurementId.trim() === "")
|
|
402
|
-
throw new
|
|
401
|
+
throw new M(h.INVALID_GOOGLE_ANALYTICS_ID, "config");
|
|
403
402
|
if (!n.googleAnalytics.measurementId.trim().match(/^(G-|UA-)/))
|
|
404
|
-
throw new
|
|
403
|
+
throw new M('Google Analytics measurement ID must start with "G-" or "UA-"', "config");
|
|
405
404
|
}
|
|
406
405
|
}
|
|
407
406
|
}, ut = (n) => {
|
|
@@ -411,7 +410,7 @@ const Xe = () => {
|
|
|
411
410
|
sessionTimeout: n?.sessionTimeout ?? 9e5,
|
|
412
411
|
globalMetadata: n?.globalMetadata ?? {},
|
|
413
412
|
sensitiveQueryParams: n?.sensitiveQueryParams ?? [],
|
|
414
|
-
errorSampling: n?.errorSampling ??
|
|
413
|
+
errorSampling: n?.errorSampling ?? Le,
|
|
415
414
|
samplingRate: n?.samplingRate ?? 1,
|
|
416
415
|
pageViewThrottleMs: n?.pageViewThrottleMs ?? 1e3,
|
|
417
416
|
clickThrottleMs: n?.clickThrottleMs ?? 300,
|
|
@@ -444,7 +443,7 @@ const Xe = () => {
|
|
|
444
443
|
return !0;
|
|
445
444
|
}
|
|
446
445
|
return !1;
|
|
447
|
-
},
|
|
446
|
+
}, Me = (n, e = 0) => {
|
|
448
447
|
if (typeof n != "object" || n === null || e > 1)
|
|
449
448
|
return !1;
|
|
450
449
|
for (const t of Object.values(n)) {
|
|
@@ -463,7 +462,7 @@ const Xe = () => {
|
|
|
463
462
|
continue;
|
|
464
463
|
}
|
|
465
464
|
if (r === "object" && e === 0) {
|
|
466
|
-
if (!
|
|
465
|
+
if (!Me(t, e + 1))
|
|
467
466
|
return !1;
|
|
468
467
|
continue;
|
|
469
468
|
}
|
|
@@ -488,7 +487,7 @@ const Xe = () => {
|
|
|
488
487
|
error: "Event name cannot be a reserved word"
|
|
489
488
|
} : { valid: !0 }, Ie = (n, e, t) => {
|
|
490
489
|
const r = ot(e), s = `${t} "${n}" metadata error`;
|
|
491
|
-
if (!
|
|
490
|
+
if (!Me(r))
|
|
492
491
|
return {
|
|
493
492
|
valid: !1,
|
|
494
493
|
error: `${s}: object has invalid types. Valid types are string, number, boolean or string arrays.`
|
|
@@ -536,7 +535,7 @@ const Xe = () => {
|
|
|
536
535
|
valid: !0,
|
|
537
536
|
sanitizedMetadata: r
|
|
538
537
|
};
|
|
539
|
-
},
|
|
538
|
+
}, ft = (n, e, t) => {
|
|
540
539
|
if (Array.isArray(e)) {
|
|
541
540
|
const r = [], s = `${t} "${n}" metadata error`;
|
|
542
541
|
for (let i = 0; i < e.length; i++) {
|
|
@@ -560,7 +559,7 @@ const Xe = () => {
|
|
|
560
559
|
};
|
|
561
560
|
}
|
|
562
561
|
return Ie(n, e, t);
|
|
563
|
-
},
|
|
562
|
+
}, Et = (n, e) => {
|
|
564
563
|
const t = ht(n);
|
|
565
564
|
if (!t.valid)
|
|
566
565
|
return a("error", "Event name validation failed", {
|
|
@@ -569,7 +568,7 @@ const Xe = () => {
|
|
|
569
568
|
}), t;
|
|
570
569
|
if (!e)
|
|
571
570
|
return { valid: !0 };
|
|
572
|
-
const r =
|
|
571
|
+
const r = ft(n, e, "customEvent");
|
|
573
572
|
return r.valid || a("error", "Event metadata validation failed", {
|
|
574
573
|
showToClient: !0,
|
|
575
574
|
data: {
|
|
@@ -868,11 +867,11 @@ class St extends S {
|
|
|
868
867
|
[u.VIEWPORT_VISIBLE]: 0,
|
|
869
868
|
[u.SCROLL]: 0
|
|
870
869
|
});
|
|
871
|
-
const
|
|
872
|
-
if (!
|
|
870
|
+
const L = e === u.SESSION_START || e === u.SESSION_END;
|
|
871
|
+
if (!L && !this.checkRateLimit())
|
|
873
872
|
return;
|
|
874
873
|
const m = e;
|
|
875
|
-
if (!
|
|
874
|
+
if (!L) {
|
|
876
875
|
if (this.sessionEventCounts.total >= 1e3) {
|
|
877
876
|
a("warn", "Session event limit reached", {
|
|
878
877
|
data: {
|
|
@@ -915,7 +914,7 @@ class St extends S {
|
|
|
915
914
|
session_end_reason: d,
|
|
916
915
|
viewport_data: _
|
|
917
916
|
});
|
|
918
|
-
if (!(!
|
|
917
|
+
if (!(!L && !this.shouldSample())) {
|
|
919
918
|
if (Ve) {
|
|
920
919
|
const A = this.get("sessionId");
|
|
921
920
|
if (!A) {
|
|
@@ -938,7 +937,7 @@ class St extends S {
|
|
|
938
937
|
}), this.emitEvent(z);
|
|
939
938
|
return;
|
|
940
939
|
}
|
|
941
|
-
this.addToQueue(z),
|
|
940
|
+
this.addToQueue(z), L || (this.sessionEventCounts.total++, this.sessionEventCounts[m] !== void 0 && this.sessionEventCounts[m]++);
|
|
942
941
|
}
|
|
943
942
|
}
|
|
944
943
|
}
|
|
@@ -1783,7 +1782,7 @@ class At extends S {
|
|
|
1783
1782
|
const { element: t, lastScrollPos: r, lastEventTime: s } = e, i = this.getScrollTop(t), o = Date.now(), l = Math.abs(i - r);
|
|
1784
1783
|
if (l < 10 || t === window && !this.isWindowScrollable())
|
|
1785
1784
|
return null;
|
|
1786
|
-
const c = this.getViewportHeight(t), d = this.getScrollHeight(t), _ = this.getScrollDirection(i, r), g = this.calculateScrollDepth(i, d, c),
|
|
1785
|
+
const c = this.getViewportHeight(t), d = this.getScrollHeight(t), _ = this.getScrollDirection(i, r), g = this.calculateScrollDepth(i, d, c), L = s > 0 ? o - s : 0, m = L > 0 ? Math.round(l / L * 1e3) : 0;
|
|
1787
1786
|
return g > e.maxDepthReached && (e.maxDepthReached = g), e.lastScrollPos = i, {
|
|
1788
1787
|
depth: g,
|
|
1789
1788
|
direction: _,
|
|
@@ -2040,7 +2039,7 @@ class yt extends S {
|
|
|
2040
2039
|
`, document.head.appendChild(r);
|
|
2041
2040
|
}
|
|
2042
2041
|
}
|
|
2043
|
-
class
|
|
2042
|
+
class Lt {
|
|
2044
2043
|
storage;
|
|
2045
2044
|
sessionStorageRef;
|
|
2046
2045
|
fallbackStorage = /* @__PURE__ */ new Map();
|
|
@@ -2218,7 +2217,7 @@ class Mt {
|
|
|
2218
2217
|
this.fallbackSessionStorage.delete(e);
|
|
2219
2218
|
}
|
|
2220
2219
|
}
|
|
2221
|
-
class
|
|
2220
|
+
class Mt extends S {
|
|
2222
2221
|
eventManager;
|
|
2223
2222
|
reportedByNav = /* @__PURE__ */ new Map();
|
|
2224
2223
|
observers = [];
|
|
@@ -2427,7 +2426,7 @@ class Nt extends S {
|
|
|
2427
2426
|
cooldownMs: me
|
|
2428
2427
|
}
|
|
2429
2428
|
}), !1;
|
|
2430
|
-
const r = this.get("config")?.errorSampling ??
|
|
2429
|
+
const r = this.get("config")?.errorSampling ?? Le;
|
|
2431
2430
|
return Math.random() < r;
|
|
2432
2431
|
}
|
|
2433
2432
|
handleError = (e) => {
|
|
@@ -2471,7 +2470,7 @@ class Nt extends S {
|
|
|
2471
2470
|
}
|
|
2472
2471
|
}
|
|
2473
2472
|
sanitize(e) {
|
|
2474
|
-
let t = e.length >
|
|
2473
|
+
let t = e.length > Ee ? e.slice(0, Ee) + "..." : e;
|
|
2475
2474
|
for (const r of le) {
|
|
2476
2475
|
const s = new RegExp(r.source, r.flags);
|
|
2477
2476
|
t = t.replace(s, "[REDACTED]");
|
|
@@ -2507,7 +2506,7 @@ class Rt extends S {
|
|
|
2507
2506
|
}
|
|
2508
2507
|
async init(e = {}) {
|
|
2509
2508
|
if (!this.isInitialized) {
|
|
2510
|
-
this.managers.storage = new
|
|
2509
|
+
this.managers.storage = new Lt();
|
|
2511
2510
|
try {
|
|
2512
2511
|
this.setupState(e), await this.setupIntegrations(), this.managers.event = new St(this.managers.storage, this.integrations.googleAnalytics, this.emitter), this.initializeHandlers(), await this.managers.event.recoverPersistedEvents().catch((t) => {
|
|
2513
2512
|
a("warn", "Failed to recover persisted events", { error: t });
|
|
@@ -2522,7 +2521,7 @@ class Rt extends S {
|
|
|
2522
2521
|
sendCustomEvent(e, t) {
|
|
2523
2522
|
if (!this.managers.event)
|
|
2524
2523
|
return;
|
|
2525
|
-
const { valid: r, error: s, sanitizedMetadata: i } =
|
|
2524
|
+
const { valid: r, error: s, sanitizedMetadata: i } = Et(e, t);
|
|
2526
2525
|
if (!r) {
|
|
2527
2526
|
if (this.get("mode") === D.QA)
|
|
2528
2527
|
throw new Error(`[TraceLog] Custom event "${e}" validation failed: ${s}`);
|
|
@@ -2582,18 +2581,16 @@ class Rt extends S {
|
|
|
2582
2581
|
this.set("suppressNextScroll", !1);
|
|
2583
2582
|
}, 500);
|
|
2584
2583
|
};
|
|
2585
|
-
this.handlers.pageView = new It(this.managers.event, e), this.handlers.pageView.startTracking(), this.handlers.click = new vt(this.managers.event), this.handlers.click.startTracking(), this.handlers.scroll = new At(this.managers.event), this.handlers.scroll.startTracking(), this.handlers.performance = new
|
|
2584
|
+
this.handlers.pageView = new It(this.managers.event, e), this.handlers.pageView.startTracking(), this.handlers.click = new vt(this.managers.event), this.handlers.click.startTracking(), this.handlers.scroll = new At(this.managers.event), this.handlers.scroll.startTracking(), this.handlers.performance = new Mt(this.managers.event), this.handlers.performance.startTracking().catch((t) => {
|
|
2586
2585
|
a("warn", "Failed to start performance tracking", { error: t });
|
|
2587
2586
|
}), this.handlers.error = new Nt(this.managers.event), this.handlers.error.startTracking(), this.get("config").viewport && (this.handlers.viewport = new wt(this.managers.event), this.handlers.viewport.startTracking());
|
|
2588
2587
|
}
|
|
2589
2588
|
}
|
|
2590
2589
|
const N = [];
|
|
2591
|
-
let
|
|
2590
|
+
let E = null, C = !1, F = !1;
|
|
2592
2591
|
const Ot = async (n) => {
|
|
2593
|
-
if (typeof window > "u" || typeof document > "u")
|
|
2594
|
-
|
|
2595
|
-
if (!window.__traceLogDisabled && !f && !b) {
|
|
2596
|
-
b = !0;
|
|
2592
|
+
if (!(typeof window > "u" || typeof document > "u") && !window.__traceLogDisabled && !E && !C) {
|
|
2593
|
+
C = !0;
|
|
2597
2594
|
try {
|
|
2598
2595
|
const e = ut(n ?? {}), t = new Rt();
|
|
2599
2596
|
try {
|
|
@@ -2605,7 +2602,7 @@ const Ot = async (n) => {
|
|
|
2605
2602
|
o(new Error("[TraceLog] Initialization timeout after 10000ms"));
|
|
2606
2603
|
}, 1e4);
|
|
2607
2604
|
});
|
|
2608
|
-
await Promise.race([r, s]),
|
|
2605
|
+
await Promise.race([r, s]), E = t;
|
|
2609
2606
|
} catch (r) {
|
|
2610
2607
|
try {
|
|
2611
2608
|
t.destroy(!0);
|
|
@@ -2615,42 +2612,50 @@ const Ot = async (n) => {
|
|
|
2615
2612
|
throw r;
|
|
2616
2613
|
}
|
|
2617
2614
|
} catch (e) {
|
|
2618
|
-
throw
|
|
2615
|
+
throw E = null, e;
|
|
2619
2616
|
} finally {
|
|
2620
|
-
|
|
2617
|
+
C = !1;
|
|
2621
2618
|
}
|
|
2622
2619
|
}
|
|
2623
|
-
}, bt = (n, e) => {
|
|
2624
|
-
if (!f)
|
|
2625
|
-
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
2626
|
-
if (F)
|
|
2627
|
-
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
2628
|
-
f.sendCustomEvent(n, e);
|
|
2629
2620
|
}, Ct = (n, e) => {
|
|
2630
|
-
if (!
|
|
2631
|
-
|
|
2632
|
-
|
|
2621
|
+
if (!(typeof window > "u" || typeof document > "u")) {
|
|
2622
|
+
if (!E)
|
|
2623
|
+
throw new Error("[TraceLog] TraceLog not initialized. Please call init() first.");
|
|
2624
|
+
if (F)
|
|
2625
|
+
throw new Error("[TraceLog] Cannot send events while TraceLog is being destroyed");
|
|
2626
|
+
E.sendCustomEvent(n, e);
|
|
2627
|
+
}
|
|
2628
|
+
}, bt = (n, e) => {
|
|
2629
|
+
if (!(typeof window > "u" || typeof document > "u")) {
|
|
2630
|
+
if (!E || C) {
|
|
2631
|
+
N.push({ event: n, callback: e });
|
|
2632
|
+
return;
|
|
2633
|
+
}
|
|
2634
|
+
E.on(n, e);
|
|
2633
2635
|
}
|
|
2634
|
-
f.on(n, e);
|
|
2635
2636
|
}, Pt = (n, e) => {
|
|
2636
|
-
if (!
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
if (!
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2637
|
+
if (!(typeof window > "u" || typeof document > "u")) {
|
|
2638
|
+
if (!E) {
|
|
2639
|
+
const t = N.findIndex((r) => r.event === n && r.callback === e);
|
|
2640
|
+
t !== -1 && N.splice(t, 1);
|
|
2641
|
+
return;
|
|
2642
|
+
}
|
|
2643
|
+
E.off(n, e);
|
|
2644
|
+
}
|
|
2645
|
+
}, Dt = () => typeof window > "u" || typeof document > "u" ? !1 : E !== null, Vt = () => {
|
|
2646
|
+
if (!(typeof window > "u" || typeof document > "u")) {
|
|
2647
|
+
if (F)
|
|
2648
|
+
throw new Error("[TraceLog] Destroy operation already in progress");
|
|
2649
|
+
if (!E)
|
|
2650
|
+
throw new Error("[TraceLog] App not initialized");
|
|
2651
|
+
F = !0;
|
|
2652
|
+
try {
|
|
2653
|
+
E.destroy(), E = null, C = !1, N.length = 0;
|
|
2654
|
+
} catch (n) {
|
|
2655
|
+
E = null, C = !1, N.length = 0, a("warn", "Error during destroy, forced cleanup completed", { error: n });
|
|
2656
|
+
} finally {
|
|
2657
|
+
F = !1;
|
|
2658
|
+
}
|
|
2654
2659
|
}
|
|
2655
2660
|
}, or = {
|
|
2656
2661
|
WEB_VITALS_THRESHOLDS: ye
|
|
@@ -2699,14 +2704,14 @@ const Ot = async (n) => {
|
|
|
2699
2704
|
LOW_ERROR_RATE_PERCENT: 1,
|
|
2700
2705
|
HIGH_ERROR_RATE_PERCENT: 5,
|
|
2701
2706
|
CRITICAL_ERROR_RATE_PERCENT: 10
|
|
2702
|
-
},
|
|
2707
|
+
}, fr = {
|
|
2703
2708
|
SHORT_TERM_TREND_HOURS: 24,
|
|
2704
2709
|
MEDIUM_TERM_TREND_DAYS: 7,
|
|
2705
2710
|
LONG_TERM_TREND_DAYS: 30,
|
|
2706
2711
|
MIN_DATA_POINTS_FOR_TREND: 5,
|
|
2707
2712
|
WEEKLY_PATTERN_MIN_WEEKS: 4,
|
|
2708
2713
|
DAILY_PATTERN_MIN_DAYS: 14
|
|
2709
|
-
},
|
|
2714
|
+
}, Er = {
|
|
2710
2715
|
MIN_SEGMENT_SIZE: 10,
|
|
2711
2716
|
MIN_COHORT_SIZE: 5,
|
|
2712
2717
|
COHORT_ANALYSIS_DAYS: [1, 3, 7, 14, 30],
|
|
@@ -2731,13 +2736,13 @@ const Ot = async (n) => {
|
|
|
2731
2736
|
PAGE_URL_UNKNOWN: "unknown"
|
|
2732
2737
|
}, _r = {
|
|
2733
2738
|
init: Ot,
|
|
2734
|
-
event:
|
|
2735
|
-
on:
|
|
2739
|
+
event: Ct,
|
|
2740
|
+
on: bt,
|
|
2736
2741
|
off: Pt,
|
|
2737
2742
|
isInitialized: Dt,
|
|
2738
2743
|
destroy: Vt
|
|
2739
2744
|
};
|
|
2740
|
-
var re, Ne = -1,
|
|
2745
|
+
var re, Ne = -1, b = function(n) {
|
|
2741
2746
|
addEventListener("pageshow", (function(e) {
|
|
2742
2747
|
e.persisted && (Ne = e.timeStamp, n(e));
|
|
2743
2748
|
}), !0);
|
|
@@ -2793,7 +2798,7 @@ var re, Ne = -1, C = function(n) {
|
|
|
2793
2798
|
}, kt = function() {
|
|
2794
2799
|
removeEventListener("visibilitychange", W, !0), removeEventListener("prerenderingchange", W, !0);
|
|
2795
2800
|
}, Re = function() {
|
|
2796
|
-
return O < 0 && (O = ve(), Ae(),
|
|
2801
|
+
return O < 0 && (O = ve(), Ae(), b((function() {
|
|
2797
2802
|
setTimeout((function() {
|
|
2798
2803
|
O = ve(), Ae();
|
|
2799
2804
|
}), 0);
|
|
@@ -2811,7 +2816,7 @@ var re, Ne = -1, C = function(n) {
|
|
|
2811
2816
|
l.name === "first-contentful-paint" && (i.disconnect(), l.startTime < r.firstHiddenTime && (s.value = Math.max(l.startTime - B(), 0), s.entries.push(l), t(!0)));
|
|
2812
2817
|
}));
|
|
2813
2818
|
}));
|
|
2814
|
-
i && (t = I(n, s, ne, e.reportAllChanges),
|
|
2819
|
+
i && (t = I(n, s, ne, e.reportAllChanges), b((function(o) {
|
|
2815
2820
|
s = p("FCP"), t = I(n, s, ne, e.reportAllChanges), ue((function() {
|
|
2816
2821
|
s.value = performance.now() - o.timeStamp, t(!0);
|
|
2817
2822
|
}));
|
|
@@ -2829,22 +2834,22 @@ var re, Ne = -1, C = function(n) {
|
|
|
2829
2834
|
}, l = k("layout-shift", o);
|
|
2830
2835
|
l && (t = I(n, r, se, e.reportAllChanges), X((function() {
|
|
2831
2836
|
o(l.takeRecords()), t(!0);
|
|
2832
|
-
})),
|
|
2837
|
+
})), b((function() {
|
|
2833
2838
|
s = 0, r = p("CLS", 0), t = I(n, r, se, e.reportAllChanges), ue((function() {
|
|
2834
2839
|
return t();
|
|
2835
2840
|
}));
|
|
2836
2841
|
})), setTimeout(t, 0));
|
|
2837
2842
|
})));
|
|
2838
|
-
},
|
|
2843
|
+
}, Ce = 0, Y = 1 / 0, U = 0, Ht = function(n) {
|
|
2839
2844
|
n.forEach((function(e) {
|
|
2840
|
-
e.interactionId && (Y = Math.min(Y, e.interactionId), U = Math.max(U, e.interactionId),
|
|
2845
|
+
e.interactionId && (Y = Math.min(Y, e.interactionId), U = Math.max(U, e.interactionId), Ce = U ? (U - Y) / 7 + 1 : 0);
|
|
2841
2846
|
}));
|
|
2842
|
-
},
|
|
2843
|
-
return re ?
|
|
2847
|
+
}, be = function() {
|
|
2848
|
+
return re ? Ce : performance.interactionCount || 0;
|
|
2844
2849
|
}, xt = function() {
|
|
2845
2850
|
"interactionCount" in performance || re || (re = k("event", Ht, { type: "event", buffered: !0, durationThreshold: 0 }));
|
|
2846
2851
|
}, T = [], G = /* @__PURE__ */ new Map(), Pe = 0, Ft = function() {
|
|
2847
|
-
var n = Math.min(T.length - 1, Math.floor((
|
|
2852
|
+
var n = Math.min(T.length - 1, Math.floor((be() - Pe) / 50));
|
|
2848
2853
|
return T[n];
|
|
2849
2854
|
}, Gt = [], Wt = function(n) {
|
|
2850
2855
|
if (Gt.forEach((function(s) {
|
|
@@ -2880,8 +2885,8 @@ var re, Ne = -1, C = function(n) {
|
|
|
2880
2885
|
}, o = k("event", i, { durationThreshold: (t = e.durationThreshold) !== null && t !== void 0 ? t : 40 });
|
|
2881
2886
|
r = I(n, s, ie, e.reportAllChanges), o && (o.observe({ type: "first-input", buffered: !0 }), X((function() {
|
|
2882
2887
|
i(o.takeRecords()), r(!0);
|
|
2883
|
-
})),
|
|
2884
|
-
Pe =
|
|
2888
|
+
})), b((function() {
|
|
2889
|
+
Pe = be(), T.length = 0, G.clear(), s = p("INP"), r = I(n, s, ie, e.reportAllChanges);
|
|
2885
2890
|
})));
|
|
2886
2891
|
})));
|
|
2887
2892
|
}, oe = [2500, 4e3], K = {}, Xt = function(n, e) {
|
|
@@ -2900,7 +2905,7 @@ var re, Ne = -1, C = function(n) {
|
|
|
2900
2905
|
addEventListener(c, (function() {
|
|
2901
2906
|
return De(l);
|
|
2902
2907
|
}), { once: !0, capture: !0 });
|
|
2903
|
-
})), X(l),
|
|
2908
|
+
})), X(l), b((function(c) {
|
|
2904
2909
|
s = p("LCP"), t = I(n, s, oe, e.reportAllChanges), ue((function() {
|
|
2905
2910
|
s.value = performance.now() - c.timeStamp, K[s.id] = !0, t(!0);
|
|
2906
2911
|
}));
|
|
@@ -2918,7 +2923,7 @@ var re, Ne = -1, C = function(n) {
|
|
|
2918
2923
|
var t = p("TTFB"), r = I(n, t, ae, e.reportAllChanges);
|
|
2919
2924
|
$t((function() {
|
|
2920
2925
|
var s = ce();
|
|
2921
|
-
s && (t.value = Math.max(s.responseStart - B(), 0), t.entries = [s], r(!0),
|
|
2926
|
+
s && (t.value = Math.max(s.responseStart - B(), 0), t.entries = [s], r(!0), b((function() {
|
|
2922
2927
|
t = p("TTFB", 0), (r = I(n, t, ae, e.reportAllChanges))(!0);
|
|
2923
2928
|
})));
|
|
2924
2929
|
}));
|
|
@@ -2939,7 +2944,7 @@ const Qt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
2939
2944
|
export {
|
|
2940
2945
|
gr as ANALYTICS_QUERY_LIMITS,
|
|
2941
2946
|
mr as ANOMALY_DETECTION,
|
|
2942
|
-
|
|
2947
|
+
f as AppConfigValidationError,
|
|
2943
2948
|
dr as CONTENT_ANALYTICS,
|
|
2944
2949
|
ar as DATA_PROTECTION,
|
|
2945
2950
|
ur as DEVICE_ANALYTICS,
|
|
@@ -2950,7 +2955,7 @@ export {
|
|
|
2950
2955
|
u as EventType,
|
|
2951
2956
|
hr as INSIGHT_THRESHOLDS,
|
|
2952
2957
|
ir as InitializationTimeoutError,
|
|
2953
|
-
|
|
2958
|
+
M as IntegrationValidationError,
|
|
2954
2959
|
rr as MAX_ARRAY_LENGTH,
|
|
2955
2960
|
qt as MAX_CUSTOM_EVENT_ARRAY_SIZE,
|
|
2956
2961
|
Kt as MAX_CUSTOM_EVENT_KEYS,
|
|
@@ -2963,14 +2968,14 @@ export {
|
|
|
2963
2968
|
D as Mode,
|
|
2964
2969
|
or as PERFORMANCE_CONFIG,
|
|
2965
2970
|
R as PermanentError,
|
|
2966
|
-
|
|
2971
|
+
Er as SEGMENTATION_ANALYTICS,
|
|
2967
2972
|
cr as SESSION_ANALYTICS,
|
|
2968
2973
|
Sr as SPECIAL_PAGE_URLS,
|
|
2969
2974
|
he as SamplingRateValidationError,
|
|
2970
2975
|
H as ScrollDirection,
|
|
2971
2976
|
Ge as SessionTimeoutValidationError,
|
|
2972
2977
|
q as SpecialApiUrl,
|
|
2973
|
-
|
|
2978
|
+
fr as TEMPORAL_ANALYSIS,
|
|
2974
2979
|
V as TraceLogValidationError,
|
|
2975
2980
|
nr as isPrimaryScrollEvent,
|
|
2976
2981
|
sr as isSecondaryScrollEvent,
|