Skip to content

Commit 92c1fc0

Browse files
authored
fix: add fix for deviceId on android builds (#405)
* fix: add fix for deviceId on android builds * fix: refactor to pass config object into getContext * fix: remove write key in example
1 parent 8e47eb6 commit 92c1fc0

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

example/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { AmplitudeSessionPlugin } from '@segment/analytics-react-native-plugin-a
3030
const segmentClient = createClient({
3131
writeKey: 'WRITE KEY',
3232
trackAppLifecycleEvents: true,
33+
collectDeviceId: true,
3334
});
3435

3536
const LoggerPlugin = new Logger();

packages/core/src/analytics.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,8 @@ export class SegmentClient {
557557
* Application Opened - the previously detected version is same as the current version
558558
*/
559559
private async checkInstalledVersion() {
560-
const context = await getContext(undefined);
560+
const context = await getContext(undefined, this.config);
561+
561562
const previousContext = this.store.context.get();
562563

563564
this.store.context.set(context);

packages/core/src/context.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ import type {
88
UserTraits,
99
} from './types';
1010

11+
interface GetContextConfig {
12+
collectDeviceId?: boolean;
13+
}
1114
export const getContext = async (
12-
userTraits: UserTraits = {}
15+
userTraits: UserTraits = {},
16+
config: GetContextConfig = {}
1317
): Promise<Context> => {
1418
const { AnalyticsReactNative } = NativeModules;
1519

@@ -31,7 +35,7 @@ export const getContext = async (
3135
deviceId,
3236
deviceType,
3337
screenDensity,
34-
}: NativeContextInfo = await AnalyticsReactNative.getContextInfo({});
38+
}: NativeContextInfo = await AnalyticsReactNative.getContextInfo(config);
3539

3640
const device: ContextDevice = {
3741
id: deviceId,

packages/core/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export type Config = {
123123
maxEventsToRetry?: number;
124124
defaultSettings?: SegmentAPISettings;
125125
autoAddSegmentDestination?: boolean;
126+
collectDeviceId?: boolean;
126127
};
127128

128129
export type ClientMethods = {

0 commit comments

Comments
 (0)