@eventra_dev/eventra-sdk 0.1.3 → 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 CHANGED
@@ -9,9 +9,10 @@ Eventra SDK allows you to send **feature usage and product analytics events** to
9
9
  It is designed to be:
10
10
 
11
11
  * lightweight
12
- * runtime-agnostic (Node.js / Browser / Bun / Deno)
12
+ * runtime-agnostic
13
13
  * resilient (batching + retry)
14
14
  * production-safe
15
+ * TypeScript-first
15
16
 
16
17
  ---
17
18
 
@@ -44,128 +45,229 @@ yarn add @eventra_dev/eventra-sdk
44
45
  ```ts
45
46
  import { Eventra } from "@eventra_dev/eventra-sdk";
46
47
 
47
- const eventra = new Eventra({
48
- apiKey: "your-api-key",
49
- endpoint: "https://api.eventra.dev/api/v1/events"
48
+ const tracker = new Eventra({
49
+ apiKey: "YOUR_PROJECT_API_KEY",
50
50
  });
51
51
 
52
- eventra.track("user_signup", {
52
+ tracker.track("checkout.completed", {
53
53
  userId: "user_123",
54
- properties: {
55
- plan: "pro"
56
- }
57
54
  });
58
55
  ```
59
56
 
60
57
  ---
61
58
 
62
- # Basic Usage
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
63
77
 
64
78
  ```ts
65
79
  import { Eventra } from "@eventra_dev/eventra-sdk";
66
80
 
67
- const client = new Eventra({
68
- apiKey: "your-api-key",
69
- endpoint: "https://api.eventra.dev/api/v1/events"
81
+ const tracker = new Eventra({
82
+ apiKey: "YOUR_PROJECT_API_KEY",
70
83
  });
71
84
 
72
- client.track("project_created", {
73
- userId: "user_1",
85
+ tracker.track("page.viewed", {
74
86
  properties: {
75
- projectId: "proj_123"
87
+ path: window.location.pathname
76
88
  }
77
89
  });
78
90
  ```
79
91
 
80
- Events are automatically:
92
+ The SDK automatically:
81
93
 
82
- * batched
83
- * retried
84
- * flushed periodically
94
+ * batches events
95
+ * retries failed requests
96
+ * flushes on page exit
85
97
 
86
98
  ---
87
99
 
88
- # Configuration
89
-
90
- You can configure the SDK behaviour:
100
+ # React Usage
91
101
 
92
102
  ```ts
93
- const eventra = new Eventra({
94
- apiKey: "your-api-key",
95
-
96
- endpoint: "https://api.eventra.dev/api/v1/events",
103
+ import { useEffect } from "react";
104
+ import { Eventra } from "@eventra_dev/eventra-sdk";
97
105
 
98
- flushInterval: 2000,
99
- maxBatchSize: 50,
100
- maxQueueSize: 10000,
101
- maxRetries: 3
106
+ const tracker = new Eventra({
107
+ apiKey: "YOUR_PROJECT_API_KEY",
102
108
  });
109
+
110
+ export function App() {
111
+
112
+ useEffect(() => {
113
+ tracker.track("app.loaded");
114
+ }, []);
115
+
116
+ return <div>Hello</div>;
117
+ }
103
118
  ```
104
119
 
105
- ### Options
120
+ ---
106
121
 
107
- | option | description |
108
- | ------------- | ---------------------------------- |
109
- | apiKey | Project API key |
110
- | endpoint | Event ingestion endpoint |
111
- | flushInterval | Batch flush interval (ms) |
112
- | maxBatchSize | Maximum events per batch |
113
- | maxQueueSize | Maximum buffered events |
114
- | maxRetries | Retry attempts for failed requests |
122
+ # Next.js Usage
123
+
124
+ Client component example:
125
+
126
+ ```ts
127
+ "use client";
128
+
129
+ import { Eventra } from "@eventra_dev/eventra-sdk";
130
+
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
+ ```
115
145
 
116
146
  ---
117
147
 
118
- # Browser Usage
148
+ # Node.js Usage
119
149
 
120
150
  ```ts
121
151
  import { Eventra } from "@eventra_dev/eventra-sdk";
122
152
 
123
- const eventra = new Eventra({
124
- apiKey: "public-api-key",
125
- endpoint: "https://api.eventra.dev/api/v1/events"
153
+ const tracker = new Eventra({
154
+ apiKey: "YOUR_PROJECT_API_KEY",
126
155
  });
127
156
 
128
- eventra.track("page_view", {
129
- properties: {
130
- path: window.location.pathname
131
- }
157
+ tracker.track("invoice.created", {
158
+ userId: "user_123",
132
159
  });
133
160
  ```
134
161
 
135
- The SDK automatically:
162
+ ---
136
163
 
137
- * batches events
138
- * retries failed requests
139
- * flushes on page exit
164
+ # NestJS Usage
165
+
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
+ ```
140
184
 
141
185
  ---
142
186
 
143
- # Node.js Usage
187
+ # Express Usage
144
188
 
145
189
  ```ts
190
+ import express from "express";
146
191
  import { Eventra } from "@eventra_dev/eventra-sdk";
147
192
 
148
- const eventra = new Eventra({
149
- apiKey: process.env.EVENTRA_API_KEY!,
150
- endpoint: "https://api.eventra.dev/api/v1/events"
193
+ const app = express();
194
+
195
+ const tracker = new Eventra({
196
+ apiKey: "YOUR_PROJECT_API_KEY",
151
197
  });
152
198
 
153
- eventra.track("job_completed", {
154
- properties: {
155
- duration: 120
156
- }
199
+ app.post("/checkout", (req, res) => {
200
+
201
+ tracker.track("checkout.completed");
202
+
203
+ res.sendStatus(200);
157
204
  });
158
205
  ```
159
206
 
160
207
  ---
161
208
 
162
- # Multi-tab Mode (Browser)
209
+ # Vanilla JavaScript (CDN)
210
+
211
+ You can use Eventra without a bundler.
212
+
213
+ ```html
214
+ <script type="module">
163
215
 
164
- To avoid duplicate event sending across multiple tabs you can enable leader mode:
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>
225
+ ```
226
+
227
+ ---
228
+
229
+ # Configuration
230
+
231
+ You can configure the SDK behaviour.
165
232
 
166
233
  ```ts
167
234
  const eventra = new Eventra({
168
- apiKey: "your-api-key",
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
+ });
246
+ ```
247
+
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:
267
+
268
+ ```ts
269
+ const tracker = new Eventra({
270
+ apiKey: "YOUR_PROJECT_API_KEY",
169
271
  multiTabMode: "leader"
170
272
  });
171
273
  ```
@@ -176,10 +278,8 @@ Only one tab will send events.
176
278
 
177
279
  # Manual Flush
178
280
 
179
- You can flush the queue manually:
180
-
181
281
  ```ts
182
- await eventra.flush();
282
+ await tracker.flush();
183
283
  ```
184
284
 
185
285
  ---
@@ -187,7 +287,7 @@ await eventra.flush();
187
287
  # Shutdown / Cleanup
188
288
 
189
289
  ```ts
190
- eventra.destroy();
290
+ tracker.destroy();
191
291
  ```
192
292
 
193
293
  Stops timers and prevents further event sending.
@@ -196,13 +296,14 @@ Stops timers and prevents further event sending.
196
296
 
197
297
  # Runtime Support
198
298
 
199
- The SDK works in:
299
+ Eventra SDK works in:
200
300
 
201
301
  * Node.js
202
302
  * Browser
203
303
  * Bun
204
304
  * Deno
205
305
  * Edge runtimes
306
+ * Serverless environments
206
307
 
207
308
  ---
208
309
 
@@ -234,7 +335,8 @@ Events are sent in batches:
234
335
  # Error Handling
235
336
 
236
337
  Client errors (4xx) are **not retried**.
237
- Server errors (5xx) are retried with **exponential backoff**.
338
+
339
+ Server errors (5xx) are retried using **exponential backoff**.
238
340
 
239
341
  ---
240
342
 
package/dist/index.cjs CHANGED
@@ -25,7 +25,7 @@ __export(index_exports, {
25
25
  module.exports = __toCommonJS(index_exports);
26
26
 
27
27
  // src/client.ts
28
- var SDK_VERSION = "0.1.3";
28
+ var SDK_VERSION = "0.1.4";
29
29
  var DEFAULTS = {
30
30
  endpoint: "http://api.eventra.dev/api/v1/ingest/batch",
31
31
  flushInterval: 2e3,
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/client.ts
2
- var SDK_VERSION = "0.1.3";
2
+ var SDK_VERSION = "0.1.4";
3
3
  var DEFAULTS = {
4
4
  endpoint: "http://api.eventra.dev/api/v1/ingest/batch",
5
5
  flushInterval: 2e3,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventra_dev/eventra-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"