@dataxamas/tracker-js 1.0.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 +256 -0
- package/dist/index.cjs +672 -0
- package/dist/index.d.cts +142 -0
- package/dist/index.d.ts +142 -0
- package/dist/index.js +672 -0
- package/dist/rrweb-F6UF6U3D.js +17611 -0
- package/dist/rrweb-M7O3D3Q3.cjs +17611 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# Dataxamas SDK
|
|
2
|
+
|
|
3
|
+
Official JavaScript/TypeScript SDK for the [Dataxamas](https://dataxamas.izakdvlpr.com) analytics platform.
|
|
4
|
+
|
|
5
|
+
One package, three capabilities:
|
|
6
|
+
|
|
7
|
+
- **Logs** — structured, colorized logs shipped to Dataxamas (works in Node and the browser).
|
|
8
|
+
- **Error tracking** — capture exceptions manually or hook global handlers automatically.
|
|
9
|
+
- **Web analytics** — page views, clicks, scroll depth, heat-map interactions, and full session replay (rrweb). Browser-only.
|
|
10
|
+
|
|
11
|
+
Written in TypeScript, ships ESM + CJS with bundled type declarations. No peer dependencies — `rrweb` is bundled and lazy-loaded only when replay actually starts.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add @dataxamas/tracker-js
|
|
19
|
+
# or
|
|
20
|
+
npm install @dataxamas/tracker-js
|
|
21
|
+
# or
|
|
22
|
+
pnpm add @dataxamas/tracker-js
|
|
23
|
+
# or
|
|
24
|
+
yarn add @dataxamas/tracker-js
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
30
|
+
|
|
31
|
+
### Browser (analytics + logs + error tracking)
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { Dataxamas } from "@dataxamas/tracker-js";
|
|
35
|
+
|
|
36
|
+
const client = new Dataxamas({
|
|
37
|
+
apiKey: "dx_live_xxx",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Global error capture is installed automatically.
|
|
41
|
+
// Start collecting page views / clicks / scroll / replay:
|
|
42
|
+
client.tracking.start();
|
|
43
|
+
|
|
44
|
+
client.logs.info("App booted", { version: "1.0.0" });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Server / Node (logs + error tracking only)
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { Dataxamas } from "@dataxamas/tracker-js";
|
|
51
|
+
|
|
52
|
+
const client = new Dataxamas({
|
|
53
|
+
apiKey: "dx_live_xxx",
|
|
54
|
+
environment: "production",
|
|
55
|
+
release: "1.0.0",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
client.logs.success("Payment processed", { amount: 1999 });
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
riskyWork();
|
|
62
|
+
} catch (error) {
|
|
63
|
+
client.exceptions.captureException(error, { userId: 42 });
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
> `client.tracking` exists on the server too, but calling `client.tracking.start()` outside a browser throws. See [Browser vs Server](#browser-vs-server).
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Browser vs Server
|
|
72
|
+
|
|
73
|
+
| Feature | Browser | Node / Server |
|
|
74
|
+
| --- | --- | --- |
|
|
75
|
+
| `client.logs.*` | ✅ | ✅ |
|
|
76
|
+
| `client.exceptions.*` | ✅ | ✅ |
|
|
77
|
+
| `client.tracking.start()` | ✅ | ❌ throws `browser environment` error |
|
|
78
|
+
|
|
79
|
+
- **Tracking is browser-only.** `DataxamasTracking.start()` throws if `window`/`document` are missing, and is a silent no-op on `localhost`/`127.0.0.1` unless `allowLocalhost` is set.
|
|
80
|
+
- **`rrweb` (session replay) is lazy-loaded.** It is only imported (`await import("rrweb")`) when replay starts in the browser, so importing the SDK on the server never pulls it in. In the build it lives in a separate chunk, keeping the main bundle small.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## API Reference
|
|
85
|
+
|
|
86
|
+
### `Dataxamas`
|
|
87
|
+
|
|
88
|
+
The all-in-one facade. Creating it wires up logs, exceptions, and tracking, and installs global error handlers (unless disabled).
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const client = new Dataxamas(options);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Options** (`DataxamasOptions`)
|
|
95
|
+
|
|
96
|
+
| Option | Type | Default | Description |
|
|
97
|
+
| --- | --- | --- | --- |
|
|
98
|
+
| `apiKey` | `string` | — | **Required.** Website API key (`dx_live_`) used by logs, errors and tracking. |
|
|
99
|
+
| `baseUrl` | `string` | `https://dataxamas.izakdvlpr.com` | API base URL. |
|
|
100
|
+
| `enableLogs` | `boolean` | `true` | Enable the logs channel. |
|
|
101
|
+
| `enableErrorTracking` | `boolean` | `true` | Enable exception capture. |
|
|
102
|
+
| `captureGlobalErrors` | `boolean` | `true` | Auto-install global error/rejection handlers. |
|
|
103
|
+
| `environment` | `string` | `undefined` | Environment tag attached to captured errors. |
|
|
104
|
+
| `release` | `string` | `undefined` | Release/version tag attached to captured errors. |
|
|
105
|
+
| `replayEnabled` | `boolean` | `true` | Allow session replay (still gated by server config). |
|
|
106
|
+
| `heatMapEnabled` | `boolean` | `true` | Collect heat-map data on clicks. |
|
|
107
|
+
| `allowLocalhost` | `boolean` | `false` | Allow tracking on `localhost`/`127.0.0.1`. |
|
|
108
|
+
|
|
109
|
+
**Properties**
|
|
110
|
+
|
|
111
|
+
| Property | Type | Description |
|
|
112
|
+
| --- | --- | --- |
|
|
113
|
+
| `logs` | `DataxamasLogs` | Structured logging. |
|
|
114
|
+
| `exceptions` | `DataxamasExceptions` | Error capture. |
|
|
115
|
+
| `tracking` | `DataxamasTracking` | Web analytics (call `.start()`). |
|
|
116
|
+
|
|
117
|
+
Throws if `apiKey` is missing.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
### `DataxamasLogs`
|
|
122
|
+
|
|
123
|
+
Structured logging. Each call logs locally (pino, colorized) **and** ships the entry to `POST /api/v1/logs`. Accessed via `client.logs`.
|
|
124
|
+
|
|
125
|
+
All methods share the signature `(message: string, data?: unknown) => void`.
|
|
126
|
+
|
|
127
|
+
| Method | Level | Use for |
|
|
128
|
+
| --- | --- | --- |
|
|
129
|
+
| `debug(message, data?)` | `DEBUG` | Verbose diagnostics. |
|
|
130
|
+
| `info(message, data?)` | `INFO` | General information. |
|
|
131
|
+
| `warn(message, data?)` | `WARN` | Recoverable issues. |
|
|
132
|
+
| `log(message, data?)` | `LOG` | Plain log lines. |
|
|
133
|
+
| `success(message, data?)` | `SUCCESS` | Successful operations. |
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
client.logs.debug("Cache lookup", { key: "profile:42" });
|
|
137
|
+
client.logs.info("User signed in", { userId: 42 });
|
|
138
|
+
client.logs.warn("Cache miss", { key: "profile:42" });
|
|
139
|
+
client.logs.success("Payment processed", { amount: 1999 });
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
When `enableLogs` is `false`, every method is a no-op.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
### `DataxamasExceptions`
|
|
147
|
+
|
|
148
|
+
Error capture. Accessed via `client.exceptions`. Delivers to `POST /api/v1/errors`, tagging `source` as `CLIENT` in the browser or `SERVER` in Node, plus `environment`/`release` when provided.
|
|
149
|
+
|
|
150
|
+
#### `captureException(error, context?)`
|
|
151
|
+
|
|
152
|
+
Capture an error (or any thrown value) with optional structured context.
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
try {
|
|
156
|
+
JSON.parse(raw);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
client.exceptions.captureException(error, { action: "parse-config", userId: 42 });
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Accepts `Error`, `string`, or any value — it is normalized to `{ name, message, stack }`. In the browser it also attaches `url` and `userAgent`.
|
|
163
|
+
|
|
164
|
+
#### `install()`
|
|
165
|
+
|
|
166
|
+
Attach global handlers so uncaught errors are captured automatically. Called for you when `captureGlobalErrors` is `true` (the default).
|
|
167
|
+
|
|
168
|
+
- **Browser:** `window` `error` + `unhandledrejection`.
|
|
169
|
+
- **Node:** `process` `uncaughtException` + `unhandledRejection`.
|
|
170
|
+
|
|
171
|
+
Idempotent and a no-op when error tracking is disabled.
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
### `DataxamasTracking`
|
|
176
|
+
|
|
177
|
+
Web analytics collector. **Browser-only.** Available as `client.tracking`, or standalone:
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
import { DataxamasTracking } from "@dataxamas/tracker-js";
|
|
181
|
+
|
|
182
|
+
const tracking = new DataxamasTracking({ apiKey: "dx_live_xxx" });
|
|
183
|
+
tracking.start();
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Options** (`DataxamasTrackingOptions`)
|
|
187
|
+
|
|
188
|
+
| Option | Type | Default | Description |
|
|
189
|
+
| --- | --- | --- | --- |
|
|
190
|
+
| `apiKey` | `string` | — | **Required.** Website API key (`dx_live_`). |
|
|
191
|
+
| `baseUrl` | `string` | `https://dataxamas.izakdvlpr.com` | API base URL. |
|
|
192
|
+
| `replayEnabled` | `boolean` | `true` | Allow session replay (gated by server config). |
|
|
193
|
+
| `heatMapEnabled` | `boolean` | `true` | Collect heat-map coordinates on clicks. |
|
|
194
|
+
| `allowLocalhost` | `boolean` | `false` | Allow tracking on `localhost`/`127.0.0.1`. |
|
|
195
|
+
|
|
196
|
+
#### `start()`
|
|
197
|
+
|
|
198
|
+
Begin collecting. Waits for `DOMContentLoaded` if the document is still loading, then tracks:
|
|
199
|
+
|
|
200
|
+
- **`PAGE_VIEW`** — on init and on SPA path changes (polled every 500 ms).
|
|
201
|
+
- **`CLICK`** — element `tagName`, `text`, `href`, `id`, `classes`, plus heat-map coordinates (viewport ratios, scroll offsets, layout fingerprint) when `heatMapEnabled`.
|
|
202
|
+
- **`SCROLL`** — scroll-depth percentage (debounced).
|
|
203
|
+
|
|
204
|
+
Events are queued and flushed to `POST /api/v1/events` with a 4s spacing. Every request sends `Authorization: Bearer <apiKey>`. The key is visible to anyone who opens the page, and it can also read events through `GET /api/v1/events` — treat it as public and rotate it from the dashboard if abused. A visitor session id is generated once and stored in `localStorage` under `@dataxamas/session`.
|
|
205
|
+
|
|
206
|
+
If `replayEnabled` is on and the server config allows it, session replay starts: `rrweb` is lazy-imported and recordings are sent to `POST /api/v1/replay`.
|
|
207
|
+
|
|
208
|
+
**Behavior notes**
|
|
209
|
+
|
|
210
|
+
- Throws `"DataxamasTracking: This SDK can only be used in a browser environment."` if called on the server.
|
|
211
|
+
- Silent no-op on `localhost`/`127.0.0.1` unless `allowLocalhost: true` — so development traffic isn't recorded by default.
|
|
212
|
+
|
|
213
|
+
**Replay privacy** — mark sensitive DOM to keep it out of recordings:
|
|
214
|
+
|
|
215
|
+
- `class="dx-mask"` — masks the element's text.
|
|
216
|
+
- `class="dx-block"` — blocks the element entirely.
|
|
217
|
+
|
|
218
|
+
All inputs are masked by default.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
### `DataxamasApiError`
|
|
223
|
+
|
|
224
|
+
Error class thrown/returned for failed API responses.
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
class DataxamasApiError extends Error {
|
|
228
|
+
code: string;
|
|
229
|
+
message: string;
|
|
230
|
+
status: number;
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
### Types
|
|
237
|
+
|
|
238
|
+
Exported for use in your own typings:
|
|
239
|
+
|
|
240
|
+
- `DataxamasOptions` — options for `new Dataxamas(...)`.
|
|
241
|
+
- `DataxamasTrackingOptions` — options for `new DataxamasTracking(...)`.
|
|
242
|
+
- `LogLevel` — `"DEBUG" | "INFO" | "WARN" | "LOG" | "SUCCESS"`.
|
|
243
|
+
- `LogsConfig` — internal config shape for `DataxamasLogs`.
|
|
244
|
+
- `ErrorSource` — `"CLIENT" | "SERVER"`.
|
|
245
|
+
- `ErrorLevel` — `"ERROR" | "WARNING" | "FATAL"`.
|
|
246
|
+
- `ExceptionsConfig` — internal config shape for `DataxamasExceptions`.
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Notes
|
|
251
|
+
|
|
252
|
+
- **Default endpoint:** `https://dataxamas.izakdvlpr.com`. Override with `baseUrl`.
|
|
253
|
+
- **Session storage key:** `localStorage["@dataxamas/session"]`.
|
|
254
|
+
- **Event flush spacing:** 4 seconds between queued analytics events.
|
|
255
|
+
- **Replay masking classes:** `dx-mask` (text) and `dx-block` (element); all inputs masked by default.
|
|
256
|
+
- **Bundle:** `rrweb` is bundled but split into its own async chunk, loaded only when replay starts — the server/import path never touches it.
|