@eventra_dev/eventra-sdk 1.0.6 → 1.1.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 +131 -246
- package/dist/index.cjs +131 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -17
- package/dist/index.d.ts +15 -17
- package/dist/index.mjs +131 -159
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,63 +4,55 @@
|
|
|
4
4
|
|
|
5
5
|
# Eventra SDK
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
[](https://www.npmjs.com/package/@eventra_dev/eventra-sdk)
|
|
9
|
-
[](https://www.typescriptlang.org/)
|
|
10
|
-
[]()
|
|
11
|
-
|
|
12
|
-
Eventra SDK allows you to send **feature usage and product analytics
|
|
13
|
-
events** to the Eventra platform.
|
|
7
|
+
Production-grade analytics SDK for tracking **feature usage, product behavior, and backend activity**.
|
|
14
8
|
|
|
15
9
|
Eventra helps you:
|
|
16
10
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
* Track feature adoption
|
|
12
|
+
* Detect unused features
|
|
13
|
+
* Understand user behavior
|
|
14
|
+
* Monitor backend usage
|
|
15
|
+
* Analyze product growth
|
|
22
16
|
|
|
23
|
-
|
|
17
|
+
---
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
- runtime-agnostic
|
|
27
|
-
- resilient (batching + retry)
|
|
28
|
-
- production-safe
|
|
29
|
-
- TypeScript-first
|
|
19
|
+
## Why Eventra
|
|
30
20
|
|
|
31
|
-
|
|
21
|
+
Eventra SDK is:
|
|
32
22
|
|
|
33
|
-
|
|
23
|
+
* Lightweight (~minimal overhead)
|
|
24
|
+
* Runtime-aware (Browser, Node, Edge, Serverless)
|
|
25
|
+
* Resilient (batching + retry + circuit breaker)
|
|
26
|
+
* Durable (browser persistence)
|
|
27
|
+
* Smart (adaptive behavior per environment)
|
|
28
|
+
* TypeScript-first
|
|
34
29
|
|
|
35
|
-
|
|
30
|
+
---
|
|
36
31
|
|
|
37
|
-
|
|
32
|
+
## Installation
|
|
38
33
|
|
|
39
|
-
```
|
|
34
|
+
```bash
|
|
40
35
|
npm i @eventra_dev/eventra-sdk
|
|
41
36
|
```
|
|
42
37
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
``` bash
|
|
38
|
+
```bash
|
|
46
39
|
pnpm add @eventra_dev/eventra-sdk
|
|
47
40
|
```
|
|
48
41
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
``` bash
|
|
42
|
+
```bash
|
|
52
43
|
yarn add @eventra_dev/eventra-sdk
|
|
53
44
|
```
|
|
54
45
|
|
|
55
|
-
|
|
46
|
+
---
|
|
56
47
|
|
|
57
|
-
|
|
48
|
+
## Quick Start
|
|
58
49
|
|
|
59
|
-
```
|
|
50
|
+
```ts
|
|
60
51
|
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
61
52
|
|
|
62
53
|
const tracker = new Eventra({
|
|
63
54
|
apiKey: "YOUR_PROJECT_API_KEY",
|
|
55
|
+
endpoint: "https://api.eventra.dev/ingest",
|
|
64
56
|
});
|
|
65
57
|
|
|
66
58
|
tracker.track("checkout.completed", {
|
|
@@ -68,19 +60,37 @@ tracker.track("checkout.completed", {
|
|
|
68
60
|
});
|
|
69
61
|
```
|
|
70
62
|
|
|
71
|
-
That's it.
|
|
63
|
+
That's it.
|
|
64
|
+
|
|
65
|
+
The SDK automatically handles:
|
|
72
66
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
* batching (browser)
|
|
68
|
+
* retries
|
|
69
|
+
* queueing
|
|
70
|
+
* flushing
|
|
71
|
+
* runtime adaptation
|
|
76
72
|
|
|
77
|
-
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Runtime Behavior
|
|
76
|
+
|
|
77
|
+
Eventra SDK adapts automatically:
|
|
78
|
+
|
|
79
|
+
| Environment | Behavior |
|
|
80
|
+
| ----------- | ------------------------------ |
|
|
81
|
+
| Browser | batching + persistence + retry |
|
|
82
|
+
| Node.js | instant send |
|
|
83
|
+
| Serverless | sync send (no event loss) |
|
|
84
|
+
| Edge | lightweight send |
|
|
85
|
+
| Workers | instant send |
|
|
78
86
|
|
|
79
|
-
|
|
87
|
+
No config needed.
|
|
80
88
|
|
|
81
|
-
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Event Properties
|
|
82
92
|
|
|
83
|
-
|
|
93
|
+
You can attach any JSON data:
|
|
84
94
|
|
|
85
95
|
```ts
|
|
86
96
|
tracker.track("checkout.completed", {
|
|
@@ -93,37 +103,30 @@ tracker.track("checkout.completed", {
|
|
|
93
103
|
});
|
|
94
104
|
```
|
|
95
105
|
|
|
96
|
-
|
|
106
|
+
Minimal:
|
|
97
107
|
|
|
98
108
|
```ts
|
|
99
109
|
tracker.track("app.loaded");
|
|
100
110
|
```
|
|
101
111
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
```ts
|
|
105
|
-
tracker.track("user.login", {
|
|
106
|
-
userId: "user_123"
|
|
107
|
-
});
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
------------------------------------------------------------------------
|
|
112
|
+
---
|
|
111
113
|
|
|
112
|
-
|
|
114
|
+
## Common Examples
|
|
113
115
|
|
|
114
|
-
|
|
116
|
+
### Feature Usage
|
|
115
117
|
|
|
116
118
|
```ts
|
|
117
119
|
tracker.track("feature.used", {
|
|
118
120
|
userId: "user_123",
|
|
119
121
|
properties: {
|
|
120
|
-
feature: "dashboard"
|
|
121
|
-
section: "analytics"
|
|
122
|
+
feature: "dashboard"
|
|
122
123
|
}
|
|
123
124
|
});
|
|
124
125
|
```
|
|
125
126
|
|
|
126
|
-
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
### Page View
|
|
127
130
|
|
|
128
131
|
```ts
|
|
129
132
|
tracker.track("page.viewed", {
|
|
@@ -133,7 +136,9 @@ tracker.track("page.viewed", {
|
|
|
133
136
|
});
|
|
134
137
|
```
|
|
135
138
|
|
|
136
|
-
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
### API Usage
|
|
137
142
|
|
|
138
143
|
```ts
|
|
139
144
|
tracker.track("api.request", {
|
|
@@ -145,7 +150,9 @@ tracker.track("api.request", {
|
|
|
145
150
|
});
|
|
146
151
|
```
|
|
147
152
|
|
|
148
|
-
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
### Error Tracking
|
|
149
156
|
|
|
150
157
|
```ts
|
|
151
158
|
tracker.track("error.occurred", {
|
|
@@ -156,262 +163,142 @@ tracker.track("error.occurred", {
|
|
|
156
163
|
});
|
|
157
164
|
```
|
|
158
165
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
# Where You Can Use Eventra SDK
|
|
166
|
+
---
|
|
162
167
|
|
|
163
|
-
|
|
168
|
+
## Where You Can Use It
|
|
164
169
|
|
|
165
|
-
* Browser
|
|
166
|
-
* React
|
|
167
|
-
* Next.js apps
|
|
170
|
+
* Browser apps
|
|
171
|
+
* React / Next.js
|
|
168
172
|
* Node.js backends
|
|
169
173
|
* NestJS services
|
|
170
174
|
* Express APIs
|
|
171
|
-
* Vanilla JavaScript
|
|
172
175
|
* Edge runtimes
|
|
173
|
-
*
|
|
174
|
-
* Deno
|
|
176
|
+
* Serverless (AWS / Vercel)
|
|
177
|
+
* Bun / Deno
|
|
175
178
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
# Browser Usage
|
|
179
|
-
|
|
180
|
-
```ts
|
|
181
|
-
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
182
|
-
|
|
183
|
-
const tracker = new Eventra({
|
|
184
|
-
apiKey: "YOUR_PROJECT_API_KEY",
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
tracker.track("page.viewed", {
|
|
188
|
-
properties: {
|
|
189
|
-
path: window.location.pathname
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
The SDK automatically:
|
|
195
|
-
|
|
196
|
-
* batches events
|
|
197
|
-
* retries failed requests
|
|
198
|
-
* flushes on page exit
|
|
179
|
+
---
|
|
199
180
|
|
|
200
|
-
|
|
181
|
+
## Usage by Environment
|
|
201
182
|
|
|
202
|
-
|
|
183
|
+
### Browser
|
|
203
184
|
|
|
204
185
|
```ts
|
|
205
|
-
import { useEffect } from "react";
|
|
206
|
-
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
207
|
-
|
|
208
186
|
const tracker = new Eventra({
|
|
209
|
-
apiKey: "
|
|
187
|
+
apiKey: "...",
|
|
210
188
|
});
|
|
211
189
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
useEffect(() => {
|
|
215
|
-
tracker.track("app.loaded");
|
|
216
|
-
}, []);
|
|
217
|
-
|
|
218
|
-
return <div>Hello</div>;
|
|
219
|
-
}
|
|
190
|
+
tracker.track("page.viewed");
|
|
220
191
|
```
|
|
221
192
|
|
|
222
|
-
|
|
193
|
+
✔ batching
|
|
194
|
+
✔ retry
|
|
195
|
+
✔ persistence (localStorage)
|
|
196
|
+
✔ flush on tab close
|
|
223
197
|
|
|
224
|
-
|
|
198
|
+
---
|
|
225
199
|
|
|
226
|
-
|
|
200
|
+
### Node.js
|
|
227
201
|
|
|
228
202
|
```ts
|
|
229
|
-
"use client";
|
|
230
|
-
|
|
231
|
-
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
232
|
-
|
|
233
203
|
const tracker = new Eventra({
|
|
234
|
-
apiKey: "
|
|
204
|
+
apiKey: "...",
|
|
235
205
|
});
|
|
236
206
|
|
|
237
|
-
|
|
238
|
-
return (
|
|
239
|
-
<button
|
|
240
|
-
onClick={() => tracker.track("checkout.started")}
|
|
241
|
-
>
|
|
242
|
-
Checkout
|
|
243
|
-
</button>
|
|
244
|
-
);
|
|
245
|
-
}
|
|
207
|
+
tracker.track("invoice.created");
|
|
246
208
|
```
|
|
247
209
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
# Node.js Usage
|
|
251
|
-
|
|
252
|
-
```ts
|
|
253
|
-
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
210
|
+
✔ immediate send
|
|
211
|
+
✔ no buffering
|
|
254
212
|
|
|
255
|
-
|
|
256
|
-
apiKey: "YOUR_PROJECT_API_KEY",
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
tracker.track("invoice.created", {
|
|
260
|
-
userId: "user_123",
|
|
261
|
-
});
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
------------------------------------------------------------------------
|
|
213
|
+
---
|
|
265
214
|
|
|
266
|
-
|
|
215
|
+
### Serverless (IMPORTANT)
|
|
267
216
|
|
|
268
217
|
```ts
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
@Injectable()
|
|
273
|
-
export class BillingService {
|
|
274
|
-
|
|
275
|
-
private tracker = new Eventra({
|
|
276
|
-
apiKey: "YOUR_PROJECT_API_KEY",
|
|
218
|
+
export default async function handler(req, res) {
|
|
219
|
+
const tracker = new Eventra({
|
|
220
|
+
apiKey: "...",
|
|
277
221
|
});
|
|
278
222
|
|
|
279
|
-
|
|
280
|
-
this.tracker.track("invoice.created", {
|
|
281
|
-
userId
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
------------------------------------------------------------------------
|
|
223
|
+
await tracker.track("function.called");
|
|
288
224
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
```ts
|
|
292
|
-
import express from "express";
|
|
293
|
-
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
294
|
-
|
|
295
|
-
const app = express();
|
|
296
|
-
|
|
297
|
-
const tracker = new Eventra({
|
|
298
|
-
apiKey: "YOUR_PROJECT_API_KEY",
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
app.post("/checkout", (req, res) => {
|
|
302
|
-
|
|
303
|
-
tracker.track("checkout.completed");
|
|
304
|
-
|
|
305
|
-
res.sendStatus(200);
|
|
306
|
-
});
|
|
225
|
+
res.status(200).end();
|
|
226
|
+
}
|
|
307
227
|
```
|
|
308
228
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
# Vanilla JavaScript (CDN)
|
|
312
|
-
|
|
313
|
-
```html
|
|
314
|
-
<script type="module">
|
|
229
|
+
✔ no event loss
|
|
230
|
+
✔ sync delivery
|
|
315
231
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const tracker = new Eventra({
|
|
319
|
-
apiKey: "YOUR_PROJECT_API_KEY",
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
tracker.track("page.viewed");
|
|
323
|
-
|
|
324
|
-
</script>
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
------------------------------------------------------------------------
|
|
232
|
+
---
|
|
328
233
|
|
|
329
|
-
|
|
234
|
+
## Configuration
|
|
330
235
|
|
|
331
236
|
```ts
|
|
332
|
-
const
|
|
333
|
-
|
|
237
|
+
const tracker = new Eventra({
|
|
334
238
|
apiKey: "YOUR_PROJECT_API_KEY",
|
|
335
|
-
endpoint: "
|
|
239
|
+
endpoint: "CUSTOM_ENDPOINT",
|
|
336
240
|
flushInterval: 2000,
|
|
337
241
|
maxBatchSize: 50,
|
|
338
242
|
maxQueueSize: 10000,
|
|
339
|
-
maxRetries: 3
|
|
340
|
-
|
|
243
|
+
maxRetries: 3,
|
|
341
244
|
});
|
|
342
245
|
```
|
|
343
246
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
# Options
|
|
347
|
-
|
|
348
|
-
| option | description |
|
|
349
|
-
| ------------- | ---------------------------------- |
|
|
350
|
-
| apiKey | Project API key |
|
|
351
|
-
| endpoint | Event ingestion endpoint |
|
|
352
|
-
| flushInterval | Batch flush interval (ms) |
|
|
353
|
-
| maxBatchSize | Maximum events per batch |
|
|
354
|
-
| maxQueueSize | Maximum buffered events |
|
|
355
|
-
| maxRetries | Retry attempts for failed requests |
|
|
356
|
-
| multiTabMode | Browser tab coordination mode |
|
|
357
|
-
|
|
358
|
-
------------------------------------------------------------------------
|
|
359
|
-
|
|
360
|
-
# Multi-Tab Mode (Browser)
|
|
247
|
+
---
|
|
361
248
|
|
|
362
|
-
|
|
363
|
-
const tracker = new Eventra({
|
|
364
|
-
apiKey: "YOUR_PROJECT_API_KEY",
|
|
365
|
-
multiTabMode: "leader"
|
|
366
|
-
});
|
|
367
|
-
```
|
|
249
|
+
## Options
|
|
368
250
|
|
|
369
|
-
|
|
251
|
+
| option | description |
|
|
252
|
+
| ------------- | ----------------------------- |
|
|
253
|
+
| apiKey | Project API key |
|
|
254
|
+
| endpoint | Event ingestion endpoint |
|
|
255
|
+
| flushInterval | Batch interval (browser only) |
|
|
256
|
+
| maxBatchSize | Events per batch |
|
|
257
|
+
| maxQueueSize | Max buffer size |
|
|
258
|
+
| maxRetries | Retry attempts |
|
|
370
259
|
|
|
371
260
|
---
|
|
372
261
|
|
|
373
|
-
|
|
262
|
+
## Manual Flush
|
|
374
263
|
|
|
375
264
|
```ts
|
|
376
265
|
await tracker.flush();
|
|
377
266
|
```
|
|
378
267
|
|
|
379
|
-
|
|
268
|
+
---
|
|
380
269
|
|
|
381
|
-
|
|
270
|
+
## Cleanup
|
|
382
271
|
|
|
383
272
|
```ts
|
|
384
273
|
tracker.destroy();
|
|
385
274
|
```
|
|
386
275
|
|
|
387
|
-
Stops timers and
|
|
276
|
+
Stops timers and clears internal state.
|
|
388
277
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
# Runtime Support
|
|
278
|
+
---
|
|
392
279
|
|
|
393
|
-
|
|
280
|
+
## Reliability Features
|
|
394
281
|
|
|
395
|
-
|
|
396
|
-
* Browser
|
|
397
|
-
* Bun
|
|
398
|
-
* Deno
|
|
399
|
-
* Edge runtimes
|
|
400
|
-
* Serverless environments
|
|
282
|
+
Eventra SDK includes:
|
|
401
283
|
|
|
402
|
-
|
|
284
|
+
* Idempotency (no duplicates)
|
|
285
|
+
* Retry with exponential backoff
|
|
286
|
+
* Circuit breaker (prevents overload)
|
|
287
|
+
* Queue persistence (browser)
|
|
288
|
+
* Safe fallback for all runtimes
|
|
289
|
+
* sendBeacon optimization (browser exit)
|
|
403
290
|
|
|
404
|
-
|
|
291
|
+
---
|
|
405
292
|
|
|
406
|
-
|
|
293
|
+
## Event Format
|
|
407
294
|
|
|
408
295
|
```json
|
|
409
296
|
{
|
|
410
297
|
"sentAt": "2026-03-12T10:00:00Z",
|
|
411
298
|
"sdk": {
|
|
412
299
|
"name": "@eventra_dev/eventra-sdk",
|
|
413
|
-
"version": "
|
|
414
|
-
"runtime": "
|
|
300
|
+
"version": "ultra",
|
|
301
|
+
"runtime": "browser"
|
|
415
302
|
},
|
|
416
303
|
"events": [
|
|
417
304
|
{
|
|
@@ -424,16 +311,14 @@ Events are sent in batches:
|
|
|
424
311
|
}
|
|
425
312
|
```
|
|
426
313
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
# Documentation
|
|
314
|
+
---
|
|
430
315
|
|
|
431
|
-
|
|
316
|
+
## Docs
|
|
432
317
|
|
|
433
318
|
https://eventra.dev/docs
|
|
434
319
|
|
|
435
|
-
|
|
320
|
+
---
|
|
436
321
|
|
|
437
|
-
|
|
322
|
+
## License
|
|
438
323
|
|
|
439
324
|
MIT
|