# AppsFlyer

Empower marketers with a suite of comprehensive measurement and analytics solutions.

[AppsFlyer](https://www.appsflyer.com/) is a popular mobile attribution platform. With the
bi-directional integration between Airship and AppsFlyer, you can import attribution data
from AppsFlyer to segment and personalize messages, as well as send events back to
AppsFlyer via Airship [Real-Time Data Streaming](https://www.airship.com/docs/reference/glossary/#rtds) (RTDS).

Airship ingests *media source*, *campaign*, *campaign ID*, *attributed Ad ID*, or
*attributed adgroup* AppsFlyer parameters as Airship attributes and then sends RTDS events
back to AppsFlyer. This enables AppsFlyer to analyze Airship-driven message response.

## AppsFlyer Integration Requirements

* **Accounts**
    1. AppsFlyer
    1. Airship
        * Messaging
        * [Real-Time Data Streaming](https://www.airship.com/docs/reference/feature-packages/#data) — *Required for outbound integration only*
* **Airship project**
    * The Airship SDK must use the same user identity as the AppsFlyer SDK.

## Configuring the Inbound Integration

In Airship:

1. Next to your project name, select the dropdown menu (
), then **Settings**.
1. Under **Project settings**, select **Partner Integrations**.
1. Select **AppsFlyer**.
1. Select **Configure** for the inbound integration and follow the onscreen instructions to:
	* Create [Attributes](https://www.airship.com/docs/reference/glossary/#attributes) and an authentication token — AppsFlyer uses the token to communicate with your project in Airship
	* Add Airship as an integrated partner in AppsFlyer

## Configuring the Outbound Integration 

In Airship:

1. Next to your project name, select the dropdown menu (
), then **Settings**.
1. Under **Project settings**, select **Partner Integrations**.
1. Select **AppsFlyer**.
1. Select **Configure** for the outbound integration and follow the onscreen instructions to:
    * Activate Airship RTDS as a partner in AppsFlyer
    * Select the Airship events to send to Appsflyer

## Android Example for Associating User IDs

**Bi-directional integration with AppsFlyer**

```java
import ...
// AppsFlyer Imports
import android.util.Log;
import com.appsflyer.AppsFlyerLib;
import com.appsflyer.AppsFlyerConversionListener;

public class SampleApplication extends Application {
    private static final String AF_DEV_KEY = "YOUR_DEV_KEY_FROM_APP_SETTINGS";
    @Override
    public void onCreate() {
        super.onCreate();
		...
        AppsFlyerLib.getInstance().init(AF_DEV_KEY, conversionListener, this);
        AppsFlyerLib.getInstance().start(this);
		...
		// Associating the channelID with AppsFlyerLib
        HashMap<String, Object> customData = new HashMap<String,Object>();
        String channelId = Airship.getChannel().getId();
        customData.put("android_channel", channelId);
        AppsFlyerLib.getInstance().setAdditionalData(customData);
    }
}
```


## Email Deep Linking with AppsFlyer

You can use AppsFlyer OneLink to create deep links that direct a user from emails to your app or other content. OneLink handles deep links intelligently, so that your links open in your app when possible, but will resolve to a web browser if your users open links on a desktop computer or do not have your app installed. OneLink can be configured to work with Airship emails.

Complete these requirements in any order:

1. **Configure a link tracking domain in Airship** — A working click tracking domain is a prerequisite for this integration. Please [contact Airship Support](https://support.airship.com) if you do not know your domain address or have not yet set one up.

1. **Host your Apple App Site Association (AASA) file** — On the same domain you have configured for click tracking you will need to host the AASA file that will be responsible for opening the app in a deep link scenario. For help with generating or configuring an AASA file contact AppsFlyer support. 

1. **Configure the AppsFlyer SDK** (iOS V6.0.4 and Android V6.0.0 or later only) — You will need the AppsFlyer SDK in your application to handle deep links. See: [AppsFlyer getting started guide](https://dev.appsflyer.com/hc/docs/sdk-installation).
