@tracelog/lib 0.5.5 → 0.6.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 +157 -180
- package/dist/browser/tracelog.esm.js +1007 -1357
- package/dist/browser/tracelog.js +2 -2
- package/dist/cjs/api.d.ts +12 -2
- package/dist/cjs/api.js +63 -27
- package/dist/cjs/app.d.ts +2 -2
- package/dist/cjs/app.js +26 -32
- package/dist/cjs/constants/config.constants.d.ts +4 -2
- package/dist/cjs/constants/config.constants.js +6 -18
- package/dist/cjs/constants/index.d.ts +0 -1
- package/dist/cjs/constants/index.js +0 -1
- package/dist/cjs/constants/storage.constants.d.ts +3 -2
- package/dist/cjs/constants/storage.constants.js +4 -4
- package/dist/cjs/handlers/click.handler.js +3 -6
- package/dist/cjs/handlers/error.handler.js +1 -11
- package/dist/cjs/handlers/page-view.handler.js +0 -4
- package/dist/cjs/handlers/performance.handler.js +14 -29
- package/dist/cjs/handlers/scroll.handler.js +7 -6
- package/dist/cjs/handlers/session.handler.js +7 -6
- package/dist/cjs/integrations/google-analytics.integration.js +2 -6
- package/dist/cjs/listeners/activity-listener-manager.js +3 -3
- package/dist/cjs/listeners/input-listener-managers.js +3 -3
- package/dist/cjs/listeners/touch-listener-manager.js +3 -3
- package/dist/cjs/listeners/unload-listener-manager.js +3 -3
- package/dist/cjs/listeners/visibility-listener-manager.js +3 -3
- package/dist/cjs/managers/event.manager.d.ts +2 -1
- package/dist/cjs/managers/event.manager.js +60 -38
- package/dist/cjs/managers/sender.manager.js +29 -36
- package/dist/cjs/managers/session.manager.js +5 -13
- package/dist/cjs/managers/state.manager.d.ts +0 -3
- package/dist/cjs/managers/state.manager.js +1 -43
- package/dist/cjs/managers/storage.manager.d.ts +16 -2
- package/dist/cjs/managers/storage.manager.js +73 -19
- package/dist/cjs/managers/user.manager.d.ts +1 -1
- package/dist/cjs/managers/user.manager.js +2 -2
- package/dist/cjs/public-api.d.ts +3 -3
- package/dist/cjs/public-api.js +1 -1
- package/dist/cjs/test-bridge.d.ts +1 -0
- package/dist/cjs/test-bridge.js +37 -2
- package/dist/cjs/types/config.types.d.ts +15 -18
- package/dist/cjs/types/config.types.js +6 -0
- package/dist/cjs/types/event.types.d.ts +1 -13
- package/dist/cjs/types/index.d.ts +0 -2
- package/dist/cjs/types/index.js +0 -2
- package/dist/cjs/types/mode.types.d.ts +1 -2
- package/dist/cjs/types/mode.types.js +0 -1
- package/dist/cjs/types/queue.types.d.ts +0 -6
- package/dist/cjs/types/state.types.d.ts +2 -0
- package/dist/cjs/types/test-bridge.types.d.ts +2 -2
- package/dist/cjs/types/validation-error.types.d.ts +0 -6
- package/dist/cjs/types/validation-error.types.js +1 -10
- package/dist/cjs/utils/browser/device-detector.utils.js +2 -24
- package/dist/cjs/utils/browser/index.d.ts +1 -0
- package/dist/cjs/utils/browser/index.js +1 -0
- package/dist/cjs/utils/browser/qa-mode.utils.d.ts +13 -0
- package/dist/cjs/utils/browser/qa-mode.utils.js +43 -0
- package/dist/cjs/utils/browser/utm-params.utils.js +0 -15
- package/dist/cjs/utils/data/uuid.utils.d.ts +13 -0
- package/dist/cjs/utils/data/uuid.utils.js +37 -1
- package/dist/cjs/utils/index.d.ts +1 -1
- package/dist/cjs/utils/index.js +1 -1
- package/dist/cjs/utils/logging.utils.d.ts +6 -0
- package/dist/cjs/utils/logging.utils.js +25 -0
- package/dist/cjs/utils/network/index.d.ts +0 -1
- package/dist/cjs/utils/network/index.js +0 -1
- package/dist/cjs/utils/network/url.utils.d.ts +2 -8
- package/dist/cjs/utils/network/url.utils.js +46 -90
- package/dist/cjs/utils/security/sanitize.utils.d.ts +1 -13
- package/dist/cjs/utils/security/sanitize.utils.js +15 -178
- package/dist/cjs/utils/validations/config-validations.utils.d.ts +3 -9
- package/dist/cjs/utils/validations/config-validations.utils.js +48 -94
- package/dist/cjs/utils/validations/event-validations.utils.js +11 -5
- package/dist/cjs/utils/validations/index.d.ts +0 -1
- package/dist/cjs/utils/validations/index.js +0 -1
- package/dist/cjs/utils/validations/metadata-validations.utils.js +0 -1
- package/dist/cjs/utils/validations/type-guards.utils.d.ts +2 -2
- package/dist/cjs/utils/validations/type-guards.utils.js +50 -4
- package/dist/esm/api.d.ts +12 -2
- package/dist/esm/api.js +62 -27
- package/dist/esm/app.d.ts +2 -2
- package/dist/esm/app.js +28 -34
- package/dist/esm/constants/config.constants.d.ts +4 -2
- package/dist/esm/constants/config.constants.js +4 -16
- package/dist/esm/constants/index.d.ts +0 -1
- package/dist/esm/constants/index.js +0 -1
- package/dist/esm/constants/storage.constants.d.ts +3 -2
- package/dist/esm/constants/storage.constants.js +3 -2
- package/dist/esm/handlers/click.handler.js +3 -6
- package/dist/esm/handlers/error.handler.js +1 -11
- package/dist/esm/handlers/page-view.handler.js +0 -4
- package/dist/esm/handlers/performance.handler.js +14 -29
- package/dist/esm/handlers/scroll.handler.js +7 -6
- package/dist/esm/handlers/session.handler.js +7 -6
- package/dist/esm/integrations/google-analytics.integration.js +3 -7
- package/dist/esm/listeners/activity-listener-manager.js +3 -3
- package/dist/esm/listeners/input-listener-managers.js +3 -3
- package/dist/esm/listeners/touch-listener-manager.js +3 -3
- package/dist/esm/listeners/unload-listener-manager.js +3 -3
- package/dist/esm/listeners/visibility-listener-manager.js +3 -3
- package/dist/esm/managers/event.manager.d.ts +2 -1
- package/dist/esm/managers/event.manager.js +62 -40
- package/dist/esm/managers/sender.manager.js +31 -38
- package/dist/esm/managers/session.manager.js +5 -13
- package/dist/esm/managers/state.manager.d.ts +0 -3
- package/dist/esm/managers/state.manager.js +1 -43
- package/dist/esm/managers/storage.manager.d.ts +16 -2
- package/dist/esm/managers/storage.manager.js +73 -19
- package/dist/esm/managers/user.manager.d.ts +1 -1
- package/dist/esm/managers/user.manager.js +2 -2
- package/dist/esm/public-api.d.ts +3 -3
- package/dist/esm/public-api.js +1 -1
- package/dist/esm/test-bridge.d.ts +1 -0
- package/dist/esm/test-bridge.js +37 -2
- package/dist/esm/types/config.types.d.ts +15 -18
- package/dist/esm/types/config.types.js +5 -1
- package/dist/esm/types/event.types.d.ts +1 -13
- package/dist/esm/types/index.d.ts +0 -2
- package/dist/esm/types/index.js +0 -2
- package/dist/esm/types/mode.types.d.ts +1 -2
- package/dist/esm/types/mode.types.js +0 -1
- package/dist/esm/types/queue.types.d.ts +0 -6
- package/dist/esm/types/state.types.d.ts +2 -0
- package/dist/esm/types/test-bridge.types.d.ts +2 -2
- package/dist/esm/types/validation-error.types.d.ts +0 -6
- package/dist/esm/types/validation-error.types.js +0 -8
- package/dist/esm/utils/browser/device-detector.utils.js +2 -24
- package/dist/esm/utils/browser/index.d.ts +1 -0
- package/dist/esm/utils/browser/index.js +1 -0
- package/dist/esm/utils/browser/qa-mode.utils.d.ts +13 -0
- package/dist/esm/utils/browser/qa-mode.utils.js +39 -0
- package/dist/esm/utils/browser/utm-params.utils.js +0 -15
- package/dist/esm/utils/data/uuid.utils.d.ts +13 -0
- package/dist/esm/utils/data/uuid.utils.js +35 -0
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/logging.utils.d.ts +6 -0
- package/dist/esm/utils/logging.utils.js +20 -0
- package/dist/esm/utils/network/index.d.ts +0 -1
- package/dist/esm/utils/network/index.js +0 -1
- package/dist/esm/utils/network/url.utils.d.ts +2 -8
- package/dist/esm/utils/network/url.utils.js +45 -88
- package/dist/esm/utils/security/sanitize.utils.d.ts +1 -13
- package/dist/esm/utils/security/sanitize.utils.js +15 -176
- package/dist/esm/utils/validations/config-validations.utils.d.ts +3 -9
- package/dist/esm/utils/validations/config-validations.utils.js +49 -94
- package/dist/esm/utils/validations/event-validations.utils.js +11 -5
- package/dist/esm/utils/validations/index.d.ts +0 -1
- package/dist/esm/utils/validations/index.js +0 -1
- package/dist/esm/utils/validations/metadata-validations.utils.js +0 -1
- package/dist/esm/utils/validations/type-guards.utils.d.ts +2 -2
- package/dist/esm/utils/validations/type-guards.utils.js +50 -4
- package/package.json +1 -1
- package/dist/cjs/app.types.d.ts +0 -2
- package/dist/cjs/app.types.js +0 -12
- package/dist/cjs/constants/api.constants.d.ts +0 -6
- package/dist/cjs/constants/api.constants.js +0 -14
- package/dist/cjs/managers/api.manager.d.ts +0 -13
- package/dist/cjs/managers/api.manager.js +0 -44
- package/dist/cjs/managers/config.builder.d.ts +0 -33
- package/dist/cjs/managers/config.builder.js +0 -116
- package/dist/cjs/managers/config.manager.d.ts +0 -56
- package/dist/cjs/managers/config.manager.js +0 -157
- package/dist/cjs/managers/tags.manager.d.ts +0 -36
- package/dist/cjs/managers/tags.manager.js +0 -171
- package/dist/cjs/types/api.types.d.ts +0 -52
- package/dist/cjs/types/api.types.js +0 -56
- package/dist/cjs/types/tag.types.d.ts +0 -43
- package/dist/cjs/types/tag.types.js +0 -31
- package/dist/cjs/utils/logging/debug-logger.utils.d.ts +0 -14
- package/dist/cjs/utils/logging/debug-logger.utils.js +0 -47
- package/dist/cjs/utils/logging/index.d.ts +0 -1
- package/dist/cjs/utils/logging/index.js +0 -5
- package/dist/cjs/utils/network/fetch-with-timeout.utils.d.ts +0 -4
- package/dist/cjs/utils/network/fetch-with-timeout.utils.js +0 -25
- package/dist/cjs/utils/validations/url-validations.utils.d.ts +0 -15
- package/dist/cjs/utils/validations/url-validations.utils.js +0 -47
- package/dist/esm/app.types.d.ts +0 -2
- package/dist/esm/app.types.js +0 -1
- package/dist/esm/constants/api.constants.d.ts +0 -6
- package/dist/esm/constants/api.constants.js +0 -11
- package/dist/esm/managers/api.manager.d.ts +0 -13
- package/dist/esm/managers/api.manager.js +0 -41
- package/dist/esm/managers/config.builder.d.ts +0 -33
- package/dist/esm/managers/config.builder.js +0 -112
- package/dist/esm/managers/config.manager.d.ts +0 -56
- package/dist/esm/managers/config.manager.js +0 -153
- package/dist/esm/managers/tags.manager.d.ts +0 -36
- package/dist/esm/managers/tags.manager.js +0 -167
- package/dist/esm/types/api.types.d.ts +0 -52
- package/dist/esm/types/api.types.js +0 -53
- package/dist/esm/types/tag.types.d.ts +0 -43
- package/dist/esm/types/tag.types.js +0 -28
- package/dist/esm/utils/logging/debug-logger.utils.d.ts +0 -14
- package/dist/esm/utils/logging/debug-logger.utils.js +0 -44
- package/dist/esm/utils/logging/index.d.ts +0 -1
- package/dist/esm/utils/logging/index.js +0 -1
- package/dist/esm/utils/network/fetch-with-timeout.utils.d.ts +0 -4
- package/dist/esm/utils/network/fetch-with-timeout.utils.js +0 -22
- package/dist/esm/utils/validations/url-validations.utils.d.ts +0 -15
- package/dist/esm/utils/validations/url-validations.utils.js +0 -42
package/README.md
CHANGED
|
@@ -6,14 +6,15 @@ A lightweight TypeScript library for web analytics and user behavior tracking. A
|
|
|
6
6
|
|
|
7
7
|
- **Zero-config tracking** - Automatically captures clicks, scrolls, page navigation, and web vitals out of the box.
|
|
8
8
|
- **Cross-tab session management** - Maintains consistent user sessions across multiple browser tabs with automatic recovery.
|
|
9
|
-
- **
|
|
9
|
+
- **Client-only architecture** - Fully autonomous with optional backend integrations (TraceLog SaaS, custom API, Google Analytics).
|
|
10
|
+
- **Privacy-first** - Built-in PII sanitization and client-side sampling controls.
|
|
10
11
|
- **Framework agnostic** - Works with vanilla JS, React, Vue, Angular, or any web application.
|
|
11
12
|
- **Lightweight** - Only one dependency (`web-vitals`) with dual ESM/CJS support.
|
|
12
13
|
- **Event-driven** - Real-time event subscription with `on()` and `off()` methods for custom integrations.
|
|
13
14
|
|
|
14
15
|
## Installation
|
|
15
16
|
|
|
16
|
-
**Prerequisites**: Modern browser with ES6+ support.
|
|
17
|
+
**Prerequisites**: Modern browser with ES6+ support.
|
|
17
18
|
|
|
18
19
|
## 📦 Which File Should I Use?
|
|
19
20
|
|
|
@@ -33,7 +34,16 @@ npm install @tracelog/lib
|
|
|
33
34
|
```typescript
|
|
34
35
|
import { tracelog } from '@tracelog/lib';
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
// Standalone mode (no backend required)
|
|
38
|
+
tracelog.init({});
|
|
39
|
+
|
|
40
|
+
// OR with TraceLog SaaS integration
|
|
41
|
+
tracelog.init({
|
|
42
|
+
integrations: {
|
|
43
|
+
tracelog: { projectId: 'your-project-id' }
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
37
47
|
tracelog.event('user_action', { data: 'example' });
|
|
38
48
|
```
|
|
39
49
|
|
|
@@ -45,7 +55,15 @@ tracelog.event('user_action', { data: 'example' });
|
|
|
45
55
|
```html
|
|
46
56
|
<script src="https://cdn.jsdelivr.net/npm/@tracelog/lib@latest/dist/browser/tracelog.js"></script>
|
|
47
57
|
<script>
|
|
48
|
-
|
|
58
|
+
// Standalone mode
|
|
59
|
+
tracelog.init({});
|
|
60
|
+
|
|
61
|
+
// OR with TraceLog SaaS
|
|
62
|
+
tracelog.init({
|
|
63
|
+
integrations: {
|
|
64
|
+
tracelog: { projectId: 'your-project-id' }
|
|
65
|
+
}
|
|
66
|
+
});
|
|
49
67
|
</script>
|
|
50
68
|
```
|
|
51
69
|
|
|
@@ -58,7 +76,7 @@ tracelog.event('user_action', { data: 'example' });
|
|
|
58
76
|
<script type="module">
|
|
59
77
|
import { tracelog } from 'https://cdn.jsdelivr.net/npm/@tracelog/lib@latest/dist/browser/tracelog.esm.js';
|
|
60
78
|
|
|
61
|
-
await tracelog.init({
|
|
79
|
+
await tracelog.init({}); // Standalone mode
|
|
62
80
|
tracelog.event('page_view');
|
|
63
81
|
</script>
|
|
64
82
|
```
|
|
@@ -66,101 +84,153 @@ tracelog.event('user_action', { data: 'example' });
|
|
|
66
84
|
**✅ Best for:** Modern browsers, no bundler, prefer native modules
|
|
67
85
|
**⚠️ Note:** Won't work in IE11 or older browsers
|
|
68
86
|
|
|
69
|
-
|
|
87
|
+
## How It Works
|
|
88
|
+
|
|
89
|
+
- **Standalone Mode** (no `integrations`): Events captured and emitted locally via `on('event')`. No network requests.
|
|
90
|
+
- **With Backend** (`integrations.tracelog` or `integrations.custom`): Events sent to configured endpoint after client-side validation.
|
|
91
|
+
|
|
92
|
+
All validation, sampling, and deduplication happen client-side. Enable QA mode with `?tlog_mode=qa` URL parameter.
|
|
70
93
|
|
|
71
94
|
## Usage
|
|
72
95
|
|
|
73
|
-
**Basic tracking with configuration:**
|
|
74
96
|
```typescript
|
|
97
|
+
// Standalone mode
|
|
75
98
|
await tracelog.init({
|
|
76
|
-
|
|
77
|
-
|
|
99
|
+
sessionTimeout: 30 * 60 * 1000,
|
|
100
|
+
samplingRate: 1.0
|
|
78
101
|
});
|
|
79
|
-
```
|
|
80
102
|
|
|
81
|
-
|
|
82
|
-
|
|
103
|
+
// With TraceLog SaaS
|
|
104
|
+
await tracelog.init({
|
|
105
|
+
integrations: {
|
|
106
|
+
tracelog: { projectId: 'your-project-id' }
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// With custom backend
|
|
111
|
+
await tracelog.init({
|
|
112
|
+
integrations: {
|
|
113
|
+
custom: { apiUrl: 'https://your-api.com/collect' }
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Custom events
|
|
83
118
|
tracelog.event('product_viewed', {
|
|
84
119
|
productId: 'abc-123',
|
|
85
120
|
category: 'electronics',
|
|
86
|
-
price: 299.99
|
|
87
|
-
tags: ['featured', 'sale']
|
|
121
|
+
price: 299.99
|
|
88
122
|
});
|
|
89
|
-
```
|
|
90
123
|
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
124
|
+
// Privacy controls
|
|
93
125
|
await tracelog.init({
|
|
94
|
-
id: 'your-project-id',
|
|
95
126
|
sensitiveQueryParams: ['token', 'session_id'],
|
|
96
|
-
|
|
97
|
-
errorSampling: 0.1
|
|
127
|
+
samplingRate: 0.5,
|
|
128
|
+
errorSampling: 0.1
|
|
98
129
|
});
|
|
99
130
|
```
|
|
100
131
|
|
|
101
132
|
## API
|
|
102
133
|
|
|
103
|
-
**
|
|
104
|
-
- `init(config
|
|
105
|
-
- `event(name: string, metadata?: Record<string, MetadataType>): void` - Send custom event
|
|
106
|
-
- `on(event: string, callback: Function): void` - Subscribe to events
|
|
107
|
-
- `off(event: string, callback: Function): void` - Unsubscribe from events
|
|
108
|
-
- `isInitialized(): boolean` - Check
|
|
109
|
-
- `destroy(): Promise<void>` - Clean up
|
|
110
|
-
|
|
111
|
-
**
|
|
112
|
-
- `
|
|
113
|
-
- `
|
|
114
|
-
- `
|
|
115
|
-
- `
|
|
116
|
-
- `
|
|
117
|
-
- `
|
|
118
|
-
- `
|
|
119
|
-
- `
|
|
120
|
-
- `
|
|
121
|
-
- `
|
|
122
|
-
- `
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
**Methods:**
|
|
135
|
+
- `init(config?: Config): Promise<void>` - Initialize tracking
|
|
136
|
+
- `event(name: string, metadata?: Record<string, MetadataType>): void` - Send custom event
|
|
137
|
+
- `on(event: string, callback: Function): void` - Subscribe to events
|
|
138
|
+
- `off(event: string, callback: Function): void` - Unsubscribe from events
|
|
139
|
+
- `isInitialized(): boolean` - Check initialization status
|
|
140
|
+
- `destroy(): Promise<void>` - Clean up and remove listeners
|
|
141
|
+
|
|
142
|
+
**Config (all optional):**
|
|
143
|
+
- `sessionTimeout`: Session timeout in ms (default: 900000)
|
|
144
|
+
- `globalMetadata`: Metadata attached to all events
|
|
145
|
+
- `samplingRate`: Event sampling rate 0-1 (default: 1.0)
|
|
146
|
+
- `errorSampling`: Error sampling rate 0-1 (default: 1.0)
|
|
147
|
+
- `sensitiveQueryParams`: Query params to remove from URLs
|
|
148
|
+
- `allowHttp`: Enable HTTP for testing
|
|
149
|
+
- `scrollContainerSelectors`: Custom scroll containers
|
|
150
|
+
- `integrations`:
|
|
151
|
+
- `tracelog.projectId`: TraceLog SaaS
|
|
152
|
+
- `custom.apiUrl`: Custom backend
|
|
153
|
+
- `googleAnalytics.measurementId`: GA4
|
|
154
|
+
|
|
155
|
+
## Event Data Structure
|
|
156
|
+
|
|
157
|
+
Each event contains a base structure with type-specific data:
|
|
158
|
+
|
|
159
|
+
**Base fields (all events):**
|
|
160
|
+
- `id`: Unique event identifier
|
|
161
|
+
- `type`: Event type (see below)
|
|
162
|
+
- `page_url`: Current page URL
|
|
163
|
+
- `timestamp`: Unix timestamp in milliseconds
|
|
164
|
+
- `referrer`: Document referrer (optional)
|
|
165
|
+
- `utm`: UTM parameters (source, medium, campaign, term, content)
|
|
166
|
+
|
|
167
|
+
**Event-specific data:**
|
|
168
|
+
|
|
169
|
+
- **`PAGE_VIEW`**: Navigation tracking
|
|
170
|
+
- `page_view.title`: Page title
|
|
171
|
+
- `page_view.pathname`: URL pathname
|
|
172
|
+
- `page_view.search`: Query string
|
|
173
|
+
- `page_view.hash`: URL hash
|
|
174
|
+
|
|
175
|
+
- **`CLICK`**: User interactions
|
|
176
|
+
- `click_data.x/y`: Viewport coordinates
|
|
177
|
+
- `click_data.relativeX/relativeY`: Element-relative position
|
|
178
|
+
- `click_data.tag/id/class`: Element identifiers
|
|
179
|
+
- `click_data.text/href/title`: Element content
|
|
180
|
+
- `click_data.role/ariaLabel`: Accessibility attributes
|
|
181
|
+
- `click_data.dataAttributes`: Data attributes
|
|
182
|
+
|
|
183
|
+
- **`SCROLL`**: Scroll engagement
|
|
184
|
+
- `scroll_data.depth`: Scroll depth percentage (0-100)
|
|
185
|
+
- `scroll_data.direction`: Scroll direction (up/down)
|
|
186
|
+
|
|
187
|
+
- **`SESSION_START`**: Session initialization
|
|
188
|
+
- No additional data
|
|
189
|
+
|
|
190
|
+
- **`SESSION_END`**: Session termination
|
|
191
|
+
- `session_end_reason`: Reason (timeout, manual, tab_close)
|
|
192
|
+
|
|
193
|
+
- **`CUSTOM`**: Business-specific events
|
|
194
|
+
- `custom_event.name`: Event name
|
|
195
|
+
- `custom_event.metadata`: Custom data (any JSON-serializable value)
|
|
196
|
+
|
|
197
|
+
- **`WEB_VITALS`**: Performance metrics
|
|
198
|
+
- `web_vitals.type`: Metric type (LCP, CLS, INP, FCP, TTFB, LONG_TASK)
|
|
199
|
+
- `web_vitals.value`: Metric value in milliseconds
|
|
200
|
+
|
|
201
|
+
- **`ERROR`**: JavaScript errors
|
|
202
|
+
- `error_data.type`: Error type (js_error, promise_rejection)
|
|
203
|
+
- `error_data.message`: Error message
|
|
204
|
+
- `error_data.filename/line/column`: Error location
|
|
205
|
+
|
|
206
|
+
## Advanced
|
|
207
|
+
|
|
208
|
+
**Event subscription:**
|
|
130
209
|
```typescript
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
**Environment-based settings:**
|
|
136
|
-
- Use `samplingRate: 0.1` to reduce data volume in high-traffic applications
|
|
137
|
-
- Configure `sessionTimeout` to match your application's user session length
|
|
210
|
+
// Important: Register listeners BEFORE init() to capture initial events (SESSION_START, PAGE_VIEW)
|
|
211
|
+
tracelog.on('event', (data) => console.log('Event:', data.type));
|
|
212
|
+
tracelog.on('queue', (data) => console.log('Queued:', data.events.length));
|
|
138
213
|
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
// Subscribe to individual events as they are tracked
|
|
142
|
-
tracelog.on('event', (eventData) => {
|
|
143
|
-
console.log('Event tracked:', eventData.type, eventData);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// Subscribe to event queue batches being sent
|
|
147
|
-
tracelog.on('queue', (queueData) => {
|
|
148
|
-
console.log('Events queued for sending:', queueData.events.length);
|
|
149
|
-
});
|
|
214
|
+
await tracelog.init({});
|
|
150
215
|
```
|
|
151
216
|
|
|
152
|
-
**
|
|
217
|
+
**Note**: Listeners are buffered if registered before `init()`, ensuring you don't miss initial events.
|
|
218
|
+
|
|
219
|
+
**Multiple integrations:**
|
|
153
220
|
```typescript
|
|
154
221
|
await tracelog.init({
|
|
155
|
-
id: 'your-project-id',
|
|
156
222
|
integrations: {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
223
|
+
tracelog: { projectId: 'your-project-id' },
|
|
224
|
+
googleAnalytics: { measurementId: 'G-XXXXXXXXXX' }
|
|
160
225
|
}
|
|
161
226
|
});
|
|
162
227
|
```
|
|
163
228
|
|
|
229
|
+
**Disable globally:**
|
|
230
|
+
```typescript
|
|
231
|
+
window.__traceLogDisabled = true;
|
|
232
|
+
```
|
|
233
|
+
|
|
164
234
|
## Compatibility
|
|
165
235
|
|
|
166
236
|
- **Runtime**: Modern browsers (Chrome 60+, Firefox 55+, Safari 12+)
|
|
@@ -168,52 +238,20 @@ await tracelog.init({
|
|
|
168
238
|
- **TypeScript**: Full type definitions included
|
|
169
239
|
- **Frameworks**: React, Vue, Angular, Svelte, vanilla JS
|
|
170
240
|
|
|
171
|
-
##
|
|
172
|
-
|
|
173
|
-
**Development mode** → Set `NODE_ENV=dev` for event-based logging to `window` → Use browser console for runtime debugging.
|
|
241
|
+
## Debug
|
|
174
242
|
|
|
175
|
-
|
|
243
|
+
Enable QA mode: `?tlog_mode=qa` URL parameter
|
|
176
244
|
|
|
177
245
|
```typescript
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
id: 'your-project-id',
|
|
181
|
-
mode: 'debug' // or 'qa' for less verbose logging
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
// Debug logs are automatically shown in console based on mode
|
|
185
|
-
// No additional event listeners needed
|
|
186
|
-
|
|
187
|
-
// Check if library is initialized
|
|
188
|
-
if (tracelog.isInitialized()) {
|
|
189
|
-
console.log('TraceLog is ready');
|
|
190
|
-
}
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
## CI/CD Integration
|
|
194
|
-
|
|
195
|
-
**Automated testing** → Validates library integrity before deployment → Detects critical issues early.
|
|
196
|
-
|
|
197
|
-
```bash
|
|
198
|
-
# Install and run tests
|
|
199
|
-
npm ci && npx playwright install --with-deps
|
|
200
|
-
npm run build:all
|
|
201
|
-
npm run test:e2e # E2E tests for validation
|
|
246
|
+
tracelog.init({});
|
|
247
|
+
console.log(tracelog.isInitialized()); // true
|
|
202
248
|
```
|
|
203
249
|
|
|
204
|
-
**GitHub Actions** → Pre-configured workflows available:
|
|
205
|
-
- `health-check.yml` - Runs on PR and push
|
|
206
|
-
- `release-quality-gate.yml` - Validates releases
|
|
207
|
-
|
|
208
|
-
**Exit codes** → `0` = tests passed → `1` = critical issues detected
|
|
209
|
-
|
|
210
250
|
## Troubleshooting
|
|
211
251
|
|
|
212
|
-
**Session
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
**CI test failures** → Verify Playwright installation → Check Node.js ≥20 → Review test patterns.
|
|
252
|
+
- **Session issues**: Check localStorage availability and session timeout
|
|
253
|
+
- **Memory usage**: Reduce `sessionTimeout`, lower `samplingRate`, call `destroy()` on cleanup
|
|
254
|
+
- **CI failures**: Verify Playwright installation and Node.js ≥20
|
|
217
255
|
|
|
218
256
|
## Development & Contributing
|
|
219
257
|
|
|
@@ -229,83 +267,22 @@ npm run test:unit # Run unit tests
|
|
|
229
267
|
npm run test:coverage # Run tests with coverage
|
|
230
268
|
```
|
|
231
269
|
|
|
232
|
-
###
|
|
233
|
-
|
|
234
|
-
This project uses a **branch protection strategy** to ensure code quality:
|
|
235
|
-
|
|
236
|
-
1. **Feature Development:**
|
|
237
|
-
```bash
|
|
238
|
-
git checkout -b feature/your-feature-name
|
|
239
|
-
# Make your changes
|
|
240
|
-
git commit -m "feat: add new feature"
|
|
241
|
-
git push origin feature/your-feature-name
|
|
242
|
-
```
|
|
270
|
+
### Workflow
|
|
243
271
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
- Build integrity
|
|
250
|
-
- E2E tests
|
|
251
|
-
- PR cannot be merged until CI passes
|
|
252
|
-
- Code review required
|
|
272
|
+
1. Create feature branch
|
|
273
|
+
2. Submit PR to `main`
|
|
274
|
+
3. CI validates: security, quality, build, tests
|
|
275
|
+
4. Merge after approval
|
|
276
|
+
5. Release via GitHub Actions
|
|
253
277
|
|
|
254
|
-
|
|
255
|
-
- Once merged to `main`, code is validated and ready
|
|
256
|
-
- Run Release workflow manually from GitHub Actions
|
|
257
|
-
- Automatic version bump, changelog, and NPM publish
|
|
258
|
-
|
|
259
|
-
### Quality Standards
|
|
260
|
-
- **Code Quality**: ESLint + Prettier enforced in CI
|
|
261
|
-
- **Type Safety**: TypeScript strict mode required
|
|
262
|
-
- **Testing**: Unit tests with Vitest, E2E tests with Playwright for all features
|
|
263
|
-
- **Security**: Dependency vulnerability scanning
|
|
264
|
-
- **Coverage**: Comprehensive test coverage with automated reporting
|
|
265
|
-
|
|
266
|
-
## Versioning
|
|
267
|
-
|
|
268
|
-
Follows [Semantic Versioning](https://semver.org/) (MAJOR.MINOR.PATCH). Breaking changes are documented in release notes with migration guides.
|
|
269
|
-
|
|
270
|
-
## Testing & Validation
|
|
271
|
-
|
|
272
|
-
Verify the installation works correctly:
|
|
273
|
-
|
|
274
|
-
### Quick Validation
|
|
275
|
-
|
|
276
|
-
Open DevTools Console and check for:
|
|
277
|
-
1. `[TraceLog:App] Initializing TraceLog` - Library loaded
|
|
278
|
-
2. `[TraceLog:SessionManager] Session started` - Session active
|
|
279
|
-
3. No errors or warnings
|
|
280
|
-
4. Events logged when you interact with the page
|
|
281
|
-
|
|
282
|
-
### Manual Test
|
|
283
|
-
|
|
284
|
-
```javascript
|
|
285
|
-
// Should work after installation
|
|
286
|
-
tracelog.init({
|
|
287
|
-
id: 'skip', // Use 'skip' for local testing
|
|
288
|
-
mode: 'debug' // Enables console logging
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
// Send a test event
|
|
292
|
-
tracelog.event('test_event', { foo: 'bar' });
|
|
293
|
-
|
|
294
|
-
// Check DevTools Console for:
|
|
295
|
-
// [TraceLog:EventManager] Tracking event: test_event
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
### Playground
|
|
299
|
-
|
|
300
|
-
The library includes a full demo at [`playground/index.html`](playground/index.html):
|
|
278
|
+
## Testing
|
|
301
279
|
|
|
302
280
|
```bash
|
|
303
|
-
npm run playground:setup #
|
|
304
|
-
npm run
|
|
281
|
+
npm run playground:setup && npm run serve # Demo at localhost:3000
|
|
282
|
+
npm run test:unit # Unit tests
|
|
283
|
+
npm run test:e2e # E2E tests
|
|
305
284
|
```
|
|
306
285
|
|
|
307
|
-
Open http://localhost:3000 to see TraceLog in action with real-time event monitoring.
|
|
308
|
-
|
|
309
286
|
## License
|
|
310
287
|
|
|
311
288
|
MIT © TraceLog. See [LICENSE](LICENSE) file for details.
|