Expo Installation
Install AppsFlyer in an Expo managed project
- Install
expo-dev-client. You can read more about expo development builds here:
expo install expo-dev-client
- Install react-native-appsflyer:
expo install react-native-appsflyer
- Add
react-native-appsflyerinto thepluginsarray inside theapp.jsonfile of your app:
...
"plugins": [
[
"react-native-appsflyer",
{
"shouldUseStrictMode": false, // optional – kids-apps strict mode
"shouldUsePurchaseConnector": true, // optional – enables Purchase Connector
"preferAppsFlyerBackupRules": false // optional – use AppsFlyer SDK backup rules (default: false)
}
]
],
...
- optional If you are developing a kids app and you wish to use our strict mode, you should add
"shouldUseStrictMode": trueas followed:
...
"plugins": [
[
"react-native-appsflyer",{"shouldUseStrictMode": true}
]
],
...
Backup Rules Configuration (Android)
The AppsFlyer SDK includes built-in backup rules in its Android manifest to ensure accurate install/reinstall detection. By default, the plugin respects your app's backup rules and does not modify them.
Default Behavior (preferAppsFlyerBackupRules: false or omitted):
- Your app's
android:dataExtractionRulesandandroid:fullBackupContentattributes are left untouched - You maintain full control over your app's backup policy
- No manifest merge conflicts occur
Opt-in Behavior (preferAppsFlyerBackupRules: true):
- If your app defines backup rules, they will be removed to let AppsFlyer SDK's built-in rules take precedence
- This ensures AppsFlyer SDK's backup rules are used, which may improve install/reinstall detection accuracy
- Use this flag if you want AppsFlyer SDK to manage backup rules for you
When to use preferAppsFlyerBackupRules: true:
- You want AppsFlyer SDK to handle backup rules automatically
- You're experiencing issues with install/reinstall detection that may be related to backup rules
- You don't have specific backup requirements for your app
Example configuration:
{
"expo": {
"plugins": [
[
"react-native-appsflyer",
{
"preferAppsFlyerBackupRules": true
}
]
]
}
}
Handling dataExtractionRules Conflict
When building your Expo app with the AppsFlyer plugin, you might encounter a build error related to the dataExtractionRules attribute. This issue arises due to a conflict between the dataExtractionRules defined in your project’s AndroidManifest.xml and the one included in the AppsFlyer SDK.
Solution: Creating a Custom Plugin to Modify AndroidManifest.xml
To resolve this, you can create a custom Expo config plugin that modifies the AndroidManifest.xml during the build process. This approach allows you to adjust the manifest without directly editing it, maintaining compatibility with the managed workflow.
Steps to Implement the Custom Plugin:
- Create the Plugin File:
- In your project’s root directory, create a file named withCustomAndroidManifest.js.
- Define the Plugin Function:
- In withCustomAndroidManifest.js, define a function that uses Expo’s withAndroidManifest to modify the manifest. This function will remove the conflicting dataExtractionRules attribute.
// withCustomAndroidManifest.js
const { withAndroidManifest } = require('@expo/config-plugins');
module.exports = function withCustomAndroidManifest(config) {
return withAndroidManifest(config, async (config) => {
const androidManifest = config.modResults;
const manifest = androidManifest.manifest;
// Ensure xmlns:tools is present in the <manifest> tag
if (!manifest.$['xmlns:tools']) {
manifest.$['xmlns:tools'] = 'http://schemas.android.com/tools';
}
const application = manifest.application[0];
// Add tools:replace attribute for dataExtractionRules and fullBackupContent
application['$']['tools:replace'] = 'android:dataExtractionRules, android:fullBackupContent';
// Set dataExtractionRules and fullBackupContent as attributes within <application>
application['$']['android:dataExtractionRules'] = '@xml/secure_store_data_extraction_rules';
application['$']['android:fullBackupContent'] = '@xml/secure_store_backup_rules';
return config;
});
};
- Update app.json or app.config.js:
- In your app configuration file, include the custom plugin to ensure it’s executed during the build process.
// app.json
{
"expo": {
// ... other configurations ...
"plugins": [
"./withCustomAndroidManifest.js",
[
"react-native-appsflyer",
{
"shouldUseStrictMode": true
}
]
]
}
}
By implementing this custom plugin, you can resolve the dataExtractionRules conflict without directly modifying the AndroidManifest.xml.
The AD_ID permission for android apps
In v6.8.0 of the AppsFlyer SDK, we added the normal permission com.google.android.gms.permission.AD_ID to the SDK's AndroidManifest,
to allow the SDK to collect the Android Advertising ID on apps targeting API 33.
If your app is targeting children, you need to revoke this permission to comply with Google's Data policy.
You can read more about it here.
Purchase Connector (optional)
Setting "shouldUsePurchaseConnector": true will:
- iOS – add the
PurchaseConnectorCocoaPod automatically - Android – add
appsflyer.enable_purchase_connector=truetogradle.properties
Plugin Options Summary
| Option | Type | Default | Description |
|---|---|---|---|
shouldUseStrictMode | boolean | false | Enable strict mode for kids apps |
shouldUsePurchaseConnector | boolean | false | Enable Purchase Connector support |
preferAppsFlyerBackupRules | boolean | false | Remove app's backup rules to use AppsFlyer SDK's built-in rules (Android only) |
Updated 14 days ago