Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
fix: add fix for deviceId on android builds (segmentio#405)
Browse files Browse the repository at this point in the history
* fix: add fix for deviceId on android builds

* fix:  refactor to pass config object into getContext

* fix: remove write key in example
  • Loading branch information
alanjcharles authored Jan 24, 2022
1 parent 8e47eb6 commit 92c1fc0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import type {
UserTraits,
} from './types';

interface GetContextConfig {
collectDeviceId?: boolean;
}
export const getContext = async (
userTraits: UserTraits = {}
userTraits: UserTraits = {},
config: GetContextConfig = {}
): Promise<Context> => {
const { AnalyticsReactNative } = NativeModules;

Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export type Config = {
maxEventsToRetry?: number;
defaultSettings?: SegmentAPISettings;
autoAddSegmentDestination?: boolean;
collectDeviceId?: boolean;
};

export type ClientMethods = {
Expand Down

0 comments on commit 92c1fc0

Please sign in to comment.