@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 +170 -68
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
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
|
|
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
|
|
48
|
-
apiKey: "
|
|
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
|
-
|
|
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
|
-
#
|
|
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
|
|
68
|
-
apiKey: "
|
|
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
|
-
|
|
73
|
-
userId: "user_1",
|
|
85
|
+
tracker.track("page.viewed", {
|
|
74
86
|
properties: {
|
|
75
|
-
|
|
87
|
+
path: window.location.pathname
|
|
76
88
|
}
|
|
77
89
|
});
|
|
78
90
|
```
|
|
79
91
|
|
|
80
|
-
|
|
92
|
+
The SDK automatically:
|
|
81
93
|
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
94
|
+
* batches events
|
|
95
|
+
* retries failed requests
|
|
96
|
+
* flushes on page exit
|
|
85
97
|
|
|
86
98
|
---
|
|
87
99
|
|
|
88
|
-
#
|
|
89
|
-
|
|
90
|
-
You can configure the SDK behaviour:
|
|
100
|
+
# React Usage
|
|
91
101
|
|
|
92
102
|
```ts
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
99
|
-
|
|
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
|
-
|
|
120
|
+
---
|
|
106
121
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
#
|
|
148
|
+
# Node.js Usage
|
|
119
149
|
|
|
120
150
|
```ts
|
|
121
151
|
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
122
152
|
|
|
123
|
-
const
|
|
124
|
-
apiKey: "
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
path: window.location.pathname
|
|
131
|
-
}
|
|
157
|
+
tracker.track("invoice.created", {
|
|
158
|
+
userId: "user_123",
|
|
132
159
|
});
|
|
133
160
|
```
|
|
134
161
|
|
|
135
|
-
|
|
162
|
+
---
|
|
136
163
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
#
|
|
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
|
|
149
|
-
|
|
150
|
-
|
|
193
|
+
const app = express();
|
|
194
|
+
|
|
195
|
+
const tracker = new Eventra({
|
|
196
|
+
apiKey: "YOUR_PROJECT_API_KEY",
|
|
151
197
|
});
|
|
152
198
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
#
|
|
209
|
+
# Vanilla JavaScript (CDN)
|
|
210
|
+
|
|
211
|
+
You can use Eventra without a bundler.
|
|
212
|
+
|
|
213
|
+
```html
|
|
214
|
+
<script type="module">
|
|
163
215
|
|
|
164
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
338
|
+
|
|
339
|
+
Server errors (5xx) are retried using **exponential backoff**.
|
|
238
340
|
|
|
239
341
|
---
|
|
240
342
|
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED