evollu / react-native-firebase-analytics

React native bridge for firebase analytics
MIT License
206 stars 54 forks source link

Can't use Analytics.logEvent #30

Closed mylake closed 7 years ago

mylake commented 7 years ago

using "react": "15.3.2", "react-native": "0.35.0", "react-native-firebase-analytics": "^1.0.5" Devices I use is => Android 7.0, API Level: 24

I have followed the README setting and want to use logEvent.

I just use the README sample code to logEvent, but I got this error as below: var Analytics = require('react-native-firebase-analytics'); Analytics.logEvent('view_item', { 'item_id': 'login' });

undefined is not an object (evaluating 'FIRAnalytics.logEvent') logEvent index.js:19

index.android.js:17 loadModuleImplementation require.js:122 guardedLoadModule require.js:58 _require require.js:49 global code require-0.js:1

Could you help me to figure out what cause this problem? Thank you

binzailani3136 commented 7 years ago

I got the same code. If you solved this, could you help me? Thanks.

juellez commented 7 years ago

I also ran into this. Fix: add the following to your MainApplication.java file:

import com.evollu.react.fa.FIRAnalyticsPackage; // <-- add this line
import com.facebook.react.ReactPackage;

...

protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          ...
          new FIRAnalyticsPackage()  // <-- add this line
      );
}
evollu commented 7 years ago

yep, link issue

janaka120 commented 7 years ago

I think the issue is still there and rnpm link the react-native-firebase-analytics package with MainActivity.java, not to MainApplication.java

maxhanzo commented 7 years ago

I'm having the same problem with iOS (linking error because of logEvent(params)), however, I've just noticed this when I tried to install everything via rnpm install react-native-firebase-analytics :

" rnpm-link info Linking react-native-firebase-analytics android dependency rnpm-link ERR! It seems something went wrong while linking. Error: Cannot find module '../project-name/node_modules/react-native/package.json' " I'm currently using react-native-cli 2.0.1

How can we solve this issue?

Thank you!

evollu commented 7 years ago

looks like you are running it in wrong folder?