@tracelog/lib 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/tracelog.esm.js +28 -29
- package/dist/browser/tracelog.esm.js.map +1 -1
- package/dist/browser/tracelog.js +1 -1
- package/dist/browser/tracelog.js.map +1 -1
- package/dist/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/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
|
@@ -85,14 +85,13 @@ 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);
|
|
@@ -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
|
}
|
|
@@ -183,7 +182,7 @@ 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
|
-
], fe = 500, ge = 5e3, x = 50, qe = x * 2,
|
|
185
|
+
], fe = 500, ge = 5e3, x = 50, qe = x * 2, Le = 1, Ze = 1e3, Je = 10, me = 5e3, et = 6e4, Se = "tlog_mode", tt = "qa", rt = () => {
|
|
187
186
|
if (sessionStorage.getItem(Ee) === "true")
|
|
188
187
|
return !0;
|
|
189
188
|
const e = new URLSearchParams(window.location.search), r = e.get(Se) === tt;
|
|
@@ -382,26 +381,26 @@ const Xe = () => {
|
|
|
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.`
|
|
@@ -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) => {
|
|
@@ -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 });
|
|
@@ -2582,7 +2581,7 @@ 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
|
}
|
|
@@ -2950,7 +2949,7 @@ export {
|
|
|
2950
2949
|
u as EventType,
|
|
2951
2950
|
hr as INSIGHT_THRESHOLDS,
|
|
2952
2951
|
ir as InitializationTimeoutError,
|
|
2953
|
-
|
|
2952
|
+
M as IntegrationValidationError,
|
|
2954
2953
|
rr as MAX_ARRAY_LENGTH,
|
|
2955
2954
|
qt as MAX_CUSTOM_EVENT_ARRAY_SIZE,
|
|
2956
2955
|
Kt as MAX_CUSTOM_EVENT_KEYS,
|