crexperium-sdk 1.2.3 → 1.2.5
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/browser.js +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/client.d.ts +6 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +85 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -19
- package/dist/index.mjs.map +1 -1
- package/dist/resources/experiments.d.ts +66 -0
- package/dist/types/experiments.d.ts +71 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Experiments API Resource
|
|
3
|
+
* Handles A/B testing and feature flagging
|
|
4
|
+
*/
|
|
5
|
+
import { BaseResource } from './base';
|
|
6
|
+
import { Experiment, VariantAssignment, AssignVariantInput, TrackConversionInput } from '../types/experiments';
|
|
7
|
+
export declare class ExperimentsResource extends BaseResource {
|
|
8
|
+
/**
|
|
9
|
+
* Get an experiment by ID or key
|
|
10
|
+
*/
|
|
11
|
+
get(experimentIdOrKey: string): Promise<Experiment>;
|
|
12
|
+
/**
|
|
13
|
+
* Get a variant assignment for a visitor
|
|
14
|
+
* This is the main SDK method for A/B testing
|
|
15
|
+
*
|
|
16
|
+
* @param experimentKey - The unique key of the experiment
|
|
17
|
+
* @param visitorId - The unique identifier for the visitor
|
|
18
|
+
* @param context - Optional context data (user agent, device, etc.)
|
|
19
|
+
* @returns The assigned variant with its payload
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const assignment = await client.experiments.assign('checkout_button_test', {
|
|
24
|
+
* visitor_id: 'visitor_123',
|
|
25
|
+
* context: {
|
|
26
|
+
* user_agent: navigator.userAgent,
|
|
27
|
+
* device_type: 'desktop',
|
|
28
|
+
* browser: 'chrome'
|
|
29
|
+
* }
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Use the variant payload
|
|
33
|
+
* const buttonColor = assignment.variant.payload.button_color;
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
assign(experimentKey: string, input: AssignVariantInput): Promise<VariantAssignment>;
|
|
37
|
+
/**
|
|
38
|
+
* Track a conversion for a visitor in an experiment
|
|
39
|
+
* Call this when a visitor completes the desired action
|
|
40
|
+
*
|
|
41
|
+
* @param experimentKey - The unique key of the experiment
|
|
42
|
+
* @param input - Conversion data including visitor_id
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* await client.experiments.trackConversion('checkout_button_test', {
|
|
47
|
+
* visitor_id: 'visitor_123',
|
|
48
|
+
* event_name: 'purchase',
|
|
49
|
+
* event_properties: {
|
|
50
|
+
* amount: 99.99,
|
|
51
|
+
* currency: 'USD'
|
|
52
|
+
* }
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
trackConversion(experimentKey: string, input: TrackConversionInput): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Get a variant assignment and automatically track the exposure
|
|
59
|
+
* This combines assign() and exposure tracking in one call
|
|
60
|
+
*
|
|
61
|
+
* @param experimentKey - The unique key of the experiment
|
|
62
|
+
* @param input - Assignment data including visitor_id
|
|
63
|
+
* @returns The assigned variant with its payload
|
|
64
|
+
*/
|
|
65
|
+
getVariant(experimentKey: string, input: AssignVariantInput): Promise<VariantAssignment>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for Experiments module (A/B Testing)
|
|
3
|
+
*/
|
|
4
|
+
export type ExperimentStatus = 'DRAFT' | 'RUNNING' | 'PAUSED' | 'COMPLETED' | 'ARCHIVED';
|
|
5
|
+
/**
|
|
6
|
+
* Experiment Variant
|
|
7
|
+
*/
|
|
8
|
+
export interface ExperimentVariant {
|
|
9
|
+
id: string;
|
|
10
|
+
experiment: string;
|
|
11
|
+
name: string;
|
|
12
|
+
key: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
rollout_percentage: number;
|
|
15
|
+
payload: Record<string, any>;
|
|
16
|
+
is_control: boolean;
|
|
17
|
+
is_active: boolean;
|
|
18
|
+
created_at: string;
|
|
19
|
+
updated_at: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Experiment
|
|
23
|
+
*/
|
|
24
|
+
export interface Experiment {
|
|
25
|
+
id: string;
|
|
26
|
+
organization: string;
|
|
27
|
+
name: string;
|
|
28
|
+
key: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
status: ExperimentStatus;
|
|
31
|
+
started_at?: string | null;
|
|
32
|
+
paused_at?: string | null;
|
|
33
|
+
completed_at?: string | null;
|
|
34
|
+
targeting_rules: Record<string, any>;
|
|
35
|
+
winning_variant?: string | null;
|
|
36
|
+
total_assignments: number;
|
|
37
|
+
created_at: string;
|
|
38
|
+
updated_at: string;
|
|
39
|
+
variants: ExperimentVariant[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Variant Assignment Response (SDK)
|
|
43
|
+
*/
|
|
44
|
+
export interface VariantAssignment {
|
|
45
|
+
variant: {
|
|
46
|
+
id: string;
|
|
47
|
+
key: string;
|
|
48
|
+
name: string;
|
|
49
|
+
payload: Record<string, any>;
|
|
50
|
+
};
|
|
51
|
+
was_created: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Assign Variant Input (SDK)
|
|
55
|
+
*/
|
|
56
|
+
export interface AssignVariantInput {
|
|
57
|
+
visitor_id: string;
|
|
58
|
+
context?: {
|
|
59
|
+
user_agent?: string;
|
|
60
|
+
device_type?: string;
|
|
61
|
+
browser?: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Track Conversion Input
|
|
66
|
+
*/
|
|
67
|
+
export interface TrackConversionInput {
|
|
68
|
+
visitor_id: string;
|
|
69
|
+
event_name?: string;
|
|
70
|
+
event_properties?: Record<string, any>;
|
|
71
|
+
}
|
package/dist/types/index.d.ts
CHANGED