@tracelog/lib 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/browser/tracelog.js +42 -36
- package/dist/cjs/api.js +4 -0
- package/dist/cjs/app.constants.d.ts +4 -0
- package/dist/cjs/app.constants.js +5 -1
- package/dist/cjs/types/window.types.d.ts +5 -0
- package/dist/esm/api.js +4 -0
- package/dist/esm/app.constants.d.ts +4 -0
- package/dist/esm/app.constants.js +4 -0
- package/dist/esm/types/window.types.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -107,6 +107,12 @@ await tracelog.init({
|
|
|
107
107
|
|
|
108
108
|
## Configuration
|
|
109
109
|
|
|
110
|
+
**Disabling TraceLog:**
|
|
111
|
+
```typescript
|
|
112
|
+
// Set this flag before initialization to disable TraceLog completely
|
|
113
|
+
window.__traceLogDisabled = true;
|
|
114
|
+
```
|
|
115
|
+
|
|
110
116
|
**Environment-based settings:**
|
|
111
117
|
- Use `samplingRate: 0.1` to reduce data volume in high-traffic applications
|
|
112
118
|
- Configure `sessionTimeout` to match your application's user session length
|
package/dist/browser/tracelog.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var y = /* @__PURE__ */ ((r) => (r.Mobile = "mobile", r.Tablet = "tablet", r.Desktop = "desktop", r.Unknown = "unknown", r))(y || {});
|
|
2
|
-
const ee = 15 * 60 * 1e3, Ze = 1e3, et = 1e4,
|
|
2
|
+
const ee = 15 * 60 * 1e3, Ze = 1e3, et = 1e4, Ue = 250, tt = 24, Ee = 500, ve = 3, rt = 5e3, xe = 1e4, nt = 10, ye = 5, Te = 500, Ie = 120, A = 1, st = 0, it = 1, z = 3e4, G = 864e5, _e = 120, we = 8 * 1024, Ae = 10, be = 10, Y = 255, T = 1e3, K = 100, Me = 3, _ = 2, at = 2e3, k = "data-tl", ot = [
|
|
3
3
|
"button",
|
|
4
4
|
"a",
|
|
5
5
|
'input[type="button"]',
|
|
@@ -224,7 +224,7 @@ const St = () => {
|
|
|
224
224
|
const e = Math.random() * 16 | 0;
|
|
225
225
|
return (r === "x" ? e : e & 3 | 8).toString(16);
|
|
226
226
|
});
|
|
227
|
-
var w = /* @__PURE__ */ ((r) => (r.Skip = "skip", r.Localhost = "localhost:", r))(w || {}), re = /* @__PURE__ */ ((r) => (r.EVENT = "event", r.QUEUE = "queue", r))(re || {}), d = /* @__PURE__ */ ((r) => (r.PAGE_VIEW = "page_view", r.CLICK = "click", r.SCROLL = "scroll", r.SESSION_START = "session_start", r.SESSION_END = "session_end", r.CUSTOM = "custom", r.WEB_VITALS = "web_vitals", r.ERROR = "error", r))(d || {}),
|
|
227
|
+
var w = /* @__PURE__ */ ((r) => (r.Skip = "skip", r.Localhost = "localhost:", r))(w || {}), re = /* @__PURE__ */ ((r) => (r.EVENT = "event", r.QUEUE = "queue", r))(re || {}), d = /* @__PURE__ */ ((r) => (r.PAGE_VIEW = "page_view", r.CLICK = "click", r.SCROLL = "scroll", r.SESSION_START = "session_start", r.SESSION_END = "session_end", r.CUSTOM = "custom", r.WEB_VITALS = "web_vitals", r.ERROR = "error", r))(d || {}), x = /* @__PURE__ */ ((r) => (r.UP = "up", r.DOWN = "down", r))(x || {}), N = /* @__PURE__ */ ((r) => (r.JS_ERROR = "js_error", r.PROMISE_REJECTION = "promise_rejection", r.NETWORK_ERROR = "network_error", r))(N || {}), H = /* @__PURE__ */ ((r) => (r.QA = "qa", r.DEBUG = "debug", r))(H || {}), yt = /* @__PURE__ */ ((r) => (r.AND = "AND", r.OR = "OR", r))(yt || {}), Tt = /* @__PURE__ */ ((r) => (r.URL_MATCHES = "url_matches", r.ELEMENT_MATCHES = "element_matches", r.DEVICE_TYPE = "device_type", r.ELEMENT_TEXT = "element_text", r.ELEMENT_ATTRIBUTE = "element_attribute", r.UTM_SOURCE = "utm_source", r.UTM_MEDIUM = "utm_medium", r.UTM_CAMPAIGN = "utm_campaign", r))(Tt || {}), It = /* @__PURE__ */ ((r) => (r.EQUALS = "equals", r.CONTAINS = "contains", r.STARTS_WITH = "starts_with", r.ENDS_WITH = "ends_with", r.REGEX = "regex", r.GREATER_THAN = "greater_than", r.LESS_THAN = "less_than", r.EXISTS = "exists", r.NOT_EXISTS = "not_exists", r))(It || {});
|
|
228
228
|
class O extends Error {
|
|
229
229
|
constructor(e, t, n) {
|
|
230
230
|
super(e), this.errorCode = t, this.layer = n, this.name = this.constructor.name, Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
|
|
@@ -522,7 +522,7 @@ const At = (r) => {
|
|
|
522
522
|
error: e instanceof Error ? e.message : e
|
|
523
523
|
}), new Error(`Metadata sanitization failed: ${e instanceof Error ? e.message : "Unknown error"}`);
|
|
524
524
|
}
|
|
525
|
-
},
|
|
525
|
+
}, Ut = (r) => {
|
|
526
526
|
if (typeof r != "object" || r === null)
|
|
527
527
|
return !1;
|
|
528
528
|
for (const e of Object.values(r)) {
|
|
@@ -539,7 +539,7 @@ const At = (r) => {
|
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
return !0;
|
|
542
|
-
},
|
|
542
|
+
}, xt = (r) => typeof r != "string" ? {
|
|
543
543
|
valid: !1,
|
|
544
544
|
error: "Event name must be a string"
|
|
545
545
|
} : r.length === 0 ? {
|
|
@@ -556,7 +556,7 @@ const At = (r) => {
|
|
|
556
556
|
error: "Event name cannot be a reserved word"
|
|
557
557
|
} : { valid: !0 }, Ht = (r, e, t) => {
|
|
558
558
|
const n = kt(e), s = `${t} "${r}" metadata error`;
|
|
559
|
-
if (!
|
|
559
|
+
if (!Ut(n))
|
|
560
560
|
return {
|
|
561
561
|
valid: !1,
|
|
562
562
|
error: `${s}: object has invalid types. Valid types are string, number, boolean or string arrays.`
|
|
@@ -605,7 +605,7 @@ const At = (r) => {
|
|
|
605
605
|
sanitizedMetadata: n
|
|
606
606
|
};
|
|
607
607
|
}, Vt = (r, e) => {
|
|
608
|
-
const t =
|
|
608
|
+
const t = xt(r);
|
|
609
609
|
if (!t.valid)
|
|
610
610
|
return a.clientError("EventValidation", "Event name validation failed", { eventName: r, error: t.error }), t;
|
|
611
611
|
if (!e)
|
|
@@ -762,7 +762,7 @@ class he {
|
|
|
762
762
|
const n = this.buildConfigUrl(e, t), s = this.buildHeaders(t), i = await Gt(n, {
|
|
763
763
|
method: "GET",
|
|
764
764
|
headers: s,
|
|
765
|
-
timeout:
|
|
765
|
+
timeout: xe
|
|
766
766
|
});
|
|
767
767
|
if (!i.ok)
|
|
768
768
|
throw new Error(`HTTP ${i.status}: ${i.statusText}`);
|
|
@@ -927,7 +927,7 @@ class Qt extends f {
|
|
|
927
927
|
}
|
|
928
928
|
}
|
|
929
929
|
async sendWithTimeout(e, t) {
|
|
930
|
-
const n = new AbortController(), s = setTimeout(() => n.abort(),
|
|
930
|
+
const n = new AbortController(), s = setTimeout(() => n.abort(), xe);
|
|
931
931
|
try {
|
|
932
932
|
const i = await fetch(e, {
|
|
933
933
|
method: "POST",
|
|
@@ -1792,7 +1792,7 @@ class Jt extends f {
|
|
|
1792
1792
|
this.processScrollEvent(s, i, o);
|
|
1793
1793
|
}
|
|
1794
1794
|
s.debounceTimer = null;
|
|
1795
|
-
},
|
|
1795
|
+
}, Ue));
|
|
1796
1796
|
}, n = this.getScrollTop(e), s = {
|
|
1797
1797
|
element: e,
|
|
1798
1798
|
lastScrollPos: n,
|
|
@@ -1801,7 +1801,7 @@ class Jt extends f {
|
|
|
1801
1801
|
this.getScrollHeight(e),
|
|
1802
1802
|
this.getViewportHeight(e)
|
|
1803
1803
|
),
|
|
1804
|
-
lastDirection:
|
|
1804
|
+
lastDirection: x.DOWN,
|
|
1805
1805
|
lastEventTime: 0,
|
|
1806
1806
|
debounceTimer: null,
|
|
1807
1807
|
listener: t
|
|
@@ -1845,7 +1845,7 @@ class Jt extends f {
|
|
|
1845
1845
|
e.debounceTimer !== null && (clearTimeout(e.debounceTimer), e.debounceTimer = null);
|
|
1846
1846
|
}
|
|
1847
1847
|
getScrollDirection(e, t) {
|
|
1848
|
-
return e > t ?
|
|
1848
|
+
return e > t ? x.DOWN : x.UP;
|
|
1849
1849
|
}
|
|
1850
1850
|
calculateScrollDepth(e, t, n) {
|
|
1851
1851
|
if (t <= n)
|
|
@@ -2388,7 +2388,7 @@ class nr extends f {
|
|
|
2388
2388
|
const e = () => {
|
|
2389
2389
|
this.set("suppressNextScroll", !0), this.suppressNextScrollTimer && clearTimeout(this.suppressNextScrollTimer), this.suppressNextScrollTimer = window.setTimeout(() => {
|
|
2390
2390
|
this.set("suppressNextScroll", !1);
|
|
2391
|
-
},
|
|
2391
|
+
}, Ue * ct);
|
|
2392
2392
|
};
|
|
2393
2393
|
this.handlers.pageView = new Xt(this.managers.event, e), this.handlers.pageView.startTracking(), this.handlers.click = new qt(this.managers.event), this.handlers.click.startTracking(), this.handlers.scroll = new Jt(this.managers.event), this.handlers.scroll.startTracking(), this.handlers.performance = new tr(this.managers.event), this.handlers.performance.startTracking().catch(() => {
|
|
2394
2394
|
a.warn("App", "Failed to start performance tracking");
|
|
@@ -2399,30 +2399,32 @@ let g = null, C = !1, q = !1;
|
|
|
2399
2399
|
const sr = async (r) => {
|
|
2400
2400
|
if (typeof window > "u" || typeof document > "u")
|
|
2401
2401
|
throw new Error("This library can only be used in a browser environment");
|
|
2402
|
-
if (
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
a.info("API", "Initializing TraceLog", { projectId: r.id });
|
|
2411
|
-
const e = Lt(r), t = new nr();
|
|
2402
|
+
if (!window.__traceLogDisabled) {
|
|
2403
|
+
if (g) {
|
|
2404
|
+
a.debug("API", "Library already initialized, skipping duplicate initialization");
|
|
2405
|
+
return;
|
|
2406
|
+
}
|
|
2407
|
+
if (C)
|
|
2408
|
+
throw a.warn("API", "Initialization already in progress"), new Error("Initialization already in progress");
|
|
2409
|
+
C = !0;
|
|
2412
2410
|
try {
|
|
2413
|
-
|
|
2414
|
-
|
|
2411
|
+
a.info("API", "Initializing TraceLog", { projectId: r.id });
|
|
2412
|
+
const e = Lt(r), t = new nr();
|
|
2415
2413
|
try {
|
|
2416
|
-
await t.
|
|
2417
|
-
} catch (
|
|
2418
|
-
|
|
2414
|
+
await t.init(e), g = t, a.info("API", "TraceLog initialized successfully", { projectId: e.id });
|
|
2415
|
+
} catch (n) {
|
|
2416
|
+
try {
|
|
2417
|
+
await t.destroy(!0);
|
|
2418
|
+
} catch (s) {
|
|
2419
|
+
a.warn("API", "Failed to cleanup partially initialized app", { cleanupError: s });
|
|
2420
|
+
}
|
|
2421
|
+
throw n;
|
|
2419
2422
|
}
|
|
2420
|
-
|
|
2423
|
+
} catch (e) {
|
|
2424
|
+
throw g = null, a.error("API", "Initialization failed", { error: e }), e;
|
|
2425
|
+
} finally {
|
|
2426
|
+
C = !1;
|
|
2421
2427
|
}
|
|
2422
|
-
} catch (e) {
|
|
2423
|
-
throw g = null, a.error("API", "Initialization failed", { error: e }), e;
|
|
2424
|
-
} finally {
|
|
2425
|
-
C = !1;
|
|
2426
2428
|
}
|
|
2427
2429
|
}, ir = (r, e) => {
|
|
2428
2430
|
if (!g)
|
|
@@ -2528,6 +2530,9 @@ const sr = async (r) => {
|
|
|
2528
2530
|
MIN_BASELINE_DAYS: 7,
|
|
2529
2531
|
MIN_EVENTS_FOR_ANOMALY_DETECTION: 50
|
|
2530
2532
|
}, Or = {
|
|
2533
|
+
PAGE_URL_EXCLUDED: "excluded",
|
|
2534
|
+
PAGE_URL_UNKNOWN: "unknown"
|
|
2535
|
+
}, Dr = {
|
|
2531
2536
|
init: sr,
|
|
2532
2537
|
event: ir,
|
|
2533
2538
|
on: ar,
|
|
@@ -2633,9 +2638,9 @@ var ae, je = -1, L = function(r) {
|
|
|
2633
2638
|
});
|
|
2634
2639
|
}), setTimeout(t, 0));
|
|
2635
2640
|
}));
|
|
2636
|
-
}, We = 0, J = 1 / 0,
|
|
2641
|
+
}, We = 0, J = 1 / 0, U = 0, hr = function(r) {
|
|
2637
2642
|
r.forEach(function(e) {
|
|
2638
|
-
e.interactionId && (J = Math.min(J, e.interactionId),
|
|
2643
|
+
e.interactionId && (J = Math.min(J, e.interactionId), U = Math.max(U, e.interactionId), We = U ? (U - J) / 7 + 1 : 0);
|
|
2639
2644
|
});
|
|
2640
2645
|
}, Be = function() {
|
|
2641
2646
|
return ae ? We : performance.interactionCount || 0;
|
|
@@ -2749,10 +2754,11 @@ export {
|
|
|
2749
2754
|
Ir as PERFORMANCE_CONFIG,
|
|
2750
2755
|
Nr as SEGMENTATION_ANALYTICS,
|
|
2751
2756
|
Ar as SESSION_ANALYTICS,
|
|
2752
|
-
|
|
2757
|
+
Or as SPECIAL_PAGE_URLS,
|
|
2758
|
+
x as ScrollDirection,
|
|
2753
2759
|
Lr as TEMPORAL_ANALYSIS,
|
|
2754
2760
|
It as TagConditionOperator,
|
|
2755
2761
|
Tt as TagConditionType,
|
|
2756
2762
|
yt as TagLogicalOperator,
|
|
2757
|
-
|
|
2763
|
+
Dr as tracelog
|
|
2758
2764
|
};
|
package/dist/cjs/api.js
CHANGED
|
@@ -21,6 +21,10 @@ const init = async (appConfig) => {
|
|
|
21
21
|
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
22
22
|
throw new Error('This library can only be used in a browser environment');
|
|
23
23
|
}
|
|
24
|
+
// Check if TraceLog is disabled
|
|
25
|
+
if (window.__traceLogDisabled) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
24
28
|
// Already initialized - safe to return
|
|
25
29
|
if (app) {
|
|
26
30
|
utils_1.debugLog.debug('API', 'Library already initialized, skipping duplicate initialization');
|
|
@@ -72,3 +72,7 @@ export declare const ANOMALY_DETECTION: {
|
|
|
72
72
|
readonly MIN_BASELINE_DAYS: 7;
|
|
73
73
|
readonly MIN_EVENTS_FOR_ANOMALY_DETECTION: 50;
|
|
74
74
|
};
|
|
75
|
+
export declare const SPECIAL_PAGE_URLS: {
|
|
76
|
+
readonly PAGE_URL_EXCLUDED: "excluded";
|
|
77
|
+
readonly PAGE_URL_UNKNOWN: "unknown";
|
|
78
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ANOMALY_DETECTION = exports.ANALYTICS_QUERY_LIMITS = exports.SEGMENTATION_ANALYTICS = exports.TEMPORAL_ANALYSIS = exports.INSIGHT_THRESHOLDS = exports.CONTENT_ANALYTICS = exports.DEVICE_ANALYTICS = exports.SESSION_ANALYTICS = exports.ENGAGEMENT_THRESHOLDS = exports.DATA_PROTECTION = exports.PERFORMANCE_CONFIG = void 0;
|
|
3
|
+
exports.SPECIAL_PAGE_URLS = exports.ANOMALY_DETECTION = exports.ANALYTICS_QUERY_LIMITS = exports.SEGMENTATION_ANALYTICS = exports.TEMPORAL_ANALYSIS = exports.INSIGHT_THRESHOLDS = exports.CONTENT_ANALYTICS = exports.DEVICE_ANALYTICS = exports.SESSION_ANALYTICS = exports.ENGAGEMENT_THRESHOLDS = exports.DATA_PROTECTION = exports.PERFORMANCE_CONFIG = void 0;
|
|
4
4
|
const performance_constants_1 = require("./constants/performance.constants");
|
|
5
5
|
const error_constants_1 = require("./constants/error.constants");
|
|
6
6
|
exports.PERFORMANCE_CONFIG = {
|
|
@@ -77,3 +77,7 @@ exports.ANOMALY_DETECTION = {
|
|
|
77
77
|
MIN_BASELINE_DAYS: 7,
|
|
78
78
|
MIN_EVENTS_FOR_ANOMALY_DETECTION: 50,
|
|
79
79
|
};
|
|
80
|
+
exports.SPECIAL_PAGE_URLS = {
|
|
81
|
+
PAGE_URL_EXCLUDED: 'excluded',
|
|
82
|
+
PAGE_URL_UNKNOWN: 'unknown',
|
|
83
|
+
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { TraceLogTestBridge } from './test-bridge.types';
|
|
2
2
|
declare global {
|
|
3
3
|
interface Window {
|
|
4
|
+
/**
|
|
5
|
+
* Flag to disable TraceLog initialization
|
|
6
|
+
* Set to true to prevent the library from running
|
|
7
|
+
*/
|
|
8
|
+
__traceLogDisabled?: boolean;
|
|
4
9
|
/**
|
|
5
10
|
* Testing bridge for E2E tests
|
|
6
11
|
* Only available when NODE_ENV=dev
|
package/dist/esm/api.js
CHANGED
|
@@ -18,6 +18,10 @@ export const init = async (appConfig) => {
|
|
|
18
18
|
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
19
19
|
throw new Error('This library can only be used in a browser environment');
|
|
20
20
|
}
|
|
21
|
+
// Check if TraceLog is disabled
|
|
22
|
+
if (window.__traceLogDisabled) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
21
25
|
// Already initialized - safe to return
|
|
22
26
|
if (app) {
|
|
23
27
|
debugLog.debug('API', 'Library already initialized, skipping duplicate initialization');
|
|
@@ -72,3 +72,7 @@ export declare const ANOMALY_DETECTION: {
|
|
|
72
72
|
readonly MIN_BASELINE_DAYS: 7;
|
|
73
73
|
readonly MIN_EVENTS_FOR_ANOMALY_DETECTION: 50;
|
|
74
74
|
};
|
|
75
|
+
export declare const SPECIAL_PAGE_URLS: {
|
|
76
|
+
readonly PAGE_URL_EXCLUDED: "excluded";
|
|
77
|
+
readonly PAGE_URL_UNKNOWN: "unknown";
|
|
78
|
+
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { TraceLogTestBridge } from './test-bridge.types';
|
|
2
2
|
declare global {
|
|
3
3
|
interface Window {
|
|
4
|
+
/**
|
|
5
|
+
* Flag to disable TraceLog initialization
|
|
6
|
+
* Set to true to prevent the library from running
|
|
7
|
+
*/
|
|
8
|
+
__traceLogDisabled?: boolean;
|
|
4
9
|
/**
|
|
5
10
|
* Testing bridge for E2E tests
|
|
6
11
|
* Only available when NODE_ENV=dev
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tracelog/lib",
|
|
3
3
|
"description": "JavaScript library for web analytics and real-time event tracking",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.3.0",
|
|
6
6
|
"main": "./dist/cjs/public-api.js",
|
|
7
7
|
"module": "./dist/esm/public-api.js",
|
|
8
8
|
"types": "./dist/esm/public-api.d.ts",
|