@tracelog/lib 2.0.2 → 2.0.3
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 +70 -25
- package/dist/browser/tracelog.esm.js +263 -284
- 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/public-api.cjs +10 -51
- package/dist/public-api.cjs.map +1 -1
- package/dist/public-api.d.mts +59 -78
- package/dist/public-api.d.ts +59 -78
- package/dist/public-api.js +10 -51
- package/dist/public-api.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -172,18 +172,14 @@ await tracelog.init({
|
|
|
172
172
|
samplingRate: 1.0, // 100% (default)
|
|
173
173
|
sensitiveQueryParams: ['token'], // Add to defaults
|
|
174
174
|
|
|
175
|
-
// Event Control
|
|
176
|
-
disabledEvents: ['scroll'], // Disable specific auto-tracked events
|
|
177
|
-
// Options: 'scroll', 'web_vitals', 'error'
|
|
178
|
-
|
|
179
175
|
// Integrations (pick one, multiple, or none)
|
|
180
176
|
integrations: {
|
|
181
177
|
tracelog: { projectId: 'your-id' }, // TraceLog SaaS
|
|
182
178
|
custom: { collectApiUrl: 'https://api.com' }, // Custom backend
|
|
183
179
|
|
|
184
180
|
// Multi-integration: Send to multiple backends simultaneously
|
|
185
|
-
// tracelog: { projectId: 'proj-123' },
|
|
186
|
-
// custom: { collectApiUrl: 'https://warehouse.com' }
|
|
181
|
+
// tracelog: { projectId: 'proj-123' }, // Analytics dashboard
|
|
182
|
+
// custom: { collectApiUrl: 'https://warehouse.com' } // Data warehouse
|
|
187
183
|
// Events sent to BOTH independently with separate error handling
|
|
188
184
|
},
|
|
189
185
|
|
|
@@ -207,37 +203,86 @@ await tracelog.init({
|
|
|
207
203
|
|
|
208
204
|
TraceLog captures these events automatically (no code required):
|
|
209
205
|
|
|
210
|
-
| Event Type | What It Tracks |
|
|
211
|
-
|
|
212
|
-
| `page_view` | Navigation, SPA route changes |
|
|
213
|
-
| `click` | User interactions with elements |
|
|
214
|
-
| `session_start` | New session creation |
|
|
215
|
-
| `scroll` | Scroll depth, velocity, engagement |
|
|
216
|
-
| `web_vitals` | Core Web Vitals (LCP, INP, CLS, FCP, TTFB) |
|
|
217
|
-
| `error` | JavaScript errors, promise rejections |
|
|
218
|
-
| `viewport_visible`| Element visibility (requires `viewport` config) |
|
|
206
|
+
| Event Type | What It Tracks |
|
|
207
|
+
|-------------------|---------------------------------------------|
|
|
208
|
+
| `page_view` | Navigation, SPA route changes |
|
|
209
|
+
| `click` | User interactions with elements |
|
|
210
|
+
| `session_start` | New session creation |
|
|
211
|
+
| `scroll` | Scroll depth, velocity, engagement |
|
|
212
|
+
| `web_vitals` | Core Web Vitals (LCP, INP, CLS, FCP, TTFB) |
|
|
213
|
+
| `error` | JavaScript errors, promise rejections |
|
|
214
|
+
| `viewport_visible`| Element visibility (requires `viewport` config) |
|
|
219
215
|
|
|
220
|
-
**
|
|
216
|
+
**Filtering Events:**
|
|
221
217
|
|
|
222
|
-
You can
|
|
218
|
+
You can filter specific events before they're sent to your backend using the `beforeSend` transformer. This gives you complete control over what data is transmitted.
|
|
223
219
|
|
|
224
220
|
```typescript
|
|
225
|
-
//
|
|
221
|
+
// Filter out high-volume events (scroll, web_vitals)
|
|
222
|
+
tracelog.setTransformer('beforeSend', (event) => {
|
|
223
|
+
// Skip scroll and web vitals events
|
|
224
|
+
if (['scroll', 'web_vitals'].includes(event.type)) {
|
|
225
|
+
return null; // Returning null excludes the event from being sent
|
|
226
|
+
}
|
|
227
|
+
return event; // Send all other events normally
|
|
228
|
+
});
|
|
229
|
+
|
|
226
230
|
await tracelog.init({
|
|
227
|
-
|
|
231
|
+
integrations: {
|
|
232
|
+
custom: { collectApiUrl: 'https://api.example.com' }
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**Advanced Filtering:**
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
// Conditional filtering based on custom logic
|
|
241
|
+
tracelog.setTransformer('beforeSend', (event) => {
|
|
242
|
+
// Only send errors in production
|
|
243
|
+
if (event.type === 'error' && process.env.NODE_ENV !== 'production') {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Only send 10% of scroll events (sampling)
|
|
248
|
+
if (event.type === 'scroll' && Math.random() > 0.1) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return event;
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**Multi-Integration Behavior:**
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
// Transformers ONLY apply to custom backends
|
|
260
|
+
// TraceLog SaaS always receives all events unmodified
|
|
261
|
+
tracelog.setTransformer('beforeSend', (event) => {
|
|
262
|
+
if (['scroll', 'web_vitals'].includes(event.type)) {
|
|
263
|
+
return null; // Filtered from custom backend only
|
|
264
|
+
}
|
|
265
|
+
return event;
|
|
228
266
|
});
|
|
229
267
|
|
|
230
|
-
// Disable multiple event types
|
|
231
268
|
await tracelog.init({
|
|
232
|
-
|
|
269
|
+
integrations: {
|
|
270
|
+
tracelog: { projectId: 'proj-123' }, // Gets ALL events (unfiltered)
|
|
271
|
+
custom: { collectApiUrl: 'https://warehouse.com' } // Gets filtered events
|
|
272
|
+
}
|
|
233
273
|
});
|
|
234
274
|
```
|
|
235
275
|
|
|
276
|
+
**Important:** Transformers (`beforeSend`, `beforeBatch`) only apply to **custom backend integrations**. TraceLog SaaS always receives all events unmodified to maintain schema integrity and ensure complete analytics. This behavior is the same as the removed `disabledEvents` configuration.
|
|
277
|
+
|
|
236
278
|
**Use Cases:**
|
|
237
|
-
- Reduce bandwidth and backend costs
|
|
238
|
-
- Already using Sentry/Datadog for errors
|
|
239
|
-
-
|
|
240
|
-
- Minimize data
|
|
279
|
+
- Reduce bandwidth and backend costs for custom backends
|
|
280
|
+
- Already using Sentry/Datadog for errors (filter out `error` events from custom backend)
|
|
281
|
+
- Data warehouse doesn't need scroll/vitals granularity
|
|
282
|
+
- Minimize custom backend data volume for privacy compliance
|
|
283
|
+
- Custom sampling logic per event type
|
|
284
|
+
|
|
285
|
+
**Note:** Filtered events are still captured locally. Use `tracelog.on('event')` to access all events client-side, even those excluded from backend transmission.
|
|
241
286
|
|
|
242
287
|
**Custom Events:**
|
|
243
288
|
```typescript
|