@eventra_dev/eventra-sdk 1.1.2 → 1.1.4
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 +82 -21
- package/dist/index.cjs +441 -86
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -3
- package/dist/index.d.ts +32 -3
- package/dist/index.mjs +441 -86
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
# Eventra SDK
|
|
6
6
|
|
|
7
|
+
[](https://www.npmjs.com/package/@eventra_dev/eventra-sdk)
|
|
8
|
+
[](https://www.npmjs.com/package/@eventra_dev/eventra-sdk)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
10
|
+
[]()
|
|
11
|
+
|
|
7
12
|
Production-grade analytics SDK for tracking **feature usage, product behavior, and backend activity**.
|
|
8
13
|
|
|
9
14
|
Eventra helps you:
|
|
@@ -52,7 +57,6 @@ import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
|
52
57
|
|
|
53
58
|
const tracker = new Eventra({
|
|
54
59
|
apiKey: "YOUR_PROJECT_API_KEY",
|
|
55
|
-
endpoint: "https://api.eventra.dev/ingest",
|
|
56
60
|
});
|
|
57
61
|
|
|
58
62
|
tracker.track("checkout.completed", {
|
|
@@ -62,6 +66,8 @@ tracker.track("checkout.completed", {
|
|
|
62
66
|
|
|
63
67
|
That's it.
|
|
64
68
|
|
|
69
|
+
By default, events are sent to `https://api.eventra.dev/api/v1/ingest/batch`.
|
|
70
|
+
|
|
65
71
|
The SDK automatically handles:
|
|
66
72
|
|
|
67
73
|
- batching
|
|
@@ -109,6 +115,8 @@ Minimal:
|
|
|
109
115
|
tracker.track("app.loaded");
|
|
110
116
|
```
|
|
111
117
|
|
|
118
|
+
Event names are trimmed to 64 characters, `userId` to 120 (API limits).
|
|
119
|
+
|
|
112
120
|
---
|
|
113
121
|
|
|
114
122
|
## Common Examples
|
|
@@ -193,7 +201,16 @@ tracker.track("page.viewed");
|
|
|
193
201
|
- batching
|
|
194
202
|
- retry
|
|
195
203
|
- persistence (localStorage)
|
|
196
|
-
- flush on tab close
|
|
204
|
+
- flush on tab close (`fetch` with `keepalive`)
|
|
205
|
+
|
|
206
|
+
Optional — single sender across tabs:
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
const tracker = new Eventra({
|
|
210
|
+
apiKey: "...",
|
|
211
|
+
multiTabMode: "leader",
|
|
212
|
+
});
|
|
213
|
+
```
|
|
197
214
|
|
|
198
215
|
---
|
|
199
216
|
|
|
@@ -224,6 +241,8 @@ export default async function handler(req, res) {
|
|
|
224
241
|
|
|
225
242
|
tracker.track("function.called");
|
|
226
243
|
|
|
244
|
+
await tracker.flush();
|
|
245
|
+
|
|
227
246
|
res.status(200).end();
|
|
228
247
|
}
|
|
229
248
|
```
|
|
@@ -239,11 +258,29 @@ export default async function handler(req, res) {
|
|
|
239
258
|
```ts
|
|
240
259
|
const tracker = new Eventra({
|
|
241
260
|
apiKey: "YOUR_PROJECT_API_KEY",
|
|
242
|
-
endpoint: "CUSTOM_ENDPOINT",
|
|
243
261
|
flushInterval: 2000,
|
|
244
262
|
maxBatchSize: 50,
|
|
245
263
|
maxQueueSize: 10000,
|
|
246
264
|
maxRetries: 3,
|
|
265
|
+
retryBaseDelayMs: 300,
|
|
266
|
+
maxPayloadBytes: 60000,
|
|
267
|
+
onEventsDropped: (count) => {
|
|
268
|
+
console.warn(`Dropped ${count} event(s) — queue full`);
|
|
269
|
+
},
|
|
270
|
+
onDeliveryFailed: ({ status, events }) => {
|
|
271
|
+
console.error(`Ingest rejected batch (${status})`, events.length);
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
`endpoint` is optional — omit it to use the production ingest URL.
|
|
277
|
+
|
|
278
|
+
For self-hosted or local development:
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
const tracker = new Eventra({
|
|
282
|
+
apiKey: "...",
|
|
283
|
+
endpoint: "...",
|
|
247
284
|
});
|
|
248
285
|
```
|
|
249
286
|
|
|
@@ -251,14 +288,22 @@ const tracker = new Eventra({
|
|
|
251
288
|
|
|
252
289
|
## Options
|
|
253
290
|
|
|
254
|
-
| option
|
|
255
|
-
| ------------- |
|
|
256
|
-
| apiKey
|
|
257
|
-
| endpoint
|
|
258
|
-
| flushInterval | Flush interval (ms)
|
|
259
|
-
| maxBatchSize
|
|
260
|
-
| maxQueueSize
|
|
261
|
-
| maxRetries
|
|
291
|
+
| option | description |
|
|
292
|
+
| ------------- | --------------------------- |
|
|
293
|
+
| apiKey | Project API key (required) |
|
|
294
|
+
| endpoint | Ingest batch URL |
|
|
295
|
+
| flushInterval | Flush interval (ms) |
|
|
296
|
+
| maxBatchSize | Events per batch |
|
|
297
|
+
| maxQueueSize | Max buffer size |
|
|
298
|
+
| maxRetries | Total delivery attempts per batch (default: 3) |
|
|
299
|
+
| retryBaseDelayMs | Base delay for exponential backoff (ms) |
|
|
300
|
+
| maxPayloadBytes | Max serialized batch size (default: 60000) |
|
|
301
|
+
| fetchImpl | Custom `fetch` (Node without native fetch, tests) |
|
|
302
|
+
| autoFlushOnExit | Flush on process exit (Node / serverless, default: `true`) |
|
|
303
|
+
| disableTimer | Disable periodic flush timer |
|
|
304
|
+
| onEventsDropped | Callback when queue is full |
|
|
305
|
+
| onDeliveryFailed | Callback on permanent ingest errors (4xx except 429) |
|
|
306
|
+
| multiTabMode | `"independent"` (default) or `"leader"` (browser only) |
|
|
262
307
|
|
|
263
308
|
---
|
|
264
309
|
|
|
@@ -270,13 +315,22 @@ await tracker.flush();
|
|
|
270
315
|
|
|
271
316
|
---
|
|
272
317
|
|
|
273
|
-
##
|
|
318
|
+
## Shutdown
|
|
319
|
+
|
|
320
|
+
Graceful shutdown — flush first, then cleanup:
|
|
321
|
+
|
|
322
|
+
```ts
|
|
323
|
+
await tracker.shutdown();
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
For Node / serverless, prefer explicit shutdown over relying on process signals:
|
|
274
327
|
|
|
275
328
|
```ts
|
|
276
|
-
tracker.
|
|
329
|
+
await tracker.flush();
|
|
330
|
+
await tracker.shutdown();
|
|
277
331
|
```
|
|
278
332
|
|
|
279
|
-
|
|
333
|
+
`destroy()` stops timers and listeners immediately without flushing.
|
|
280
334
|
|
|
281
335
|
---
|
|
282
336
|
|
|
@@ -284,12 +338,19 @@ Stops timers, removes listeners, and clears internal state.
|
|
|
284
338
|
|
|
285
339
|
Eventra SDK includes:
|
|
286
340
|
|
|
287
|
-
- Idempotency (
|
|
288
|
-
- Retry with exponential backoff
|
|
289
|
-
- Circuit breaker
|
|
341
|
+
- Idempotency (UUID v4 per event, stable across retries)
|
|
342
|
+
- Retry with exponential backoff + jitter (capped)
|
|
343
|
+
- Circuit breaker with half-open recovery
|
|
290
344
|
- Queue-based delivery (all runtimes)
|
|
291
|
-
-
|
|
292
|
-
-
|
|
345
|
+
- Safe dequeue (events removed only after successful ingest)
|
|
346
|
+
- Queue persistence (browser) with merge + cross-tab sync
|
|
347
|
+
- Multi-tab leader election with re-election
|
|
348
|
+
- `fetch` + `keepalive` on tab close (with `x-api-key`, size-checked)
|
|
349
|
+
- `pagehide` + `visibilitychange` flush hooks
|
|
350
|
+
- Property validation at `track()` (depth + size)
|
|
351
|
+
- Payload byte limits per batch
|
|
352
|
+
- Permanent error handling via `onDeliveryFailed` (401, 422, etc.)
|
|
353
|
+
- Automatic requeue on network errors and 429 / 5xx
|
|
293
354
|
|
|
294
355
|
---
|
|
295
356
|
|
|
@@ -300,12 +361,12 @@ Eventra SDK includes:
|
|
|
300
361
|
"sentAt": "2026-03-12T10:00:00Z",
|
|
301
362
|
"sdk": {
|
|
302
363
|
"name": "@eventra_dev/eventra-sdk",
|
|
303
|
-
"version": "1.
|
|
364
|
+
"version": "1.1.3",
|
|
304
365
|
"runtime": "browser"
|
|
305
366
|
},
|
|
306
367
|
"events": [
|
|
307
368
|
{
|
|
308
|
-
"idempotencyKey": "
|
|
369
|
+
"idempotencyKey": "550e8400-e29b-41d4-a716-446655440000",
|
|
309
370
|
"name": "user_signup",
|
|
310
371
|
"userId": "user_123",
|
|
311
372
|
"timestamp": "2026-03-12T10:00:00Z",
|