@rudderstack/analytics-js 3.31.7 → 3.32.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [3.32.0](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js@3.31.8...@rudderstack/analytics-js@3.32.0) (2026-08-24)
6
+
7
+ ### Dependency Updates
8
+
9
+ * `@rudderstack/analytics-js-cookies` updated to version `0.5.13`
10
+ * `@rudderstack/analytics-js-common` updated to version `3.28.4`
11
+ * `@rudderstack/analytics-js-plugins` updated to version `3.15.13`
12
+
13
+ ### Features
14
+
15
+ * sdk-5054 add state-backed custom context store ([#3129](https://github.com/rudderlabs/rudder-sdk-js/issues/3129)) ([b5ef16f](https://github.com/rudderlabs/rudder-sdk-js/commit/b5ef16fbc71bbdd21fbbdeb38ae98133cf7a7b4b))
16
+ * sdk-5055 seed load-time custom context ([#3132](https://github.com/rudderlabs/rudder-sdk-js/issues/3132)) ([fdda1e0](https://github.com/rudderlabs/rudder-sdk-js/commit/fdda1e046bbdb108f022f550e991a3b8e6c5e6e2))
17
+ * sdk-5056 enrich events with custom context ([#3133](https://github.com/rudderlabs/rudder-sdk-js/issues/3133)) ([fafbd52](https://github.com/rudderlabs/rudder-sdk-js/commit/fafbd5265fb61bdae844f4df1307fd8c11b9d6f1))
18
+ * sdk-5057 add custom context validation foundation ([#3128](https://github.com/rudderlabs/rudder-sdk-js/issues/3128)) ([a197998](https://github.com/rudderlabs/rudder-sdk-js/commit/a19799864f80357f6e67d9e8b0a0d3d065d483aa))
19
+ * sdk-5058 expose custom context public api ([#3131](https://github.com/rudderlabs/rudder-sdk-js/issues/3131)) ([08686ce](https://github.com/rudderlabs/rudder-sdk-js/commit/08686ce687069c5f344c15653691dc35879bc63a))
20
+
21
+ ## [3.31.8](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js@3.31.7...@rudderstack/analytics-js@3.31.8) (2026-08-19)
22
+
23
+ ### Dependency Updates
24
+
25
+ * `@rudderstack/analytics-js-plugins` updated to version `3.15.14`
26
+
5
27
  ## [3.31.7](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js@3.31.6...@rudderstack/analytics-js@3.31.7) (2026-08-13)
6
28
 
7
29
  ### Dependency Updates
@@ -1,3 +1,5 @@
1
+ import { Signal } from '@preact/signals-core';
2
+
1
3
  type LoggerProvider$1 = Record<Exclude<Lowercase<LogLevel>, Lowercase<'NONE'>>, (...data: any[]) => void>;
2
4
  interface ILogger {
3
5
  minLogLevel: number;
@@ -202,6 +204,15 @@ type ConsentOptions = {
202
204
  trackConsent?: boolean;
203
205
  };
204
206
 
207
+ type CustomContextValue = string | number | boolean | Date | CustomContext | CustomContextValue[];
208
+ interface CustomContext {
209
+ [key: string]: CustomContextValue;
210
+ }
211
+ type InputCustomContextValue = string | number | boolean | Date | null | undefined | InputCustomContext | InputCustomContextValue[];
212
+ interface InputCustomContext {
213
+ [key: string]: InputCustomContextValue;
214
+ }
215
+
205
216
  type UaChTrackLevel = 'none' | 'default' | 'full';
206
217
  /**
207
218
  * Represents the options parameter for anonymousId
@@ -305,6 +316,7 @@ type SourceConfigurationOverride = {
305
316
  * Represents the options parameter in the load API
306
317
  */
307
318
  type LoadOptions = {
319
+ context?: InputCustomContext;
308
320
  logLevel?: LogLevel;
309
321
  integrations?: IntegrationOpts;
310
322
  configUrl?: string;
@@ -456,6 +468,38 @@ type ScreenInfo = {
456
468
  };
457
469
  type UTMParameters = Record<string, string>;
458
470
 
471
+ type PageCallOptions = {
472
+ category?: string;
473
+ name?: string;
474
+ properties?: Nullable<ApiObject>;
475
+ options?: Nullable<ApiOptions>;
476
+ callback?: ApiCallback;
477
+ };
478
+ type TrackCallOptions = {
479
+ name: string;
480
+ properties?: Nullable<ApiObject>;
481
+ options?: Nullable<ApiOptions>;
482
+ callback?: ApiCallback;
483
+ };
484
+ type IdentifyCallOptions = {
485
+ userId?: Nullable<string>;
486
+ traits?: Nullable<IdentifyTraits>;
487
+ options?: Nullable<ApiOptions>;
488
+ callback?: ApiCallback;
489
+ };
490
+ type AliasCallOptions = {
491
+ to: string;
492
+ from?: string;
493
+ options?: Nullable<ApiOptions>;
494
+ callback?: ApiCallback;
495
+ };
496
+ type GroupCallOptions = {
497
+ groupId?: Nullable<string>;
498
+ traits?: Nullable<ApiObject>;
499
+ options?: Nullable<ApiOptions>;
500
+ callback?: ApiCallback;
501
+ };
502
+
459
503
  type PageLifecycle = {
460
504
  pageViewId: string;
461
505
  };
@@ -682,6 +726,18 @@ interface IRudderAnalytics<T = any> {
682
726
  * To get group traits set in the SDK
683
727
  */
684
728
  getGroupTraits(): Nullable<ApiObject> | undefined;
729
+ /**
730
+ * Merge fields into the in-memory custom context for subsequent event calls.
731
+ */
732
+ setCustomContext(context: InputCustomContext): void;
733
+ /**
734
+ * Get a defensive snapshot of the current in-memory custom context.
735
+ */
736
+ getCustomContext(): CustomContext;
737
+ /**
738
+ * Clear the complete in-memory custom context.
739
+ */
740
+ clearCustomContext(): void;
685
741
  /**
686
742
  * To manually start user session in the SDK
687
743
  */
@@ -717,7 +773,7 @@ type RSAnalytics = Pick<IRudderAnalytics, 'track' | 'page' | 'identify' | 'group
717
773
  * For now, it is the same as the base destination config
718
774
  * but in the future, it can be extended to include more properties
719
775
  */
720
- type CustomDestinationConfig = BaseDestinationConfig & {};
776
+ type CustomDestinationConfig = BaseDestinationConfig;
721
777
  /**
722
778
  * Type for the custom integration to be used in addCustomIntegration API
723
779
  * Defines the contract that all custom integrations must implement
@@ -921,38 +977,6 @@ interface IInMemoryStorageOptions {
921
977
  enabled?: boolean;
922
978
  }
923
979
 
924
- type PageCallOptions = {
925
- category?: string;
926
- name?: string;
927
- properties?: Nullable<ApiObject>;
928
- options?: Nullable<ApiOptions>;
929
- callback?: ApiCallback;
930
- };
931
- type TrackCallOptions = {
932
- name: string;
933
- properties?: Nullable<ApiObject>;
934
- options?: Nullable<ApiOptions>;
935
- callback?: ApiCallback;
936
- };
937
- type IdentifyCallOptions = {
938
- userId?: Nullable<string>;
939
- traits?: Nullable<IdentifyTraits>;
940
- options?: Nullable<ApiOptions>;
941
- callback?: ApiCallback;
942
- };
943
- type AliasCallOptions = {
944
- to: string;
945
- from?: string;
946
- options?: Nullable<ApiOptions>;
947
- callback?: ApiCallback;
948
- };
949
- type GroupCallOptions = {
950
- groupId?: Nullable<string>;
951
- traits?: Nullable<ApiObject>;
952
- options?: Nullable<ApiOptions>;
953
- callback?: ApiCallback;
954
- };
955
-
956
980
  /**
957
981
  * A buffer queue to serve as a store for any type of data
958
982
  */
@@ -1130,7 +1154,7 @@ interface IConfigManager {
1130
1154
 
1131
1155
  interface IEventManager {
1132
1156
  init(): void;
1133
- addEvent(event: APIEvent): void;
1157
+ addEvent(event: APIEvent, customContext: CustomContext): void;
1134
1158
  resume(): void;
1135
1159
  }
1136
1160
 
@@ -1151,6 +1175,17 @@ type RudderAnalyticsPreloader = {
1151
1175
  [index: string]: (...args: any[]) => any;
1152
1176
  };
1153
1177
 
1178
+ type CustomContextState = Signal<CustomContext>;
1179
+
1180
+ declare class CustomContextStore {
1181
+ private readonly state;
1182
+ private readonly logger;
1183
+ constructor(state: CustomContextState, logger: ILogger);
1184
+ set(context: unknown): void;
1185
+ get(): CustomContext;
1186
+ clear(): void;
1187
+ }
1188
+
1154
1189
  interface IAnalytics {
1155
1190
  preloadBuffer: BufferQueue<PreloadedEventCall>;
1156
1191
  initialized: boolean;
@@ -1165,6 +1200,7 @@ interface IAnalytics {
1165
1200
  userSessionManager?: IUserSessionManager;
1166
1201
  pluginsManager?: IPluginsManager;
1167
1202
  clientDataStore?: Store;
1203
+ customContextStore: CustomContextStore;
1168
1204
  /**
1169
1205
  * Start application lifecycle if not already started
1170
1206
  */
@@ -1278,6 +1314,18 @@ interface IAnalytics {
1278
1314
  * To get group traits set in the SDK
1279
1315
  */
1280
1316
  getGroupTraits(): Nullable<ApiObject> | undefined;
1317
+ /**
1318
+ * Merge fields into the current custom context
1319
+ */
1320
+ setCustomContext(context: InputCustomContext): void;
1321
+ /**
1322
+ * Get a defensive snapshot of the current custom context
1323
+ */
1324
+ getCustomContext(): CustomContext;
1325
+ /**
1326
+ * Clear the current custom context
1327
+ */
1328
+ clearCustomContext(): void;
1281
1329
  /**
1282
1330
  * To manually start user session in the SDK
1283
1331
  */
@@ -1439,6 +1487,9 @@ declare class RudderAnalytics implements IRudderAnalytics<IAnalytics> {
1439
1487
  getUserTraits(): Nullable<ApiObject> | undefined;
1440
1488
  getGroupId(): Nullable<string> | undefined;
1441
1489
  getGroupTraits(): Nullable<ApiObject> | undefined;
1490
+ setCustomContext(context: InputCustomContext): void;
1491
+ getCustomContext(): CustomContext;
1492
+ clearCustomContext(): void;
1442
1493
  startSession(sessionId?: number): void;
1443
1494
  endSession(): void;
1444
1495
  getSessionId(): Nullable<number> | undefined;
@@ -1454,4 +1505,4 @@ declare global {
1454
1505
  }
1455
1506
 
1456
1507
  export { RudderAnalytics };
1457
- 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 };
1508
+ export type { AnonymousIdOptions, ApiCallback, ApiObject, ApiOptions, BeaconQueueOpts, ConsentOptions, CookieSameSite, CustomContext, CustomContextValue, CustomDestinationConfig, DestinationsQueueOpts, IdentifyTraits, InputCustomContext, InputCustomContextValue, IntegrationOpts, LoadOptions, LogLevel, PluginName, PreloadedEventCall, QueueOpts, RSACustomIntegration, RSAEvent, RSALogger, RSAnalytics, RudderAnalyticsPreloader, SessionOpts, UaChTrackLevel };
@@ -1,3 +1,5 @@
1
+ import { Signal } from '@preact/signals-core';
2
+
1
3
  type LoggerProvider$1 = Record<Exclude<Lowercase<LogLevel>, Lowercase<'NONE'>>, (...data: any[]) => void>;
2
4
  interface ILogger {
3
5
  minLogLevel: number;
@@ -202,6 +204,15 @@ type ConsentOptions = {
202
204
  trackConsent?: boolean;
203
205
  };
204
206
 
207
+ type CustomContextValue = string | number | boolean | Date | CustomContext | CustomContextValue[];
208
+ interface CustomContext {
209
+ [key: string]: CustomContextValue;
210
+ }
211
+ type InputCustomContextValue = string | number | boolean | Date | null | undefined | InputCustomContext | InputCustomContextValue[];
212
+ interface InputCustomContext {
213
+ [key: string]: InputCustomContextValue;
214
+ }
215
+
205
216
  type UaChTrackLevel = 'none' | 'default' | 'full';
206
217
  /**
207
218
  * Represents the options parameter for anonymousId
@@ -305,6 +316,7 @@ type SourceConfigurationOverride = {
305
316
  * Represents the options parameter in the load API
306
317
  */
307
318
  type LoadOptions = {
319
+ context?: InputCustomContext;
308
320
  logLevel?: LogLevel;
309
321
  integrations?: IntegrationOpts;
310
322
  configUrl?: string;
@@ -456,6 +468,38 @@ type ScreenInfo = {
456
468
  };
457
469
  type UTMParameters = Record<string, string>;
458
470
 
471
+ type PageCallOptions = {
472
+ category?: string;
473
+ name?: string;
474
+ properties?: Nullable<ApiObject>;
475
+ options?: Nullable<ApiOptions>;
476
+ callback?: ApiCallback;
477
+ };
478
+ type TrackCallOptions = {
479
+ name: string;
480
+ properties?: Nullable<ApiObject>;
481
+ options?: Nullable<ApiOptions>;
482
+ callback?: ApiCallback;
483
+ };
484
+ type IdentifyCallOptions = {
485
+ userId?: Nullable<string>;
486
+ traits?: Nullable<IdentifyTraits>;
487
+ options?: Nullable<ApiOptions>;
488
+ callback?: ApiCallback;
489
+ };
490
+ type AliasCallOptions = {
491
+ to: string;
492
+ from?: string;
493
+ options?: Nullable<ApiOptions>;
494
+ callback?: ApiCallback;
495
+ };
496
+ type GroupCallOptions = {
497
+ groupId?: Nullable<string>;
498
+ traits?: Nullable<ApiObject>;
499
+ options?: Nullable<ApiOptions>;
500
+ callback?: ApiCallback;
501
+ };
502
+
459
503
  type PageLifecycle = {
460
504
  pageViewId: string;
461
505
  };
@@ -682,6 +726,18 @@ interface IRudderAnalytics<T = any> {
682
726
  * To get group traits set in the SDK
683
727
  */
684
728
  getGroupTraits(): Nullable<ApiObject> | undefined;
729
+ /**
730
+ * Merge fields into the in-memory custom context for subsequent event calls.
731
+ */
732
+ setCustomContext(context: InputCustomContext): void;
733
+ /**
734
+ * Get a defensive snapshot of the current in-memory custom context.
735
+ */
736
+ getCustomContext(): CustomContext;
737
+ /**
738
+ * Clear the complete in-memory custom context.
739
+ */
740
+ clearCustomContext(): void;
685
741
  /**
686
742
  * To manually start user session in the SDK
687
743
  */
@@ -717,7 +773,7 @@ type RSAnalytics = Pick<IRudderAnalytics, 'track' | 'page' | 'identify' | 'group
717
773
  * For now, it is the same as the base destination config
718
774
  * but in the future, it can be extended to include more properties
719
775
  */
720
- type CustomDestinationConfig = BaseDestinationConfig & {};
776
+ type CustomDestinationConfig = BaseDestinationConfig;
721
777
  /**
722
778
  * Type for the custom integration to be used in addCustomIntegration API
723
779
  * Defines the contract that all custom integrations must implement
@@ -921,38 +977,6 @@ interface IInMemoryStorageOptions {
921
977
  enabled?: boolean;
922
978
  }
923
979
 
924
- type PageCallOptions = {
925
- category?: string;
926
- name?: string;
927
- properties?: Nullable<ApiObject>;
928
- options?: Nullable<ApiOptions>;
929
- callback?: ApiCallback;
930
- };
931
- type TrackCallOptions = {
932
- name: string;
933
- properties?: Nullable<ApiObject>;
934
- options?: Nullable<ApiOptions>;
935
- callback?: ApiCallback;
936
- };
937
- type IdentifyCallOptions = {
938
- userId?: Nullable<string>;
939
- traits?: Nullable<IdentifyTraits>;
940
- options?: Nullable<ApiOptions>;
941
- callback?: ApiCallback;
942
- };
943
- type AliasCallOptions = {
944
- to: string;
945
- from?: string;
946
- options?: Nullable<ApiOptions>;
947
- callback?: ApiCallback;
948
- };
949
- type GroupCallOptions = {
950
- groupId?: Nullable<string>;
951
- traits?: Nullable<ApiObject>;
952
- options?: Nullable<ApiOptions>;
953
- callback?: ApiCallback;
954
- };
955
-
956
980
  /**
957
981
  * A buffer queue to serve as a store for any type of data
958
982
  */
@@ -1130,7 +1154,7 @@ interface IConfigManager {
1130
1154
 
1131
1155
  interface IEventManager {
1132
1156
  init(): void;
1133
- addEvent(event: APIEvent): void;
1157
+ addEvent(event: APIEvent, customContext: CustomContext): void;
1134
1158
  resume(): void;
1135
1159
  }
1136
1160
 
@@ -1151,6 +1175,17 @@ type RudderAnalyticsPreloader = {
1151
1175
  [index: string]: (...args: any[]) => any;
1152
1176
  };
1153
1177
 
1178
+ type CustomContextState = Signal<CustomContext>;
1179
+
1180
+ declare class CustomContextStore {
1181
+ private readonly state;
1182
+ private readonly logger;
1183
+ constructor(state: CustomContextState, logger: ILogger);
1184
+ set(context: unknown): void;
1185
+ get(): CustomContext;
1186
+ clear(): void;
1187
+ }
1188
+
1154
1189
  interface IAnalytics {
1155
1190
  preloadBuffer: BufferQueue<PreloadedEventCall>;
1156
1191
  initialized: boolean;
@@ -1165,6 +1200,7 @@ interface IAnalytics {
1165
1200
  userSessionManager?: IUserSessionManager;
1166
1201
  pluginsManager?: IPluginsManager;
1167
1202
  clientDataStore?: Store;
1203
+ customContextStore: CustomContextStore;
1168
1204
  /**
1169
1205
  * Start application lifecycle if not already started
1170
1206
  */
@@ -1278,6 +1314,18 @@ interface IAnalytics {
1278
1314
  * To get group traits set in the SDK
1279
1315
  */
1280
1316
  getGroupTraits(): Nullable<ApiObject> | undefined;
1317
+ /**
1318
+ * Merge fields into the current custom context
1319
+ */
1320
+ setCustomContext(context: InputCustomContext): void;
1321
+ /**
1322
+ * Get a defensive snapshot of the current custom context
1323
+ */
1324
+ getCustomContext(): CustomContext;
1325
+ /**
1326
+ * Clear the current custom context
1327
+ */
1328
+ clearCustomContext(): void;
1281
1329
  /**
1282
1330
  * To manually start user session in the SDK
1283
1331
  */
@@ -1439,6 +1487,9 @@ declare class RudderAnalytics implements IRudderAnalytics<IAnalytics> {
1439
1487
  getUserTraits(): Nullable<ApiObject> | undefined;
1440
1488
  getGroupId(): Nullable<string> | undefined;
1441
1489
  getGroupTraits(): Nullable<ApiObject> | undefined;
1490
+ setCustomContext(context: InputCustomContext): void;
1491
+ getCustomContext(): CustomContext;
1492
+ clearCustomContext(): void;
1442
1493
  startSession(sessionId?: number): void;
1443
1494
  endSession(): void;
1444
1495
  getSessionId(): Nullable<number> | undefined;
@@ -1454,4 +1505,4 @@ declare global {
1454
1505
  }
1455
1506
 
1456
1507
  export { RudderAnalytics };
1457
- 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 };
1508
+ export type { AnonymousIdOptions, ApiCallback, ApiObject, ApiOptions, BeaconQueueOpts, ConsentOptions, CookieSameSite, CustomContext, CustomContextValue, CustomDestinationConfig, DestinationsQueueOpts, IdentifyTraits, InputCustomContext, InputCustomContextValue, IntegrationOpts, LoadOptions, LogLevel, PluginName, PreloadedEventCall, QueueOpts, RSACustomIntegration, RSAEvent, RSALogger, RSAnalytics, RudderAnalyticsPreloader, SessionOpts, UaChTrackLevel };