@eventra_dev/eventra-sdk 0.1.2 → 0.1.3
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 +157 -103
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,194 +1,248 @@
|
|
|
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 (Node.js / Browser / Bun / Deno)
|
|
13
|
+
* resilient (batching + retry)
|
|
14
|
+
* production-safe
|
|
11
15
|
|
|
12
16
|
---
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
# Installation
|
|
15
19
|
|
|
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
|
|
20
|
+
Install the SDK using your preferred package manager.
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
### npm
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm i @eventra_dev/eventra-sdk
|
|
26
|
+
```
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
### pnpm
|
|
28
29
|
|
|
29
30
|
```bash
|
|
30
|
-
pnpm add @eventra
|
|
31
|
+
pnpm add @eventra_dev/eventra-sdk
|
|
31
32
|
```
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
### yarn
|
|
34
35
|
|
|
35
36
|
```bash
|
|
36
|
-
|
|
37
|
+
yarn add @eventra_dev/eventra-sdk
|
|
37
38
|
```
|
|
38
39
|
|
|
39
40
|
---
|
|
40
41
|
|
|
41
|
-
#
|
|
42
|
-
|
|
43
|
-
## Browser
|
|
42
|
+
# Quick Start
|
|
44
43
|
|
|
45
44
|
```ts
|
|
46
|
-
import { Eventra } from "@eventra
|
|
45
|
+
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
47
46
|
|
|
48
|
-
const
|
|
49
|
-
apiKey: "
|
|
47
|
+
const eventra = new Eventra({
|
|
48
|
+
apiKey: "your-api-key",
|
|
49
|
+
endpoint: "https://api.eventra.dev/api/v1/events"
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
userId: "user_123"
|
|
52
|
+
eventra.track("user_signup", {
|
|
53
|
+
userId: "user_123",
|
|
54
|
+
properties: {
|
|
55
|
+
plan: "pro"
|
|
56
|
+
}
|
|
54
57
|
});
|
|
55
58
|
```
|
|
56
59
|
|
|
57
60
|
---
|
|
58
61
|
|
|
59
|
-
|
|
62
|
+
# Basic Usage
|
|
60
63
|
|
|
61
64
|
```ts
|
|
62
|
-
import { Eventra } from "@eventra
|
|
65
|
+
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
63
66
|
|
|
64
|
-
const
|
|
65
|
-
apiKey:
|
|
67
|
+
const client = new Eventra({
|
|
68
|
+
apiKey: "your-api-key",
|
|
69
|
+
endpoint: "https://api.eventra.dev/api/v1/events"
|
|
66
70
|
});
|
|
67
71
|
|
|
68
|
-
|
|
69
|
-
userId: "
|
|
72
|
+
client.track("project_created", {
|
|
73
|
+
userId: "user_1",
|
|
74
|
+
properties: {
|
|
75
|
+
projectId: "proj_123"
|
|
76
|
+
}
|
|
70
77
|
});
|
|
71
78
|
```
|
|
72
79
|
|
|
73
|
-
|
|
80
|
+
Events are automatically:
|
|
81
|
+
|
|
82
|
+
* batched
|
|
83
|
+
* retried
|
|
84
|
+
* flushed periodically
|
|
74
85
|
|
|
75
|
-
|
|
86
|
+
---
|
|
76
87
|
|
|
77
|
-
|
|
78
|
-
|------|------|
|
|
79
|
-
| flushInterval | 2000 ms |
|
|
80
|
-
| maxBatchSize | 50 |
|
|
81
|
-
| maxRetries | 3 |
|
|
82
|
-
| maxQueueSize | 10000 |
|
|
83
|
-
| retryBaseDelayMs | 300 |
|
|
88
|
+
# Configuration
|
|
84
89
|
|
|
85
|
-
|
|
90
|
+
You can configure the SDK behaviour:
|
|
86
91
|
|
|
87
92
|
```ts
|
|
88
|
-
const
|
|
89
|
-
apiKey: "
|
|
93
|
+
const eventra = new Eventra({
|
|
94
|
+
apiKey: "your-api-key",
|
|
95
|
+
|
|
96
|
+
endpoint: "https://api.eventra.dev/api/v1/events",
|
|
97
|
+
|
|
90
98
|
flushInterval: 2000,
|
|
91
|
-
maxBatchSize: 50
|
|
99
|
+
maxBatchSize: 50,
|
|
100
|
+
maxQueueSize: 10000,
|
|
101
|
+
maxRetries: 3
|
|
92
102
|
});
|
|
93
103
|
```
|
|
94
104
|
|
|
105
|
+
### Options
|
|
106
|
+
|
|
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 |
|
|
115
|
+
|
|
95
116
|
---
|
|
96
117
|
|
|
97
|
-
#
|
|
118
|
+
# Browser Usage
|
|
98
119
|
|
|
99
|
-
|
|
120
|
+
```ts
|
|
121
|
+
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
100
122
|
|
|
101
|
-
|
|
123
|
+
const eventra = new Eventra({
|
|
124
|
+
apiKey: "public-api-key",
|
|
125
|
+
endpoint: "https://api.eventra.dev/api/v1/events"
|
|
126
|
+
});
|
|
102
127
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
128
|
+
eventra.track("page_view", {
|
|
129
|
+
properties: {
|
|
130
|
+
path: window.location.pathname
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
```
|
|
106
134
|
|
|
107
|
-
|
|
135
|
+
The SDK automatically:
|
|
108
136
|
|
|
109
|
-
|
|
137
|
+
* batches events
|
|
138
|
+
* retries failed requests
|
|
139
|
+
* flushes on page exit
|
|
110
140
|
|
|
111
|
-
|
|
141
|
+
---
|
|
112
142
|
|
|
113
|
-
|
|
114
|
-
✔ HTTP 5xx
|
|
143
|
+
# Node.js Usage
|
|
115
144
|
|
|
116
|
-
|
|
145
|
+
```ts
|
|
146
|
+
import { Eventra } from "@eventra_dev/eventra-sdk";
|
|
147
|
+
|
|
148
|
+
const eventra = new Eventra({
|
|
149
|
+
apiKey: process.env.EVENTRA_API_KEY!,
|
|
150
|
+
endpoint: "https://api.eventra.dev/api/v1/events"
|
|
151
|
+
});
|
|
117
152
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
153
|
+
eventra.track("job_completed", {
|
|
154
|
+
properties: {
|
|
155
|
+
duration: 120
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
```
|
|
121
159
|
|
|
122
160
|
---
|
|
123
161
|
|
|
124
|
-
|
|
162
|
+
# Multi-tab Mode (Browser)
|
|
125
163
|
|
|
164
|
+
To avoid duplicate event sending across multiple tabs you can enable leader mode:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
const eventra = new Eventra({
|
|
168
|
+
apiKey: "your-api-key",
|
|
169
|
+
multiTabMode: "leader"
|
|
170
|
+
});
|
|
126
171
|
```
|
|
127
|
-
|
|
128
|
-
|
|
172
|
+
|
|
173
|
+
Only one tab will send events.
|
|
129
174
|
|
|
130
175
|
---
|
|
131
176
|
|
|
132
|
-
#
|
|
177
|
+
# Manual Flush
|
|
133
178
|
|
|
134
|
-
|
|
179
|
+
You can flush the queue manually:
|
|
135
180
|
|
|
136
181
|
```ts
|
|
137
|
-
|
|
182
|
+
await eventra.flush();
|
|
138
183
|
```
|
|
139
184
|
|
|
140
|
-
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
# Shutdown / Cleanup
|
|
141
188
|
|
|
142
189
|
```ts
|
|
143
|
-
|
|
144
|
-
apiKey: "API_KEY",
|
|
145
|
-
multiTabMode: "leader"
|
|
146
|
-
});
|
|
190
|
+
eventra.destroy();
|
|
147
191
|
```
|
|
148
192
|
|
|
149
|
-
|
|
193
|
+
Stops timers and prevents further event sending.
|
|
150
194
|
|
|
151
195
|
---
|
|
152
196
|
|
|
153
|
-
#
|
|
197
|
+
# Runtime Support
|
|
154
198
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
199
|
+
The SDK works in:
|
|
200
|
+
|
|
201
|
+
* Node.js
|
|
202
|
+
* Browser
|
|
203
|
+
* Bun
|
|
204
|
+
* Deno
|
|
205
|
+
* Edge runtimes
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
# Event Format
|
|
210
|
+
|
|
211
|
+
Events are sent in batches:
|
|
212
|
+
|
|
213
|
+
```json
|
|
214
|
+
{
|
|
215
|
+
"sentAt": "2026-03-12T10:00:00Z",
|
|
216
|
+
"sdk": {
|
|
217
|
+
"name": "@eventra_dev/eventra-sdk",
|
|
218
|
+
"version": "0.1.2",
|
|
219
|
+
"runtime": "node"
|
|
220
|
+
},
|
|
221
|
+
"events": [
|
|
222
|
+
{
|
|
223
|
+
"name": "user_signup",
|
|
224
|
+
"userId": "user_123",
|
|
225
|
+
"timestamp": "2026-03-12T10:00:00Z",
|
|
226
|
+
"properties": {}
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
}
|
|
170
230
|
```
|
|
171
231
|
|
|
172
232
|
---
|
|
173
233
|
|
|
174
|
-
#
|
|
234
|
+
# Error Handling
|
|
175
235
|
|
|
176
|
-
|
|
236
|
+
Client errors (4xx) are **not retried**.
|
|
237
|
+
Server errors (5xx) are retried with **exponential backoff**.
|
|
177
238
|
|
|
178
|
-
|
|
239
|
+
---
|
|
179
240
|
|
|
180
|
-
|
|
181
|
-
invoice.created
|
|
182
|
-
checkout.completed
|
|
183
|
-
team.invited
|
|
184
|
-
```
|
|
241
|
+
# Documentation
|
|
185
242
|
|
|
186
|
-
|
|
243
|
+
Full documentation:
|
|
187
244
|
|
|
188
|
-
|
|
189
|
-
button_clicked
|
|
190
|
-
modal_opened
|
|
191
|
-
```
|
|
245
|
+
https://eventra.dev/docs
|
|
192
246
|
|
|
193
247
|
---
|
|
194
248
|
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED