crexperium-sdk 1.2.4 → 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 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -2
- 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
package/dist/index.mjs
CHANGED
|
@@ -602,6 +602,82 @@ class DealsResource extends BaseResource {
|
|
|
602
602
|
}
|
|
603
603
|
}
|
|
604
604
|
|
|
605
|
+
/**
|
|
606
|
+
* Experiments API Resource
|
|
607
|
+
* Handles A/B testing and feature flagging
|
|
608
|
+
*/
|
|
609
|
+
class ExperimentsResource extends BaseResource {
|
|
610
|
+
/**
|
|
611
|
+
* Get an experiment by ID or key
|
|
612
|
+
*/
|
|
613
|
+
async get(experimentIdOrKey) {
|
|
614
|
+
return this.http.get(`/api/v1/experiments/${experimentIdOrKey}/`);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Get a variant assignment for a visitor
|
|
618
|
+
* This is the main SDK method for A/B testing
|
|
619
|
+
*
|
|
620
|
+
* @param experimentKey - The unique key of the experiment
|
|
621
|
+
* @param visitorId - The unique identifier for the visitor
|
|
622
|
+
* @param context - Optional context data (user agent, device, etc.)
|
|
623
|
+
* @returns The assigned variant with its payload
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* ```typescript
|
|
627
|
+
* const assignment = await client.experiments.assign('checkout_button_test', {
|
|
628
|
+
* visitor_id: 'visitor_123',
|
|
629
|
+
* context: {
|
|
630
|
+
* user_agent: navigator.userAgent,
|
|
631
|
+
* device_type: 'desktop',
|
|
632
|
+
* browser: 'chrome'
|
|
633
|
+
* }
|
|
634
|
+
* });
|
|
635
|
+
*
|
|
636
|
+
* // Use the variant payload
|
|
637
|
+
* const buttonColor = assignment.variant.payload.button_color;
|
|
638
|
+
* ```
|
|
639
|
+
*/
|
|
640
|
+
async assign(experimentKey, input) {
|
|
641
|
+
return this.http.post(`/api/v1/experiments/${experimentKey}/assign/`, input);
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Track a conversion for a visitor in an experiment
|
|
645
|
+
* Call this when a visitor completes the desired action
|
|
646
|
+
*
|
|
647
|
+
* @param experimentKey - The unique key of the experiment
|
|
648
|
+
* @param input - Conversion data including visitor_id
|
|
649
|
+
*
|
|
650
|
+
* @example
|
|
651
|
+
* ```typescript
|
|
652
|
+
* await client.experiments.trackConversion('checkout_button_test', {
|
|
653
|
+
* visitor_id: 'visitor_123',
|
|
654
|
+
* event_name: 'purchase',
|
|
655
|
+
* event_properties: {
|
|
656
|
+
* amount: 99.99,
|
|
657
|
+
* currency: 'USD'
|
|
658
|
+
* }
|
|
659
|
+
* });
|
|
660
|
+
* ```
|
|
661
|
+
*/
|
|
662
|
+
async trackConversion(experimentKey, input) {
|
|
663
|
+
await this.http.post(`/api/v1/experiments/${experimentKey}/convert/`, input);
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Get a variant assignment and automatically track the exposure
|
|
667
|
+
* This combines assign() and exposure tracking in one call
|
|
668
|
+
*
|
|
669
|
+
* @param experimentKey - The unique key of the experiment
|
|
670
|
+
* @param input - Assignment data including visitor_id
|
|
671
|
+
* @returns The assigned variant with its payload
|
|
672
|
+
*/
|
|
673
|
+
async getVariant(experimentKey, input) {
|
|
674
|
+
const assignment = await this.assign(experimentKey, input);
|
|
675
|
+
// Exposure is automatically tracked by the backend on assign
|
|
676
|
+
// but we return the assignment for client use
|
|
677
|
+
return assignment;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
605
681
|
/**
|
|
606
682
|
* Storage utilities for browser localStorage/cookies
|
|
607
683
|
*/
|
|
@@ -13767,6 +13843,7 @@ class CRMClient {
|
|
|
13767
13843
|
this._events = new EventsResource(this.http);
|
|
13768
13844
|
this._contacts = new ContactsResource(this.http);
|
|
13769
13845
|
this._deals = new DealsResource(this.http);
|
|
13846
|
+
this._experiments = new ExperimentsResource(this.http);
|
|
13770
13847
|
// Initialize browser plugins if in browser
|
|
13771
13848
|
if (isBrowser) {
|
|
13772
13849
|
this.initBrowserPlugins();
|
|
@@ -13790,6 +13867,12 @@ class CRMClient {
|
|
|
13790
13867
|
get deals() {
|
|
13791
13868
|
return this._deals;
|
|
13792
13869
|
}
|
|
13870
|
+
/**
|
|
13871
|
+
* Experiments resource for A/B testing and feature flags
|
|
13872
|
+
*/
|
|
13873
|
+
get experiments() {
|
|
13874
|
+
return this._experiments;
|
|
13875
|
+
}
|
|
13793
13876
|
/**
|
|
13794
13877
|
* Visitor ID plugin (browser only)
|
|
13795
13878
|
*/
|
|
@@ -13853,7 +13936,7 @@ class CRMClient {
|
|
|
13853
13936
|
*/
|
|
13854
13937
|
// Main client
|
|
13855
13938
|
// Version
|
|
13856
|
-
const VERSION = '1.
|
|
13939
|
+
const VERSION = '1.2.5';
|
|
13857
13940
|
|
|
13858
|
-
export { AuthenticationError, AutoPageViewPlugin, CRMClient, CRMError, Config, ConsoleLevel, ContactsResource, DealsResource, DeviceInfoPlugin, EventsResource, NetworkError, RateLimitError, ResourceNotFoundError, ServerError, SessionEventType, SessionReplayPlugin, VERSION, ValidationError, VisitorIdPlugin, detectBrowser, detectDeviceType, detectOS, generateUUID, getDeviceInfo, getLocalStorageItem, isLocalStorageAvailable, removeLocalStorageItem, setLocalStorageItem };
|
|
13941
|
+
export { AuthenticationError, AutoPageViewPlugin, CRMClient, CRMError, Config, ConsoleLevel, ContactsResource, DealsResource, DeviceInfoPlugin, EventsResource, ExperimentsResource, NetworkError, RateLimitError, ResourceNotFoundError, ServerError, SessionEventType, SessionReplayPlugin, VERSION, ValidationError, VisitorIdPlugin, detectBrowser, detectDeviceType, detectOS, generateUUID, getDeviceInfo, getLocalStorageItem, isLocalStorageAvailable, removeLocalStorageItem, setLocalStorageItem };
|
|
13859
13942
|
//# sourceMappingURL=index.mjs.map
|