React Native API reference

At a glance: API reference to integrate AppsFlyer SDK into iOS/Android apps developed with React Native to measure installs, in-app events, media sources, and more.

 Related reading

For a complete picture of working with the React Native plugin in AppsFlyer, be sure to read these articles:

initSDK

Description

Initialize the AppsFlyer SDK with the dev key and app ID.

The dev key is required for all apps, while the app ID is required only for iOS. (You can pass the app ID on Android as well, and it will be ignored.

Method signature

initSdk(options, success, error)

Example

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import appsFlyer from 'react-native-appsflyer';

appsFlyer.initSdk(
  {
    devKey: 'K2***********99',
    isDebug: false,
    appId: '41*****44',
  },
  (res) => {
    console.log(res);
  },
  (err) => {
    console.error(err);
  }
);
);

trackAppLaunch (deprecated)

Description

Two functions:

  • Sends an immediate app launch event to AppsFlyer.
  • Restarts SDK functionality if it was stopped with stopTracking.

Method signature

trackAppLaunch()

Example

state = {
  appState: AppState.currentState,
};

componentDidMount();
{
  AppState.addEventListener('change', this._handleAppStateChange);
}

componentWillUnmount();
{
  AppState.removeEventListener('change', this._handleAppStateChange);
}

_handleAppStateChange = (nextAppState) => {
  if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
    if (Platform.OS === 'ios') {
      appsFlyer.trackAppLaunch();
    }
  }

  this.setState({appState: nextAppState});
};

onInstallConversionData

Description

Allows access of AppsFlyer attribution/conversion data from the SDK (deferred deep linking).

The code implementation for the conversion listener must be made prior to the initialization code of the SDK.

Method signature

onInstallConversionData(callback) : function:unregister

Example

this.onInstallConversionDataCanceller = appsFlyer.onInstallConversionData(
  (res) => {
    if (JSON.parse(res.data.is_first_launch) == true) {
      if (res.data.af_status === 'Non-organic') {
        var media_source = res.data.media_source;
        var campaign = res.data.campaign;
        alert('This is first launch and a Non-Organic install. Media source: ' + media_source + ' Campaign: ' + campaign);
      } else if (res.data.af_status === 'Organic') {
        alert('This is first launch and a Organic Install');
      }
    } else {
      alert('This is not first launch');
    }
  }
);

appsFlyer.initSdk(/*...*/);

onAppOpenAttribution

Description

Get deep link data when the app opens via a deep link. 

Method signature

onAppOpenAttribution(callback) : function:unregister)

Example

this.onAppOpenAttributionCanceller = appsFlyer.onAppOpenAttribution((res) => {
  console.log(res);
});

appsFlyer.initSdk(/*...*/);

logEvent

Description

Sends in-app events to AppsFlyer. See recording in-app events.

Method signature

logEvent(eventName, eventValues, success, error)

Example

const eventName = 'af_add_to_cart';
const eventValues = {
  af_content_id: 'id123',
  af_currency: 'USD',
  af_revenue: '2',
};

appsFlyer.logEvent(
  eventName,
  eventValues,
  (res) => {
    console.log(res);
  },
  (err) => {
    console.error(err);
  }
);

setCustomerUserId

Description

Sets the Customer User ID (CUID). See setting the Customer User ID.

Method signature

setCustomerUserId(userId, callback)

Example

appsFlyer.setCustomerUserId('some_user_id', (res) => {
  //..
});

getAppsFlyerUID

Description

Get the AppsFlyer ID. For more information see here.

Method signature

getAppsFlyerUID(callback)

Example

appsFlyer.getAppsFlyerUID((err, appsFlyerUID) => {
  if (err) {
    console.error(err);
  } else {
    console.log('on getAppsFlyerUID: ' + appsFlyerUID);
  }
});

stop

Description

Stop all SDK functionality. See user privacy (opt-out).

Method signature

stop(isStopped, callback)

Example

appsFlyer.stop(true, (res) => {
  //...
});

logLocation

Description

Manually record the location of the user. 

Method signature

logLocation(longitude, latitude, callback)

Example

const latitude = -18.406655;
const longitude = 46.40625;

appsFlyer.logLocation(longitude, latitude, (err, coords) => {
  if (err) {
    console.error(err);
  } else {
    //...
  }
});

setUserEmails

Description

Set and encrypt user emails.

Method signature

setUserEmails(options, success, error)

Example

const options = {
  emailsCryptType: 2,
  emails: ['user1@gmail.com', 'user2@gmail.com'],
};

appsFlyer.setUserEmails(
  options,
  (res) => {
    //...
  },
  (err) => {
    console.error(err);
  }
);

setAdditionalData

Description

Adds additional data to be sent to external partner platforms.

Method signature

setAdditionalData(additionalData, callback)

Example

appsFlyer.setAdditionalData(
  {
    val1: 'data1',
    val2: false,
    val3: 23,
  },
  (res) => {
    //...
  }
);

updateServerUninstallToken - Android only

Description

Manually pass the Firebase/GCM device token for uninstall measurement.

Method signature

updateServerUninstallToken(token, callback)

Example

appsFlyer.updateServerUninstallToken('token', (res) => {
  //...
});

setCollectIMEI - Android only

Description

Indicates if the IMEI should be sent to AppsFlyer.

Method signature

setCollectIMEI(isCollect, callback)

Example

appsFlyer.setCollectAndroidIMEI(true, (res) => {
   //...
});

setCollectAndroidID - Android only

Description

Indicates if the Android ID should be sent to AppsFlyer.

Method signature

setCollectAndroidID(isCollect, callback)

Example

appsFlyer.setCollectAndroidID(true, (res) => {
   //...
});

setAppInviteOneLinkID

Description

Set the OneLink template ID for creating custom attribution links for user invites.

Used together with generateInviteLink.

Method signature

setAppInviteOneLinkID(oneLinkID, callback)

Example

appsFlyer.setAppInviteOneLinkID('abcd', (res) => {
  //...
});

logCrossPromotionImpression

Description

Used to attribute an impression use the following API call.

Make sure to use the promoted app ID as it displays within the AppsFlyer dashboard.

Method signature

logCrossPromotionImpression(appId, campaign)

Example

appsFlyer.logCrossPromotionImpression("com.myandroid.app", "myCampaign");

logCrossPromotionAndOpenStore

Description

Used to attribute the click and launch the app store's app page.

Method signature

logCrossPromotionAndOpenStore(appId, campaign, params)

Example

var crossPromOptions = {
  customerID: '1234',
  myCustomParameter: 'newUser',
};

appsFlyer.logCrossPromotionAndOpenStore(
  'com.myandroid.app',
  'myCampaign',
  crossPromOptions
);
            

setCurrencyCode

Description

Sets the currency code for all events.

  • Default currency: USD
  • Currency code is a 3-character ISO 4217 code.

Method signature

setCurrencyCode(currencyCode, callback)

Example

appsFlyer.setCurrencyCode('USD', () => {});

setDeviceTrackingDisabled

Description

Used to anonymize specific user identifiers within AppsFlyer analytics. This complies with both the latest privacy requirements (GDPR, COPPA) and Facebook's data and privacy policies.

Method signature

setDeviceTrackingDisabled(isDeviceTrackingDisabled, callback)

Example

appsFlyer.setDeviceTrackingDisabled(true, () => {});

setOneLinkCustomDomains

Description

Used during the SDK initialization to indicate set OneLink custom links/branded domains. Learn more about Branded Links.

Method signature

setOneLinkCustomDomains(domains, successC, errorC)

Example

appsFlyer.setOneLinkCustomDomains(["click.mybrand.com"],
    (res) => {
        console.log(res);
    }, (error) => {
        console.log(error);
    });            

setResolveDeepLinkURLs

Description

Used during the SDK initialization to indicate that links from certain domains (domains used by ESP when wrapping your deep links) should be resolved in order to get the original deep link. Learn more.

Method signature

setResolveDeepLinkURLs(urls, successC, errorC)

Example

appsFlyer.setResolveDeepLinkURLs(["click.esp-domain.com"],
    (res) => {
        console.log(res);
    }, (error) => {
        console.log(error);
    });            

performOnAppAttribution

Description

This function allows developers to manually re-trigger onAppOpenAttribution with a specific link (URI or URL), without recording a new re-engagement.
This method may be required if the app needs to redirect users based on the given link, or resolve the AppsFlyer short URL while staying in the foreground/opened. This might be needed because regular onAppOpenAttribution callback is only called if the app was opened with the deep link.

Method signature

performOnAppAttribution(url, callback)

Example

let uriString = "sdktest://test"
 appsFlyer.performOnAppAttribution(uriString, (res) => {
 console.log(res);
 })     

setSharingFilterForAllPartners

Description

Used by advertisers to exclude all networks/integrated partners from getting data. Learn more.

Method signature

setSharingFilterForAllPartners()

Example

setSharingFilterForAllPartners()

setSharingFilter

Description

Used by advertisers to set some (one or more) networks/integrated partners to exclude from getting data. Learn more.

Method signature

setSharingFilter(partners, sucessC, errorC)

Example

 let partners = ["facebook_int","googleadwords_int","snapchat_int","doubleclick_int"]
        appsFlyer.setSharingFilterForAllPartners(partners,
        (res) => {
            console.log(res);
        }, (error) => {
            console.log(error);
        })
Was this article helpful?