5

I'm trying to implement AppsFlyer in a react native app but I have this error "Cannot read property 'initSdk' of undefined"

I imported react-native-appsflyer

import React, { Component } from 'react';
import {
 Alert,
 Platform,
 AppRegistry,
 NetInfo,
 Text,
} from 'react-native';
//...

import appsFlyer from 'react-native-appsflyer';

//...

And tried to call the initSdk method

export default class  App extends Component {

    initSdk(){
        console.log('allo appsflyer');

        let options = {
          devKey:  'AF_DEV_KEY',
          appId: "IOS_APP_ID",
          isDebug: true
        };

       appsFlyer.initSdk(options,
           (result) => {
             this.setState( { ...this.state, initSdkResponse: result });
             console.log(initSdkResponse);
           },
           (error) => {
             console.error(error);
           }
           )
     }

And launched it in my startApp function

    startApp(root) {
        this.initSdk();
        console.log('app store update --> root', root);

        switch (root) {
          //...  
        }
    }
}

Someone to help me please ?

Joris
  • 697
  • 2
  • 9
  • 24
  • 1
    I also get this occasionally, it's extremely annoying and inconsistent. I think it has something to do with appsflyer's react-native-module not being properly integrated when the app builds. – Sean Dec 11 '18 at 01:11
  • Yes, I reinstalled Appsflyer module from scratch and it's working – Joris Dec 11 '18 at 01:18

1 Answers1

0

This error might occur if the native dependencies were not properly linked, this should be resolved if you run react-native link react-native-appsflyer from the project's root (for Android native dependencies) and add relevant Pod dependencies for iOS:

Add the appsFlyerFramework to Podfile and run pod install. Example:

pod 'react-native-appsflyer',
:path => '../node_modules/react-native-appsflyer'

(assuming your Podfile is located in iOS directory) Run pod install

If you are not using cocoapods you can follow the manual integration instructions: https://github.com/AppsFlyerSDK/react-native-appsflyer#manual-integration-integrating-without-cocoapods