@amplitude/analytics-react-native 1.9.0 → 1.10.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.
Files changed (42) hide show
  1. package/lib/commonjs/config/joined-config.js +5 -4
  2. package/lib/commonjs/config/joined-config.js.map +1 -1
  3. package/lib/commonjs/config.js +16 -3
  4. package/lib/commonjs/config.js.map +1 -1
  5. package/lib/commonjs/diagnostics/diagnostics-storage.js +17 -20
  6. package/lib/commonjs/diagnostics/diagnostics-storage.js.map +1 -1
  7. package/lib/commonjs/react-native-client.js +23 -7
  8. package/lib/commonjs/react-native-client.js.map +1 -1
  9. package/lib/commonjs/remote-config/remote-config-customstorage.js +57 -0
  10. package/lib/commonjs/remote-config/remote-config-customstorage.js.map +1 -0
  11. package/lib/commonjs/version.js +1 -1
  12. package/lib/commonjs/version.js.map +1 -1
  13. package/lib/module/config/joined-config.js +5 -4
  14. package/lib/module/config/joined-config.js.map +1 -1
  15. package/lib/module/config.js +14 -2
  16. package/lib/module/config.js.map +1 -1
  17. package/lib/module/diagnostics/diagnostics-storage.js +17 -20
  18. package/lib/module/diagnostics/diagnostics-storage.js.map +1 -1
  19. package/lib/module/react-native-client.js +24 -8
  20. package/lib/module/react-native-client.js.map +1 -1
  21. package/lib/module/remote-config/remote-config-customstorage.js +51 -0
  22. package/lib/module/remote-config/remote-config-customstorage.js.map +1 -0
  23. package/lib/module/version.js +1 -1
  24. package/lib/module/version.js.map +1 -1
  25. package/lib/typescript/config/joined-config.d.ts +4 -0
  26. package/lib/typescript/config/joined-config.d.ts.map +1 -1
  27. package/lib/typescript/config.d.ts +3 -1
  28. package/lib/typescript/config.d.ts.map +1 -1
  29. package/lib/typescript/diagnostics/diagnostics-storage.d.ts +9 -10
  30. package/lib/typescript/diagnostics/diagnostics-storage.d.ts.map +1 -1
  31. package/lib/typescript/react-native-client.d.ts.map +1 -1
  32. package/lib/typescript/remote-config/remote-config-customstorage.d.ts +15 -0
  33. package/lib/typescript/remote-config/remote-config-customstorage.d.ts.map +1 -0
  34. package/lib/typescript/version.d.ts +1 -1
  35. package/lib/typescript/version.d.ts.map +1 -1
  36. package/package.json +3 -3
  37. package/src/config/joined-config.ts +5 -5
  38. package/src/config.ts +27 -2
  39. package/src/diagnostics/diagnostics-storage.ts +17 -20
  40. package/src/react-native-client.ts +28 -8
  41. package/src/remote-config/remote-config-customstorage.ts +65 -0
  42. package/src/version.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,aAAa,EAEb,iBAAiB,IAAI,kBAAkB,EACvC,0BAA0B,EAC1B,KAAK,EACL,kBAAkB,EAClB,OAAO,EACP,WAAW,EAIX,cAAc,EACf,MAAM,2BAA2B,CAAC;AAKnC,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;CA8B5B,CAAC;AAEF,qBAAa,iBAAkB,SAAQ,MAAO,YAAW,kBAAkB;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IACpC,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,eAAe,EAAE,0BAA0B,CAAC;IAC5C,WAAW,CAAC,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC;IAGhD,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAS,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAChC,SAAS,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;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EAKrD;IAED,IAAI,iBAAiB,IAIW,MAAM,GAAG,SAAS,CAFjD;IAED,IAAI,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAKjD;IAED,OAAO,CAAC,aAAa;CAatB;AAED,eAAO,MAAM,oBAAoB,WACvB,MAAM,YACJ,kBAAkB,KAC3B,QAAQ,kBAAkB,CAgE5B,CAAC;AAEF,eAAO,MAAM,mBAAmB,kBAClB,kBAAkB;;;;;;;;;;;;;yBAS/B,CAAC;AAkBF,eAAO,MAAM,mBAAmB,eAAsB,kBAAkB,KAAG,QAAQ,QAAQ,KAAK,EAAE,CAAC,GAAG,SAAS,CAe9G,CAAC;AAEF,eAAO,MAAM,qBAAqB,eACpB,kBAAkB,KAC7B,QAAQ,QAAQ,sBAAsB,CAAC,GAAG,SAAS,CAErD,CAAC;AAEF,eAAO,MAAM,iBAAiB,SAAgB,MAAM,oBA6BnD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,aAAa,kBAAkB,KAAQ,OAM1E,CAAC"}
@@ -1,24 +1,23 @@
1
- import { CounterRecord, EventRecord, HistogramRecord, HistogramStats, IDiagnosticsStorage, ILogger, TagRecord } from '@amplitude/analytics-core';
1
+ import { CounterRecord, EventRecord, HistogramRecord, HistogramStats, IDiagnosticsStorage, ILogger, ReactNativeStorageData, Storage, TagRecord } from '@amplitude/analytics-core';
2
2
  /**
3
- * Diagnostics storage for React Native, backed by AsyncStorage.
3
+ * Diagnostics storage for React Native, backed by the storage configured on the client.
4
4
  *
5
- * The blob is held in memory and serialized to a single AsyncStorage key. Keeping memory as the
6
- * source of truth avoids read-modify-write races: AsyncStorage has no transactions, so merging
7
- * from disk on every mutation could interleave. One key also means one write per save tick
8
- * instead of one per data type.
5
+ * The blob is held in memory and persisted to a single storage key. Keeping memory as the source
6
+ * of truth avoids read-modify-write races when the injected storage has no transactions. One key
7
+ * also means one write per save tick instead of one per data type.
9
8
  *
10
- * AsyncStorage is an optional peer dependency. When it isn't installed this degrades to
11
- * memory-only — diagnostics still accumulate and flush for the life of the app, and are lost on
12
- * app kill. Nothing here throws on that path.
9
+ * When no storage is configured this degrades to memory-only — diagnostics still accumulate and
10
+ * flush for the life of the app, and are lost on app kill. Nothing here throws on that path.
13
11
  */
14
12
  export declare class ReactNativeDiagnosticsStorage implements IDiagnosticsStorage {
13
+ private readonly storage?;
15
14
  readonly storageKey: string;
16
15
  private readonly logger;
17
16
  private blob;
18
17
  private readonly ready;
19
18
  /** Serializes writes so concurrent callers can't clobber each other's snapshot of the blob. */
20
19
  private writeQueue;
21
- constructor(apiKey: string, logger: ILogger);
20
+ constructor(apiKey: string, logger: ILogger, storage?: Storage<ReactNativeStorageData> | undefined);
22
21
  private hydrate;
23
22
  private persist;
24
23
  setTags(tags: Record<string, string>): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostics-storage.d.ts","sourceRoot":"","sources":["../../../src/diagnostics/diagnostics-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,WAAW,EACX,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,OAAO,EACP,SAAS,EACV,MAAM,2BAA2B,CAAC;AAenC;;;;;;;;;;;GAWG;AACH,qBAAa,6BAA8B,YAAW,mBAAmB;IACvE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,IAAI,CAAgC;IAC5C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,+FAA+F;IAC/F,OAAO,CAAC,UAAU,CAAoC;gBAE1C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;YAM7B,OAAO;IAerB,OAAO,CAAC,OAAO;IAiBT,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAWpD,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAA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BAAqB;IAU7B,OAAO,CAAC,8BAA8B;IAItC,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAgBnC;IAEF;;;OAGG;YACW,uBAAuB;IAgDrC,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,cAAc;CAGvB;AAED,eAAO,MAAM,cAAc,QAAO,iBAmIjC,CAAC;;AAEF,wBAAgC"}
@@ -0,0 +1,15 @@
1
+ import { ILogger, ReactNativeStorageData, RemoteConfigInfo, RemoteConfigStorage, Storage } from '@amplitude/analytics-core';
2
+ /**
3
+ * Remote config storage backed by a caller-provided `Storage` implementation.
4
+ * Used on React Native, where the host app supplies AsyncStorage or its own
5
+ * persistence layer instead of `localStorage`.
6
+ */
7
+ export declare class RemoteConfigCustomStorage implements RemoteConfigStorage {
8
+ private readonly logger;
9
+ private readonly storage;
10
+ private readonly key;
11
+ constructor(apiKey: string, logger: ILogger, storage: Storage<ReactNativeStorageData>);
12
+ fetchConfig(): Promise<RemoteConfigInfo>;
13
+ setConfig(config: RemoteConfigInfo): Promise<boolean>;
14
+ }
15
+ //# sourceMappingURL=remote-config-customstorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-config-customstorage.d.ts","sourceRoot":"","sources":["../../../src/remote-config/remote-config-customstorage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,EACnB,OAAO,EAER,MAAM,2BAA2B,CAAC;AAEnC;;;;GAIG;AACH,qBAAa,yBAA0B,YAAW,mBAAmB;IAKjE,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL1B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;gBAG3B,MAAM,EAAE,MAAM,EACG,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,OAAO,CAAC,sBAAsB,CAAC;IAKrD,WAAW,IAAI,OAAO,CAAC,gBAAgB,CAAC;IA6BxC,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAU5D"}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.9.0";
1
+ export declare const VERSION = "1.10.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAU,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amplitude/analytics-react-native",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Official React Native SDK",
5
5
  "keywords": [
6
6
  "analytics",
@@ -42,8 +42,8 @@
42
42
  "@amplitude/ua-parser-js": "^0.7.31",
43
43
  "@react-native-async-storage/async-storage": "^1.17.11",
44
44
  "tslib": "^2.4.1",
45
- "@amplitude/analytics-core": "2.56.0",
46
- "@amplitude/plugin-network-capture-browser": "1.10.15"
45
+ "@amplitude/analytics-core": "2.57.0",
46
+ "@amplitude/plugin-network-capture-browser": "1.10.16"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/react": "^18.0.26",
@@ -23,6 +23,10 @@ type RemoteConfigReactNativeSDK = {
23
23
  * Primarily merges autocapture settings from the remote config into the React Native config.
24
24
  * Mirrors browser remote-config joining, except elementInteractions translations.
25
25
  *
26
+ * Unlike browser, remote autocapture is applied only when local autocapture is already
27
+ * truthy (`true` or an options object). A falsey local value (`false`, `undefined`, `null`)
28
+ * is treated as an explicit opt-out and is not overridden by remote config.
29
+ *
26
30
  * @param remoteConfig - The remote configuration to apply, or null if none available
27
31
  * @param reactNativeConfig - The React Native config object to update (modified in place)
28
32
  */
@@ -50,7 +54,7 @@ export function updateReactNativeConfigWithRemoteConfig(
50
54
  // merge remoteConfig.autocapture and reactNativeConfig.autocapture
51
55
  // if a field is in remoteConfig.autocapture, use that value
52
56
  // if a field is not in remoteConfig.autocapture, use the value from reactNativeConfig.autocapture
53
- if (typedRemoteConfig && 'autocapture' in typedRemoteConfig) {
57
+ if (typedRemoteConfig && 'autocapture' in typedRemoteConfig && reactNativeConfig.autocapture) {
54
58
  if (typeof typedRemoteConfig.autocapture === 'boolean') {
55
59
  reactNativeConfig.autocapture = typedRemoteConfig.autocapture;
56
60
  }
@@ -58,10 +62,6 @@ export function updateReactNativeConfigWithRemoteConfig(
58
62
  if (typeof typedRemoteConfig.autocapture === 'object' && typedRemoteConfig.autocapture !== null) {
59
63
  const transformedAutocaptureRemoteConfig = { ...typedRemoteConfig.autocapture };
60
64
 
61
- if (reactNativeConfig.autocapture === undefined) {
62
- reactNativeConfig.autocapture = typedRemoteConfig.autocapture;
63
- }
64
-
65
65
  // Handle Network Tracking config initialization
66
66
  const transformedNetworkTracking = transformNetworkTrackingRemoteConfig(
67
67
  typedRemoteConfig.autocapture.networkTracking,
package/src/config.ts CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  ReactNativeTrackingOptions,
7
7
  Event,
8
8
  ReactNativeOptions,
9
+ ReactNativeStorageData,
9
10
  Storage,
10
11
  UserSession,
11
12
  CookieStorage,
@@ -49,6 +50,18 @@ export const getDefaultConfig = () => {
49
50
  };
50
51
  };
51
52
 
53
+ const createEventsStorageAdapter = (
54
+ storageProvider?: Storage<ReactNativeStorageData>,
55
+ ): Storage<Event[]> | undefined => {
56
+ return storageProvider as Storage<Event[]> | undefined;
57
+ };
58
+
59
+ const createGeneralStorageAdapter = (
60
+ storageProvider?: Storage<ReactNativeStorageData>,
61
+ ): Storage<ReactNativeStorageData> | undefined => {
62
+ return storageProvider;
63
+ };
64
+
52
65
  export class ReactNativeConfig extends Config implements IReactNativeConfig {
53
66
  appVersion?: string;
54
67
  cookieExpiration: number;
@@ -63,6 +76,7 @@ export class ReactNativeConfig extends Config implements IReactNativeConfig {
63
76
  trackingSessionEvents: boolean;
64
77
  trackingOptions: ReactNativeTrackingOptions;
65
78
  autocapture?: IReactNativeConfig['autocapture'];
79
+ storage?: Storage<ReactNativeStorageData>;
66
80
 
67
81
  // NOTE: These protected properties are used to cache values from async storage
68
82
  protected _deviceId?: string;
@@ -78,14 +92,17 @@ export class ReactNativeConfig extends Config implements IReactNativeConfig {
78
92
 
79
93
  constructor(apiKey: string, options?: ReactNativeOptions) {
80
94
  const defaultConfig = getDefaultConfig();
95
+ const storageProvider = createEventsStorageAdapter(options?.storageProvider);
81
96
  super({
82
97
  flushIntervalMillis: 1000,
83
98
  flushMaxRetries: 5,
84
99
  flushQueueSize: 30,
85
100
  transportProvider: defaultConfig.transportProvider,
86
101
  ...options,
102
+ storageProvider,
87
103
  apiKey,
88
104
  });
105
+ this.storage = createGeneralStorageAdapter(options?.storageProvider);
89
106
 
90
107
  // NOTE: Define `cookieStorage` first to persist user session
91
108
  // user session properties expect `cookieStorage` to be defined
@@ -237,7 +254,9 @@ export const useReactNativeConfig = async (
237
254
  let userId = options?.userId ?? previousCookies?.userId;
238
255
  let lastEventId = previousCookies?.lastEventId;
239
256
 
240
- const storageProvider = options?.storageProvider ?? (await createEventsStorage(options));
257
+ const storageProvider = options?.storageProvider
258
+ ? createEventsStorageAdapter(options.storageProvider)
259
+ : await createEventsStorage(options);
241
260
 
242
261
  if (options?.migrateLegacyData !== false) {
243
262
  const legacySessionData = await new RemnantDataMigration(
@@ -322,13 +341,19 @@ export const createEventsStorage = async (overrides?: ReactNativeOptions): Promi
322
341
  if (!hasStorageProviderProperty || overrides.storageProvider) {
323
342
  for (const storage of [overrides?.storageProvider, new LocalStorage<Event[]>()]) {
324
343
  if (storage && (await storage.isEnabled())) {
325
- return storage;
344
+ return createEventsStorageAdapter(storage);
326
345
  }
327
346
  }
328
347
  }
329
348
  return undefined;
330
349
  };
331
350
 
351
+ export const createStorageProvider = async (
352
+ overrides?: ReactNativeOptions,
353
+ ): Promise<Storage<ReactNativeStorageData> | undefined> => {
354
+ return overrides?.storageProvider ?? createGeneralStorageAdapter(await createEventsStorage(overrides));
355
+ };
356
+
332
357
  export const getTopLevelDomain = async (url?: string) => {
333
358
  if (
334
359
  !(await new CookieStorage<number>().isEnabled()) ||
@@ -5,9 +5,10 @@ import {
5
5
  HistogramStats,
6
6
  IDiagnosticsStorage,
7
7
  ILogger,
8
+ ReactNativeStorageData,
9
+ Storage,
8
10
  TagRecord,
9
11
  } from '@amplitude/analytics-core';
10
- import { getAsyncStorage } from '../storage/local-storage';
11
12
 
12
13
  const MAX_PERSISTENT_STORAGE_EVENTS_COUNT = 10;
13
14
 
@@ -22,16 +23,14 @@ interface DiagnosticsBlob {
22
23
  const emptyBlob = (): DiagnosticsBlob => ({ tags: {}, counters: {}, histograms: {}, events: [] });
23
24
 
24
25
  /**
25
- * Diagnostics storage for React Native, backed by AsyncStorage.
26
+ * Diagnostics storage for React Native, backed by the storage configured on the client.
26
27
  *
27
- * The blob is held in memory and serialized to a single AsyncStorage key. Keeping memory as the
28
- * source of truth avoids read-modify-write races: AsyncStorage has no transactions, so merging
29
- * from disk on every mutation could interleave. One key also means one write per save tick
30
- * instead of one per data type.
28
+ * The blob is held in memory and persisted to a single storage key. Keeping memory as the source
29
+ * of truth avoids read-modify-write races when the injected storage has no transactions. One key
30
+ * also means one write per save tick instead of one per data type.
31
31
  *
32
- * AsyncStorage is an optional peer dependency. When it isn't installed this degrades to
33
- * memory-only — diagnostics still accumulate and flush for the life of the app, and are lost on
34
- * app kill. Nothing here throws on that path.
32
+ * When no storage is configured this degrades to memory-only — diagnostics still accumulate and
33
+ * flush for the life of the app, and are lost on app kill. Nothing here throws on that path.
35
34
  */
36
35
  export class ReactNativeDiagnosticsStorage implements IDiagnosticsStorage {
37
36
  readonly storageKey: string;
@@ -41,21 +40,20 @@ export class ReactNativeDiagnosticsStorage implements IDiagnosticsStorage {
41
40
  /** Serializes writes so concurrent callers can't clobber each other's snapshot of the blob. */
42
41
  private writeQueue: Promise<void> = Promise.resolve();
43
42
 
44
- constructor(apiKey: string, logger: ILogger) {
43
+ constructor(apiKey: string, logger: ILogger, private readonly storage?: Storage<ReactNativeStorageData>) {
45
44
  this.logger = logger;
46
45
  this.storageKey = `AMP_diagnostics_${apiKey.substring(0, 10)}`;
47
46
  this.ready = this.hydrate();
48
47
  }
49
48
 
50
49
  private async hydrate(): Promise<void> {
51
- const storage = getAsyncStorage();
52
- if (!storage) {
50
+ if (!this.storage) {
53
51
  return;
54
52
  }
55
53
  try {
56
- const raw = await storage.getItem(this.storageKey);
57
- if (raw) {
58
- this.blob = JSON.parse(raw) as DiagnosticsBlob;
54
+ const persisted = await this.storage.get(this.storageKey);
55
+ if (persisted && !Array.isArray(persisted)) {
56
+ this.blob = persisted as DiagnosticsBlob;
59
57
  }
60
58
  } catch (error) {
61
59
  this.logger.debug('ReactNativeDiagnosticsStorage: Failed to read persisted diagnostics', error);
@@ -63,16 +61,15 @@ export class ReactNativeDiagnosticsStorage implements IDiagnosticsStorage {
63
61
  }
64
62
 
65
63
  private persist(): Promise<void> {
66
- const storage = getAsyncStorage();
67
- if (!storage) {
64
+ if (!this.storage) {
68
65
  return Promise.resolve();
69
66
  }
70
67
  this.writeQueue = this.writeQueue.then(async () => {
71
68
  try {
72
- await storage.setItem(this.storageKey, JSON.stringify(this.blob));
69
+ await this.storage?.set(this.storageKey, this.blob);
73
70
  } catch (error) {
74
- // The JS package resolved but the native bridge is missing, or the entry exceeded the
75
- // platform size limit. Memory stays authoritative and the next save tick rewrites.
71
+ // The backing store may be unavailable or the entry may exceed its platform size limit.
72
+ // Memory stays authoritative and the next save tick rewrites.
76
73
  this.logger.debug('ReactNativeDiagnosticsStorage: Failed to persist diagnostics', error);
77
74
  }
78
75
  });
@@ -28,6 +28,7 @@ import {
28
28
  IRemoteConfigClient,
29
29
  RemoteConfigClient,
30
30
  RemoteConfig,
31
+ RemoteConfigGroup,
31
32
  Source,
32
33
  ReactNativeAutocaptureOptions,
33
34
  NavigationState,
@@ -43,10 +44,11 @@ import { networkConnectivityCheckerPlugin } from './plugins/network-connectivity
43
44
  import { ReactNativeDiagnosticsStorage } from './diagnostics/diagnostics-storage';
44
45
  import { LIBPREFIX } from './lib-prefix';
45
46
  import { VERSION } from './version';
46
- import { useReactNativeConfig, createCookieStorage, shouldFetchRemoteConfig } from './config';
47
+ import { useReactNativeConfig, createCookieStorage, createStorageProvider, shouldFetchRemoteConfig } from './config';
47
48
  import { updateReactNativeConfigWithRemoteConfig } from './config/joined-config';
48
49
  import { parseOldCookies } from './cookie-migration';
49
50
  import { isNative } from './utils/platform';
51
+ import { RemoteConfigCustomStorage } from './remote-config/remote-config-customstorage';
50
52
  import * as Capture from './amp-capture';
51
53
  import {
52
54
  APP_BUILD,
@@ -89,7 +91,18 @@ const getActiveRouteName = (navigationState: NavigationState): string | undefine
89
91
  return routeName;
90
92
  };
91
93
 
92
- const getRemoteConfigPlatform = () => {
94
+ const getRemoteConfigSdkKey = () => {
95
+ if (Platform.OS === 'ios') {
96
+ return 'configs.analyticsSDK.iosSDK';
97
+ }
98
+ if (Platform.OS === 'android') {
99
+ return 'configs.analyticsSDK.androidSDK';
100
+ }
101
+ // unexpected React Native platform, just use Browser SDK.
102
+ return 'configs.analyticsSDK.browserSDK';
103
+ };
104
+
105
+ const getRemoteConfigPlatform = (): { configGroup: RemoteConfigGroup; diagnosticsKey: string } => {
93
106
  switch (Platform.OS) {
94
107
  case 'ios':
95
108
  return {
@@ -169,7 +182,11 @@ export class AmplitudeReactNative extends AmplitudeCore implements ReactNativeCl
169
182
  let diagnosticsSampleRate = 0;
170
183
 
171
184
  // Step 0.2: Fetch only the platform-specific diagnostics config.
185
+ let remoteConfigStorage: RemoteConfigCustomStorage | undefined;
172
186
  if (fetchRemoteConfig) {
187
+ if (options.storageProvider) {
188
+ remoteConfigStorage = new RemoteConfigCustomStorage(options.apiKey, loggerProvider, options.storageProvider);
189
+ }
173
190
  const remoteConfigPlatform = getRemoteConfigPlatform();
174
191
  remoteConfigClient = new RemoteConfigClient(
175
192
  options.apiKey,
@@ -178,6 +195,7 @@ export class AmplitudeReactNative extends AmplitudeCore implements ReactNativeCl
178
195
  /* istanbul ignore next */ options.remoteConfig?.serverUrl,
179
196
  undefined,
180
197
  remoteConfigPlatform.configGroup,
198
+ remoteConfigStorage,
181
199
  );
182
200
  const diagnosticsRemoteConfigPromise = new Promise<void>((resolve) => {
183
201
  remoteConfigClient?.subscribe(
@@ -206,7 +224,7 @@ export class AmplitudeReactNative extends AmplitudeCore implements ReactNativeCl
206
224
  });
207
225
  analyticsRemoteConfigPromise = new Promise<RemoteConfig | null>((resolve) => {
208
226
  remoteConfigClient?.subscribe(
209
- 'configs.analyticsSDK.reactNativeSDK',
227
+ getRemoteConfigSdkKey(),
210
228
  'all',
211
229
  (remoteConfig: RemoteConfig | null, source: Source, lastFetch: Date) => {
212
230
  loggerProvider.debug(
@@ -228,16 +246,17 @@ export class AmplitudeReactNative extends AmplitudeCore implements ReactNativeCl
228
246
  await diagnosticsRemoteConfigPromise;
229
247
  }
230
248
 
231
- // Step 0.3: Initialize diagnostics client as early as possible so it can record failures
232
- // during config setup. Mirrors the browser SDK; storage is injected because RN has no
233
- // IndexedDB. The platform-specific remote config sample rate keeps the client inert when
234
- // diagnostics are not configured, since the default sample rate is 0.
249
+ const storageProvider = await createStorageProvider(options);
250
+
251
+ // Step 0.3: Initialize diagnostics as early as possible so it can record failures during
252
+ // config setup. React Native has no IndexedDB, so diagnostics uses the same storage provider
253
+ // that will be passed to the final config.
235
254
  const diagnosticsClient = new DiagnosticsClient(
236
255
  options.apiKey,
237
256
  loggerProvider,
238
257
  serverZone,
239
258
  { sampleRate: diagnosticsSampleRate },
240
- new ReactNativeDiagnosticsStorage(options.apiKey, loggerProvider),
259
+ new ReactNativeDiagnosticsStorage(options.apiKey, loggerProvider, storageProvider),
241
260
  );
242
261
  diagnosticsClient.setTag('library', `${LIBPREFIX}/${VERSION}`);
243
262
  diagnosticsClient.setTag('platform', 'ReactNative');
@@ -253,6 +272,7 @@ export class AmplitudeReactNative extends AmplitudeCore implements ReactNativeCl
253
272
  ...options,
254
273
  loggerProvider,
255
274
  serverZone,
275
+ storageProvider,
256
276
  deviceId: options.deviceId ?? oldCookies.deviceId,
257
277
  sessionId: oldCookies.sessionId,
258
278
  optOut: options.optOut ?? oldCookies.optOut,
@@ -0,0 +1,65 @@
1
+ import {
2
+ ILogger,
3
+ ReactNativeStorageData,
4
+ RemoteConfigInfo,
5
+ RemoteConfigStorage,
6
+ Storage,
7
+ safeJsonStringify,
8
+ } from '@amplitude/analytics-core';
9
+
10
+ /**
11
+ * Remote config storage backed by a caller-provided `Storage` implementation.
12
+ * Used on React Native, where the host app supplies AsyncStorage or its own
13
+ * persistence layer instead of `localStorage`.
14
+ */
15
+ export class RemoteConfigCustomStorage implements RemoteConfigStorage {
16
+ private readonly key: string;
17
+
18
+ constructor(
19
+ apiKey: string,
20
+ private readonly logger: ILogger,
21
+ private readonly storage: Storage<ReactNativeStorageData>,
22
+ ) {
23
+ this.key = `AMP_remote_config_${apiKey.substring(0, 10)}`;
24
+ }
25
+
26
+ async fetchConfig(): Promise<RemoteConfigInfo> {
27
+ const failedRemoteConfigInfo: RemoteConfigInfo = {
28
+ remoteConfig: null,
29
+ lastFetch: new Date(),
30
+ };
31
+
32
+ let result: ReactNativeStorageData | undefined;
33
+ try {
34
+ result = await this.storage.get(this.key);
35
+ } catch (error) {
36
+ this.logger.debug('Remote config customstorage failed to access: ', error);
37
+ return failedRemoteConfigInfo;
38
+ }
39
+
40
+ // The storage may be shared with other SDK data (e.g. the event queue), so
41
+ // reject anything that is not a plain object before reading config fields.
42
+ if (!result || typeof result !== 'object' || Array.isArray(result)) {
43
+ this.logger.debug('Remote config customstorage gets no valid config for the key');
44
+ return failedRemoteConfigInfo;
45
+ }
46
+
47
+ const remoteConfigInfo = result as RemoteConfigInfo;
48
+ this.logger.debug(`Remote config customstorage parsed successfully: ${safeJsonStringify(remoteConfigInfo)}`);
49
+ return {
50
+ remoteConfig: remoteConfigInfo.remoteConfig ?? null,
51
+ lastFetch: remoteConfigInfo.lastFetch ? new Date(remoteConfigInfo.lastFetch) : new Date(),
52
+ };
53
+ }
54
+
55
+ async setConfig(config: RemoteConfigInfo): Promise<boolean> {
56
+ try {
57
+ await this.storage.set(this.key, config);
58
+ this.logger.debug('Remote config customstorage set successfully.');
59
+ return true;
60
+ } catch (error) {
61
+ this.logger.debug('Remote config customstorage failed to set: ', error);
62
+ return false;
63
+ }
64
+ }
65
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '1.9.0';
1
+ export const VERSION = '1.10.0';