@rudderstack/analytics-js 3.22.0 → 3.22.1-beta.pr.2309.2d82a3e

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.
@@ -12,6 +12,7 @@ interface ILogger {
12
12
  setMinLogLevel(logLevel: LogLevel): void;
13
13
  }
14
14
  type LogLevel = 'LOG' | 'INFO' | 'DEBUG' | 'WARN' | 'ERROR' | 'NONE';
15
+ type RSALogger = Pick<ILogger, 'log' | 'info' | 'debug' | 'warn' | 'error' | 'setMinLogLevel'>;
15
16
 
16
17
  type LoggerProvider = Record<Exclude<Lowercase<LogLevel>, Lowercase<'NONE'>>, (...data: any[]) => void>;
17
18
 
@@ -60,6 +61,7 @@ type IntegrationOpts = {
60
61
  [index: string]: DestinationIntgConfig;
61
62
  };
62
63
 
64
+ type Traits = Nullable<ApiObject>;
63
65
  type ApiCallback = (data?: any) => void;
64
66
  /**
65
67
  * Represents the options parameter in the APIs
@@ -159,6 +161,11 @@ type CookieSameSite = 'Strict' | 'Lax' | 'None';
159
161
  type OneTrustCookieCategory = {
160
162
  oneTrustCookieCategory: string;
161
163
  };
164
+ type ConsentManagement = {
165
+ deniedConsentIds: Consents;
166
+ allowedConsentIds: Consents;
167
+ provider: ConsentManagementProvider;
168
+ };
162
169
  type ConsentManagementMetadata = {
163
170
  providers: ConsentManagementProviderMetadata[];
164
171
  };
@@ -419,6 +426,137 @@ type IdentifyTraits = {
419
426
  [index: string]: string | number | boolean | ApiObject | null | Date | (string | number | boolean | null | Date | ApiObject)[] | undefined;
420
427
  };
421
428
 
429
+ type AppInfo = {
430
+ readonly name: string;
431
+ readonly version: string;
432
+ readonly namespace: string;
433
+ readonly installType: string;
434
+ };
435
+ type LibraryInfo = {
436
+ readonly name: string;
437
+ readonly version: string;
438
+ readonly snippetVersion?: string;
439
+ };
440
+ type OSInfo = {
441
+ readonly name: string;
442
+ readonly version: string;
443
+ };
444
+ type ScreenInfo = {
445
+ readonly density: number;
446
+ readonly width: number;
447
+ readonly height: number;
448
+ readonly innerWidth: number;
449
+ readonly innerHeight: number;
450
+ };
451
+ type UTMParameters = Record<string, string>;
452
+
453
+ type PageLifecycle = {
454
+ pageViewId: string;
455
+ };
456
+ type AutoTrack = {
457
+ page: PageLifecycle;
458
+ };
459
+ type RudderContext = {
460
+ [index: string]: string | number | boolean | ApiObject | UADataValues | Nullable<string> | (string | number | boolean | ApiObject)[] | undefined;
461
+ traits?: Nullable<ApiObject>;
462
+ sessionId?: number;
463
+ sessionStart?: boolean;
464
+ consentManagement?: ConsentManagement;
465
+ 'ua-ch'?: UADataValues;
466
+ app: AppInfo;
467
+ library: LibraryInfo;
468
+ userAgent: Nullable<string>;
469
+ os: OSInfo;
470
+ locale: Nullable<string>;
471
+ screen: ScreenInfo;
472
+ campaign?: UTMParameters;
473
+ trulyAnonymousTracking?: boolean;
474
+ timezone: string;
475
+ autoTrack?: AutoTrack;
476
+ };
477
+ type RudderEvent = {
478
+ type: RudderEventType;
479
+ channel: string;
480
+ anonymousId: string;
481
+ context: RudderContext;
482
+ originalTimestamp: string;
483
+ integrations: IntegrationOpts;
484
+ messageId: string;
485
+ event: Nullable<string>;
486
+ previousId?: string;
487
+ userId?: Nullable<string>;
488
+ sentAt?: string;
489
+ properties?: Nullable<ApiObject>;
490
+ name?: Nullable<string>;
491
+ category?: Nullable<string>;
492
+ traits?: Traits;
493
+ groupId?: Nullable<string>;
494
+ };
495
+ type RSAEvent = {
496
+ message: RudderEvent;
497
+ };
498
+
499
+ type DestinationConnectionMode = 'hybrid' | 'cloud' | 'device';
500
+ type DestinationEvent = {
501
+ eventName: string;
502
+ };
503
+ type ConsentsConfig = {
504
+ consent: string;
505
+ };
506
+ type ConsentManagementProviderConfig = {
507
+ provider: ConsentManagementProvider;
508
+ consents: ConsentsConfig[];
509
+ resolutionStrategy: string | undefined;
510
+ };
511
+ /**
512
+ * The common configuration properties for all device
513
+ * and hybrid mode supported destinations.
514
+ */
515
+ type BaseDestinationConfig = {
516
+ blacklistedEvents: DestinationEvent[];
517
+ whitelistedEvents: DestinationEvent[];
518
+ eventFilteringOption: EventFilteringOption;
519
+ consentManagement: ConsentManagementProviderConfig[];
520
+ connectionMode: DestinationConnectionMode;
521
+ };
522
+ type DestinationConfig = BaseDestinationConfig & {
523
+ iubendaConsentPurposes?: IubendaConsentPurpose[];
524
+ oneTrustCookieCategories?: OneTrustCookieCategory[];
525
+ ketchConsentPurposes?: KetchConsentPurpose[];
526
+ clickEventConversions?: Conversion[];
527
+ pageLoadConversions?: Conversion[];
528
+ conversionID?: string;
529
+ conversionLinker?: boolean;
530
+ disableAdPersonalization?: boolean;
531
+ dynamicRemarketing?: boolean;
532
+ sendPageView?: boolean;
533
+ defaultPageConversion?: string;
534
+ enableConversionEventsFiltering?: boolean;
535
+ trackConversions?: boolean;
536
+ trackDynamicRemarketing?: boolean;
537
+ tagID?: string;
538
+ advertiserId?: string;
539
+ partnerId?: string;
540
+ measurementId?: string;
541
+ capturePageView?: string;
542
+ useNativeSDKToSend?: boolean;
543
+ extendPageViewParams?: boolean;
544
+ eventMappingFromConfig?: EventMapping[];
545
+ appKey?: string;
546
+ dataCenter?: string;
547
+ enableBrazeLogging?: boolean;
548
+ enableNestedArrayOperations?: boolean;
549
+ enableSubscriptionGroupInGroupCall?: boolean;
550
+ supportDedup?: boolean;
551
+ trackAnonymousUser?: boolean;
552
+ serverUrl?: string;
553
+ containerID?: string;
554
+ fs_debug_mode?: boolean;
555
+ fs_org?: boolean;
556
+ siteID?: string;
557
+ [key: string]: any;
558
+ };
559
+
422
560
  type AnalyticsIdentifyMethod = {
423
561
  (userId: string, traits?: Nullable<IdentifyTraits>, options?: Nullable<ApiOptions>, callback?: ApiCallback): void;
424
562
  (userId: string, traits?: Nullable<IdentifyTraits>, callback?: ApiCallback): void;
@@ -556,7 +694,82 @@ interface IRudderAnalytics<T = any> {
556
694
  * @param options Consent API options
557
695
  */
558
696
  consent(options?: ConsentOptions): void;
697
+ /**
698
+ * To add a custom integration for a custom destination
699
+ * @param destinationId The ID of the custom destination from the RudderStack dashboard
700
+ * @param integration The custom integration object
701
+ */
702
+ addCustomIntegration(destinationId: string, integration: RSACustomIntegration): void;
559
703
  }
704
+ type RSAnalytics = Pick<IRudderAnalytics, 'track' | 'page' | 'identify' | 'group' | 'alias' | 'getAnonymousId' | 'getUserId' | 'getUserTraits' | 'getGroupId' | 'getGroupTraits' | 'getSessionId'>;
705
+ /**
706
+ * Type for the custom destination configuration object
707
+ * For now, it is the same as the base destination config
708
+ * but in the future, it can be extended to include more properties
709
+ */
710
+ type CustomDestinationConfig = BaseDestinationConfig & {};
711
+ /**
712
+ * Type for the custom integration to be used in addCustomIntegration API
713
+ * Defines the contract that all custom integrations must implement
714
+ */
715
+ type RSACustomIntegration = {
716
+ /**
717
+ * Initialize the integration
718
+ * @param destinationConfig - The custom destination configuration object
719
+ * @param analytics - The RudderStack analytics instance
720
+ * @param logger - The logger instance for this integration
721
+ * @optional
722
+ */
723
+ init?: (destinationConfig: CustomDestinationConfig, analytics: RSAnalytics, logger: RSALogger) => void;
724
+ /**
725
+ * Check if the integration is ready to process events
726
+ * @param analytics - The RudderStack analytics instance
727
+ * @param logger - The logger instance for this integration
728
+ * @returns boolean indicating whether the integration is ready
729
+ * @required
730
+ */
731
+ isReady: (analytics: RSAnalytics, logger: RSALogger) => boolean;
732
+ /**
733
+ * Process track events
734
+ * @param analytics - The RudderStack analytics instance
735
+ * @param logger - The logger instance for this integration
736
+ * @param event - The track event payload to process
737
+ * @optional
738
+ */
739
+ track?: (analytics: RSAnalytics, logger: RSALogger, event: RSAEvent) => void;
740
+ /**
741
+ * Process page events
742
+ * @param analytics - The RudderStack analytics instance
743
+ * @param logger - The logger instance for this integration
744
+ * @param event - The page event payload to process
745
+ * @optional
746
+ */
747
+ page?: (analytics: RSAnalytics, logger: RSALogger, event: RSAEvent) => void;
748
+ /**
749
+ * Process identify events
750
+ * @param analytics - The RudderStack analytics instance
751
+ * @param logger - The logger instance for this integration
752
+ * @param event - The identify event payload to process
753
+ * @optional
754
+ */
755
+ identify?: (analytics: RSAnalytics, logger: RSALogger, event: RSAEvent) => void;
756
+ /**
757
+ * Process group events
758
+ * @param analytics - The RudderStack analytics instance
759
+ * @param logger - The logger instance for this integration
760
+ * @param event - The group event payload to process
761
+ * @optional
762
+ */
763
+ group?: (analytics: RSAnalytics, logger: RSALogger, event: RSAEvent) => void;
764
+ /**
765
+ * Process alias events
766
+ * @param analytics - The RudderStack analytics instance
767
+ * @param logger - The logger instance for this integration
768
+ * @param event - The alias event payload to process
769
+ * @optional
770
+ */
771
+ alias?: (analytics: RSAnalytics, logger: RSALogger, event: RSAEvent) => void;
772
+ };
560
773
 
561
774
  type SDKError = unknown | Error | ErrorEvent | Event | PromiseRejectionEvent;
562
775
  type ErrorInfo = {
@@ -825,61 +1038,6 @@ interface IUserSessionManager {
825
1038
  setAuthToken(token: Nullable<string>): void;
826
1039
  }
827
1040
 
828
- type DestinationConnectionMode = 'hybrid' | 'cloud' | 'device';
829
- type DestinationEvent = {
830
- eventName: string;
831
- };
832
- type ConsentsConfig = {
833
- consent: string;
834
- };
835
- type ConsentManagementProviderConfig = {
836
- provider: ConsentManagementProvider;
837
- consents: ConsentsConfig[];
838
- resolutionStrategy: string | undefined;
839
- };
840
- type DestinationConfig = {
841
- blacklistedEvents: DestinationEvent[];
842
- whitelistedEvents: DestinationEvent[];
843
- iubendaConsentPurposes?: IubendaConsentPurpose[];
844
- oneTrustCookieCategories?: OneTrustCookieCategory[];
845
- ketchConsentPurposes?: KetchConsentPurpose[];
846
- consentManagement?: ConsentManagementProviderConfig[];
847
- eventFilteringOption: EventFilteringOption;
848
- clickEventConversions?: Conversion[];
849
- pageLoadConversions?: Conversion[];
850
- conversionID?: string;
851
- conversionLinker?: boolean;
852
- disableAdPersonalization?: boolean;
853
- dynamicRemarketing?: boolean;
854
- sendPageView?: boolean;
855
- defaultPageConversion?: string;
856
- enableConversionEventsFiltering?: boolean;
857
- trackConversions?: boolean;
858
- trackDynamicRemarketing?: boolean;
859
- tagID?: string;
860
- advertiserId?: string;
861
- partnerId?: string;
862
- measurementId?: string;
863
- capturePageView?: string;
864
- useNativeSDKToSend?: boolean;
865
- connectionMode?: DestinationConnectionMode;
866
- extendPageViewParams?: boolean;
867
- eventMappingFromConfig?: EventMapping[];
868
- appKey?: string;
869
- dataCenter?: string;
870
- enableBrazeLogging?: boolean;
871
- enableNestedArrayOperations?: boolean;
872
- enableSubscriptionGroupInGroupCall?: boolean;
873
- supportDedup?: boolean;
874
- trackAnonymousUser?: boolean;
875
- serverUrl?: string;
876
- containerID?: string;
877
- fs_debug_mode?: boolean;
878
- fs_org?: boolean;
879
- siteID?: string;
880
- [key: string]: any;
881
- };
882
-
883
1041
  type StatsCollection = {
884
1042
  errors: {
885
1043
  enabled: boolean;
@@ -1132,6 +1290,13 @@ interface IAnalytics {
1132
1290
  * To set auth token
1133
1291
  */
1134
1292
  setAuthToken(token: string): void;
1293
+ /**
1294
+ * Add a custom integration for a custom destination
1295
+ * @param destinationId - Unique ID for the custom destination from the RudderStack dashboard
1296
+ * @param integration - The custom integration instance implementing RSACustomIntegration
1297
+ * @param isBufferedInvocation - Internal flag to indicate if this is a buffered call
1298
+ */
1299
+ addCustomIntegration(destinationId: string, integration: RSACustomIntegration, isBufferedInvocation?: boolean): void;
1135
1300
  }
1136
1301
 
1137
1302
  declare class RudderAnalytics implements IRudderAnalytics<IAnalytics> {
@@ -1140,6 +1305,12 @@ declare class RudderAnalytics implements IRudderAnalytics<IAnalytics> {
1140
1305
  defaultAnalyticsKey: string;
1141
1306
  logger: Logger;
1142
1307
  constructor();
1308
+ /**
1309
+ * Create an instance of the current instance that can be used
1310
+ * to call a subset of methods of the current instance.
1311
+ * It is typically used to expose the analytics instance to the integrations (standard and custom)
1312
+ */
1313
+ createSafeAnalyticsInstance(): void;
1143
1314
  static initializeGlobalResources(): void;
1144
1315
  /**
1145
1316
  * Set instance to use if no specific writeKey is provided in methods
@@ -1234,6 +1405,7 @@ declare class RudderAnalytics implements IRudderAnalytics<IAnalytics> {
1234
1405
  getSessionId(): Nullable<number> | undefined;
1235
1406
  setAuthToken(token: string): void;
1236
1407
  consent(options?: ConsentOptions): void;
1408
+ addCustomIntegration(destinationId: string, integration: RSACustomIntegration): void;
1237
1409
  }
1238
1410
  //# sourceMappingURL=RudderAnalytics.d.ts.map
1239
1411
 
@@ -1245,4 +1417,4 @@ declare global {
1245
1417
  //# sourceMappingURL=index.d.ts.map
1246
1418
 
1247
1419
  export { RudderAnalytics };
1248
- export type { AnonymousIdOptions, ApiCallback, ApiObject, ApiOptions, BeaconQueueOpts, ConsentOptions, CookieSameSite, DestinationsQueueOpts, IdentifyTraits, IntegrationOpts, LoadOptions, LogLevel, PluginName, PreloadedEventCall, QueueOpts, RudderAnalyticsPreloader, SessionOpts, UaChTrackLevel };
1420
+ export type { AnonymousIdOptions, ApiCallback, ApiObject, ApiOptions, BeaconQueueOpts, ConsentOptions, CookieSameSite, CustomDestinationConfig, DestinationsQueueOpts, IdentifyTraits, IntegrationOpts, LoadOptions, LogLevel, PluginName, PreloadedEventCall, QueueOpts, RSACustomIntegration, RSAEvent, RSALogger, RSAnalytics, RudderAnalyticsPreloader, SessionOpts, UaChTrackLevel };