blinker-sdk 1.0.1 → 2.0.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/README.md +226 -147
- package/dist/blinker.min.js +452 -1
- package/dist/capture/deduplication.d.ts +26 -0
- package/dist/capture/deduplication.d.ts.map +1 -0
- package/dist/capture/errorHandler.d.ts +5 -0
- package/dist/capture/errorHandler.d.ts.map +1 -0
- package/dist/capture/index.d.ts +4 -0
- package/dist/capture/index.d.ts.map +1 -0
- package/dist/capture/types.d.ts +13 -0
- package/dist/capture/types.d.ts.map +1 -0
- package/dist/context/SessionManager.d.ts +16 -0
- package/dist/context/SessionManager.d.ts.map +1 -0
- package/dist/context/UserContext.d.ts +19 -0
- package/dist/context/UserContext.d.ts.map +1 -0
- package/dist/context/index.d.ts +4 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/types.d.ts +18 -0
- package/dist/context/types.d.ts.map +1 -0
- package/dist/core/Blinker.d.ts +45 -0
- package/dist/core/Blinker.d.ts.map +1 -0
- package/dist/core/config.d.ts +29 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/types.d.ts +54 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/filters/FilterEngine.d.ts +9 -0
- package/dist/filters/FilterEngine.d.ts.map +1 -0
- package/dist/filters/defaults.d.ts +3 -0
- package/dist/filters/defaults.d.ts.map +1 -0
- package/dist/filters/index.d.ts +4 -0
- package/dist/filters/index.d.ts.map +1 -0
- package/dist/filters/types.d.ts +8 -0
- package/dist/filters/types.d.ts.map +1 -0
- package/dist/index.cjs.js +2192 -266
- package/dist/index.d.ts +7 -32
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +2192 -266
- package/dist/queue/EventQueue.d.ts +21 -0
- package/dist/queue/EventQueue.d.ts.map +1 -0
- package/dist/queue/index.d.ts +4 -0
- package/dist/queue/index.d.ts.map +1 -0
- package/dist/queue/storage.d.ts +16 -0
- package/dist/queue/storage.d.ts.map +1 -0
- package/dist/queue/types.d.ts +21 -0
- package/dist/queue/types.d.ts.map +1 -0
- package/dist/sampling/RateLimiter.d.ts +12 -0
- package/dist/sampling/RateLimiter.d.ts.map +1 -0
- package/dist/sampling/Sampler.d.ts +16 -0
- package/dist/sampling/Sampler.d.ts.map +1 -0
- package/dist/sampling/index.d.ts +4 -0
- package/dist/sampling/index.d.ts.map +1 -0
- package/dist/sampling/types.d.ts +10 -0
- package/dist/sampling/types.d.ts.map +1 -0
- package/dist/transport/index.d.ts +3 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/sender.d.ts +4 -0
- package/dist/transport/sender.d.ts.map +1 -0
- package/dist/transport/types.d.ts +12 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/utils/browser.d.ts +10 -0
- package/dist/utils/browser.d.ts.map +1 -0
- package/dist/utils/hash.d.ts +4 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +9 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/widget/Avatar.d.ts +20 -0
- package/dist/widget/Avatar.d.ts.map +1 -0
- package/dist/widget/Dialog.d.ts +25 -0
- package/dist/widget/Dialog.d.ts.map +1 -0
- package/dist/widget/QuestionEngine.d.ts +7 -0
- package/dist/widget/QuestionEngine.d.ts.map +1 -0
- package/dist/widget/Widget.d.ts +28 -0
- package/dist/widget/Widget.d.ts.map +1 -0
- package/dist/widget/index.d.ts +8 -0
- package/dist/widget/index.d.ts.map +1 -0
- package/dist/widget/styles.d.ts +5 -0
- package/dist/widget/styles.d.ts.map +1 -0
- package/dist/widget/types.d.ts +46 -0
- package/dist/widget/types.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/Blinker.d.ts +0 -65
- package/dist/Blinker.d.ts.map +0 -1
- package/dist/errorHandler.d.ts +0 -19
- package/dist/errorHandler.d.ts.map +0 -1
- package/dist/sender.d.ts +0 -11
- package/dist/sender.d.ts.map +0 -1
- package/dist/types.d.ts +0 -92
- package/dist/types.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -4,13 +4,19 @@ Universal JavaScript SDK for error tracking and event capture. Works with **any
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
7
|
+
- **Zero dependencies** - Lightweight and fast
|
|
8
|
+
- **Universal** - Works in any JavaScript environment
|
|
9
|
+
- **Automatic error capture** - Catches global errors and unhandled rejections
|
|
10
|
+
- **Smart filtering** - Ignores common non-bugs (401, 403, ResizeObserver) by default
|
|
11
|
+
- **Event batching** - Efficient sending with configurable batch size
|
|
12
|
+
- **Offline support** - Persists events when offline, sends when back online
|
|
13
|
+
- **Deduplication** - Prevents flood of identical errors
|
|
14
|
+
- **Rate limiting** - Protects against excessive event sending
|
|
15
|
+
- **Sampling** - Sample events for high-traffic apps
|
|
16
|
+
- **Session tracking** - Automatic session management with pageview counting
|
|
17
|
+
- **User context** - Identify users and attach custom context
|
|
18
|
+
- **Multiple formats** - ESM, CommonJS, and UMD (CDN)
|
|
19
|
+
- **Type-safe** - Full TypeScript support
|
|
14
20
|
|
|
15
21
|
## Installation
|
|
16
22
|
|
|
@@ -43,8 +49,11 @@ import { blinker } from 'blinker-sdk';
|
|
|
43
49
|
blinker.init({ token: 'your-blinker-token' });
|
|
44
50
|
|
|
45
51
|
// That's it! Errors are now automatically captured.
|
|
52
|
+
// ✅ Batches events for efficient sending
|
|
53
|
+
// ✅ Works offline with localStorage persistence
|
|
54
|
+
// ✅ Deduplicates repeated errors
|
|
46
55
|
// ✅ Ignores 401/403 errors by default
|
|
47
|
-
// ✅ Filters out common browser noise
|
|
56
|
+
// ✅ Filters out common browser noise
|
|
48
57
|
```
|
|
49
58
|
|
|
50
59
|
## Usage
|
|
@@ -57,18 +66,140 @@ import { blinker } from 'blinker-sdk';
|
|
|
57
66
|
// Minimal setup - just the token!
|
|
58
67
|
blinker.init({ token: 'your-blinker-token' });
|
|
59
68
|
|
|
60
|
-
// Or with
|
|
69
|
+
// Or with all options
|
|
61
70
|
blinker.init({
|
|
62
|
-
token: 'your-blinker-token',
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
token: 'your-blinker-token',
|
|
72
|
+
// Capture options
|
|
73
|
+
captureErrors: true,
|
|
74
|
+
captureRejections: true,
|
|
75
|
+
// Batching
|
|
76
|
+
enableBatching: true,
|
|
77
|
+
batchSize: 10,
|
|
78
|
+
flushInterval: 5000,
|
|
79
|
+
// Offline persistence
|
|
80
|
+
enableOfflineStorage: true,
|
|
81
|
+
maxStoredEvents: 100,
|
|
82
|
+
// Deduplication
|
|
83
|
+
enableDeduplication: true,
|
|
84
|
+
deduplicationWindow: 60000,
|
|
85
|
+
// Rate limiting & sampling
|
|
86
|
+
maxEventsPerMinute: 100,
|
|
87
|
+
sampleRate: 1.0,
|
|
88
|
+
// Filters
|
|
89
|
+
filters: {
|
|
90
|
+
ignoreHttpCodes: [401, 403],
|
|
91
|
+
captureAll: false
|
|
92
|
+
},
|
|
93
|
+
// Debug
|
|
94
|
+
debug: false
|
|
66
95
|
});
|
|
67
96
|
```
|
|
68
97
|
|
|
98
|
+
### User Identification
|
|
99
|
+
|
|
100
|
+
Identify users to associate events with specific users:
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
// Identify a user with just an ID
|
|
104
|
+
blinker.identify('user-123');
|
|
105
|
+
|
|
106
|
+
// Identify with traits
|
|
107
|
+
blinker.identify('user-123', {
|
|
108
|
+
name: 'John Doe',
|
|
109
|
+
email: 'john@example.com',
|
|
110
|
+
plan: 'pro',
|
|
111
|
+
company: 'Acme Inc'
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Clear user context on logout
|
|
115
|
+
blinker.clearContext();
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Custom Context
|
|
119
|
+
|
|
120
|
+
Add custom context that's included in all events:
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
// Set context values
|
|
124
|
+
blinker.setContext('environment', 'production');
|
|
125
|
+
blinker.setContext('appVersion', '2.1.0');
|
|
126
|
+
blinker.setContext('feature', 'checkout');
|
|
127
|
+
|
|
128
|
+
// Get current context
|
|
129
|
+
const context = blinker.getContext();
|
|
130
|
+
// { environment: 'production', appVersion: '2.1.0', feature: 'checkout' }
|
|
131
|
+
|
|
132
|
+
// Clear all context
|
|
133
|
+
blinker.clearContext();
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Session Information
|
|
137
|
+
|
|
138
|
+
Access session tracking data:
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
// Get current session ID
|
|
142
|
+
const sessionId = blinker.getSessionId();
|
|
143
|
+
|
|
144
|
+
// Get full session info
|
|
145
|
+
const session = blinker.getSession();
|
|
146
|
+
// {
|
|
147
|
+
// sessionId: 'abc123...',
|
|
148
|
+
// startTime: 1706700000000,
|
|
149
|
+
// pageViews: 5,
|
|
150
|
+
// duration: 120000
|
|
151
|
+
// }
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Queue Control
|
|
155
|
+
|
|
156
|
+
Manage the event queue:
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
// Get number of pending events
|
|
160
|
+
const pending = blinker.getQueueSize();
|
|
161
|
+
console.log(`${pending} events waiting to be sent`);
|
|
162
|
+
|
|
163
|
+
// Force flush all queued events immediately
|
|
164
|
+
await blinker.flush();
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Track Custom Events
|
|
168
|
+
|
|
169
|
+
```javascript
|
|
170
|
+
// Basic event
|
|
171
|
+
blinker.track('click', 'Button clicked');
|
|
172
|
+
|
|
173
|
+
// Event with payload
|
|
174
|
+
blinker.track('purchase', 'User made a purchase', {
|
|
175
|
+
productId: '12345',
|
|
176
|
+
amount: 99.99,
|
|
177
|
+
currency: 'USD'
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Page view
|
|
181
|
+
blinker.trackPageView();
|
|
182
|
+
|
|
183
|
+
// Page view with custom name
|
|
184
|
+
blinker.trackPageView('Home Page', { section: 'hero' });
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Manual Error Capture
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
try {
|
|
191
|
+
// Your code
|
|
192
|
+
} catch (error) {
|
|
193
|
+
blinker.captureError(error, { context: 'checkout' });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Or with a string
|
|
197
|
+
blinker.captureError('Something went wrong', { userId: '123' });
|
|
198
|
+
```
|
|
199
|
+
|
|
69
200
|
### Error Filters (Smart Defaults)
|
|
70
201
|
|
|
71
|
-
The SDK comes with **intelligent default filters** that ignore common non-bug errors.
|
|
202
|
+
The SDK comes with **intelligent default filters** that ignore common non-bug errors.
|
|
72
203
|
|
|
73
204
|
#### Default Behavior
|
|
74
205
|
|
|
@@ -80,13 +211,10 @@ By default, the SDK **ignores**:
|
|
|
80
211
|
```javascript
|
|
81
212
|
// Minimal initialization - all defaults applied automatically!
|
|
82
213
|
blinker.init({ token: 'your-token' });
|
|
83
|
-
// ✅ Automatically ignores: 401, 403, ResizeObserver loop, Script error
|
|
84
214
|
```
|
|
85
215
|
|
|
86
216
|
#### Capture Everything
|
|
87
217
|
|
|
88
|
-
If you want to capture ALL errors including auth failures:
|
|
89
|
-
|
|
90
218
|
```javascript
|
|
91
219
|
blinker.init({
|
|
92
220
|
token: 'your-token',
|
|
@@ -96,8 +224,6 @@ blinker.init({
|
|
|
96
224
|
|
|
97
225
|
#### Custom HTTP Code Filters
|
|
98
226
|
|
|
99
|
-
Customize which HTTP codes to ignore:
|
|
100
|
-
|
|
101
227
|
```javascript
|
|
102
228
|
// Only ignore 401 (capture 403)
|
|
103
229
|
blinker.init({
|
|
@@ -110,18 +236,10 @@ blinker.init({
|
|
|
110
236
|
token: 'your-token',
|
|
111
237
|
filters: { ignoreHttpCodes: [401, 403, 404, 429] }
|
|
112
238
|
});
|
|
113
|
-
|
|
114
|
-
// Capture ALL HTTP errors (empty array)
|
|
115
|
-
blinker.init({
|
|
116
|
-
token: 'your-token',
|
|
117
|
-
filters: { ignoreHttpCodes: [] }
|
|
118
|
-
});
|
|
119
239
|
```
|
|
120
240
|
|
|
121
241
|
#### Ignore Specific Error Types
|
|
122
242
|
|
|
123
|
-
Filter out specific JavaScript error types:
|
|
124
|
-
|
|
125
243
|
```javascript
|
|
126
244
|
blinker.init({
|
|
127
245
|
token: 'your-token',
|
|
@@ -131,82 +249,20 @@ blinker.init({
|
|
|
131
249
|
|
|
132
250
|
#### Ignore Message Patterns
|
|
133
251
|
|
|
134
|
-
Filter errors by message content (case-insensitive substring matching):
|
|
135
|
-
|
|
136
252
|
```javascript
|
|
137
253
|
blinker.init({
|
|
138
254
|
token: 'your-token',
|
|
139
255
|
filters: {
|
|
140
256
|
ignoreMessagePatterns: [
|
|
141
|
-
'ResizeObserver loop',
|
|
142
|
-
'Script error',
|
|
143
|
-
'ChunkLoadError',
|
|
144
|
-
'
|
|
145
|
-
'Network request failed', // Offline users
|
|
146
|
-
'AbortError' // Cancelled requests
|
|
257
|
+
'ResizeObserver loop',
|
|
258
|
+
'Script error',
|
|
259
|
+
'ChunkLoadError',
|
|
260
|
+
'Network request failed'
|
|
147
261
|
]
|
|
148
262
|
}
|
|
149
263
|
});
|
|
150
264
|
```
|
|
151
265
|
|
|
152
|
-
#### Full Filter Configuration
|
|
153
|
-
|
|
154
|
-
All filter options together:
|
|
155
|
-
|
|
156
|
-
```javascript
|
|
157
|
-
blinker.init({
|
|
158
|
-
token: 'your-token',
|
|
159
|
-
filters: {
|
|
160
|
-
ignoreHttpCodes: [401, 403, 404],
|
|
161
|
-
ignoreErrorTypes: ['AbortError'],
|
|
162
|
-
ignoreMessagePatterns: ['ResizeObserver loop', 'Script error', 'ChunkLoadError'],
|
|
163
|
-
captureAll: false
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
#### Check Current Filters
|
|
169
|
-
|
|
170
|
-
```javascript
|
|
171
|
-
// Get the current filter configuration
|
|
172
|
-
const filters = blinker.getFilters();
|
|
173
|
-
console.log(filters);
|
|
174
|
-
// { ignoreHttpCodes: [401, 403], ignoreErrorTypes: [], ... }
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### Track Custom Events
|
|
178
|
-
|
|
179
|
-
```javascript
|
|
180
|
-
// Basic event
|
|
181
|
-
blinker.track('click', 'Button clicked');
|
|
182
|
-
|
|
183
|
-
// Event with payload
|
|
184
|
-
blinker.track('purchase', 'User made a purchase', {
|
|
185
|
-
productId: '12345',
|
|
186
|
-
amount: 99.99,
|
|
187
|
-
currency: 'USD'
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
// Page view
|
|
191
|
-
blinker.trackPageView();
|
|
192
|
-
|
|
193
|
-
// Page view with custom name
|
|
194
|
-
blinker.trackPageView('Home Page', { section: 'hero' });
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
### Manual Error Capture
|
|
198
|
-
|
|
199
|
-
```javascript
|
|
200
|
-
try {
|
|
201
|
-
// Your code
|
|
202
|
-
} catch (error) {
|
|
203
|
-
blinker.captureError(error, { context: 'checkout' });
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Or with a string
|
|
207
|
-
blinker.captureError('Something went wrong', { userId: '123' });
|
|
208
|
-
```
|
|
209
|
-
|
|
210
266
|
### Check SDK Status
|
|
211
267
|
|
|
212
268
|
```javascript
|
|
@@ -217,6 +273,9 @@ if (blinker.isInitialized()) {
|
|
|
217
273
|
|
|
218
274
|
// Get current config (without sensitive data)
|
|
219
275
|
const config = blinker.getConfig();
|
|
276
|
+
|
|
277
|
+
// Get current filters
|
|
278
|
+
const filters = blinker.getFilters();
|
|
220
279
|
```
|
|
221
280
|
|
|
222
281
|
### Cleanup
|
|
@@ -237,6 +296,10 @@ import { blinker } from 'blinker-sdk';
|
|
|
237
296
|
blinker.init({ token: process.env.REACT_APP_BLINKER_TOKEN });
|
|
238
297
|
|
|
239
298
|
function App() {
|
|
299
|
+
useEffect(() => {
|
|
300
|
+
blinker.identify(user.id, { name: user.name, email: user.email });
|
|
301
|
+
}, [user]);
|
|
302
|
+
|
|
240
303
|
const handleClick = () => {
|
|
241
304
|
blinker.track('click', 'CTA button clicked', { page: 'home' });
|
|
242
305
|
};
|
|
@@ -280,20 +343,6 @@ blinker.init({ token: import.meta.env.VITE_BLINKER_TOKEN });
|
|
|
280
343
|
createApp(App).mount('#app');
|
|
281
344
|
```
|
|
282
345
|
|
|
283
|
-
### Angular
|
|
284
|
-
|
|
285
|
-
```typescript
|
|
286
|
-
// app.module.ts
|
|
287
|
-
import { blinker } from 'blinker-sdk';
|
|
288
|
-
|
|
289
|
-
blinker.init({ token: environment.blinkerToken });
|
|
290
|
-
|
|
291
|
-
@NgModule({
|
|
292
|
-
// ...
|
|
293
|
-
})
|
|
294
|
-
export class AppModule {}
|
|
295
|
-
```
|
|
296
|
-
|
|
297
346
|
### Vanilla JavaScript
|
|
298
347
|
|
|
299
348
|
```html
|
|
@@ -304,12 +353,15 @@ export class AppModule {}
|
|
|
304
353
|
</head>
|
|
305
354
|
<body>
|
|
306
355
|
<button id="myButton">Click me</button>
|
|
307
|
-
|
|
356
|
+
|
|
308
357
|
<script>
|
|
309
358
|
const { blinker } = BlinkerSDK;
|
|
310
|
-
|
|
359
|
+
|
|
311
360
|
blinker.init({ token: 'your-token' });
|
|
312
|
-
|
|
361
|
+
|
|
362
|
+
// Identify user
|
|
363
|
+
blinker.identify('user-123', { name: 'John' });
|
|
364
|
+
|
|
313
365
|
document.getElementById('myButton').addEventListener('click', () => {
|
|
314
366
|
blinker.track('click', 'Button clicked');
|
|
315
367
|
});
|
|
@@ -329,15 +381,24 @@ Initialize the SDK with configuration options.
|
|
|
329
381
|
| `token` | `string` | **required** | Your Blinker API token |
|
|
330
382
|
| `captureErrors` | `boolean` | `true` | Auto-capture window errors |
|
|
331
383
|
| `captureRejections` | `boolean` | `true` | Auto-capture unhandled rejections |
|
|
332
|
-
| `
|
|
384
|
+
| `enableBatching` | `boolean` | `true` | Enable event batching |
|
|
385
|
+
| `batchSize` | `number` | `10` | Events per batch |
|
|
386
|
+
| `flushInterval` | `number` | `5000` | Batch flush interval (ms) |
|
|
387
|
+
| `enableOfflineStorage` | `boolean` | `true` | Persist events when offline |
|
|
388
|
+
| `maxStoredEvents` | `number` | `100` | Max offline events to store |
|
|
389
|
+
| `enableDeduplication` | `boolean` | `true` | Enable error deduplication |
|
|
390
|
+
| `deduplicationWindow` | `number` | `60000` | Dedup window (ms) |
|
|
391
|
+
| `maxEventsPerMinute` | `number` | `100` | Rate limit (0 = unlimited) |
|
|
392
|
+
| `sampleRate` | `number` | `1.0` | Sample rate (0.0-1.0) |
|
|
333
393
|
| `filters` | `FilterSettings` | see below | Error filter configuration |
|
|
394
|
+
| `debug` | `boolean` | `false` | Enable debug logging |
|
|
334
395
|
|
|
335
396
|
#### FilterSettings
|
|
336
397
|
|
|
337
398
|
| Option | Type | Default | Description |
|
|
338
399
|
|--------|------|---------|-------------|
|
|
339
400
|
| `ignoreHttpCodes` | `number[]` | `[401, 403]` | HTTP status codes to ignore |
|
|
340
|
-
| `ignoreErrorTypes` | `string[]` | `[]` | JS error types to ignore
|
|
401
|
+
| `ignoreErrorTypes` | `string[]` | `[]` | JS error types to ignore |
|
|
341
402
|
| `ignoreMessagePatterns` | `string[]` | `['ResizeObserver loop', 'Script error']` | Message patterns to ignore |
|
|
342
403
|
| `captureAll` | `boolean` | `false` | When true, disables all filters |
|
|
343
404
|
|
|
@@ -345,31 +406,56 @@ Initialize the SDK with configuration options.
|
|
|
345
406
|
|
|
346
407
|
Track a custom event.
|
|
347
408
|
|
|
348
|
-
| Parameter | Type | Description |
|
|
349
|
-
|-----------|------|-------------|
|
|
350
|
-
| `type` | `string` | Event type (e.g., 'click', 'purchase') |
|
|
351
|
-
| `message` | `string` | Event description |
|
|
352
|
-
| `payload` | `object` | Optional additional data |
|
|
353
|
-
|
|
354
409
|
**Returns:** `Promise<{ success: boolean, error?: string }>`
|
|
355
410
|
|
|
356
411
|
### `blinker.captureError(error, payload?)`
|
|
357
412
|
|
|
358
413
|
Manually capture an error.
|
|
359
414
|
|
|
360
|
-
| Parameter | Type | Description |
|
|
361
|
-
|-----------|------|-------------|
|
|
362
|
-
| `error` | `Error \| string` | Error object or message |
|
|
363
|
-
| `payload` | `object` | Optional additional data |
|
|
364
|
-
|
|
365
415
|
### `blinker.trackPageView(pageName?, payload?)`
|
|
366
416
|
|
|
367
417
|
Track a page view.
|
|
368
418
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
419
|
+
### `blinker.identify(userId, traits?)`
|
|
420
|
+
|
|
421
|
+
Identify the current user. Traits are optional metadata about the user.
|
|
422
|
+
|
|
423
|
+
### `blinker.setContext(key, value)`
|
|
424
|
+
|
|
425
|
+
Set a custom context value that will be included in all events.
|
|
426
|
+
|
|
427
|
+
### `blinker.getContext()`
|
|
428
|
+
|
|
429
|
+
Get all custom context values. Returns `Record<string, unknown>`.
|
|
430
|
+
|
|
431
|
+
### `blinker.clearContext()`
|
|
432
|
+
|
|
433
|
+
Clear all user context (use on logout).
|
|
434
|
+
|
|
435
|
+
### `blinker.getSessionId()`
|
|
436
|
+
|
|
437
|
+
Get current session ID. Returns `string`.
|
|
438
|
+
|
|
439
|
+
### `blinker.getSession()`
|
|
440
|
+
|
|
441
|
+
Get full session info. Returns `SessionInfo | null`.
|
|
442
|
+
|
|
443
|
+
```typescript
|
|
444
|
+
interface SessionInfo {
|
|
445
|
+
sessionId: string;
|
|
446
|
+
startTime: number;
|
|
447
|
+
pageViews: number;
|
|
448
|
+
duration: number;
|
|
449
|
+
}
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### `blinker.flush()`
|
|
453
|
+
|
|
454
|
+
Force flush all queued events immediately. Returns `Promise<void>`.
|
|
455
|
+
|
|
456
|
+
### `blinker.getQueueSize()`
|
|
457
|
+
|
|
458
|
+
Get number of events waiting to be sent. Returns `number`.
|
|
373
459
|
|
|
374
460
|
### `blinker.isInitialized()`
|
|
375
461
|
|
|
@@ -383,45 +469,41 @@ Get current configuration (without token). Returns config object or `null`.
|
|
|
383
469
|
|
|
384
470
|
Get current filter settings. Returns `FilterSettings` object.
|
|
385
471
|
|
|
386
|
-
```javascript
|
|
387
|
-
const filters = blinker.getFilters();
|
|
388
|
-
// { ignoreHttpCodes: [401, 403], ignoreErrorTypes: [], ignoreMessagePatterns: [...], captureAll: false }
|
|
389
|
-
```
|
|
390
|
-
|
|
391
472
|
### `blinker.destroy()`
|
|
392
473
|
|
|
393
474
|
Remove error handlers and reset SDK state.
|
|
394
475
|
|
|
395
476
|
## Event Payload
|
|
396
477
|
|
|
397
|
-
Events sent to the API
|
|
478
|
+
Events sent to the API include:
|
|
398
479
|
|
|
399
480
|
```json
|
|
400
481
|
{
|
|
401
482
|
"type": "error",
|
|
402
483
|
"message": "Error message",
|
|
403
|
-
"payload": {
|
|
404
|
-
"custom": "data"
|
|
405
|
-
},
|
|
484
|
+
"payload": { "custom": "data" },
|
|
406
485
|
"timestamp": "2024-01-15T12:00:00.000Z",
|
|
407
486
|
"url": "https://example.com/page",
|
|
408
|
-
"userAgent": "Mozilla/5.0..."
|
|
487
|
+
"userAgent": "Mozilla/5.0...",
|
|
488
|
+
"sessionId": "abc123...",
|
|
489
|
+
"userId": "user-123",
|
|
490
|
+
"userTraits": { "name": "John", "plan": "pro" },
|
|
491
|
+
"context": { "appVersion": "2.1.0" },
|
|
492
|
+
"count": 5
|
|
409
493
|
}
|
|
410
494
|
```
|
|
411
495
|
|
|
412
496
|
## TypeScript
|
|
413
497
|
|
|
414
|
-
The SDK
|
|
498
|
+
The SDK includes full type definitions.
|
|
415
499
|
|
|
416
500
|
```typescript
|
|
417
|
-
import { blinker, BlinkerConfig, FilterSettings } from 'blinker-sdk';
|
|
418
|
-
|
|
419
|
-
// Minimal config - just the token!
|
|
420
|
-
blinker.init({ token: 'your-token' });
|
|
501
|
+
import { blinker, BlinkerConfig, FilterSettings, SessionInfo } from 'blinker-sdk';
|
|
421
502
|
|
|
422
|
-
// Or with full typed config
|
|
423
503
|
const config: BlinkerConfig = {
|
|
424
504
|
token: 'your-token',
|
|
505
|
+
enableBatching: true,
|
|
506
|
+
sampleRate: 0.5,
|
|
425
507
|
filters: {
|
|
426
508
|
ignoreHttpCodes: [401, 403, 404],
|
|
427
509
|
captureAll: false
|
|
@@ -430,14 +512,12 @@ const config: BlinkerConfig = {
|
|
|
430
512
|
|
|
431
513
|
blinker.init(config);
|
|
432
514
|
|
|
433
|
-
// Get typed filters
|
|
434
515
|
const filters: FilterSettings = blinker.getFilters();
|
|
516
|
+
const session: SessionInfo | null = blinker.getSession();
|
|
435
517
|
```
|
|
436
518
|
|
|
437
519
|
## Multiple Instances
|
|
438
520
|
|
|
439
|
-
If you need multiple SDK instances (e.g., different tokens for different app sections):
|
|
440
|
-
|
|
441
521
|
```javascript
|
|
442
522
|
import { Blinker } from 'blinker-sdk';
|
|
443
523
|
|
|
@@ -460,4 +540,3 @@ The SDK uses modern JavaScript features (ES2018) including `async/await` and `fe
|
|
|
460
540
|
## License
|
|
461
541
|
|
|
462
542
|
MIT
|
|
463
|
-
|