alphana-sdk 1.6.6 → 1.9.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/dist/index.d.mts CHANGED
@@ -4,6 +4,11 @@ interface TrackerConfig {
4
4
  * Defaults to `https://api.alphana.ir/api/events` (Alphana Cloud).
5
5
  */
6
6
  endpoint?: string;
7
+ /**
8
+ * Override unified ingest URL. When omitted, derived from `endpoint` as
9
+ * `…/api/collect`.
10
+ */
11
+ collectEndpoint?: string;
7
12
  /**
8
13
  * App ID obtained from the UserTracker dashboard.
9
14
  * Sent in every request body so the backend associates events with the correct app.
@@ -39,6 +44,16 @@ interface TrackerConfig {
39
44
  * Default: 5000 (5 s)
40
45
  */
41
46
  flushInterval?: number;
47
+ /**
48
+ * Gzip-compress large ingest payloads before upload when the browser supports
49
+ * `CompressionStream`. Default: true
50
+ */
51
+ compressPayloads?: boolean;
52
+ /**
53
+ * Minimum UTF-8 JSON size (bytes) before gzip compression is attempted.
54
+ * Default: 1024
55
+ */
56
+ compressionThresholdBytes?: number;
42
57
  /**
43
58
  * Automatically capture console.info/warn/error, window.onerror, and
44
59
  * unhandledrejection events and send them to the backend log endpoint.
@@ -46,15 +61,11 @@ interface TrackerConfig {
46
61
  */
47
62
  trackLogs?: boolean;
48
63
  /**
49
- * List of page paths for which heatmap data should be captured client-side.
50
- * Paths should match the dashboard "Heatmap pages" list (decoded Unicode is
51
- * fine the SDK normalizes percent-encoding vs `window.location` mismatches).
52
- *
53
- * If empty or undefined, the SDK may still collect moves locally, but the
54
- * backend only persists points when the app has at least one registered
55
- * heatmap page and the path matches.
56
- *
57
- * Example: `heatmapPages: ["/", "/pricing", "/dashboard"]`
64
+ * @deprecated Optional client-side path filter only. Heatmap pages are
65
+ * registered in the Alphana dashboard; the backend persists points only for
66
+ * those paths. Leave unset so the SDK collects on every page and the server
67
+ * filters — no SDK configuration is required when you add a page in the
68
+ * dashboard.
58
69
  */
59
70
  heatmapPages?: string[];
60
71
  /**
@@ -144,11 +155,23 @@ interface HeatmapPoint {
144
155
  pw?: number;
145
156
  /** Page scrollHeight at the time of the event (used for accurate remapping) */
146
157
  ph?: number;
158
+ /** Viewport (innerWidth) at capture time — disambiguates responsive layouts. */
159
+ vw?: number;
147
160
  type: "move" | "click" | "scroll";
148
161
  path: string;
149
162
  timestamp: number;
150
163
  /** Text/label of the clicked element — only present on click events. */
151
164
  target?: string;
165
+ /**
166
+ * Stable CSS selector of the anchored element (clicks only). Lets the
167
+ * dashboard place the point relative to the element in the screenshot, so it
168
+ * stays accurate even when the visitor's layout differed from the capture.
169
+ */
170
+ selector?: string;
171
+ /** Click X as a fraction (0–1) of the anchored element's width (clicks only). */
172
+ relX?: number;
173
+ /** Click Y as a fraction (0–1) of the anchored element's height (clicks only). */
174
+ relY?: number;
152
175
  }
153
176
  interface RageClick {
154
177
  path: string;
@@ -357,15 +380,17 @@ interface LogEntry {
357
380
  }
358
381
  /**
359
382
  * Automatically captures console.info/warn/error output and unhandled errors,
360
- * then ships them to the backend `/logs/ingest` endpoint.
383
+ * then ships them to the unified `/api/collect` ingest endpoint.
361
384
  *
362
385
  * All console methods are restored exactly in `destroy()`.
363
386
  */
364
387
  declare class LogCapture {
365
- private readonly endpoint;
388
+ private readonly collectUrl;
366
389
  private readonly sessionId;
367
390
  private readonly appId?;
368
391
  private readonly authHeaders;
392
+ private readonly compressPayloads;
393
+ private readonly compressionThresholdBytes;
369
394
  private origInfo;
370
395
  private origWarn;
371
396
  private origError;
@@ -374,9 +399,12 @@ declare class LogCapture {
374
399
  private initialized;
375
400
  constructor(options: {
376
401
  endpoint: string;
402
+ collectEndpoint?: string;
377
403
  sessionId: string;
378
404
  secretKey?: string;
379
405
  appId?: string;
406
+ compressPayloads?: boolean;
407
+ compressionThresholdBytes?: number;
380
408
  });
381
409
  init(): void;
382
410
  destroy(): void;
@@ -540,6 +568,8 @@ declare class UserTracker {
540
568
  getHeatmapData(path: string): HeatmapPoint[];
541
569
  /** Heatmap points for all tracked paths. */
542
570
  getHeatmapData(): Record<string, HeatmapPoint[]>;
571
+ private get collectUrl();
572
+ private currentPath;
543
573
  /**
544
574
  * Immediately drain the event queue and POST pending events to `/batch`.
545
575
  * Fire-and-forget; errors are intentionally swallowed like other analytics calls.
@@ -553,7 +583,6 @@ declare class UserTracker {
553
583
  * cancelled by the browser before it completes.
554
584
  */
555
585
  private flushBeacon;
556
- private buildBatchBody;
557
586
  private sendBatch;
558
587
  }
559
588
 
package/dist/index.d.ts CHANGED
@@ -4,6 +4,11 @@ interface TrackerConfig {
4
4
  * Defaults to `https://api.alphana.ir/api/events` (Alphana Cloud).
5
5
  */
6
6
  endpoint?: string;
7
+ /**
8
+ * Override unified ingest URL. When omitted, derived from `endpoint` as
9
+ * `…/api/collect`.
10
+ */
11
+ collectEndpoint?: string;
7
12
  /**
8
13
  * App ID obtained from the UserTracker dashboard.
9
14
  * Sent in every request body so the backend associates events with the correct app.
@@ -39,6 +44,16 @@ interface TrackerConfig {
39
44
  * Default: 5000 (5 s)
40
45
  */
41
46
  flushInterval?: number;
47
+ /**
48
+ * Gzip-compress large ingest payloads before upload when the browser supports
49
+ * `CompressionStream`. Default: true
50
+ */
51
+ compressPayloads?: boolean;
52
+ /**
53
+ * Minimum UTF-8 JSON size (bytes) before gzip compression is attempted.
54
+ * Default: 1024
55
+ */
56
+ compressionThresholdBytes?: number;
42
57
  /**
43
58
  * Automatically capture console.info/warn/error, window.onerror, and
44
59
  * unhandledrejection events and send them to the backend log endpoint.
@@ -46,15 +61,11 @@ interface TrackerConfig {
46
61
  */
47
62
  trackLogs?: boolean;
48
63
  /**
49
- * List of page paths for which heatmap data should be captured client-side.
50
- * Paths should match the dashboard "Heatmap pages" list (decoded Unicode is
51
- * fine the SDK normalizes percent-encoding vs `window.location` mismatches).
52
- *
53
- * If empty or undefined, the SDK may still collect moves locally, but the
54
- * backend only persists points when the app has at least one registered
55
- * heatmap page and the path matches.
56
- *
57
- * Example: `heatmapPages: ["/", "/pricing", "/dashboard"]`
64
+ * @deprecated Optional client-side path filter only. Heatmap pages are
65
+ * registered in the Alphana dashboard; the backend persists points only for
66
+ * those paths. Leave unset so the SDK collects on every page and the server
67
+ * filters — no SDK configuration is required when you add a page in the
68
+ * dashboard.
58
69
  */
59
70
  heatmapPages?: string[];
60
71
  /**
@@ -144,11 +155,23 @@ interface HeatmapPoint {
144
155
  pw?: number;
145
156
  /** Page scrollHeight at the time of the event (used for accurate remapping) */
146
157
  ph?: number;
158
+ /** Viewport (innerWidth) at capture time — disambiguates responsive layouts. */
159
+ vw?: number;
147
160
  type: "move" | "click" | "scroll";
148
161
  path: string;
149
162
  timestamp: number;
150
163
  /** Text/label of the clicked element — only present on click events. */
151
164
  target?: string;
165
+ /**
166
+ * Stable CSS selector of the anchored element (clicks only). Lets the
167
+ * dashboard place the point relative to the element in the screenshot, so it
168
+ * stays accurate even when the visitor's layout differed from the capture.
169
+ */
170
+ selector?: string;
171
+ /** Click X as a fraction (0–1) of the anchored element's width (clicks only). */
172
+ relX?: number;
173
+ /** Click Y as a fraction (0–1) of the anchored element's height (clicks only). */
174
+ relY?: number;
152
175
  }
153
176
  interface RageClick {
154
177
  path: string;
@@ -357,15 +380,17 @@ interface LogEntry {
357
380
  }
358
381
  /**
359
382
  * Automatically captures console.info/warn/error output and unhandled errors,
360
- * then ships them to the backend `/logs/ingest` endpoint.
383
+ * then ships them to the unified `/api/collect` ingest endpoint.
361
384
  *
362
385
  * All console methods are restored exactly in `destroy()`.
363
386
  */
364
387
  declare class LogCapture {
365
- private readonly endpoint;
388
+ private readonly collectUrl;
366
389
  private readonly sessionId;
367
390
  private readonly appId?;
368
391
  private readonly authHeaders;
392
+ private readonly compressPayloads;
393
+ private readonly compressionThresholdBytes;
369
394
  private origInfo;
370
395
  private origWarn;
371
396
  private origError;
@@ -374,9 +399,12 @@ declare class LogCapture {
374
399
  private initialized;
375
400
  constructor(options: {
376
401
  endpoint: string;
402
+ collectEndpoint?: string;
377
403
  sessionId: string;
378
404
  secretKey?: string;
379
405
  appId?: string;
406
+ compressPayloads?: boolean;
407
+ compressionThresholdBytes?: number;
380
408
  });
381
409
  init(): void;
382
410
  destroy(): void;
@@ -540,6 +568,8 @@ declare class UserTracker {
540
568
  getHeatmapData(path: string): HeatmapPoint[];
541
569
  /** Heatmap points for all tracked paths. */
542
570
  getHeatmapData(): Record<string, HeatmapPoint[]>;
571
+ private get collectUrl();
572
+ private currentPath;
543
573
  /**
544
574
  * Immediately drain the event queue and POST pending events to `/batch`.
545
575
  * Fire-and-forget; errors are intentionally swallowed like other analytics calls.
@@ -553,7 +583,6 @@ declare class UserTracker {
553
583
  * cancelled by the browser before it completes.
554
584
  */
555
585
  private flushBeacon;
556
- private buildBatchBody;
557
586
  private sendBatch;
558
587
  }
559
588