@dataxamas/tracker-js 2.4.0 → 2.6.0

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
@@ -201,10 +201,35 @@ Begin collecting. Waits for `DOMContentLoaded` if the document is still loading,
201
201
  - **`CLICK`** — element `tagName`, `text`, `href`, `id`, `classes`, plus heat-map coordinates (viewport ratios, scroll offsets, layout fingerprint) when `heatMapEnabled`.
202
202
  - **`SCROLL`** — scroll-depth percentage (debounced).
203
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. Nothing is stored in the browser to identify the visitor: the server derives the session id from `sha256(daily salt + IP + user agent + websiteId)`, and the salt is replaced every day.
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. Nothing is stored in the browser to identify the visitor: the server derives the session id from `sha256(daily salt + IP + user agent + websiteId)`, and the salt is replaced every day. A second key with a monthly salt links a visitor's visits to the same site within the month, for retention cohorts.
205
205
 
206
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
207
 
208
+ #### `track(name, data?)`
209
+
210
+ Sends a custom event. No-op outside the browser.
211
+
212
+ ```ts
213
+ tracking.track("signup", { plan: "pro" });
214
+ ```
215
+
216
+ #### `identify(userId)`
217
+
218
+ Ties the next events to a user of your system, so retention recognizes the same person across months, browsers and devices. No-op outside the browser.
219
+
220
+ ```ts
221
+ // After sign-in, on every page load
222
+ tracking.identify(user.id);
223
+
224
+ // On sign-out
225
+ tracking.identify(null);
226
+ ```
227
+
228
+ - The id travels with each event, but the server stores only `sha256(websiteId + userId)` — never the raw value.
229
+ - It lives in memory only: call it again on every page load.
230
+ - Use an opaque, stable id — never an email or a name.
231
+ - Script tag: `window.dataxamas.track(name, data)` and `window.dataxamas.identify(userId)`.
232
+
208
233
  **Behavior notes**
209
234
 
210
235
  - Throws `"DataxamasTracking: This SDK can only be used in a browser environment."` if called on the server.
@@ -250,7 +275,7 @@ Exported for use in your own typings:
250
275
  ## Notes
251
276
 
252
277
  - **Default endpoint:** `https://dataxamas.com`. Override with `baseUrl`.
253
- - **Visitor identity:** computed server-side, no cookies or `localStorage`. Only replay touches the browser, in `sessionStorage["@dataxamas/replay-recording"]`, and only for sampled visitors.
278
+ - **Visitor identity:** computed server-side, no cookies or `localStorage` — a daily key for the visit, a monthly key (or the `identify()` hash) for retention. Only replay touches the browser, in `sessionStorage["@dataxamas/replay-recording"]`, and only for sampled visitors.
254
279
  - **Event flush spacing:** 4 seconds between queued analytics events.
255
280
  - **Replay masking classes:** `dx-mask` (text) and `dx-block` (element); all inputs masked by default.
256
281
  - **Bundle:** `rrweb` is bundled but split into its own async chunk, loaded only when replay starts — the server/import path never touches it.
package/dist/index.cjs CHANGED
@@ -358,6 +358,7 @@ var DataxamasTracking = class {
358
358
  this.allowLocalhost = _nullishCoalesce(options.allowLocalhost, () => ( false));
359
359
  this.started = false;
360
360
  this.currentPage = isBrowser() ? window.location.pathname : "";
361
+ this.userId = null;
361
362
  this.heatMapEnabled = _nullishCoalesce(options.heatMapEnabled, () => ( true));
362
363
  this.replayEnabled = _nullishCoalesce(options.replayEnabled, () => ( true));
363
364
  this.webVitalsEnabled = _nullishCoalesce(options.webVitalsEnabled, () => ( true));
@@ -427,7 +428,8 @@ var DataxamasTracking = class {
427
428
  path,
428
429
  referrer: document.referrer,
429
430
  query: name === "PAGE_VIEW" ? this.utmQuery() : void 0,
430
- data
431
+ data,
432
+ userId: _nullishCoalesce(this.userId, () => ( void 0))
431
433
  });
432
434
  await this.processQueue();
433
435
  }
@@ -814,6 +816,14 @@ var DataxamasTracking = class {
814
816
  if (!isBrowser()) return;
815
817
  void this.sendEvent({ name, data });
816
818
  }
819
+ /**
820
+ * Liga os próximos eventos ao usuário logado no site (o id do seu sistema), para a retenção reconhecer quem volta
821
+ * em outro navegador ou depois da virada do mês. O servidor guarda só um hash. `null` desfaz, no logout.
822
+ */
823
+ identify(userId) {
824
+ if (!isBrowser()) return;
825
+ this.userId = _optionalChain([userId, 'optionalAccess', _29 => _29.trim, 'call', _30 => _30()]) || null;
826
+ }
817
827
  start() {
818
828
  if (!isBrowser()) {
819
829
  throw new Error("DataxamasTracking: This SDK can only be used in a browser environment.");
package/dist/index.d.cts CHANGED
@@ -111,6 +111,7 @@ declare class DataxamasTracking {
111
111
  private allowLocalhost;
112
112
  private started;
113
113
  private currentPage;
114
+ private userId;
114
115
  private heatMapEnabled;
115
116
  private replayEnabled;
116
117
  private webVitalsEnabled;
@@ -183,6 +184,11 @@ declare class DataxamasTracking {
183
184
  private startTracking;
184
185
  /** Evento customizado (ex.: `signup_done`), usado em metas e funis. Antes do `start()` não envia nada. */
185
186
  track(name: string, data?: Record<string, unknown>): void;
187
+ /**
188
+ * Liga os próximos eventos ao usuário logado no site (o id do seu sistema), para a retenção reconhecer quem volta
189
+ * em outro navegador ou depois da virada do mês. O servidor guarda só um hash. `null` desfaz, no logout.
190
+ */
191
+ identify(userId: string | null): void;
186
192
  start(): void;
187
193
  }
188
194
 
package/dist/index.d.ts CHANGED
@@ -111,6 +111,7 @@ declare class DataxamasTracking {
111
111
  private allowLocalhost;
112
112
  private started;
113
113
  private currentPage;
114
+ private userId;
114
115
  private heatMapEnabled;
115
116
  private replayEnabled;
116
117
  private webVitalsEnabled;
@@ -183,6 +184,11 @@ declare class DataxamasTracking {
183
184
  private startTracking;
184
185
  /** Evento customizado (ex.: `signup_done`), usado em metas e funis. Antes do `start()` não envia nada. */
185
186
  track(name: string, data?: Record<string, unknown>): void;
187
+ /**
188
+ * Liga os próximos eventos ao usuário logado no site (o id do seu sistema), para a retenção reconhecer quem volta
189
+ * em outro navegador ou depois da virada do mês. O servidor guarda só um hash. `null` desfaz, no logout.
190
+ */
191
+ identify(userId: string | null): void;
186
192
  start(): void;
187
193
  }
188
194
 
package/dist/index.js CHANGED
@@ -358,6 +358,7 @@ var DataxamasTracking = class {
358
358
  this.allowLocalhost = options.allowLocalhost ?? false;
359
359
  this.started = false;
360
360
  this.currentPage = isBrowser() ? window.location.pathname : "";
361
+ this.userId = null;
361
362
  this.heatMapEnabled = options.heatMapEnabled ?? true;
362
363
  this.replayEnabled = options.replayEnabled ?? true;
363
364
  this.webVitalsEnabled = options.webVitalsEnabled ?? true;
@@ -427,7 +428,8 @@ var DataxamasTracking = class {
427
428
  path,
428
429
  referrer: document.referrer,
429
430
  query: name === "PAGE_VIEW" ? this.utmQuery() : void 0,
430
- data
431
+ data,
432
+ userId: this.userId ?? void 0
431
433
  });
432
434
  await this.processQueue();
433
435
  }
@@ -814,6 +816,14 @@ var DataxamasTracking = class {
814
816
  if (!isBrowser()) return;
815
817
  void this.sendEvent({ name, data });
816
818
  }
819
+ /**
820
+ * Liga os próximos eventos ao usuário logado no site (o id do seu sistema), para a retenção reconhecer quem volta
821
+ * em outro navegador ou depois da virada do mês. O servidor guarda só um hash. `null` desfaz, no logout.
822
+ */
823
+ identify(userId) {
824
+ if (!isBrowser()) return;
825
+ this.userId = userId?.trim() || null;
826
+ }
817
827
  start() {
818
828
  if (!isBrowser()) {
819
829
  throw new Error("DataxamasTracking: This SDK can only be used in a browser environment.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataxamas/tracker-js",
3
- "version": "2.4.0",
3
+ "version": "2.6.0",
4
4
  "type": "module",
5
5
  "description": "Node.js SDK for Dataxamas Analytics API",
6
6
  "license": "MIT",