@probat/react 0.1.5 → 0.2.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
@@ -93,6 +93,38 @@ function Button() {
93
93
  }
94
94
  ```
95
95
 
96
+ ### 4. Heatmap Tracking (Automatic)
97
+
98
+ Heatmap tracking is automatically enabled when you use `ProbatProvider`. It tracks:
99
+ - **Click events**: User clicks across your website
100
+ - **Cursor movements**: Mouse movement patterns for engagement analysis
101
+
102
+ The tracking automatically associates data with the active experiment (`proposalId`) and variant (`variantLabel`) based on the experiment context. No additional configuration needed!
103
+
104
+ ```tsx
105
+ // Heatmap tracking is automatically initialized by ProbatProvider
106
+ <ProbatProvider clientKey="your-key" environment="dev">
107
+ <YourApp />
108
+ </ProbatProvider>
109
+ ```
110
+
111
+ To manually control heatmap tracking:
112
+
113
+ ```tsx
114
+ import { initHeatmapTracking, stopHeatmapTracking } from '@probat/react';
115
+
116
+ // Initialize with custom config
117
+ initHeatmapTracking({
118
+ apiBaseUrl: 'https://api.probat.com',
119
+ batchSize: 10,
120
+ batchInterval: 5000,
121
+ trackCursor: true, // Enable cursor movement tracking
122
+ });
123
+
124
+ // Stop tracking when needed
125
+ stopHeatmapTracking();
126
+ ```
127
+
96
128
  ## API Reference
97
129
 
98
130
  ### `<ProbatProvider>`
@@ -108,8 +140,12 @@ Wraps your app and provides Probat configuration to all child components.
108
140
  - Default: `"https://gushi.onrender.com"`
109
141
  - `clientKey?: string` - Client key for identification (optional)
110
142
  - `environment?: "dev" | "prod"` - Explicitly set environment. If not provided, will auto-detect based on hostname.
143
+ - `proposalId?: string` - Optional proposal/experiment ID for heatmap tracking segregation
144
+ - `variantLabel?: string` - Optional variant label for heatmap tracking segregation
111
145
  - `children: React.ReactNode` - Your app components
112
146
 
147
+ **Note**: `proposalId` and `variantLabel` are automatically set from localStorage when experiments are active. You typically don't need to pass these manually.
148
+
113
149
  #### Example
114
150
 
115
151
  ```tsx
@@ -177,6 +213,58 @@ trackMetric('purchase', 'proposal-id', 'variant-a', { amount: 100 });
177
213
  trackImpression('proposal-id', 'control', 'experiment-id');
178
214
  ```
179
215
 
216
+ ### Heatmap Tracking Functions
217
+
218
+ #### `initHeatmapTracking(config)`
219
+
220
+ Initialize heatmap tracking with custom configuration.
221
+
222
+ ##### Parameters
223
+
224
+ - `config: HeatmapConfig` - Configuration object:
225
+ - `apiBaseUrl: string` - Base URL for the heatmap API (default: from ProbatProvider)
226
+ - `batchSize?: number` - Number of clicks to batch before sending (default: `10`)
227
+ - `batchInterval?: number` - Time in ms to wait before sending batch (default: `5000`)
228
+ - `trackCursor?: boolean` - Enable cursor movement tracking (default: `true`)
229
+ - `cursorThrottle?: number` - Throttle cursor events in ms (default: `100`)
230
+ - `cursorBatchSize?: number` - Number of cursor movements to batch (default: `50`)
231
+ - `enabled?: boolean` - Enable/disable tracking (default: `true`)
232
+ - `excludeSelectors?: string[]` - CSS selectors to exclude from tracking
233
+ - `excludedOrigins?: string[]` - Origins to exclude from tracking
234
+
235
+ ##### Example
236
+
237
+ ```tsx
238
+ import { initHeatmapTracking } from '@probat/react';
239
+
240
+ initHeatmapTracking({
241
+ apiBaseUrl: 'https://api.probat.com',
242
+ batchSize: 20,
243
+ trackCursor: true,
244
+ cursorThrottle: 100,
245
+ });
246
+ ```
247
+
248
+ #### `stopHeatmapTracking()`
249
+
250
+ Stop heatmap tracking and send any pending batches.
251
+
252
+ ##### Example
253
+
254
+ ```tsx
255
+ import { stopHeatmapTracking } from '@probat/react';
256
+
257
+ stopHeatmapTracking();
258
+ ```
259
+
260
+ #### `getHeatmapTracker()`
261
+
262
+ Get the current heatmap tracker instance (for advanced usage).
263
+
264
+ ##### Returns
265
+
266
+ - `HeatmapTracker | null` - The tracker instance or null if not initialized
267
+
180
268
  ### `withExperiment(Control, options)`
181
269
 
182
270
  Higher-Order Component for wrapping components with experiment variants (backward compatible with old injection pattern).
package/dist/index.d.mts CHANGED
@@ -10,6 +10,8 @@ interface ProbatContextValue {
10
10
  environment: "dev" | "prod";
11
11
  clientKey?: string;
12
12
  repoFullName?: string;
13
+ proposalId?: string;
14
+ variantLabel?: string;
13
15
  }
14
16
  interface ProbatProviderProps {
15
17
  /**
@@ -21,6 +23,14 @@ interface ProbatProviderProps {
21
23
  * - Default: "https://gushi.onrender.com"
22
24
  */
23
25
  apiBaseUrl?: string;
26
+ /**
27
+ * Optional: proposal/experiment id for heatmap segregation
28
+ */
29
+ proposalId?: string;
30
+ /**
31
+ * Optional: variant label for heatmap segregation
32
+ */
33
+ variantLabel?: string;
24
34
  /**
25
35
  * Client key for identification (optional)
26
36
  */
@@ -40,7 +50,7 @@ interface ProbatProviderProps {
40
50
  repoFullName?: string;
41
51
  children: React.ReactNode;
42
52
  }
43
- declare function ProbatProvider({ apiBaseUrl, clientKey, environment: explicitEnvironment, repoFullName: explicitRepoFullName, children, }: ProbatProviderProps): React.JSX.Element;
53
+ declare function ProbatProvider({ apiBaseUrl, clientKey, environment: explicitEnvironment, repoFullName: explicitRepoFullName, proposalId, variantLabel, children, }: ProbatProviderProps): React.JSX.Element;
44
54
  declare function useProbatContext(): ProbatContextValue;
45
55
 
46
56
  /**
@@ -180,6 +190,54 @@ declare function extractClickMeta(event?: {
180
190
  target?: EventTarget | null;
181
191
  } | null): Record<string, any> | undefined;
182
192
 
193
+ /**
194
+ * Universal Heatmap Tracker for User Websites
195
+ *
196
+ * Tracks all clicks across the entire user website for heatmap visualization.
197
+ * This is injected into user websites via the probat-react package.
198
+ */
199
+ interface HeatmapConfig {
200
+ apiBaseUrl: string;
201
+ batchSize?: number;
202
+ batchInterval?: number;
203
+ enabled?: boolean;
204
+ excludeSelectors?: string[];
205
+ trackCursor?: boolean;
206
+ cursorThrottle?: number;
207
+ cursorBatchSize?: number;
208
+ proposalId?: string;
209
+ variantLabel?: string;
210
+ }
211
+ declare class HeatmapTracker {
212
+ private clicks;
213
+ private movements;
214
+ private sessionId;
215
+ private config;
216
+ private batchTimer;
217
+ private cursorBatchTimer;
218
+ private lastCursorTime;
219
+ private isInitialized;
220
+ constructor(config: HeatmapConfig);
221
+ private getOrCreateSessionId;
222
+ private shouldExcludeElement;
223
+ private extractElementInfo;
224
+ private handleMouseMove;
225
+ private scheduleCursorBatchSend;
226
+ private sendCursorBatch;
227
+ private handleClick;
228
+ private scheduleBatchSend;
229
+ private sendBatch;
230
+ init(): void;
231
+ stop(): void;
232
+ }
233
+ /**
234
+ * Initialize heatmap tracking for user websites
235
+ * Called automatically by ProbatProvider
236
+ */
237
+ declare function initHeatmapTracking(config: HeatmapConfig): HeatmapTracker;
238
+ declare function getHeatmapTracker(): HeatmapTracker | null;
239
+ declare function stopHeatmapTracking(): void;
240
+
183
241
  type Choice = {
184
242
  experiment_id: string;
185
243
  label: string;
@@ -190,4 +248,4 @@ declare function writeChoice(proposalId: string, experiment_id: string, label: s
190
248
  declare function hasTrackedVisit(proposalId: string, label: string): boolean;
191
249
  declare function markTrackedVisit(proposalId: string, label: string): void;
192
250
 
193
- export { type Choice, type ProbatContextValue, ProbatProvider, ProbatProviderClient, type ProbatProviderProps as ProbatProviderClientProps, type ProbatProviderProps, type RetrieveResponse, type UseExperimentReturn, type UseProbatMetricsReturn, type WithExperimentOptions, detectEnvironment, extractClickMeta, fetchDecision, hasTrackedVisit, markTrackedVisit, readChoice, sendMetric, useExperiment, useProbatContext, useProbatMetrics, withExperiment, writeChoice };
251
+ export { type Choice, type ProbatContextValue, ProbatProvider, ProbatProviderClient, type ProbatProviderProps as ProbatProviderClientProps, type ProbatProviderProps, type RetrieveResponse, type UseExperimentReturn, type UseProbatMetricsReturn, type WithExperimentOptions, detectEnvironment, extractClickMeta, fetchDecision, getHeatmapTracker, hasTrackedVisit, initHeatmapTracking, markTrackedVisit, readChoice, sendMetric, stopHeatmapTracking, useExperiment, useProbatContext, useProbatMetrics, withExperiment, writeChoice };
package/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@ interface ProbatContextValue {
10
10
  environment: "dev" | "prod";
11
11
  clientKey?: string;
12
12
  repoFullName?: string;
13
+ proposalId?: string;
14
+ variantLabel?: string;
13
15
  }
14
16
  interface ProbatProviderProps {
15
17
  /**
@@ -21,6 +23,14 @@ interface ProbatProviderProps {
21
23
  * - Default: "https://gushi.onrender.com"
22
24
  */
23
25
  apiBaseUrl?: string;
26
+ /**
27
+ * Optional: proposal/experiment id for heatmap segregation
28
+ */
29
+ proposalId?: string;
30
+ /**
31
+ * Optional: variant label for heatmap segregation
32
+ */
33
+ variantLabel?: string;
24
34
  /**
25
35
  * Client key for identification (optional)
26
36
  */
@@ -40,7 +50,7 @@ interface ProbatProviderProps {
40
50
  repoFullName?: string;
41
51
  children: React.ReactNode;
42
52
  }
43
- declare function ProbatProvider({ apiBaseUrl, clientKey, environment: explicitEnvironment, repoFullName: explicitRepoFullName, children, }: ProbatProviderProps): React.JSX.Element;
53
+ declare function ProbatProvider({ apiBaseUrl, clientKey, environment: explicitEnvironment, repoFullName: explicitRepoFullName, proposalId, variantLabel, children, }: ProbatProviderProps): React.JSX.Element;
44
54
  declare function useProbatContext(): ProbatContextValue;
45
55
 
46
56
  /**
@@ -180,6 +190,54 @@ declare function extractClickMeta(event?: {
180
190
  target?: EventTarget | null;
181
191
  } | null): Record<string, any> | undefined;
182
192
 
193
+ /**
194
+ * Universal Heatmap Tracker for User Websites
195
+ *
196
+ * Tracks all clicks across the entire user website for heatmap visualization.
197
+ * This is injected into user websites via the probat-react package.
198
+ */
199
+ interface HeatmapConfig {
200
+ apiBaseUrl: string;
201
+ batchSize?: number;
202
+ batchInterval?: number;
203
+ enabled?: boolean;
204
+ excludeSelectors?: string[];
205
+ trackCursor?: boolean;
206
+ cursorThrottle?: number;
207
+ cursorBatchSize?: number;
208
+ proposalId?: string;
209
+ variantLabel?: string;
210
+ }
211
+ declare class HeatmapTracker {
212
+ private clicks;
213
+ private movements;
214
+ private sessionId;
215
+ private config;
216
+ private batchTimer;
217
+ private cursorBatchTimer;
218
+ private lastCursorTime;
219
+ private isInitialized;
220
+ constructor(config: HeatmapConfig);
221
+ private getOrCreateSessionId;
222
+ private shouldExcludeElement;
223
+ private extractElementInfo;
224
+ private handleMouseMove;
225
+ private scheduleCursorBatchSend;
226
+ private sendCursorBatch;
227
+ private handleClick;
228
+ private scheduleBatchSend;
229
+ private sendBatch;
230
+ init(): void;
231
+ stop(): void;
232
+ }
233
+ /**
234
+ * Initialize heatmap tracking for user websites
235
+ * Called automatically by ProbatProvider
236
+ */
237
+ declare function initHeatmapTracking(config: HeatmapConfig): HeatmapTracker;
238
+ declare function getHeatmapTracker(): HeatmapTracker | null;
239
+ declare function stopHeatmapTracking(): void;
240
+
183
241
  type Choice = {
184
242
  experiment_id: string;
185
243
  label: string;
@@ -190,4 +248,4 @@ declare function writeChoice(proposalId: string, experiment_id: string, label: s
190
248
  declare function hasTrackedVisit(proposalId: string, label: string): boolean;
191
249
  declare function markTrackedVisit(proposalId: string, label: string): void;
192
250
 
193
- export { type Choice, type ProbatContextValue, ProbatProvider, ProbatProviderClient, type ProbatProviderProps as ProbatProviderClientProps, type ProbatProviderProps, type RetrieveResponse, type UseExperimentReturn, type UseProbatMetricsReturn, type WithExperimentOptions, detectEnvironment, extractClickMeta, fetchDecision, hasTrackedVisit, markTrackedVisit, readChoice, sendMetric, useExperiment, useProbatContext, useProbatMetrics, withExperiment, writeChoice };
251
+ export { type Choice, type ProbatContextValue, ProbatProvider, ProbatProviderClient, type ProbatProviderProps as ProbatProviderClientProps, type ProbatProviderProps, type RetrieveResponse, type UseExperimentReturn, type UseProbatMetricsReturn, type WithExperimentOptions, detectEnvironment, extractClickMeta, fetchDecision, getHeatmapTracker, hasTrackedVisit, initHeatmapTracking, markTrackedVisit, readChoice, sendMetric, stopHeatmapTracking, useExperiment, useProbatContext, useProbatMetrics, withExperiment, writeChoice };