Skip to content

Commit f698356

Browse files
authored
fix: fix IDFA Plugin crash on non-ios platforms (#433)
Co-authored-by: Oscar Bazaldua <[email protected]>
1 parent 4c6e977 commit f698356

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

example/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Logger } from './plugins/Logger';
2323
// import { FacebookAppEventsPlugin } from '@segment/analytics-react-native-plugin-facebook-app-events';
2424

2525
// @ts-ignore
26-
// import { IdfaPlugin } from '@segment/analytics-react-native-plugin-idfa';
26+
import { IdfaPlugin } from '@segment/analytics-react-native-plugin-idfa';
2727
// @ts-ignore
2828
import { AmplitudeSessionPlugin } from '@segment/analytics-react-native-plugin-amplitude-session';
2929

@@ -43,7 +43,7 @@ segmentClient.add({ plugin: LoggerPlugin });
4343
// To test the Facebook App Events plugin make sure to add your Facebook App Id to Info.plist
4444
// segmentClient.add({ plugin: new FacebookAppEventsPlugin() });
4545

46-
// segmentClient.add({ plugin: new IdfaPlugin() });
46+
segmentClient.add({ plugin: new IdfaPlugin() });
4747
segmentClient.add({ plugin: new AmplitudeSessionPlugin() });
4848

4949
const MainStack = createStackNavigator();
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
/**
22
* This module is just here to have a way to mock the Native Module of IDFA with Detox
33
*/
4-
import { NativeModules } from 'react-native';
4+
import { NativeModules, Platform } from 'react-native';
55

6-
export const { AnalyticsReactNativePluginIdfa } = NativeModules;
6+
export const AnalyticsReactNativePluginIdfa = Platform.select({
7+
default: {
8+
getTrackingAuthorizationStatus: () => {
9+
return Promise.reject('IDFA is only supported on iOS');
10+
},
11+
},
12+
ios: NativeModules.AnalyticsReactNativePluginIdfa,
13+
});

packages/plugins/plugin-idfa/src/IdfaPlugin.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ export class IdfaPlugin extends Plugin {
2323
}
2424

2525
getTrackingStatus() {
26-
getTrackingAuthorizationStatus().then((idfa: IdfaData) => {
27-
// update our context with the idfa data
28-
this.analytics?.context.set({ device: { ...idfa } });
29-
});
26+
getTrackingAuthorizationStatus()
27+
.then((idfa: IdfaData) => {
28+
// update our context with the idfa data
29+
this.analytics?.context.set({ device: { ...idfa } });
30+
})
31+
.catch((err: any) => {
32+
console.warn(err);
33+
});
3034
}
3135
}

0 commit comments

Comments
 (0)