# AppsFlyer と Unity の統合

> AppsFlyer のダッシュボードで Unity Ads 統合をアクティブ化し、完全なデータ共有を有効にしてイベントをマップし、パートナーの権限を設定します。

> **Important:**
>
> 以下のドキュメントでは、Unity が開発、所有、または運用するものではない製品またはサービス ("サードパーティ製品") を取り上げます。
> その情報は、古かったり、不完全であったりする可能性がありますが、利便性のために提供しています。
> サードパーティ製品を使用する際は、その製品の規約に従うものとします。
> Unity はそれらの製品に関して一切保証を行わず、その使用によって生じた損害や損失 (サードパーティプロバイダーのコンテンツ、広告、製品、資料に関する問題を含む) について責任を負いません。

Unity のユーザー獲得キャンペーン用に、AppsFlyer をモバイル計測パートナー (MMP) として設定します。統合には以下の設定タスクがあります。

* [AppsFlyer のダッシュボードで Unity Ads をアクティブ化する](#activate-unity-ads-in-the-appsflyer-dashboard)。
* [統合の全般設定を行う](#configure-general-integration-settings)。
* [データ共有設定を行い](#configure-data-sharing-settings)、インストール後のイベントをマップする。
* [パートナーの権限を設定する](#set-partner-permissions)。

AppsFlyer との統合の最新情報については、[AppsFlyer のヘルプセンター](https://support.appsflyer.com/hc/en-us/articles/208005086-Unity-Ads-campaign-configuration) を参照してください。

## 前提条件##prerequisites

設定前に、以下の要件を満たしていることを確認してください。

* [Unity ユーザー獲得ダッシュボード](https://cloud.unity.com/acquire) に少なくとも 1 つのアプリケーションを[追加する](../../getting-started/add-an-app#add-an-app-to-the-dashboard)。
* User Acquisition (ユーザー獲得) ダッシュボードから [ゲーム ID](../../getting-started/locate-advertiser-credentials#game-id) を取得する。
* 最新バージョンの [AppsFlyer SDK](https://github.com/AppsFlyerSDK/appsflyer-unity-plugin) をダウンロードする。

## Unity と AppsFlyer の統合##integrate-unity-with-appsflyer

AppsFlyer をユーザー獲得キャンペーンに統合するために、以下の手順を実行します。

### AppsFlyer のダッシュボードで Unity Ads をアクティブ化する##activate-unity-ads-in-the-appsflyer-dashboard

[AppsFlyer のダッシュボード](https://hq1.appsflyer.com/auth/login) で Unity Ads をアクティブ化するには、以下の手順を実行します。

1. AppsFlyer のダッシュボードで **Collaborate** > **Partner Marketplace** に移動します。
2. **Unity Ads** を検索し、**Set up integration** を選択して **Integration** タブを開きます。
3. **Activate Partner** トグルをアクティブ化します。
4. 一部の広告主には、**Advanced Privacy** トグルが **Integration** タブにある場合があります。ダッシュボードにこのトグルが表示されている場合は、必ず無効にしてください。

> **Important:**
>
> 統合設定で **Advanced Privacy** トグルがアクティブ化されている場合、AppsFlyer でキャンペーンとイベントデータを共有することはできません。


**Deactivate the Advanced Privacy toggle:**
![AppsFlyer インテグレーション設定の Advanced Privacy トグル。](/api/media?file=/user-acquisition/media/images/appsflyer-advanced-privacy.png)

### 統合の全般設定を行う##configure-general-integration-settings

**Integration** タブで、**General settings** と **Install attribution** の両方のセクションを以下のように設定します。

1. **General settings**

   #### General settings

   **General settings** セクションを以下のように設定します。

   1. **Share organic/non-organic indication** トグルをアクティブ化します。


   **Share organic and non-organic:**
   ![AppsFlyer インテグレーション設定のオーガニック/非オーガニック共有トグル。](/api/media?file=/user-acquisition/media/images/appsflyer-share-organic-non-organic.png)

   2. Unity [ゲーム ID](../../getting-started/locate-advertiser-credentials#game-id) を入力します。

   > **Note:**
   >
   > User Acquisition (ユーザー獲得) ダッシュボードに表示されているゲーム ID を正確に入力してください。ゲーム ID が一致しない場合、Unity でイベントを正しく受信できません。

2. **Install attribution**

   #### Install attribution

   **Install attribution** セクションを以下のように設定します。

   1. **Install engaged click-through lookback window** の間隔を **Days** に設定します。
   2. スライダーでルックバックウィンドウの長さを **2** 日に設定します。
   3. **Install view-through attribution** トグルをアクティブ化します。
   4. **Install engaged view-through lookback window** の間隔を **Days** に設定します。
      5.スライダーでルックバックウィンドウの長さを **7** 日に設定します。


   **Set attribution lookback windows:**
   ![AppsFlyer インテグレーションタブのクリックスルールックバックウィンドウのスライダー。](/api/media?file=/user-acquisition/media/images/appsflyer-install-attribution.png)

### データ共有設定を行う##configure-data-sharing-settings

**Integration** タブで、以下のデータ共有設定を行います。

1. **Default postbacks**

   #### Default postbacks

   **Default postbacks** セクションで、**for users from** ドロップダウンを使って、**Install** イベントに対して **All media sources, including organic** を選択します。


   **Share all sources, including organic:**
   ![AppsFlyer インテグレーションタブのデフォルトのポストバックセクション。](/api/media?file=/user-acquisition/media/images/appsflyer-default-install-postbacks.png)

2. **In-app event settings**

   #### In-app event settings

   **In-app event settings** セクションを以下のように設定します。

   1. **game\_id** フィールドに [ゲーム ID](../../getting-started/locate-advertiser-credentials#game-id) を入力します。
   2. **In-app event postbacks** トグルをアクティブ化します。
   3. **In-app event postback window** を **lifetime** に設定します。


   **Set a lifetime postback window:**
   ![AppsFlyer インテグレーションタブのアプリケーション内イベントの生存期間後見ウィンドウ](/api/media?file=/user-acquisition/media/images/appsflyer-lifetime-postback-window.png)

3. **Map events**

   #### イベントをマップする

   **Integration** タブ > **In-app event postbacks** セクションで、AppsFlyer イベントを Unity イベントにマップします。

   AppsFlyer のダッシュボードで設定した任意のアプリ内イベントをマップできます。AppsFlyer イベント名のリストについては、AppsFlyer の [アプリ内イベント](https://support.appsflyer.com/hc/en-us/articles/4410481112081-In-app-events-Event-structure#predefined-event-names) に関するドキュメントを参照してください。

   > **Important:**
   >
   > **AppsFlyer event** の名称がアプリのコード内のイベント識別子と正確に一致していることを確認してください。イベントを誤ってマップすると、そのデータはキャンペーンで無視されます。

   以下の正しいイベントマッピングの例を参照してください。

   | `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:**
   ![AppsFlyer イベントマッピングテーブル](/api/media?file=/user-acquisition/media/images/appsflyer-event-mapping.png)

   必ず以下の選択を行ってください。

   * すべてのイベントで、**for users from** ドロップダウンから **All media sources, including organic** を選択します。
   * **Level Complete** および **Purchase** イベントでは、**including** ドロップダウンから **Values & revenue** を選択します。
   * **Session events** については、**including** ドロップダウンから **Values & no revenue** を選択します。

4. **Enable ad revenue data**

   #### 広告収益データを有効化

   > **Important:**
   >
   > AppsFlyer の **Revenue Settings** メニューにアクセスして Unity と広告収益データを共有するには、AppsFlyer ROI360 サブスクリプションが必要です。詳細や手順については、AppsFlyer ヘルプセンターの [広告収益アトリビューション](https://support.appsflyer.com/hc/en-us/articles/217490046-ROI360-guide-ad-revenue-attribution#connect-to-ad-revenue-integrated-partners) に関するドキュメントを参照してください。

   広告収益イベントデータをキャンペーンと共有するには、以下の手順を実行します。

   1. AppsFlyer 統合設定の **Ad revenue** タブに移動します。
   2. **Get ad revenue data** トグルをアクティブ化します。


   **Enable Ad revenue:**
   ![AppsFlyer インテグレーション設定の Get ad revenue (広告収益の取得) トグル。](/api/media?file=/user-acquisition/media/images/appsflyer-get-ad-revenue.png)

   3. AppsFlyer のダッシュボードのサイドメニューから **Settings** > **Revenue Settings** に進みます。
   4. **Revenue settings** ページの **Ad revenue** タブで、**New ad revenue integration** を選択します。
      5.収益パートナーのリストから **Unity Ads** を選択します。
      6.パートナー設定で、レポートタイプとして **Impression-level (via SDK) with Device-level (via S2S API)** を選択します。


   **Send impression-level and device-level reports:**
   ![AppsFlyer ダッシュボードでの広告収益の設定](/api/media?file=/user-acquisition/media/images/appsflyer-ad-revenue-setup.png)

   7. API 認証情報を入力します。[ゲーム ID](/user-acquisition/getting-started/locate-advertiser-credentials.md#game-id) を **アプリケーションキー** フィールドに入力します。Unity のダッシュボードから **秘密鍵** を取得するには、以下の手順を参照してください。

      **Retrieve your Secret key:**

      Unity Dashboard から秘密鍵を取得するには、以下の手順を実行します。

      1. 左側のナビゲーションメニューから **API Management** (API 管理) に進みます。
      2. **Advertising Management API** (広告管理 API) > **Service account** (サービスアカウント) を選択します。


      **Retrieve secret keys from your Advertising Management Service account:**
      ![Unity ユーザー獲得ダッシュボードの API 管理ページ](/api/media?file=/user-acquisition/media/images/api-service-account.png)

      3. サービスアカウントがない場合は、**+ New** (+ 新規) を選択します。すでにサービスアカウントがある場合は、テーブルから選択します。
      4. サービスアカウントページで **Keys** (キー) セクションに進みます。
         5.**+ Add key** (+ キーの追加) を選択して新しいキーを生成します。
         6.**Secret key** (秘密鍵) の後にあるコピー用ボタンを選択して ID をコピーします。

   8. AppsFlyer のダッシュボードの **Integration** タブに戻ります。

   9 となります。**In-app event postbacks** セクションで、広告収益イベントを `ad_revenue` にマップします。以下の正しい広告収益マッピングの例を参照してください。

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

### パートナーの権限を設定する##set-partner-permissions

**Permissions** タブで、以下の権限設定を行います。

1. **Toggle Ad Network Permissions** トグルをアクティブ化して他のすべてのトグルを有効にします。
2. 以下のトグルをアクティブ化します。

* **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)**

各権限の説明については、AppsFlyer のヘルプセンターにある [権限タブ](https://support.appsflyer.com/hc/en-us/articles/4410395957521-Set-up-an-integrated-partner#permissions-tab) のドキュメントを参照してください。
