# Integrate AppsFlyer with Unity

> Activate the Unity Ads integration in the AppsFlyer dashboard, enable full data-sharing, map events, and set partner permissions.

> **Important:**
>
> The following documentation discusses products or services (“Third-party Products”) not developed, owned, or operated by Unity.
> This information might be outdated or incomplete and is provided for your convenience.
> Your use of any Third-party Product is subject to its own terms.
> Unity makes no warranties regarding these products and isn't liable for any damages or losses arising from their use, including issues related to content, advertising, or materials from Third-party providers.

Set up AppsFlyer as your Mobile Measurement Partner (MMP) for Unity User Acquisition campaigns. Integration includes the following setup tasks:

* [Activate Unity Ads in the AppsFlyer dashboard](#activate-unity-ads-in-the-appsflyer-dashboard).
* [Configure general integration settings](#configure-general-integration-settings).
* [Configure data-sharing settings](#configure-data-sharing-settings) and map post-install events.
* [Set partner permissions](#set-partner-permissions).

For the most up-to-date AppsFlyer integration information, consult the [AppsFlyer Help Center.](https://support.appsflyer.com/hc/en-us/articles/208005086-Unity-Ads-campaign-configuration)

## Prerequisites

Before setup, ensure you meet the following requirements:

* [Add](../../getting-started/add-an-app#add-an-app-to-the-dashboard) at least one app in the [Unity User Acquisition dashboard](https://cloud.unity.com/acquire).
* Retrieve your [Game ID](../../getting-started/locate-advertiser-credentials#game-id) from the User Acquisition dashboard.
* Download the latest version of the [AppsFlyer SDK](https://github.com/AppsFlyerSDK/appsflyer-unity-plugin).

## Integrate Unity with AppsFlyer

Complete the following steps to integrate AppsFlyer with your User Acquisition campaign:

### Activate Unity Ads in the AppsFlyer dashboard

To activate Unity Ads in the [AppsFlyer dashboard](https://hq1.appsflyer.com/auth/login), follow these steps:

1. In the AppsFlyer dashboard, go to **Collaborate** > **Partner Marketplace**.
2. Search for **Unity Ads** and select **Set up integration** to open in the **Integration** tab.
3. Activate the **Activate Partner** toggle.
4. Some advertisers might have an **Advanced Privacy** toggle in the **Integration** tab. If your dashboard contains this toggle, ensure that you deactivate it.

> **Important:**
>
> If the **Advanced Privacy** toggle is activated in your integration setup, AppsFlyer can't share any event data with your campaign.


**Deactivate the Advanced Privacy toggle:**
![The Advanced Privacy toggle in the AppsFlyer integration setup](/api/media?file=/user-acquisition/media/images/appsflyer-advanced-privacy.png)

### Configure general integration settings

In the **Integration** tab, configure both the **General settings** and **Install attribution** sections as follows:

1. **General settings**

   #### General settings

   Configure the **General settings** section as follows:

   1. Activate the **Share organic/non-organic indication** toggle.


   **Share organic and non-organic:**
   ![The Share organic/non-organic toggle in the AppsFlyer integration setup](/api/media?file=/user-acquisition/media/images/appsflyer-share-organic-non-organic.png)

   2. Enter your Unity [Game ID](../../getting-started/locate-advertiser-credentials#game-id).

   > **Note:**
   >
   > Enter your Game ID exactly as shown in the User Acquisition dashboard. Mismatched Game IDs prevent Unity from receiving events correctly.

2. **Install attribution**

   #### Install attribution

   Configure the **Install attribution** section as follows:

   1. Set the **Install engaged click-through lookback window** interval to **Days**.
   2. Use the slider to set the lookback window length to **2** days.
   3. Activate the **Install view-through attribution** toggle.
   4. Set the **Install engaged view-through lookback window** interval to **Days**.
   5. Use the slider to set the lookback window length to **7** days.


   **Set attribution lookback windows:**
   ![The click-through lookback window slider in the AppsFlyer Integration tab](/api/media?file=/user-acquisition/media/images/appsflyer-install-attribution.png)

### Configure data-sharing settings

In the **Integration** tab, configure the following data-sharing settings:

1. **Default postbacks**

   #### Default postbacks

   In the **Default postbacks** section, use the **for users from** dropdown to select **All media sources, including organic** for **Install** events.


   **Share all sources, including organic:**
   ![The Default postbacks section of the AppsFlyer Integration tab](/api/media?file=/user-acquisition/media/images/appsflyer-default-install-postbacks.png)

2. **In-app event settings**

   #### In-app event settings

   Configure the **In-app event settings** section as follows:

   1. Enter your [Game ID](../../getting-started/locate-advertiser-credentials#game-id) in the **game\_id** field.
   2. Activate the **In-app event postbacks** toggle.
   3. Set the **In-app event postback window** to **lifetime**.


   **Set a lifetime postback window:**
   ![The lifetime in-app event postback lookback window in the AppsFlyer Integration tab](/api/media?file=/user-acquisition/media/images/appsflyer-lifetime-postback-window.png)

3. **Map events**

   #### Map events

   In the **Integration** tab > **In-app event postbacks** section, map AppsFlyer events to Unity events.

   You can map any in-app event you set up in the AppsFlyer dashboard. Refer to AppsFlyer's [In-app events](https://support.appsflyer.com/hc/en-us/articles/4410481112081-In-app-events-Event-structure#predefined-event-names) documentation for a list of AppsFlyer event names.

   > **Important:**
   >
   > Ensure that your **AppsFlyer event** name matches the event identifiers in your app's code exactly. If you incorrectly map an event, your campaign ignores the data.

   Refer to the following example of correct event mapping:

   | `af_purchase`          | `purchase`       | All media sources, including organic | Values & revenue    |
   | ---------------------- | ---------------- | ------------------------------------ | ------------------- |
   | `milestone_event_name` | `level_complete` | All media sources, including organic | Values & revenue    |
   | `af_app_opened`        | `session`        | All media sources, including organic | Values & no revenue |


   **Map events to Unity event names:**
   ![The AppsFlyer event mapping table](/api/media?file=/user-acquisition/media/images/appsflyer-event-mapping.png)

   Ensure that you make the following selections:

   * For all events, select **All media sources, including organic** in the **for users from** dropdown.
   * For **Level Complete** and **Purchase** events, select **Values & revenue** from the **including** dropdown.
   * For **Session events**, select **Values & no revenue** from the **including** dropdown.

4. **Enable ad revenue data**

   #### Enable ad revenue data

   > **Important:**
   >
   > To access the AppsFlyer **Revenue Settings** menu and share ad revenue data with Unity, you need an AppsFlyer ROI360 subscription. Refer to the [Ad revenue attribution](https://support.appsflyer.com/hc/en-us/articles/217490046-ROI360-guide-ad-revenue-attribution#connect-to-ad-revenue-integrated-partners) documentation in the AppsFlyer Help Center for details and instructions.

   To share ad revenue event data with your campaign, follow these steps:

   1. Go to the **Ad revenue** tab of your AppsFlyer integration setup.
   2. Activate the **Get ad revenue data** toggle.


   **Enable Ad revenue:**
   ![The Get ad revenue toggle in the AppsFlyer integration setup](/api/media?file=/user-acquisition/media/images/appsflyer-get-ad-revenue.png)

   3. From the AppsFlyer dashboard side menu, go to **Settings** > **Revenue Settings**.
   4. In the **Ad revenue** tab of the **Revenue settings** page, select **New ad revenue integration**.
   5. Select **Unity Ads** from the list of revenue partners.
   6. In the partner configuration, select **Impression-level (via SDK) with Device-level (via S2S API)** as the report type.


   **Send impression-level and device-level reports:**
   ![The ad revenue setup in the AppsFlyer dashboard](/api/media?file=/user-acquisition/media/images/appsflyer-ad-revenue-setup.png)

   7. Enter your API credentials. Enter your [Game ID](/user-acquisition/getting-started/locate-advertiser-credentials.md#game-id) in the **App Key** field. To retrieve your **Secret key** from the Unity dashboard, refer to the following steps:

      **Retrieve your Secret key:**

      To retrieve your Secret key from the Unity Dashboard, follow these steps:

      1. From the left navigation menu, go to **API Management**.
      2. Select **Advertising Management API** > **Service account**.


      **Retrieve secret keys from your Advertising Management Service account:**
      ![The API Management page of the Unity User Acquisition Dashboard](/api/media?file=/user-acquisition/media/images/api-service-account.png)

      3. If you don't have a service account, select **+ New**. If you have a service account already, select it from the table.
      4. In the service account page, go to the **Keys** section.
      5. Select **+ Add key** to generate a new key.
      6. Select the copy buttons following the **Secret key** to copy the ID.

   8. Go back to the **Integration** tab of the AppsFlyer dashboard.

   9. In the **In-app event postbacks** section, map Ad Revenue events to `ad_revenue`. Refer to the following example of correct ad revenue mapping:

   | `af_ad_revenue` | `ad_revenue` | All media sources, including organic | Values & revenue |
   | --------------- | ------------ | ------------------------------------ | ---------------- |

### Set partner permissions

In the **Permissions** tab, configure the following permissions settings:

1. Activate the **Toggle Ad Network Permissions** toggle to enable all other toggles.
2. Activate the following toggles:

* **Configure integration**
* **Configure in-app event postbacks**
* **Access retention report**
* **Access aggregate conversions and in-app event data**
* **Access aggregate revenue data**
* **View validation rules**
* **Access Protect360 dashboard and raw data**
* **Access ad revenue raw data (UA signals)**

For descriptions of each permission, refer to the [Permissions tab](https://support.appsflyer.com/hc/en-us/articles/4410395957521-Set-up-an-integrated-partner#permissions-tab) documentation in the AppsFlyer Help Center.
