> ## Documentation Index
> Fetch the complete documentation index at: https://docs.notifly.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# AppsFlyer attribution integration

> Use AppsFlyer attribution data to choose campaign recipients based on how they found your app.

> [!TIP]
>
> The AppsFlyer integration is available on Notifly's Pro and Enterprise plans.

> [!NOTE]
>
> Before setup, ask Notifly whether your project can use the integration, whether imported data counts toward data point usage, and what fees may apply.

## Overview

Send app install attribution data from AppsFlyer to Notifly. Use the data to build user groups or set conditions for who receives a campaign.

Notifly uses the AppsFlyer ID to match each analytics partner postback to a user. To enable matching, read the ID in your app and save it as the Notifly user property `$appsflyer_id`.

## Attribution fields

AppsFlyer install postbacks can include the fields below. Which fields arrive depends on the app’s privacy settings and the ad network’s data-sharing policy.

| Field | Description |
| - | - |
| `appsflyer_id` | Unique ID that AppsFlyer generates for each app install |
| `app_id` | App identifier |
| `platform` | Platform (`ios` or `android`) |
| `country_code` | Country code (ISO 3166 alpha-2) |
| `media_source` | Attributed media source |
| `pid` | Attributed ad network ID |
| `c` | Campaign name |
| `af_ad` | Ad name |
| `af_ad_id` | Ad ID |
| `af_adset` | Ad set name |
| `af_adset_id` | Ad set ID |
| `af_siteid` | Publisher or site ID |
| `install_time` | Install time |
| `match_type` | Attribution match type |
| `customer_user_id` | User ID set by the advertiser |
| `advertising_id` | Android GAID |
| `idfa` | iOS IDFA |

## Set up the integration

### 1. Activate the Notifly partner in AppsFlyer

1. In the AppsFlyer sidebar, select **Collaborate** > **Partner Integrations**, then open the **Marketplace** tab.
2. Search for **Notifly** and open its integration settings.
3. On the **Integration** tab, turn on **Activate partner** and configure the remaining integration settings.
4. If a postback section is available, confirm that install postbacks are enabled.
5. Click **Save Integration**.

> [!NOTE]
>
> For more details, see [Set up an integrated partner in AppsFlyer](https://support.appsflyer.com/hc/en-us/articles/4410395957521-Set-up-an-integrated-partner).

### 2. Store the AppsFlyer ID using the SDK

The AppsFlyer SDK generates a new ID for each app install. Call `getAppsFlyerUID` to get the ID, then use the Notifly SDK's `setUserProperties` to save it as `$appsflyer_id`.

### Prerequisites

* Install and initialize the AppsFlyer SDK.
* Install and initialize the Notifly SDK.

> [tab] Android (Kotlin)
>
> ```kotlin title="MainApplication.kt" theme={null}
> import android.app.Application
> import com.appsflyer.AppsFlyerLib
> import tech.notifly.Notifly
>
> class MainApplication : Application() {
>     override fun onCreate() {
>         super.onCreate()
>
>         Notifly.initialize(
>             applicationContext,
>             NOTIFLY_PROJECT_ID,
>             NOTIFLY_USERNAME,
>             // The SDK requires a password argument for compatibility. Pass the username again and keep passwords and API Secret Keys out of app code.
>             NOTIFLY_USERNAME
>         )
>
>         AppsFlyerLib.getInstance().init(AF_DEV_KEY, null, this)
>         AppsFlyerLib.getInstance().start(this)
>
>         val appsflyerId = AppsFlyerLib.getInstance().getAppsFlyerUID(this)
>
>         Notifly.setUserProperties(
>             applicationContext,
>             mapOf("\$appsflyer_id" to appsflyerId)
>         )
>     }
> }
> ```
>
> * [AppsFlyer Android `getAppsFlyerUID` reference](https://dev.appsflyer.com/hc/docs/android-sdk-reference-appsflyerlib#getappsflyeruid)
> * [Notifly Android `setUserProperties` guide](https://docs.notifly.tech/en/developer-guide/android-sdk#set-user-properties-notifly-setuserproperties)

> [tab] iOS (Swift)
>
> ```swift title="AppDelegate.swift" theme={null}
> import AppsFlyerLib
> import notifly_sdk
>
> func onAppLaunch() {
>     let appsflyerId = AppsFlyerLib.shared().getAppsFlyerUID()
>
>     let props: [String: Any] = [
>         "$appsflyer_id": appsflyerId
>     ]
>     Notifly.setUserProperties(userProperties: props)
> }
> ```
>
> * [AppsFlyer iOS `getAppsFlyerUID` reference](https://dev.appsflyer.com/hc/docs/ios-sdk-reference-appsflyerlib#getappsflyeruid)
> * [Notifly iOS `setUserProperties` guide](https://docs.notifly.tech/en/developer-guide/ios-sdk#2-set-user-properties)

> [tab] React Native
>
> ```typescript title="App.tsx" theme={null}
> import appsFlyer from 'react-native-appsflyer';
> import notifly from 'notifly-sdk';
>
> export function setAppsFlyerIdToNotifly() {
>   appsFlyer.getAppsFlyerUID((err, appsFlyerUID) => {
>     if (err || !appsFlyerUID) return;
>     notifly.setUserProperties({ $appsflyer_id: appsFlyerUID });
>   });
> }
> ```
>
> The example uses a callback with the AppsFlyer React Native plugin v6.18.0. With v7, await `getAppsFlyerUID()` without a callback, then store the returned ID as `$appsflyer_id`.
>
> * [AppsFlyer React Native v6.18.0 API reference](https://github.com/AppsFlyerSDK/appsflyer-react-native-plugin/blob/v6.18.0/Docs/RN_API.md#getappsflyeruid)
> * [AppsFlyer React Native v7.0.4 API reference](https://github.com/AppsFlyerSDK/appsflyer-react-native-plugin/blob/v7.0.4/Docs/RN_API.md#getappsflyeruid)
> * [Notifly React Native `setUserProperties` guide](https://docs.notifly.tech/en/developer-guide/react-native-sdk#2-set-user-properties)

> [tab] Flutter
>
> ```dart title="main.dart" theme={null}
> import 'package:appsflyer_sdk/appsflyer_sdk.dart';
> import 'package:notifly_flutter/notifly_flutter.dart';
>
> Future<void> setAppsFlyerIdToNotifly(AppsflyerSdk af) async {
>   final appsflyerId = await af.getAppsFlyerUID();
>   if (appsflyerId == null || appsflyerId.isEmpty) return;
>
>   await NotiflyPlugin.setUserProperties({
>     r'$appsflyer_id': appsflyerId,
>   });
> }
> ```
>
> This example uses the AppsFlyer Flutter plugin v6.18.1. In v7, the class is named `AppsFlyerSdk` and the method is still `getAppsFlyerUID()`.
>
> * [AppsFlyer Flutter v6.18.1 API reference](https://pub.dev/documentation/appsflyer_sdk/6.18.1/appsflyer_sdk/AppsflyerSdk/getAppsFlyerUID.html)
> * [AppsFlyer Flutter v7.0.4 API reference](https://pub.dev/documentation/appsflyer_sdk/7.0.4/appsflyer_sdk/AppsFlyerSdk/getAppsFlyerUID.html)
> * [Notifly Flutter `setUserProperties` guide](https://docs.notifly.tech/en/developer-guide/flutter-sdk#2-set-user-properties)

## Campaign examples

After setup, use attribution properties to choose which users receive a campaign.

### Example audience conditions

* To find users with an AppsFlyer ID stored in Notifly, filter for users who have `$appsflyer_id`.
* Use `media_source` to target users acquired through a particular ad network. For example, set `media_source = "googleadwords_int"`.

### Example messaging campaign

* Use the ad campaign name (`c`) to tailor the message that introduces your app to new users from each campaign. Send it as a push notification or in-app popup.

## FAQ

> [accordion] What happens if I don't set \$appsflyer\_id?
>
> Notifly needs `$appsflyer_id` to match the postback to a user. Only matched attribution data is available in user groups and campaigns.

> [accordion] What happens if the install postback arrives before I set \$appsflyer\_id?
>
> Notifly cannot match any postback that arrives before `$appsflyer_id` is set. Set `$appsflyer_id` as early as possible when the app starts.

> [accordion] How do I test the integration?
>
> 1. Run the app to set `$appsflyer_id`.
> 2. In the Notifly console, check that the user's properties include `$appsflyer_id`.
> 3. Follow the [AppsFlyer SDK integration testing guide](https://support.appsflyer.com/hc/en-us/articles/360001559405-Testing-the-SDK-integration-for-marketers) to run a test install on a registered device. Check the user's Notifly profile for the attribution data.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.