mixpanel / mixpanel-react-native

Official React Native Tracking Library for Mixpanel Analytics
https://mixpanel.com
Apache License 2.0
105 stars 44 forks source link

Issue with intialisation on v3.0.2 #236

Closed pratyush0103 closed 4 months ago

pratyush0103 commented 5 months ago

When I am initializing on web I get this error ->

-- TypeError: Cannot read properties of undefined (reading 'Brand') at MixpanelMain.getMetaData (mixpanel-main.js:44:1) at MixpanelMain. (mixpanel-main.js:88:1) at Generator.next () at asyncGeneratorStep (asyncToGenerator.js:3:1) at _next (asyncToGenerator.js:22:1)

I looked into the code and found out that you guys are extracting Constants from Platform

const {OS, Version, constants} = Platform;
const {Brand, Manufacturer, Model} = constants;

the thing is constants are undefined on web so when we are trying to get Brand from it its throwing an error, 
A quick fix is initializing constants with an empty obj before initializing mix-panel like this -> 

Platform.constants = { Brand: '', Manufacturer: '', Model: '', };

but this needs to be fixed.

zihejia commented 4 months ago

@pratyush0103 , thanks for bringing this up. Do you mind opening a pull request for it?

pratyush0103 commented 4 months ago

@zihejia, there you go https://github.com/mixpanel/mixpanel-react-native/pull/238.