segmentio / analytics-react-native

The hassle-free way to add analytics to your React-Native app.
https://segment.com/docs/sources/mobile/react-native/
MIT License
354 stars 181 forks source link

Expo Go & @segment/analytics-react-native-plugin-idfa: Cannot read property 'getTrackingAuthorizationStatus' of null #928

Closed 0xPT closed 3 months ago

0xPT commented 3 months ago

Hi, I'm using Expo Go in development, and I'm having no problems with the @segment/analytics-react-native by itself, but I am running into an issue with the IDFA plugin for it. I'm getting this error when importing it: TypeError: Cannot read property 'getTrackingAuthorizationStatus' of null, js engine: hermes. I'm able to get around it by using a dynamic import, based on if it's in Expo Go or not, but that seems incorrect.

Steps to reproduce

  1. Import @segment/analytics-react-native
  2. Import @segment/analytics-react-native-plugin-idfa
  3. Should crash

Expected behavior I would expect either a warning or the error to be handled gracefully to allow for Expo Go development.

Actual behavior I get a full TypeError that causes the app to not be able to load.

oscb commented 3 months ago

Right now we don't have support for Expo Go, specially with plugins as they require native modules. I suggest for your dev builds you conditionally add plugins only when not running in expo go mode:

const isRunningInExpoGo = Constants.appOwnership === 'expo'

if (!isRunningInExpoGo) {
  client.add({plugin: IDFA) 
}