@eventra_dev/eventra-sdk 1.0.7 → 1.1.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 CHANGED
@@ -4,63 +4,55 @@
4
4
 
5
5
  # Eventra SDK
6
6
 
7
- [![npm version](https://img.shields.io/npm/v/@eventra_dev/eventra-sdk.svg)](https://www.npmjs.com/package/@eventra_dev/eventra-sdk)
8
- [![npm downloads](https://img.shields.io/npm/dm/@eventra_dev/eventra-sdk.svg)](https://www.npmjs.com/package/@eventra_dev/eventra-sdk)
9
- [![TypeScript](https://img.shields.io/badge/typescript-ready-blue.svg)](https://www.typescriptlang.org/)
10
- [![License](https://img.shields.io/npm/l/@eventra_dev/eventra-sdk)]()
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
- - Track feature adoption
18
- - Detect unused features
19
- - Understand user behavior
20
- - Monitor backend usage
21
- - Analyze product growth
11
+ * Track feature adoption
12
+ * Detect unused features
13
+ * Understand user behavior
14
+ * Monitor backend usage
15
+ * Analyze product growth
22
16
 
23
- It is designed to be:
17
+ ---
24
18
 
25
- - lightweight
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
- # Installation
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
- Install the SDK using your preferred package manager.
30
+ ---
36
31
 
37
- ### npm
32
+ ## Installation
38
33
 
39
- ``` bash
34
+ ```bash
40
35
  npm i @eventra_dev/eventra-sdk
41
36
  ```
42
37
 
43
- ### pnpm
44
-
45
- ``` bash
38
+ ```bash
46
39
  pnpm add @eventra_dev/eventra-sdk
47
40
  ```
48
41
 
49
- ### yarn
50
-
51
- ``` bash
42
+ ```bash
52
43
  yarn add @eventra_dev/eventra-sdk
53
44
  ```
54
45
 
55
- ------------------------------------------------------------------------
46
+ ---
56
47
 
57
- # Quick Start
48
+ ## Quick Start
58
49
 
59
- ``` ts
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. Events are automatically:
63
+ That's it.
64
+
65
+ The SDK automatically handles:
72
66
 
73
- - batched
74
- - retried
75
- - flushed
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
- # Event Properties
87
+ No config needed.
80
88
 
81
- Eventra allows you to pass **optional properties** with every event.
89
+ ---
90
+
91
+ ## Event Properties
82
92
 
83
- Properties are completely flexible — you can send **any JSON-compatible data**.
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
- Properties are optional:
106
+ Minimal:
97
107
 
98
108
  ```ts
99
109
  tracker.track("app.loaded");
100
110
  ```
101
111
 
102
- Or with userId only:
103
-
104
- ```ts
105
- tracker.track("user.login", {
106
- userId: "user_123"
107
- });
108
- ```
109
-
110
- ------------------------------------------------------------------------
112
+ ---
111
113
 
112
- # Common Examples
114
+ ## Common Examples
113
115
 
114
- ## Feature Usage
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
- ## Page View
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
- ## API Usage
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
- ## Error Tracking
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
- Eventra SDK works in many environments:
168
+ ## Where You Can Use It
164
169
 
165
- * Browser applications
166
- * React apps
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
- * Bun
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
- # React Usage
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: "YOUR_PROJECT_API_KEY",
187
+ apiKey: "...",
210
188
  });
211
189
 
212
- export function App() {
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
- # Next.js Usage
198
+ ---
225
199
 
226
- Client component example:
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: "YOUR_PROJECT_API_KEY",
204
+ apiKey: "...",
235
205
  });
236
206
 
237
- export function CheckoutButton() {
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
- const tracker = new Eventra({
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
- # NestJS Usage
215
+ ### Serverless (IMPORTANT)
267
216
 
268
217
  ```ts
269
- import { Injectable } from "@nestjs/common";
270
- import { Eventra } from "@eventra_dev/eventra-sdk";
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
- charge(userId: string) {
280
- this.tracker.track("invoice.created", {
281
- userId
282
- });
283
- }
284
- }
285
- ```
286
-
287
- ------------------------------------------------------------------------
223
+ await tracker.track("function.called");
288
224
 
289
- # Express Usage
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
- import { Eventra } from "https://esm.sh/@eventra_dev/eventra-sdk";
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
- # Configuration
234
+ ## Configuration
330
235
 
331
236
  ```ts
332
- const eventra = new Eventra({
333
-
237
+ const tracker = new Eventra({
334
238
  apiKey: "YOUR_PROJECT_API_KEY",
335
- endpoint: "IF YOU NEED SOMETHING DIFFERENT",
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
- ```ts
363
- const tracker = new Eventra({
364
- apiKey: "YOUR_PROJECT_API_KEY",
365
- multiTabMode: "leader"
366
- });
367
- ```
249
+ ## Options
368
250
 
369
- Only one tab will send events.
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
- # Manual Flush
262
+ ## Manual Flush
374
263
 
375
264
  ```ts
376
265
  await tracker.flush();
377
266
  ```
378
267
 
379
- ------------------------------------------------------------------------
268
+ ---
380
269
 
381
- # Shutdown / Cleanup
270
+ ## Cleanup
382
271
 
383
272
  ```ts
384
273
  tracker.destroy();
385
274
  ```
386
275
 
387
- Stops timers and prevents further event sending.
276
+ Stops timers and clears internal state.
388
277
 
389
- ------------------------------------------------------------------------
390
-
391
- # Runtime Support
278
+ ---
392
279
 
393
- Eventra SDK works in:
280
+ ## Reliability Features
394
281
 
395
- * Node.js
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
- # Event Format
291
+ ---
405
292
 
406
- Events are sent in batches:
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": "1.0.2",
414
- "runtime": "node"
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
- Full documentation:
316
+ ## Docs
432
317
 
433
318
  https://eventra.dev/docs
434
319
 
435
- ------------------------------------------------------------------------
320
+ ---
436
321
 
437
- # License
322
+ ## License
438
323
 
439
324
  MIT