@eventra_dev/eventra-sdk 0.1.2 → 0.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 +249 -93
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,194 +1,350 @@
|
|
|
1
1
|
# Eventra SDK
|
|
2
2
|
|
|
3
|
-

|
|
4
|
-

|
|
3
|
+
[](https://www.npmjs.com/package/@eventra_dev/eventra-sdk)
|
|
4
|
+
[](https://www.npmjs.com/package/@eventra_dev/eventra-sdk)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
Eventra SDK allows you to send **feature usage and product analytics events** to the Eventra platform.
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
It is designed to be:
|
|
10
|
+
|
|
11
|
+
* lightweight
|
|
12
|
+
* runtime-agnostic
|
|
13
|
+
* resilient (batching + retry)
|
|
14
|
+
* production-safe
|
|
15
|
+
* TypeScript-first
|
|
11
16
|
|
|
12
17
|
---
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
# Installation
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
- Safe retry policy
|
|
18
|
-
- Exponential backoff with jitter
|
|
19
|
-
- sendBeacon support for browsers
|
|
20
|
-
- Multi-runtime support (Browser / Node / Bun / Deno / Edge)
|
|
21
|
-
- Optional multi-tab leader mode
|
|
22
|
-
- Queue overflow protection
|
|
23
|
-
- Zero dependencies
|
|
21
|
+
Install the SDK using your preferred package manager.
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
### npm
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm i @eventra_dev/eventra-sdk
|
|
27
|
+
```
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
### pnpm
|
|
28
30
|
|
|
29
31
|
```bash
|
|
30
|
-
pnpm add @eventra
|
|
32
|
+
pnpm add @eventra_dev/eventra-sdk
|
|
31
33
|
```
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
### yarn
|
|
34
36
|
|
|
35
37
|
```bash
|
|
36
|
-
|
|
38
|
+
yarn add @eventra_dev/eventra-sdk
|
|
37
39
|
```
|
|
38
40
|
|
|
39
41
|
---
|
|
40
42
|
|
|
41
|
-
#
|
|
42
|
-
|
|
43
|
-
## Browser
|
|
43
|
+
# Quick Start
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
|
-
import { Eventra } from "@eventra
|
|
46
|
+
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
47
47
|
|
|
48
48
|
const tracker = new Eventra({
|
|
49
|
-
apiKey: "
|
|
49
|
+
apiKey: "YOUR_PROJECT_API_KEY",
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
tracker.track("checkout.completed", {
|
|
53
|
-
userId: "user_123"
|
|
53
|
+
userId: "user_123",
|
|
54
54
|
});
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
---
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
# Where You Can Use Eventra SDK
|
|
60
|
+
|
|
61
|
+
Eventra SDK works in many environments:
|
|
62
|
+
|
|
63
|
+
* Browser applications
|
|
64
|
+
* React apps
|
|
65
|
+
* Next.js apps
|
|
66
|
+
* Node.js backends
|
|
67
|
+
* NestJS services
|
|
68
|
+
* Express APIs
|
|
69
|
+
* Vanilla JavaScript
|
|
70
|
+
* Edge runtimes
|
|
71
|
+
* Bun
|
|
72
|
+
* Deno
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
# Browser Usage
|
|
60
77
|
|
|
61
78
|
```ts
|
|
62
|
-
import { Eventra } from "@eventra
|
|
79
|
+
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
63
80
|
|
|
64
81
|
const tracker = new Eventra({
|
|
65
|
-
apiKey:
|
|
82
|
+
apiKey: "YOUR_PROJECT_API_KEY",
|
|
66
83
|
});
|
|
67
84
|
|
|
68
|
-
tracker.track("
|
|
69
|
-
|
|
85
|
+
tracker.track("page.viewed", {
|
|
86
|
+
properties: {
|
|
87
|
+
path: window.location.pathname
|
|
88
|
+
}
|
|
70
89
|
});
|
|
71
90
|
```
|
|
72
91
|
|
|
73
|
-
|
|
92
|
+
The SDK automatically:
|
|
74
93
|
|
|
75
|
-
|
|
94
|
+
* batches events
|
|
95
|
+
* retries failed requests
|
|
96
|
+
* flushes on page exit
|
|
76
97
|
|
|
77
|
-
|
|
78
|
-
|------|------|
|
|
79
|
-
| flushInterval | 2000 ms |
|
|
80
|
-
| maxBatchSize | 50 |
|
|
81
|
-
| maxRetries | 3 |
|
|
82
|
-
| maxQueueSize | 10000 |
|
|
83
|
-
| retryBaseDelayMs | 300 |
|
|
98
|
+
---
|
|
84
99
|
|
|
85
|
-
|
|
100
|
+
# React Usage
|
|
86
101
|
|
|
87
102
|
```ts
|
|
103
|
+
import { useEffect } from "react";
|
|
104
|
+
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
105
|
+
|
|
88
106
|
const tracker = new Eventra({
|
|
89
|
-
apiKey: "
|
|
90
|
-
flushInterval: 2000,
|
|
91
|
-
maxBatchSize: 50
|
|
107
|
+
apiKey: "YOUR_PROJECT_API_KEY",
|
|
92
108
|
});
|
|
109
|
+
|
|
110
|
+
export function App() {
|
|
111
|
+
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
tracker.track("app.loaded");
|
|
114
|
+
}, []);
|
|
115
|
+
|
|
116
|
+
return <div>Hello</div>;
|
|
117
|
+
}
|
|
93
118
|
```
|
|
94
119
|
|
|
95
120
|
---
|
|
96
121
|
|
|
97
|
-
#
|
|
122
|
+
# Next.js Usage
|
|
123
|
+
|
|
124
|
+
Client component example:
|
|
98
125
|
|
|
99
|
-
|
|
126
|
+
```ts
|
|
127
|
+
"use client";
|
|
100
128
|
|
|
101
|
-
|
|
129
|
+
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
102
130
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
131
|
+
const tracker = new Eventra({
|
|
132
|
+
apiKey: "YOUR_PROJECT_API_KEY",
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
export function CheckoutButton() {
|
|
136
|
+
return (
|
|
137
|
+
<button
|
|
138
|
+
onClick={() => tracker.track("checkout.started")}
|
|
139
|
+
>
|
|
140
|
+
Checkout
|
|
141
|
+
</button>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
```
|
|
106
145
|
|
|
107
146
|
---
|
|
108
147
|
|
|
109
|
-
|
|
148
|
+
# Node.js Usage
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
110
152
|
|
|
111
|
-
|
|
153
|
+
const tracker = new Eventra({
|
|
154
|
+
apiKey: "YOUR_PROJECT_API_KEY",
|
|
155
|
+
});
|
|
112
156
|
|
|
113
|
-
|
|
114
|
-
|
|
157
|
+
tracker.track("invoice.created", {
|
|
158
|
+
userId: "user_123",
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
115
163
|
|
|
116
|
-
|
|
164
|
+
# NestJS Usage
|
|
117
165
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
166
|
+
```ts
|
|
167
|
+
import { Injectable } from "@nestjs/common";
|
|
168
|
+
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
169
|
+
|
|
170
|
+
@Injectable()
|
|
171
|
+
export class BillingService {
|
|
172
|
+
|
|
173
|
+
private tracker = new Eventra({
|
|
174
|
+
apiKey: "YOUR_PROJECT_API_KEY",
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
charge(userId: string) {
|
|
178
|
+
this.tracker.track("invoice.created", {
|
|
179
|
+
userId
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
```
|
|
121
184
|
|
|
122
185
|
---
|
|
123
186
|
|
|
124
|
-
|
|
187
|
+
# Express Usage
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
import express from "express";
|
|
191
|
+
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
192
|
+
|
|
193
|
+
const app = express();
|
|
125
194
|
|
|
195
|
+
const tracker = new Eventra({
|
|
196
|
+
apiKey: "YOUR_PROJECT_API_KEY",
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
app.post("/checkout", (req, res) => {
|
|
200
|
+
|
|
201
|
+
tracker.track("checkout.completed");
|
|
202
|
+
|
|
203
|
+
res.sendStatus(200);
|
|
204
|
+
});
|
|
126
205
|
```
|
|
127
|
-
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
# Vanilla JavaScript (CDN)
|
|
210
|
+
|
|
211
|
+
You can use Eventra without a bundler.
|
|
212
|
+
|
|
213
|
+
```html
|
|
214
|
+
<script type="module">
|
|
215
|
+
|
|
216
|
+
import { Eventra } from "https://esm.sh/@eventra_dev/eventra-sdk";
|
|
217
|
+
|
|
218
|
+
const tracker = new Eventra({
|
|
219
|
+
apiKey: "YOUR_PROJECT_API_KEY",
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
tracker.track("page.viewed");
|
|
223
|
+
|
|
224
|
+
</script>
|
|
128
225
|
```
|
|
129
226
|
|
|
130
227
|
---
|
|
131
228
|
|
|
132
|
-
#
|
|
229
|
+
# Configuration
|
|
133
230
|
|
|
134
|
-
|
|
231
|
+
You can configure the SDK behaviour.
|
|
135
232
|
|
|
136
233
|
```ts
|
|
137
|
-
|
|
234
|
+
const eventra = new Eventra({
|
|
235
|
+
|
|
236
|
+
apiKey: "YOUR_PROJECT_API_KEY",
|
|
237
|
+
|
|
238
|
+
endpoint: "https://api.eventra.dev/api/v1/events",
|
|
239
|
+
|
|
240
|
+
flushInterval: 2000,
|
|
241
|
+
maxBatchSize: 50,
|
|
242
|
+
maxQueueSize: 10000,
|
|
243
|
+
maxRetries: 3
|
|
244
|
+
|
|
245
|
+
});
|
|
138
246
|
```
|
|
139
247
|
|
|
140
|
-
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
# Options
|
|
251
|
+
|
|
252
|
+
| option | description |
|
|
253
|
+
| ------------- | ---------------------------------- |
|
|
254
|
+
| apiKey | Project API key |
|
|
255
|
+
| endpoint | Event ingestion endpoint |
|
|
256
|
+
| flushInterval | Batch flush interval (ms) |
|
|
257
|
+
| maxBatchSize | Maximum events per batch |
|
|
258
|
+
| maxQueueSize | Maximum buffered events |
|
|
259
|
+
| maxRetries | Retry attempts for failed requests |
|
|
260
|
+
| multiTabMode | Browser tab coordination mode |
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
# Multi-Tab Mode (Browser)
|
|
265
|
+
|
|
266
|
+
To avoid duplicate event sending across multiple tabs:
|
|
141
267
|
|
|
142
268
|
```ts
|
|
143
269
|
const tracker = new Eventra({
|
|
144
|
-
apiKey: "
|
|
270
|
+
apiKey: "YOUR_PROJECT_API_KEY",
|
|
145
271
|
multiTabMode: "leader"
|
|
146
272
|
});
|
|
147
273
|
```
|
|
148
274
|
|
|
149
|
-
|
|
275
|
+
Only one tab will send events.
|
|
150
276
|
|
|
151
277
|
---
|
|
152
278
|
|
|
153
|
-
#
|
|
279
|
+
# Manual Flush
|
|
154
280
|
|
|
281
|
+
```ts
|
|
282
|
+
await tracker.flush();
|
|
155
283
|
```
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
▼
|
|
164
|
-
Eventra Ingest API
|
|
165
|
-
│
|
|
166
|
-
idempotent pipeline
|
|
167
|
-
│
|
|
168
|
-
▼
|
|
169
|
-
Eventra Event Store
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
# Shutdown / Cleanup
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
tracker.destroy();
|
|
170
291
|
```
|
|
171
292
|
|
|
293
|
+
Stops timers and prevents further event sending.
|
|
294
|
+
|
|
172
295
|
---
|
|
173
296
|
|
|
174
|
-
#
|
|
297
|
+
# Runtime Support
|
|
175
298
|
|
|
176
|
-
|
|
299
|
+
Eventra SDK works in:
|
|
177
300
|
|
|
178
|
-
|
|
301
|
+
* Node.js
|
|
302
|
+
* Browser
|
|
303
|
+
* Bun
|
|
304
|
+
* Deno
|
|
305
|
+
* Edge runtimes
|
|
306
|
+
* Serverless environments
|
|
179
307
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
# Event Format
|
|
311
|
+
|
|
312
|
+
Events are sent in batches:
|
|
313
|
+
|
|
314
|
+
```json
|
|
315
|
+
{
|
|
316
|
+
"sentAt": "2026-03-12T10:00:00Z",
|
|
317
|
+
"sdk": {
|
|
318
|
+
"name": "@eventra_dev/eventra-sdk",
|
|
319
|
+
"version": "0.1.2",
|
|
320
|
+
"runtime": "node"
|
|
321
|
+
},
|
|
322
|
+
"events": [
|
|
323
|
+
{
|
|
324
|
+
"name": "user_signup",
|
|
325
|
+
"userId": "user_123",
|
|
326
|
+
"timestamp": "2026-03-12T10:00:00Z",
|
|
327
|
+
"properties": {}
|
|
328
|
+
}
|
|
329
|
+
]
|
|
330
|
+
}
|
|
184
331
|
```
|
|
185
332
|
|
|
186
|
-
|
|
333
|
+
---
|
|
187
334
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
335
|
+
# Error Handling
|
|
336
|
+
|
|
337
|
+
Client errors (4xx) are **not retried**.
|
|
338
|
+
|
|
339
|
+
Server errors (5xx) are retried using **exponential backoff**.
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
# Documentation
|
|
344
|
+
|
|
345
|
+
Full documentation:
|
|
346
|
+
|
|
347
|
+
https://eventra.dev/docs
|
|
192
348
|
|
|
193
349
|
---
|
|
194
350
|
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED