AppsFlyer React Native SDK
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
-
TypeError: AppsFlyerConsent.forGDPRUser is not a function
cause Attempting to use deprecated consent management methods after version 6.16.2.fixReplace `AppsFlyerConsent.forGDPRUser` or `AppsFlyerConsent.forNonGDPRUser` with the new `AppsFlyerConsent` constructor as per the latest documentation for DMA compliance. -
Type error: Property 'purchaseRevenueAdditionalParametersForProducts' does not exist on type 'PurchaseRevenueDataSource'
cause Using the old TypeScript interfaces for Purchase Connector data sources after the breaking change in version 6.17.1.fixUpdate your TypeScript code to use the `additionalParameters` object directly on the `PurchaseRevenueDataSource` or `PurchaseRevenueDataSourceStoreKit2` interfaces. -
Could not GET 'https://repo.maven.apache.org/maven2/com/appsflyer/af-android-sdk/6.15.1/af-android-sdk-6.15.1.pom'. Received status code 403 from server: Forbidden
cause Common error during Android build due to network issues, repository access, or incorrect Gradle setup.fixVerify your internet connection. Ensure your `android/build.gradle` file's `allprojects` block includes `mavenCentral()` or `google()` repositories. Sometimes, clearing Gradle cache (`./gradlew clean` and deleting `.gradle` folder in `android/` directory) helps. -
ERROR: JAVA_HOME is set to an invalid directory. It must be set to a JDK, not a JRE.
cause Incorrect Java Development Kit (JDK) configuration, often after upgrading the Android SDK version which now requires Java 17.fixEnsure `JAVA_HOME` environment variable points to a valid JDK installation (e.g., OpenJDK 17) and not just a JRE. Reinstalling or updating your JDK and adjusting environment variables is usually required.
Warnings
- breaking Starting with version 6.17.1, the TypeScript interfaces for Purchase Connector data sources (`PurchaseRevenueDataSource` and `PurchaseRevenueDataSourceStoreKit2`) have undergone breaking changes. Specifically, `purchaseRevenueAdditionalParametersForProducts()` and `purchaseRevenueAdditionalParametersStoreKit2ForProducts()` functions have been replaced with a simpler `additionalParameters` object.
- deprecated Starting with version 6.16.2, `AppsFlyerConsent.forGDPRUser` and `AppsFlyerConsent.forNonGDPRUser` constructors have been deprecated. Using these will result in warnings or runtime errors.
- breaking Version 6.15.1 introduced significant changes for Android builds, upgrading to targetSDKVersion 34, Java 17, and Gradle 8.7. This requires your React Native project's Android setup to match these versions or be compatible, potentially causing build failures if not addressed.
- breaking As of version 6.15.1, the iOS minimum deployment target has been increased to 12.0. Projects targeting older iOS versions will fail to build.
Install
-
npm install react-native-appsflyer -
yarn add react-native-appsflyer -
pnpm add react-native-appsflyer
Imports
- appsFlyer
const appsFlyer = require('react-native-appsflyer');import appsFlyer from 'react-native-appsflyer';
- AppsFlyerConsent
import AppsFlyerConsent from 'react-native-appsflyer/AppsFlyerConsent';
import { AppsFlyerConsent } from 'react-native-appsflyer'; - DeepLinkResult
import { DeepLinkResult } from 'react-native-appsflyer';import type { DeepLinkResult } from 'react-native-appsflyer';
Quickstart
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);
}
}
);