@probat/react 0.4.5 → 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,9 +4,9 @@ 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
- /** API key for authenticating SDK requests (probat_sk_...) */
9
+ /** Publishable API key for authenticating SDK requests (probat_pk_...) */
10
10
  apiKey?: string;
11
11
  /**
12
12
  * Bootstrap assignments to avoid flash on first render.
@@ -14,6 +14,8 @@ interface ProbatProviderProps {
14
14
  * e.g. { "cta-copy-test": "ai_v1" }
15
15
  */
16
16
  bootstrap?: Record<string, string>;
17
+ /** Automatically send $session_start/$session_end lifecycle events. */
18
+ trackSessionLifecycle?: boolean;
17
19
  children: React$1.ReactNode;
18
20
  }
19
21
 
@@ -148,10 +150,38 @@ interface UseExperimentReturn {
148
150
  * Resolves the variant assignment for an experiment.
149
151
  * No tracking — use `useTrack` or `<Track>` to observe impressions/clicks.
150
152
  *
151
- * Priority: bootstrap > localStorage cache > fetchDecision.
153
+ * Priority: __probat_force URL param > bootstrap > localStorage cache > fetchDecision.
152
154
  */
153
155
  declare function useExperiment(id: string, options?: UseExperimentOptions): UseExperimentReturn;
154
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
+
155
185
  interface UseProbatMetricsReturn {
156
186
  /**
157
187
  * Send a custom event with arbitrary properties.
@@ -163,7 +193,9 @@ interface UseProbatMetricsReturn {
163
193
  * capture("purchase", { revenue: 42, currency: "USD" });
164
194
  * ```
165
195
  */
166
- 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;
167
199
  }
168
200
  /**
169
201
  * Minimal metrics hook. Provides a single `capture(event, props)` function
@@ -175,9 +207,9 @@ interface DecisionResponse {
175
207
  variant_key: string;
176
208
  }
177
209
  interface MetricPayload {
178
- event: string;
179
- environment: "dev" | "prod";
180
- properties: Record<string, unknown>;
210
+ event: ProbatEventType;
211
+ environment: ProbatEnvironment;
212
+ properties: StructuredEventProperties;
181
213
  }
182
214
  /**
183
215
  * Fetch the variant assignment for an experiment.
@@ -188,7 +220,8 @@ declare function fetchDecision(host: string, experimentId: string, distinctId: s
188
220
  /**
189
221
  * Fire-and-forget metric send. Never throws.
190
222
  */
191
- declare function sendMetric(host: string, event: string, properties: Record<string, unknown>, apiKey?: string): 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;
192
225
 
193
226
  /**
194
227
  * Factory that creates a typed context + hook pair for passing a variantKey
@@ -216,4 +249,4 @@ declare function createExperimentContext(experimentId: string): {
216
249
  useVariantKey: () => string;
217
250
  };
218
251
 
219
- 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,9 +4,9 @@ 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
- /** API key for authenticating SDK requests (probat_sk_...) */
9
+ /** Publishable API key for authenticating SDK requests (probat_pk_...) */
10
10
  apiKey?: string;
11
11
  /**
12
12
  * Bootstrap assignments to avoid flash on first render.
@@ -14,6 +14,8 @@ interface ProbatProviderProps {
14
14
  * e.g. { "cta-copy-test": "ai_v1" }
15
15
  */
16
16
  bootstrap?: Record<string, string>;
17
+ /** Automatically send $session_start/$session_end lifecycle events. */
18
+ trackSessionLifecycle?: boolean;
17
19
  children: React$1.ReactNode;
18
20
  }
19
21
 
@@ -148,10 +150,38 @@ interface UseExperimentReturn {
148
150
  * Resolves the variant assignment for an experiment.
149
151
  * No tracking — use `useTrack` or `<Track>` to observe impressions/clicks.
150
152
  *
151
- * Priority: bootstrap > localStorage cache > fetchDecision.
153
+ * Priority: __probat_force URL param > bootstrap > localStorage cache > fetchDecision.
152
154
  */
153
155
  declare function useExperiment(id: string, options?: UseExperimentOptions): UseExperimentReturn;
154
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
+
155
185
  interface UseProbatMetricsReturn {
156
186
  /**
157
187
  * Send a custom event with arbitrary properties.
@@ -163,7 +193,9 @@ interface UseProbatMetricsReturn {
163
193
  * capture("purchase", { revenue: 42, currency: "USD" });
164
194
  * ```
165
195
  */
166
- 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;
167
199
  }
168
200
  /**
169
201
  * Minimal metrics hook. Provides a single `capture(event, props)` function
@@ -175,9 +207,9 @@ interface DecisionResponse {
175
207
  variant_key: string;
176
208
  }
177
209
  interface MetricPayload {
178
- event: string;
179
- environment: "dev" | "prod";
180
- properties: Record<string, unknown>;
210
+ event: ProbatEventType;
211
+ environment: ProbatEnvironment;
212
+ properties: StructuredEventProperties;
181
213
  }
182
214
  /**
183
215
  * Fetch the variant assignment for an experiment.
@@ -188,7 +220,8 @@ declare function fetchDecision(host: string, experimentId: string, distinctId: s
188
220
  /**
189
221
  * Fire-and-forget metric send. Never throws.
190
222
  */
191
- declare function sendMetric(host: string, event: string, properties: Record<string, unknown>, apiKey?: string): 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;
192
225
 
193
226
  /**
194
227
  * Factory that creates a typed context + hook pair for passing a variantKey
@@ -216,4 +249,4 @@ declare function createExperimentContext(experimentId: string): {
216
249
  useVariantKey: () => string;
217
250
  };
218
251
 
219
- 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 };