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

# AppsFlyer

> Give your team visibility into campaign performance, scale app installs, and maximize customer LTV with a new standard of privacy-enhancing measurement and deep linking solutions.

## Supported syncing

| Sync Type | Description | Supported Sync Modes | API Reference |
| - | - | - | - |
| **Server-to-server events** | Sync mobile events that occur outside the app to AppsFlyer | Insert | [Server-to-server events docs](https://dev.appsflyer.com/hc/reference/post_s2s_inappevent) |
| **Audiences** | Import predefined audience segments as lists into AppsFlyer | Add, Remove | [Import audience docs](https://support.appsflyer.com/hc/en-us/articles/360013291857-Audiences-import-an-audience#use-the-import-audience-api) |

For more information about sync modes, refer to the [sync modes](https://docs.hightouch.com/syncs/types-and-modes.md#sync-modes) docs.

## Connect to AppsFlyer

Go to the [**Destinations** overview page](https://app.hightouch.com/destinations?from=docs) and click the **Add destination** button. Select **AppsFlyer** and click **Continue**. You can then authenticate Hightouch to AppsFlyer by entering the following fields depending on your use case:

To sync S2S events:

* **AppsFlyer V2 S2S key** to use AppsFlyer's `api3` events endpoint. Follow [these instructions in AppsFlyer's docs](https://support.appsflyer.com/hc/en-us/articles/360004562377-Managing-AppsFlyer-tokens) to create a S2S key.
* **Dev key** *(legacy)* to use AppsFlyer's `api2` events endpoint. As of December 2023, AppsFlyer has deprecated `api2`. We recommend updating your configuration to use the S2S key for best performance. If you choose to use a dev key, follow [these instructions in AppsFlyer's docs](https://support.appsflyer.com/hc/en-us/articles/211719806-App-settings-#sdk-authentication-dev-key)

For more information about upgrading from `api2` to `api3`, see AppsFlyer's announcement [here](https://support.appsflyer.com/hc/en-us/articles/20509378973457-Bulletin-Upgrading-the-AppsFlyer-S2S-API).

To sync to audiences:

* **AppsFlyer V2 API key**: You can create a V2 API key by following [these instructions](https://support.appsflyer.com/hc/en-us/articles/360004562377-Managing-API-and-Server-to-server-S2S-tokens#manage-your-tokens).

You only need to provide credentials for the sync type you intend to use. For example, if you would only like to sync S2S events, you do not need to provide an API key but are required to provide a S2S key.

## Sync configuration

Once you've set up your AppsFlyer destination and have a [model](https://docs.hightouch.com/getting-started/concepts.md#models) to pull data from, you can set up your sync configuration to begin syncing data. Go to the [**Syncs** overview page](https://app.hightouch.com/syncs?from=docs) and click the **Add sync** button to begin. Then, select the relevant model and the AppsFlyer destination you want to sync to.

### Syncing server-to-server events

You can use server-to-server events to send mobile events that occur outside the app from your servers to AppsFlyer.

Appsflyer's API requires the following event parameters:

* `app_id`
* `eventName`
* `eventValue`

The sync configuration form ensures all these are set and provides some additional options.

> [!WARNING]
>
> To ensure syncs send each event, your event model must use a truly unique [primary key](https://docs.hightouch.com/getting-started/concepts.md#unique-primary-key-requirement). See the [events syncs](https://docs.hightouch.com/syncs/types-and-modes.md#event-syncs) documentation for more information.

#### Appsflyer app ID

The app ID is the identifier used in the AppsFlyer dashboard. Insert it exactly as it appears on the dashboard. You can either provide a static value or select to **use a column** from your model. Hightouch syncs the static or column value as the [`app_id` path parameter](https://dev.appsflyer.com/hc/reference/post_s2s_inappevent#path-params) the API requires.

#### Event name

Providing an event name is required to send an event to the Appsflyer API. You can either provide a static value or select to **use a column** from your model. Hightouch syncs the static or column value as the [`eventName` body parameter](https://dev.appsflyer.com/hc/reference/post_s2s_inappevent#path-params) the API requires.

#### Event timestamp

You can optionally select a column that contains timestamps of when events occurred. If this field is empty, Appsflyer uses the time the event arrives at the server.

#### Field mapping

Hightouch lets you map model columns to event metadata. Some of the metadata fields you can map to include:

* AppsFlyer ID
* IDFV
* IP
* Operating system

The AppsFlyer ID is a required field, so ensure you include that in your mapping.

#### Event value mapping

Each event *must* contain a JSON `eventValue`, for example:

```json theme={null}
{
    "af_revenue": "6", 
    "af_currency": "USD",
    "af_content_type": "wallets",
    "af_content_id": "15854",
    "your_custom_attribute" :"456.123"
}
```

Hightouch lets you map these fields to create the JSON object the `eventValue` field expects.

![Field mapping in the Hightouch UI](https://mintcdn.com/hightouch-3c037897/L_vQfA0JQEpeGUUo/images/destinations/destination-appsflyer-event-value-mapping.png?fit=max\&auto=format\&n=L_vQfA0JQEpeGUUo\&q=85\&s=73359df180e2bd5da9015773f9e2c49e)

#### Custom mappings

You can also map additional custom data that Hightouch sends to the AppsFlyer platform as JSON using the `custom_data` field.

### Syncing audiences

This sync type lets you update which users belong to an audience.
You must use an existing audience in AppsFlyer.

#### Record matching

To identify which users to add or update in an audience, select model columns and the corresponding AppsFlyer fields. You can match on the following fields:

* App ID
* IDFV
* IDFA
* GAID
* OAID
* IMEI
* CUID
* Email
* Phone
* Braze ID
* Amplitude ID

You must include the App ID for all audience types.
Depending on whether you're syncing an Android or iOS audience, you need to include at least one additional identifier.

For Android audiences, you must also include at least one of the following:

* GAID
* OAID
* IMEI
* CUID
* Braze ID
* Amplitude ID

For iOS audiences, you must also include at least one of the following:

* IDFV
* CUID
* Braze ID
* Amplitude ID

See [AppsFlyer's docs](https://support.appsflyer.com/hc/en-us/articles/360013291857#identifier-hash) on identifiers for more information.

#### Select an existing audience or create a new one

You can create a new audience or use an existing one. When creating a new audience, you can optionally enter a name; otherwise, Hightouch defaults to the name of the associated model. To use an existing audience, you need to enter the audience's `import_key`.

To get an audience's `import_key` follow these instructions:

1. In the AppsFlyer left-side panel, go to **Integration > Audiences**.
2. Click on the name of the audience you want to update.
3. Select the **Import** tab.
4. In the **Import using API** section, choose **Add new devices/users**
5. Copy the `import_key` in the **API request body**.

For more information about the **Import Audience API**, refer to [AppsFlyer's docs](https://support.appsflyer.com/hc/en-us/articles/360013291857-Audiences-import-an-audience?query=import%20key).

#### Handling PII and hashing

By default, Hightouch automatically hashes fields that require it before sending them to Appsflyer.

You can disable this behavior in the sync configuration. If disabled, the data from the model should be appropriately normalized and hashed according to [Appsflyers's hashing requirements](https://support.appsflyer.com/hc/en-us/articles/360017807278-Audiences-additional-identifiers).

#### Delete behavior

The [delete behavior](https://docs.hightouch.com/syncs/overview.md#delete-behavior) you select dictates what to do when an audience member no longer appears in your model's query results. You have the following options:

| Behavior | Description |
| - | - |
| **Do nothing** | Keep the user in the audience |
| **Delete** | Remove the user from the audience |

## Tips and troubleshooting

To see the exact API requests and responses from each sync run, use the [live debugger](https://docs.hightouch.com/syncs/debugger.md). To get notified by Slack, PagerDuty, SMS, or email when a sync fails, set up [sync alerts](https://docs.hightouch.com/syncs/alerting.md). If you run into an issue this page doesn't cover, [contact support](#pylon-chat).
