首页 > 解决方案 > Mixpanel.sharedInstanceWithToken 不是本机反应中的功能

问题描述

我想将 Mixpanel 与 React Native 集成,我使用了这个 github 源 https://github.com/davodesign84/react-native-mixpanel

我尝试了与描述相同的方法,但收到了此消息

Mixpanel.sharedInstanceWithToken is not a function

'Mixpanel.sharedInstanceWithToken' is undefined)

    var Mixpanel = require('react-native-mixpanel');

     componentDidMount() {
        console.log('============>', Mixpanel) // it returns object 
        Mixpanel.sharedInstanceWithToken('xxx');
    }

在此处输入图像描述

我试了很多次都没有成功。应用程序启动成功,但在我使用 Mixpanel.sharedInstanceWithToken('xxx') 的屏幕中停止

谢谢你。

标签: react-nativecocoapodsmixpanel

解决方案


正如@savelichalex 在评论中提到的那样,使用它会起作用:

const Mixpanel = require('react-native-mixpanel');
Mixpanel.default.sharedInstanceWithToken('MY_TOKEN');

推荐阅读