@tracelog/lib 2.1.2-rc.78.4 → 2.1.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 +4 -97
- package/dist/browser/tracelog.esm.js +441 -570
- 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 +6 -171
- package/dist/public-api.cjs.map +1 -1
- package/dist/public-api.d.mts +2 -45
- package/dist/public-api.d.ts +2 -45
- package/dist/public-api.js +6 -171
- package/dist/public-api.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,29 +81,24 @@ tracelog.setTransformer('beforeSend', (event) => {
|
|
|
81
81
|
return { ...event, custom_metadata: { app: 'v1' } };
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
-
// 4.
|
|
85
|
-
tracelog.setCustomHeaders(() => ({
|
|
86
|
-
'Authorization': `Bearer ${getAuthToken()}`
|
|
87
|
-
}));
|
|
88
|
-
|
|
89
|
-
// 5. Initialize FIFTH (starts tracking immediately)
|
|
84
|
+
// 4. Initialize FOURTH (starts tracking immediately)
|
|
90
85
|
await tracelog.init({
|
|
91
86
|
integrations: {
|
|
92
87
|
custom: { collectApiUrl: 'https://api.example.com' }
|
|
93
88
|
}
|
|
94
89
|
});
|
|
95
90
|
|
|
96
|
-
//
|
|
91
|
+
// 5. Track custom events (after init)
|
|
97
92
|
tracelog.event('button_clicked', {
|
|
98
93
|
buttonId: 'signup-cta',
|
|
99
94
|
source: 'homepage'
|
|
100
95
|
});
|
|
101
96
|
|
|
102
|
-
//
|
|
97
|
+
// 6. Cleanup (on consent revoke or app unmount)
|
|
103
98
|
tracelog.destroy();
|
|
104
99
|
```
|
|
105
100
|
|
|
106
|
-
**Why this order?** You must obtain user consent before initializing. Events like `SESSION_START` and `PAGE_VIEW` fire during initialization. Registering listeners
|
|
101
|
+
**Why this order?** You must obtain user consent before initializing. Events like `SESSION_START` and `PAGE_VIEW` fire during initialization. Registering listeners and transformers before init ensures you don't miss them.
|
|
107
102
|
|
|
108
103
|
**That's it!** TraceLog now automatically tracks:
|
|
109
104
|
- Page views & navigation (including SPA routes)
|
|
@@ -127,8 +122,6 @@ tracelog.destroy();
|
|
|
127
122
|
| `off(event, callback)` | Unsubscribe from events |
|
|
128
123
|
| `setTransformer(hook, fn)` | Transform events before sending (see [Transformers](#transformers)) |
|
|
129
124
|
| `removeTransformer(hook)` | Remove a previously set transformer |
|
|
130
|
-
| `setCustomHeaders(provider)` | Add custom HTTP headers to requests (see [Custom Headers](#custom-headers)) |
|
|
131
|
-
| `removeCustomHeaders()` | Remove custom headers provider |
|
|
132
125
|
| `isInitialized()` | Check initialization status |
|
|
133
126
|
| `setQaMode(enabled)` | Enable/disable QA mode (console logging) |
|
|
134
127
|
| `destroy()` | Stop tracking and cleanup |
|
|
@@ -599,92 +592,6 @@ tracelog.setTransformer('beforeSend', (data) => {
|
|
|
599
592
|
|
|
600
593
|
---
|
|
601
594
|
|
|
602
|
-
## Custom Headers
|
|
603
|
-
|
|
604
|
-
Add custom HTTP headers to requests sent to custom backends. Useful for authentication, tenant identification, or API versioning.
|
|
605
|
-
|
|
606
|
-
**Important**: Custom headers **only apply to custom backend integrations**. TraceLog SaaS always receives requests without custom headers.
|
|
607
|
-
|
|
608
|
-
### Static Headers (Config)
|
|
609
|
-
|
|
610
|
-
Set fixed headers in configuration:
|
|
611
|
-
|
|
612
|
-
```typescript
|
|
613
|
-
await tracelog.init({
|
|
614
|
-
integrations: {
|
|
615
|
-
custom: {
|
|
616
|
-
collectApiUrl: 'https://api.example.com/collect',
|
|
617
|
-
headers: {
|
|
618
|
-
'X-Tenant-Id': 'tenant-123',
|
|
619
|
-
'X-Brand': 'my-brand',
|
|
620
|
-
'X-API-Version': '2.0'
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
});
|
|
625
|
-
```
|
|
626
|
-
|
|
627
|
-
### Dynamic Headers (Provider)
|
|
628
|
-
|
|
629
|
-
Set headers dynamically at runtime (e.g., auth tokens that expire):
|
|
630
|
-
|
|
631
|
-
```typescript
|
|
632
|
-
// Set before or after init
|
|
633
|
-
tracelog.setCustomHeaders(() => ({
|
|
634
|
-
'Authorization': `Bearer ${getAuthToken()}`,
|
|
635
|
-
'X-Request-ID': crypto.randomUUID()
|
|
636
|
-
}));
|
|
637
|
-
|
|
638
|
-
await tracelog.init({
|
|
639
|
-
integrations: {
|
|
640
|
-
custom: { collectApiUrl: 'https://api.example.com/collect' }
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
```
|
|
644
|
-
|
|
645
|
-
### Static + Dynamic Headers
|
|
646
|
-
|
|
647
|
-
Combine both approaches. Dynamic headers override static on key collision:
|
|
648
|
-
|
|
649
|
-
```typescript
|
|
650
|
-
await tracelog.init({
|
|
651
|
-
integrations: {
|
|
652
|
-
custom: {
|
|
653
|
-
collectApiUrl: 'https://api.example.com/collect',
|
|
654
|
-
headers: {
|
|
655
|
-
'X-Brand': 'static-brand', // Static
|
|
656
|
-
'X-Tenant-Id': 'tenant-123' // Static
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
});
|
|
661
|
-
|
|
662
|
-
// Dynamic provider overrides 'X-Brand'
|
|
663
|
-
tracelog.setCustomHeaders(() => ({
|
|
664
|
-
'X-Brand': 'dynamic-brand', // Overrides static
|
|
665
|
-
'Authorization': 'Bearer token' // New header
|
|
666
|
-
}));
|
|
667
|
-
|
|
668
|
-
// Result: { 'X-Tenant-Id': 'tenant-123', 'X-Brand': 'dynamic-brand', 'Authorization': 'Bearer token' }
|
|
669
|
-
```
|
|
670
|
-
|
|
671
|
-
### Removing Headers
|
|
672
|
-
|
|
673
|
-
```typescript
|
|
674
|
-
// Remove dynamic provider (static headers from config remain)
|
|
675
|
-
tracelog.removeCustomHeaders();
|
|
676
|
-
```
|
|
677
|
-
|
|
678
|
-
### sendBeacon Limitation
|
|
679
|
-
|
|
680
|
-
⚠️ Custom headers are **NOT applied** to `sendBeacon()` requests (page unload). The browser API doesn't support custom headers. For scenarios requiring headers on all requests:
|
|
681
|
-
- Ensure async sends complete before page unload
|
|
682
|
-
- Use short-lived tokens that don't require refresh per request
|
|
683
|
-
|
|
684
|
-
**→ [Custom Headers API Reference](./API_REFERENCE.md#setcustomheadersprovider-customheadersprovider-void)**
|
|
685
|
-
|
|
686
|
-
---
|
|
687
|
-
|
|
688
595
|
## Integration Modes
|
|
689
596
|
|
|
690
597
|
TraceLog supports multiple integration modes. Choose what fits your needs:
|