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/client.d.ts CHANGED
@@ -5,6 +5,7 @@ import { SDKConfig } from './config';
5
5
  import { EventsResource } from './resources/events';
6
6
  import { ContactsResource } from './resources/contacts';
7
7
  import { DealsResource } from './resources/deals';
8
+ import { ExperimentsResource } from './resources/experiments';
8
9
  import { VisitorIdPlugin } from './plugins/visitor-id';
9
10
  import { DeviceInfoPlugin } from './plugins/device-info';
10
11
  import { SessionReplayPlugin } from './plugins/session-replay';
@@ -14,6 +15,7 @@ export declare class CRMClient {
14
15
  private _events;
15
16
  private _contacts;
16
17
  private _deals;
18
+ private _experiments;
17
19
  private plugins;
18
20
  private _visitorId?;
19
21
  private _deviceInfo?;
@@ -32,6 +34,10 @@ export declare class CRMClient {
32
34
  * Deals resource for managing deals
33
35
  */
34
36
  get deals(): DealsResource;
37
+ /**
38
+ * Experiments resource for A/B testing and feature flags
39
+ */
40
+ get experiments(): ExperimentsResource;
35
41
  /**
36
42
  * Visitor ID plugin (browser only)
37
43
  */
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { Config, SDKConfig } from './config';
7
7
  export { EventsResource } from './resources/events';
8
8
  export { ContactsResource } from './resources/contacts';
9
9
  export { DealsResource } from './resources/deals';
10
+ export { ExperimentsResource } from './resources/experiments';
10
11
  export * from './types';
11
12
  export * from './errors';
12
13
  export { VisitorIdPlugin, Plugin } from './plugins/visitor-id';
@@ -15,4 +16,4 @@ export { AutoPageViewPlugin } from './plugins/auto-page-view';
15
16
  export { SessionReplayPlugin } from './plugins/session-replay';
16
17
  export { DeviceInfo, getDeviceInfo, detectDeviceType, detectBrowser, detectOS } from './utils/device';
17
18
  export { isLocalStorageAvailable, getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem, generateUUID, } from './utils/storage';
18
- export declare const VERSION = "1.1.0";
19
+ export declare const VERSION = "1.2.5";
package/dist/index.js CHANGED
@@ -604,6 +604,82 @@ class DealsResource extends BaseResource {
604
604
  }
605
605
  }
606
606
 
607
+ /**
608
+ * Experiments API Resource
609
+ * Handles A/B testing and feature flagging
610
+ */
611
+ class ExperimentsResource extends BaseResource {
612
+ /**
613
+ * Get an experiment by ID or key
614
+ */
615
+ async get(experimentIdOrKey) {
616
+ return this.http.get(`/api/v1/experiments/${experimentIdOrKey}/`);
617
+ }
618
+ /**
619
+ * Get a variant assignment for a visitor
620
+ * This is the main SDK method for A/B testing
621
+ *
622
+ * @param experimentKey - The unique key of the experiment
623
+ * @param visitorId - The unique identifier for the visitor
624
+ * @param context - Optional context data (user agent, device, etc.)
625
+ * @returns The assigned variant with its payload
626
+ *
627
+ * @example
628
+ * ```typescript
629
+ * const assignment = await client.experiments.assign('checkout_button_test', {
630
+ * visitor_id: 'visitor_123',
631
+ * context: {
632
+ * user_agent: navigator.userAgent,
633
+ * device_type: 'desktop',
634
+ * browser: 'chrome'
635
+ * }
636
+ * });
637
+ *
638
+ * // Use the variant payload
639
+ * const buttonColor = assignment.variant.payload.button_color;
640
+ * ```
641
+ */
642
+ async assign(experimentKey, input) {
643
+ return this.http.post(`/api/v1/experiments/${experimentKey}/assign/`, input);
644
+ }
645
+ /**
646
+ * Track a conversion for a visitor in an experiment
647
+ * Call this when a visitor completes the desired action
648
+ *
649
+ * @param experimentKey - The unique key of the experiment
650
+ * @param input - Conversion data including visitor_id
651
+ *
652
+ * @example
653
+ * ```typescript
654
+ * await client.experiments.trackConversion('checkout_button_test', {
655
+ * visitor_id: 'visitor_123',
656
+ * event_name: 'purchase',
657
+ * event_properties: {
658
+ * amount: 99.99,
659
+ * currency: 'USD'
660
+ * }
661
+ * });
662
+ * ```
663
+ */
664
+ async trackConversion(experimentKey, input) {
665
+ await this.http.post(`/api/v1/experiments/${experimentKey}/convert/`, input);
666
+ }
667
+ /**
668
+ * Get a variant assignment and automatically track the exposure
669
+ * This combines assign() and exposure tracking in one call
670
+ *
671
+ * @param experimentKey - The unique key of the experiment
672
+ * @param input - Assignment data including visitor_id
673
+ * @returns The assigned variant with its payload
674
+ */
675
+ async getVariant(experimentKey, input) {
676
+ const assignment = await this.assign(experimentKey, input);
677
+ // Exposure is automatically tracked by the backend on assign
678
+ // but we return the assignment for client use
679
+ return assignment;
680
+ }
681
+ }
682
+
607
683
  /**
608
684
  * Storage utilities for browser localStorage/cookies
609
685
  */
@@ -13219,18 +13295,13 @@ class SessionReplayPlugin {
13219
13295
  */
13220
13296
  async init() {
13221
13297
  try {
13222
- console.log('[SessionReplay] Initializing session replay...');
13223
13298
  // Start session on backend
13224
13299
  await this.startSession();
13225
- console.log('[SessionReplay] Session started on backend, sessionId:', this.session?.sessionId);
13226
13300
  // Start rrweb recording
13227
- console.log('[SessionReplay] Starting rrweb recording...');
13228
13301
  this.startRrwebRecording();
13229
- console.log('[SessionReplay] rrweb recording started');
13230
13302
  // IMPORTANT: Flush initial events (Type 4 Meta + Type 2 Full Snapshot) immediately
13231
13303
  // so the session is playable right away, don't wait for the 5s flush interval
13232
13304
  setTimeout(() => {
13233
- console.log('[SessionReplay] Performing initial flush of critical events...');
13234
13305
  this.flush();
13235
13306
  }, 100); // Small delay to ensure rrweb events are captured
13236
13307
  // Intercept console methods
@@ -13305,17 +13376,9 @@ class SessionReplayPlugin {
13305
13376
  this.stopRecording = record({
13306
13377
  emit: (event) => {
13307
13378
  // Debug: Log event types
13308
- if (event.type === 4) {
13309
- console.log('[SessionReplay] Captured Meta event (type 4)');
13310
- }
13311
- else if (event.type === 2) {
13312
- console.log('[SessionReplay] Captured Full Snapshot event (type 2)');
13313
- }
13314
13379
  this.eventBuffer.push(event);
13315
- console.log(`[SessionReplay] Event buffered. Type: ${event.type}, Buffer size: ${this.eventBuffer.length}`);
13316
13380
  // Auto-flush if buffer reaches max size
13317
13381
  if (this.eventBuffer.length >= (this.config.buffering?.maxBufferSize || 100)) {
13318
- console.log('[SessionReplay] Buffer full, flushing...');
13319
13382
  this.flush();
13320
13383
  }
13321
13384
  },
@@ -13657,16 +13720,12 @@ class SessionReplayPlugin {
13657
13720
  * Flush buffered events to backend
13658
13721
  */
13659
13722
  async flush() {
13660
- console.log(`[SessionReplay] flush() called. Session: ${!!this.session}, Event buffer: ${this.eventBuffer.length}, Telemetry buffer: ${this.telemetryBuffer.length}`);
13661
13723
  if (!this.session) {
13662
- console.warn('[SessionReplay] flush() skipped - no session yet!');
13663
13724
  return;
13664
13725
  }
13665
13726
  if (this.eventBuffer.length === 0 && this.telemetryBuffer.length === 0) {
13666
- console.log('[SessionReplay] flush() skipped - buffers empty');
13667
13727
  return;
13668
13728
  }
13669
- console.log(`[SessionReplay] Flushing ${this.eventBuffer.length} events to backend...`);
13670
13729
  const eventsToSend = [...this.eventBuffer];
13671
13730
  const telemetryToSend = [...this.telemetryBuffer];
13672
13731
  // Clear buffers
@@ -13786,6 +13845,7 @@ class CRMClient {
13786
13845
  this._events = new EventsResource(this.http);
13787
13846
  this._contacts = new ContactsResource(this.http);
13788
13847
  this._deals = new DealsResource(this.http);
13848
+ this._experiments = new ExperimentsResource(this.http);
13789
13849
  // Initialize browser plugins if in browser
13790
13850
  if (isBrowser) {
13791
13851
  this.initBrowserPlugins();
@@ -13809,6 +13869,12 @@ class CRMClient {
13809
13869
  get deals() {
13810
13870
  return this._deals;
13811
13871
  }
13872
+ /**
13873
+ * Experiments resource for A/B testing and feature flags
13874
+ */
13875
+ get experiments() {
13876
+ return this._experiments;
13877
+ }
13812
13878
  /**
13813
13879
  * Visitor ID plugin (browser only)
13814
13880
  */
@@ -13872,7 +13938,7 @@ class CRMClient {
13872
13938
  */
13873
13939
  // Main client
13874
13940
  // Version
13875
- const VERSION = '1.1.0';
13941
+ const VERSION = '1.2.5';
13876
13942
 
13877
13943
  exports.AuthenticationError = AuthenticationError;
13878
13944
  exports.AutoPageViewPlugin = AutoPageViewPlugin;
@@ -13883,6 +13949,7 @@ exports.ContactsResource = ContactsResource;
13883
13949
  exports.DealsResource = DealsResource;
13884
13950
  exports.DeviceInfoPlugin = DeviceInfoPlugin;
13885
13951
  exports.EventsResource = EventsResource;
13952
+ exports.ExperimentsResource = ExperimentsResource;
13886
13953
  exports.NetworkError = NetworkError;
13887
13954
  exports.RateLimitError = RateLimitError;
13888
13955
  exports.ResourceNotFoundError = ResourceNotFoundError;