AppsFlyer React Native SDK

6.17.9 · active · verified Tue Apr 21

react-native-appsflyer is the official React Native plugin for integrating the AppsFlyer mobile attribution and marketing analytics SDK. It provides comprehensive functionalities for tracking installs, in-app events, deep linking, and consent management across iOS and Android platforms. The current stable version is 6.17.9, with frequent patch releases, indicating active development and maintenance. Key differentiators include robust support for purchase validation via the Purchase Connector (since 6.17.1), unified deep linking (UDL), and explicit handling of consent for DMA compliance. The plugin is built for Android AppsFlyer SDK v6.17.6 and iOS AppsFlyer SDK v6.17.9, and is tested with React Native v0.62.0 and above, ensuring compatibility with modern React Native projects. It ships with TypeScript types, facilitating type-safe development.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the AppsFlyer SDK for both iOS and Android, log a custom in-app event (purchase), and set up a listener for Unified Deep Links. Remember to replace placeholder keys.

import appsFlyer from 'react-native-appsflyer';
import { Platform } from 'react-native';
import type { DeepLinkResult } from 'react-native-appsflyer';

const appsFlyerDevKey = process.env.APPSFLYER_DEV_KEY ?? 'YOUR_APPSFLYER_DEV_KEY';
// iOS App ID is required for iOS initialization
const appleAppID = Platform.OS === 'ios' ? (process.env.APPLE_APP_ID ?? 'YOUR_APPLE_APP_ID') : '';

appsFlyer.initSdk(
  {
    devKey: appsFlyerDevKey,
    isDebug: true,
    appId: appleAppID, // Only for iOS. Ensure this is a string.
    // Add conversion data and deep link listeners here if needed
    // onInstallConversionDataListener: (data) => console.log('Install Conversion Data:', data),
    // onDeepLinkListener: (result) => console.log('Deep Link Listener Data:', result),
  },
  (success) => {
    console.log('AppsFlyer SDK initialized successfully:', success);
    // Log a custom in-app event, e.g., a purchase
    appsFlyer.logEvent(
      'af_purchase',
      {
        af_content_id: 'product_id_123',
        af_content_type: 'product',
        af_currency: 'USD',
        af_price: 29.99,
        af_revenue: 29.99,
      },
      (eventSuccess) => console.log('Purchase event logged:', eventSuccess),
      (eventError) => console.error('Error logging purchase event:', eventError)
    );
  },
  (error) => {
    console.error('AppsFlyer SDK initialization failed:', error);
  }
);

// Example of setting up a global deep link listener
appsFlyer.onDeepLink(
  (res: DeepLinkResult) => {
    console.log('Unified Deep Link received:', res);
    // Implement deep link routing logic here
    if (res.status === 'FOUND' && res.deepLink) {
      console.log('Deep link data:', res.deepLink);
    }
  }
);

view raw JSON →