skip to Main Content

Using “react”: “15.3.2”, “react-native”: “0.35.0”, “react-native-fbsdk”: “^0.3.0”
the android virtual Devices I use is => Android 7.0, API Level: 24

I have followed the Readme setting https://github.com/facebook/react-native-fbsdk

I want to use Analytics for Apps.

On iOS it works well both on App Launches and AppEventsLogger

On Android it works well on App Launches, and I could got the data on facebook analytics website

but about the AppEventsLogger.logPurchase or AppEventsLogger.logEvent, I will got failed msg

const FBSDK = require('react-native-fbsdk');
const {
  AppEventsLogger,
} = FBSDK;
AppEventsLogger.logPurchase(15, 'USD', {'param': 'value'})

but I got the error like this

Attempt to invoke virtual method 'void com.facebook.appevents.AppEventsLogger.logPurchase(java.math.BigDecimal, java.util.Currency, android.os.Bundle)' on a null object reference
logPurchase
    FBAppEventsLoggerModule.java:175
invoke
    Method.java:-2

do other people have this problem

2

Answers


  1. Chosen as BEST ANSWER

    I try call it after the component is mounted, and it works

    like this

        export default class FbTest extends Component {
    
          componentDidMount() {
              AppEventsLogger.logPurchase(20, 'USD', {'param': 'testlala'});
          }
    

  2. Looks like the AppEventLogger object is not initialized..
    Do you set up the facebook android sdk correctly? Are other features in the react-native-fbsdk works for you, e.g Login, Like?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search