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.
@@ -7,6 +7,11 @@ interface TrackerConfig {
7
7
  * Defaults to `https://api.alphana.ir/api/events` (Alphana Cloud).
8
8
  */
9
9
  endpoint?: string;
10
+ /**
11
+ * Override unified ingest URL. When omitted, derived from `endpoint` as
12
+ * `…/api/collect`.
13
+ */
14
+ collectEndpoint?: string;
10
15
  /**
11
16
  * App ID obtained from the UserTracker dashboard.
12
17
  * Sent in every request body so the backend associates events with the correct app.
@@ -42,6 +47,16 @@ interface TrackerConfig {
42
47
  * Default: 5000 (5 s)
43
48
  */
44
49
  flushInterval?: number;
50
+ /**
51
+ * Gzip-compress large ingest payloads before upload when the browser supports
52
+ * `CompressionStream`. Default: true
53
+ */
54
+ compressPayloads?: boolean;
55
+ /**
56
+ * Minimum UTF-8 JSON size (bytes) before gzip compression is attempted.
57
+ * Default: 1024
58
+ */
59
+ compressionThresholdBytes?: number;
45
60
  /**
46
61
  * Automatically capture console.info/warn/error, window.onerror, and
47
62
  * unhandledrejection events and send them to the backend log endpoint.
@@ -49,15 +64,11 @@ interface TrackerConfig {
49
64
  */
50
65
  trackLogs?: boolean;
51
66
  /**
52
- * List of page paths for which heatmap data should be captured client-side.
53
- * Paths should match the dashboard "Heatmap pages" list (decoded Unicode is
54
- * fine the SDK normalizes percent-encoding vs `window.location` mismatches).
55
- *
56
- * If empty or undefined, the SDK may still collect moves locally, but the
57
- * backend only persists points when the app has at least one registered
58
- * heatmap page and the path matches.
59
- *
60
- * Example: `heatmapPages: ["/", "/pricing", "/dashboard"]`
67
+ * @deprecated Optional client-side path filter only. Heatmap pages are
68
+ * registered in the Alphana dashboard; the backend persists points only for
69
+ * those paths. Leave unset so the SDK collects on every page and the server
70
+ * filters — no SDK configuration is required when you add a page in the
71
+ * dashboard.
61
72
  */
62
73
  heatmapPages?: string[];
63
74
  /**
@@ -147,11 +158,23 @@ interface HeatmapPoint {
147
158
  pw?: number;
148
159
  /** Page scrollHeight at the time of the event (used for accurate remapping) */
149
160
  ph?: number;
161
+ /** Viewport (innerWidth) at capture time — disambiguates responsive layouts. */
162
+ vw?: number;
150
163
  type: "move" | "click" | "scroll";
151
164
  path: string;
152
165
  timestamp: number;
153
166
  /** Text/label of the clicked element — only present on click events. */
154
167
  target?: string;
168
+ /**
169
+ * Stable CSS selector of the anchored element (clicks only). Lets the
170
+ * dashboard place the point relative to the element in the screenshot, so it
171
+ * stays accurate even when the visitor's layout differed from the capture.
172
+ */
173
+ selector?: string;
174
+ /** Click X as a fraction (0–1) of the anchored element's width (clicks only). */
175
+ relX?: number;
176
+ /** Click Y as a fraction (0–1) of the anchored element's height (clicks only). */
177
+ relY?: number;
155
178
  }
156
179
  interface RageClick {
157
180
  path: string;
@@ -364,15 +387,17 @@ declare function UserTrackerProvider({ config, children, }: UserTrackerProviderP
364
387
  type LogLevel = "info" | "warn" | "error";
365
388
  /**
366
389
  * Automatically captures console.info/warn/error output and unhandled errors,
367
- * then ships them to the backend `/logs/ingest` endpoint.
390
+ * then ships them to the unified `/api/collect` ingest endpoint.
368
391
  *
369
392
  * All console methods are restored exactly in `destroy()`.
370
393
  */
371
394
  declare class LogCapture {
372
- private readonly endpoint;
395
+ private readonly collectUrl;
373
396
  private readonly sessionId;
374
397
  private readonly appId?;
375
398
  private readonly authHeaders;
399
+ private readonly compressPayloads;
400
+ private readonly compressionThresholdBytes;
376
401
  private origInfo;
377
402
  private origWarn;
378
403
  private origError;
@@ -381,9 +406,12 @@ declare class LogCapture {
381
406
  private initialized;
382
407
  constructor(options: {
383
408
  endpoint: string;
409
+ collectEndpoint?: string;
384
410
  sessionId: string;
385
411
  secretKey?: string;
386
412
  appId?: string;
413
+ compressPayloads?: boolean;
414
+ compressionThresholdBytes?: number;
387
415
  });
388
416
  init(): void;
389
417
  destroy(): void;
@@ -546,6 +574,8 @@ declare class UserTracker {
546
574
  getHeatmapData(path: string): HeatmapPoint[];
547
575
  /** Heatmap points for all tracked paths. */
548
576
  getHeatmapData(): Record<string, HeatmapPoint[]>;
577
+ private get collectUrl();
578
+ private currentPath;
549
579
  /**
550
580
  * Immediately drain the event queue and POST pending events to `/batch`.
551
581
  * Fire-and-forget; errors are intentionally swallowed like other analytics calls.
@@ -559,7 +589,6 @@ declare class UserTracker {
559
589
  * cancelled by the browser before it completes.
560
590
  */
561
591
  private flushBeacon;
562
- private buildBatchBody;
563
592
  private sendBatch;
564
593
  }
565
594
 
@@ -7,6 +7,11 @@ interface TrackerConfig {
7
7
  * Defaults to `https://api.alphana.ir/api/events` (Alphana Cloud).
8
8
  */
9
9
  endpoint?: string;
10
+ /**
11
+ * Override unified ingest URL. When omitted, derived from `endpoint` as
12
+ * `…/api/collect`.
13
+ */
14
+ collectEndpoint?: string;
10
15
  /**
11
16
  * App ID obtained from the UserTracker dashboard.
12
17
  * Sent in every request body so the backend associates events with the correct app.
@@ -42,6 +47,16 @@ interface TrackerConfig {
42
47
  * Default: 5000 (5 s)
43
48
  */
44
49
  flushInterval?: number;
50
+ /**
51
+ * Gzip-compress large ingest payloads before upload when the browser supports
52
+ * `CompressionStream`. Default: true
53
+ */
54
+ compressPayloads?: boolean;
55
+ /**
56
+ * Minimum UTF-8 JSON size (bytes) before gzip compression is attempted.
57
+ * Default: 1024
58
+ */
59
+ compressionThresholdBytes?: number;
45
60
  /**
46
61
  * Automatically capture console.info/warn/error, window.onerror, and
47
62
  * unhandledrejection events and send them to the backend log endpoint.
@@ -49,15 +64,11 @@ interface TrackerConfig {
49
64
  */
50
65
  trackLogs?: boolean;
51
66
  /**
52
- * List of page paths for which heatmap data should be captured client-side.
53
- * Paths should match the dashboard "Heatmap pages" list (decoded Unicode is
54
- * fine the SDK normalizes percent-encoding vs `window.location` mismatches).
55
- *
56
- * If empty or undefined, the SDK may still collect moves locally, but the
57
- * backend only persists points when the app has at least one registered
58
- * heatmap page and the path matches.
59
- *
60
- * Example: `heatmapPages: ["/", "/pricing", "/dashboard"]`
67
+ * @deprecated Optional client-side path filter only. Heatmap pages are
68
+ * registered in the Alphana dashboard; the backend persists points only for
69
+ * those paths. Leave unset so the SDK collects on every page and the server
70
+ * filters — no SDK configuration is required when you add a page in the
71
+ * dashboard.
61
72
  */
62
73
  heatmapPages?: string[];
63
74
  /**
@@ -147,11 +158,23 @@ interface HeatmapPoint {
147
158
  pw?: number;
148
159
  /** Page scrollHeight at the time of the event (used for accurate remapping) */
149
160
  ph?: number;
161
+ /** Viewport (innerWidth) at capture time — disambiguates responsive layouts. */
162
+ vw?: number;
150
163
  type: "move" | "click" | "scroll";
151
164
  path: string;
152
165
  timestamp: number;
153
166
  /** Text/label of the clicked element — only present on click events. */
154
167
  target?: string;
168
+ /**
169
+ * Stable CSS selector of the anchored element (clicks only). Lets the
170
+ * dashboard place the point relative to the element in the screenshot, so it
171
+ * stays accurate even when the visitor's layout differed from the capture.
172
+ */
173
+ selector?: string;
174
+ /** Click X as a fraction (0–1) of the anchored element's width (clicks only). */
175
+ relX?: number;
176
+ /** Click Y as a fraction (0–1) of the anchored element's height (clicks only). */
177
+ relY?: number;
155
178
  }
156
179
  interface RageClick {
157
180
  path: string;
@@ -364,15 +387,17 @@ declare function UserTrackerProvider({ config, children, }: UserTrackerProviderP
364
387
  type LogLevel = "info" | "warn" | "error";
365
388
  /**
366
389
  * Automatically captures console.info/warn/error output and unhandled errors,
367
- * then ships them to the backend `/logs/ingest` endpoint.
390
+ * then ships them to the unified `/api/collect` ingest endpoint.
368
391
  *
369
392
  * All console methods are restored exactly in `destroy()`.
370
393
  */
371
394
  declare class LogCapture {
372
- private readonly endpoint;
395
+ private readonly collectUrl;
373
396
  private readonly sessionId;
374
397
  private readonly appId?;
375
398
  private readonly authHeaders;
399
+ private readonly compressPayloads;
400
+ private readonly compressionThresholdBytes;
376
401
  private origInfo;
377
402
  private origWarn;
378
403
  private origError;
@@ -381,9 +406,12 @@ declare class LogCapture {
381
406
  private initialized;
382
407
  constructor(options: {
383
408
  endpoint: string;
409
+ collectEndpoint?: string;
384
410
  sessionId: string;
385
411
  secretKey?: string;
386
412
  appId?: string;
413
+ compressPayloads?: boolean;
414
+ compressionThresholdBytes?: number;
387
415
  });
388
416
  init(): void;
389
417
  destroy(): void;
@@ -546,6 +574,8 @@ declare class UserTracker {
546
574
  getHeatmapData(path: string): HeatmapPoint[];
547
575
  /** Heatmap points for all tracked paths. */
548
576
  getHeatmapData(): Record<string, HeatmapPoint[]>;
577
+ private get collectUrl();
578
+ private currentPath;
549
579
  /**
550
580
  * Immediately drain the event queue and POST pending events to `/batch`.
551
581
  * Fire-and-forget; errors are intentionally swallowed like other analytics calls.
@@ -559,7 +589,6 @@ declare class UserTracker {
559
589
  * cancelled by the browser before it completes.
560
590
  */
561
591
  private flushBeacon;
562
- private buildBatchBody;
563
592
  private sendBatch;
564
593
  }
565
594