@probat/react 0.4.4 → 0.4.6

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,14 +4,18 @@ interface ProbatProviderProps {
4
4
  /** Your end-user's ID. When provided, used as the distinct_id for variant
5
5
  * assignment (consistent across devices) and attached to all events. */
6
6
  customerId?: string;
7
- /** Base URL for the Probat API. Defaults to https://gushi.onrender.com */
7
+ /** Base URL for the Probat API. Defaults to https://api.probat.app */
8
8
  host?: string;
9
+ /** Publishable API key for authenticating SDK requests (probat_pk_...) */
10
+ apiKey?: string;
9
11
  /**
10
12
  * Bootstrap assignments to avoid flash on first render.
11
13
  * Map of experiment id → variant key.
12
14
  * e.g. { "cta-copy-test": "ai_v1" }
13
15
  */
14
16
  bootstrap?: Record<string, string>;
17
+ /** Automatically send $session_start/$session_end lifecycle events. */
18
+ trackSessionLifecycle?: boolean;
15
19
  children: React$1.ReactNode;
16
20
  }
17
21
 
@@ -69,6 +73,8 @@ interface UseTrackBaseOptions {
69
73
  experimentId: string;
70
74
  /** Stable instance id when multiple instances of the same experiment exist on a page */
71
75
  componentInstanceId?: string;
76
+ /** Whether the variant assignment has been resolved. When false, all tracking is suppressed. */
77
+ resolved?: boolean;
72
78
  /** Auto-track impressions (default true) */
73
79
  impression?: boolean;
74
80
  /** Auto-track clicks (default true) */
@@ -144,10 +150,38 @@ interface UseExperimentReturn {
144
150
  * Resolves the variant assignment for an experiment.
145
151
  * No tracking — use `useTrack` or `<Track>` to observe impressions/clicks.
146
152
  *
147
- * Priority: bootstrap > localStorage cache > fetchDecision.
153
+ * Priority: __probat_force URL param > bootstrap > localStorage cache > fetchDecision.
148
154
  */
149
155
  declare function useExperiment(id: string, options?: UseExperimentOptions): UseExperimentReturn;
150
156
 
157
+ declare const PROBAT_ENV_DEV: "dev";
158
+ declare const PROBAT_ENV_PROD: "prod";
159
+ type ProbatEnvironment = typeof PROBAT_ENV_DEV | typeof PROBAT_ENV_PROD;
160
+ type ProbatEventType = "$experiment_exposure" | "$experiment_click" | "$pageview" | "$pageleave" | "$session_start" | "$session_end" | "$goal_reached" | "$feature_interaction" | string;
161
+ interface StructuredEventProperties {
162
+ distinct_id: string;
163
+ session_id: string;
164
+ $page_url: string;
165
+ $pathname: string;
166
+ $referrer: string;
167
+ captured_at: string;
168
+ environment: ProbatEnvironment;
169
+ source: "react-sdk" | "react-native-sdk";
170
+ $session_sequence: number;
171
+ $session_start_at: string;
172
+ experiment_id?: string;
173
+ variant_key?: string;
174
+ component_instance_id?: string;
175
+ $funnel_id?: string;
176
+ $funnel_step?: number;
177
+ [key: string]: unknown;
178
+ }
179
+ interface StructuredEvent {
180
+ event: ProbatEventType;
181
+ environment: ProbatEnvironment;
182
+ properties: StructuredEventProperties;
183
+ }
184
+
151
185
  interface UseProbatMetricsReturn {
152
186
  /**
153
187
  * Send a custom event with arbitrary properties.
@@ -159,7 +193,9 @@ interface UseProbatMetricsReturn {
159
193
  * capture("purchase", { revenue: 42, currency: "USD" });
160
194
  * ```
161
195
  */
162
- capture: (event: string, properties?: Record<string, unknown>) => void;
196
+ capture: (event: ProbatEventType, properties?: Record<string, unknown>) => void;
197
+ captureGoal: (funnelId: string, funnelStep: number, properties?: Record<string, unknown>) => void;
198
+ captureFeatureInteraction: (interactionName: string, properties?: Record<string, unknown>) => void;
163
199
  }
164
200
  /**
165
201
  * Minimal metrics hook. Provides a single `capture(event, props)` function
@@ -171,20 +207,21 @@ interface DecisionResponse {
171
207
  variant_key: string;
172
208
  }
173
209
  interface MetricPayload {
174
- event: string;
175
- environment: "dev" | "prod";
176
- properties: Record<string, unknown>;
210
+ event: ProbatEventType;
211
+ environment: ProbatEnvironment;
212
+ properties: StructuredEventProperties;
177
213
  }
178
214
  /**
179
215
  * Fetch the variant assignment for an experiment.
180
216
  * Returns the variant key string (e.g. "control", "ai_v1").
181
217
  * Deduplicates concurrent calls for the same experiment.
182
218
  */
183
- declare function fetchDecision(host: string, experimentId: string, distinctId: string): Promise<string>;
219
+ declare function fetchDecision(host: string, experimentId: string, distinctId: string, apiKey?: string): Promise<string>;
184
220
  /**
185
221
  * Fire-and-forget metric send. Never throws.
186
222
  */
187
- declare function sendMetric(host: string, event: string, properties: Record<string, unknown>): void;
223
+ declare function sendMetric(host: string, event: ProbatEventType, properties: Record<string, unknown>, apiKey?: string): void;
224
+ declare function flushMetrics(host: string, forceBeacon?: boolean, apiKey?: string): void;
188
225
 
189
226
  /**
190
227
  * Factory that creates a typed context + hook pair for passing a variantKey
@@ -212,4 +249,4 @@ declare function createExperimentContext(experimentId: string): {
212
249
  useVariantKey: () => string;
213
250
  };
214
251
 
215
- export { type DecisionResponse, Experiment, type ExperimentProps, type ExperimentTrackOptions, type MetricPayload, ProbatProviderClient, type ProbatProviderProps, Track, type TrackProps, type UseExperimentOptions, type UseExperimentReturn, type UseProbatMetricsReturn, type UseTrackCustomerOptions, type UseTrackExplicitOptions, type UseTrackOptions, createExperimentContext, fetchDecision, sendMetric, useExperiment, useProbatMetrics, useTrack };
252
+ export { type DecisionResponse, Experiment, type ExperimentProps, type ExperimentTrackOptions, type MetricPayload, PROBAT_ENV_DEV, PROBAT_ENV_PROD, type ProbatEnvironment, type ProbatEventType, ProbatProviderClient, type ProbatProviderProps, type StructuredEvent, type StructuredEventProperties, Track, type TrackProps, type UseExperimentOptions, type UseExperimentReturn, type UseProbatMetricsReturn, type UseTrackCustomerOptions, type UseTrackExplicitOptions, type UseTrackOptions, createExperimentContext, fetchDecision, flushMetrics, sendMetric, useExperiment, useProbatMetrics, useTrack };
package/dist/index.d.ts CHANGED
@@ -4,14 +4,18 @@ interface ProbatProviderProps {
4
4
  /** Your end-user's ID. When provided, used as the distinct_id for variant
5
5
  * assignment (consistent across devices) and attached to all events. */
6
6
  customerId?: string;
7
- /** Base URL for the Probat API. Defaults to https://gushi.onrender.com */
7
+ /** Base URL for the Probat API. Defaults to https://api.probat.app */
8
8
  host?: string;
9
+ /** Publishable API key for authenticating SDK requests (probat_pk_...) */
10
+ apiKey?: string;
9
11
  /**
10
12
  * Bootstrap assignments to avoid flash on first render.
11
13
  * Map of experiment id → variant key.
12
14
  * e.g. { "cta-copy-test": "ai_v1" }
13
15
  */
14
16
  bootstrap?: Record<string, string>;
17
+ /** Automatically send $session_start/$session_end lifecycle events. */
18
+ trackSessionLifecycle?: boolean;
15
19
  children: React$1.ReactNode;
16
20
  }
17
21
 
@@ -69,6 +73,8 @@ interface UseTrackBaseOptions {
69
73
  experimentId: string;
70
74
  /** Stable instance id when multiple instances of the same experiment exist on a page */
71
75
  componentInstanceId?: string;
76
+ /** Whether the variant assignment has been resolved. When false, all tracking is suppressed. */
77
+ resolved?: boolean;
72
78
  /** Auto-track impressions (default true) */
73
79
  impression?: boolean;
74
80
  /** Auto-track clicks (default true) */
@@ -144,10 +150,38 @@ interface UseExperimentReturn {
144
150
  * Resolves the variant assignment for an experiment.
145
151
  * No tracking — use `useTrack` or `<Track>` to observe impressions/clicks.
146
152
  *
147
- * Priority: bootstrap > localStorage cache > fetchDecision.
153
+ * Priority: __probat_force URL param > bootstrap > localStorage cache > fetchDecision.
148
154
  */
149
155
  declare function useExperiment(id: string, options?: UseExperimentOptions): UseExperimentReturn;
150
156
 
157
+ declare const PROBAT_ENV_DEV: "dev";
158
+ declare const PROBAT_ENV_PROD: "prod";
159
+ type ProbatEnvironment = typeof PROBAT_ENV_DEV | typeof PROBAT_ENV_PROD;
160
+ type ProbatEventType = "$experiment_exposure" | "$experiment_click" | "$pageview" | "$pageleave" | "$session_start" | "$session_end" | "$goal_reached" | "$feature_interaction" | string;
161
+ interface StructuredEventProperties {
162
+ distinct_id: string;
163
+ session_id: string;
164
+ $page_url: string;
165
+ $pathname: string;
166
+ $referrer: string;
167
+ captured_at: string;
168
+ environment: ProbatEnvironment;
169
+ source: "react-sdk" | "react-native-sdk";
170
+ $session_sequence: number;
171
+ $session_start_at: string;
172
+ experiment_id?: string;
173
+ variant_key?: string;
174
+ component_instance_id?: string;
175
+ $funnel_id?: string;
176
+ $funnel_step?: number;
177
+ [key: string]: unknown;
178
+ }
179
+ interface StructuredEvent {
180
+ event: ProbatEventType;
181
+ environment: ProbatEnvironment;
182
+ properties: StructuredEventProperties;
183
+ }
184
+
151
185
  interface UseProbatMetricsReturn {
152
186
  /**
153
187
  * Send a custom event with arbitrary properties.
@@ -159,7 +193,9 @@ interface UseProbatMetricsReturn {
159
193
  * capture("purchase", { revenue: 42, currency: "USD" });
160
194
  * ```
161
195
  */
162
- capture: (event: string, properties?: Record<string, unknown>) => void;
196
+ capture: (event: ProbatEventType, properties?: Record<string, unknown>) => void;
197
+ captureGoal: (funnelId: string, funnelStep: number, properties?: Record<string, unknown>) => void;
198
+ captureFeatureInteraction: (interactionName: string, properties?: Record<string, unknown>) => void;
163
199
  }
164
200
  /**
165
201
  * Minimal metrics hook. Provides a single `capture(event, props)` function
@@ -171,20 +207,21 @@ interface DecisionResponse {
171
207
  variant_key: string;
172
208
  }
173
209
  interface MetricPayload {
174
- event: string;
175
- environment: "dev" | "prod";
176
- properties: Record<string, unknown>;
210
+ event: ProbatEventType;
211
+ environment: ProbatEnvironment;
212
+ properties: StructuredEventProperties;
177
213
  }
178
214
  /**
179
215
  * Fetch the variant assignment for an experiment.
180
216
  * Returns the variant key string (e.g. "control", "ai_v1").
181
217
  * Deduplicates concurrent calls for the same experiment.
182
218
  */
183
- declare function fetchDecision(host: string, experimentId: string, distinctId: string): Promise<string>;
219
+ declare function fetchDecision(host: string, experimentId: string, distinctId: string, apiKey?: string): Promise<string>;
184
220
  /**
185
221
  * Fire-and-forget metric send. Never throws.
186
222
  */
187
- declare function sendMetric(host: string, event: string, properties: Record<string, unknown>): void;
223
+ declare function sendMetric(host: string, event: ProbatEventType, properties: Record<string, unknown>, apiKey?: string): void;
224
+ declare function flushMetrics(host: string, forceBeacon?: boolean, apiKey?: string): void;
188
225
 
189
226
  /**
190
227
  * Factory that creates a typed context + hook pair for passing a variantKey
@@ -212,4 +249,4 @@ declare function createExperimentContext(experimentId: string): {
212
249
  useVariantKey: () => string;
213
250
  };
214
251
 
215
- export { type DecisionResponse, Experiment, type ExperimentProps, type ExperimentTrackOptions, type MetricPayload, ProbatProviderClient, type ProbatProviderProps, Track, type TrackProps, type UseExperimentOptions, type UseExperimentReturn, type UseProbatMetricsReturn, type UseTrackCustomerOptions, type UseTrackExplicitOptions, type UseTrackOptions, createExperimentContext, fetchDecision, sendMetric, useExperiment, useProbatMetrics, useTrack };
252
+ export { type DecisionResponse, Experiment, type ExperimentProps, type ExperimentTrackOptions, type MetricPayload, PROBAT_ENV_DEV, PROBAT_ENV_PROD, type ProbatEnvironment, type ProbatEventType, ProbatProviderClient, type ProbatProviderProps, type StructuredEvent, type StructuredEventProperties, Track, type TrackProps, type UseExperimentOptions, type UseExperimentReturn, type UseProbatMetricsReturn, type UseTrackCustomerOptions, type UseTrackExplicitOptions, type UseTrackOptions, createExperimentContext, fetchDecision, flushMetrics, sendMetric, useExperiment, useProbatMetrics, useTrack };