diff --git a/example/src/App.tsx b/example/src/App.tsx index 7c8395980..db2ac2cab 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -30,6 +30,7 @@ import { AmplitudeSessionPlugin } from '@segment/analytics-react-native-plugin-a const segmentClient = createClient({ writeKey: 'WRITE KEY', trackAppLifecycleEvents: true, + collectDeviceId: true, }); const LoggerPlugin = new Logger(); diff --git a/packages/core/src/analytics.ts b/packages/core/src/analytics.ts index 31c623ec6..b615b6f23 100644 --- a/packages/core/src/analytics.ts +++ b/packages/core/src/analytics.ts @@ -557,7 +557,8 @@ export class SegmentClient { * Application Opened - the previously detected version is same as the current version */ private async checkInstalledVersion() { - const context = await getContext(undefined); + const context = await getContext(undefined, this.config); + const previousContext = this.store.context.get(); this.store.context.set(context); diff --git a/packages/core/src/context.ts b/packages/core/src/context.ts index dc03f26ae..ca9fe1c65 100644 --- a/packages/core/src/context.ts +++ b/packages/core/src/context.ts @@ -8,8 +8,12 @@ import type { UserTraits, } from './types'; +interface GetContextConfig { + collectDeviceId?: boolean; +} export const getContext = async ( - userTraits: UserTraits = {} + userTraits: UserTraits = {}, + config: GetContextConfig = {} ): Promise => { const { AnalyticsReactNative } = NativeModules; @@ -31,7 +35,7 @@ export const getContext = async ( deviceId, deviceType, screenDensity, - }: NativeContextInfo = await AnalyticsReactNative.getContextInfo({}); + }: NativeContextInfo = await AnalyticsReactNative.getContextInfo(config); const device: ContextDevice = { id: deviceId, diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 649b3031a..ed7ae4561 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -123,6 +123,7 @@ export type Config = { maxEventsToRetry?: number; defaultSettings?: SegmentAPISettings; autoAddSegmentDestination?: boolean; + collectDeviceId?: boolean; }; export type ClientMethods = {