---
title: "AppsFlyer"
description: "モバイルアトリビューション追跡を高度に行うために、AppsFlyerをAdaptyと連携させましょう。"
---

[AppsFlyer](https://www.appsflyer.com/) は、モバイルアトリビューションとマーケティング分析のリーディングプラットフォームです。マーケティングキャンペーンのデータを収集・整理するサードパーティサービスであり、企業がキャンペーンのパフォーマンスを一か所で確認できるようにします。

Adaptyは、各ストアからのサブスクリプションイベントを一か所で追跡できる完全なデータセットを提供しています。Adaptyを使えば、サブスクライバーの行動を簡単に把握し、好みを理解して、ターゲットを絞った効果的なコミュニケーションに活用できます。この連携により、AppsFlyerでサブスクリプションイベントを追跡し、キャンペーンが生み出す収益を正確に分析できます。

AdaptyとAppsFlyerの連携は、主に2つの方向で機能します。

1. **AppsFlyerからアトリビューションデータを受信する**  
   [アプリのコードでAppsFlyerアトリビューションをAdaptyに送信する設定](appsflyer#connect-your-app-to-appsflyer)を完了すると、AdaptyはAppsFlyerからアトリビューションデータを受信し始めます。このデータはユーザーのプロファイルページで確認できます。

  <img src="/assets/shared/img/c2991f6-CleanShot_2023-08-04_at_16.29.202x.webp"
  style={{
    border: '1px solid #727272', /* border width and color */
    width: '700px', /* image width */
    display: 'block', /* for alignment */
    margin: '0 auto' /* center alignment */
  }}
/>

2. **AppsFlyerにサブスクリプションイベントを送信する**  
   Adaptyは、連携で設定されたすべてのサブスクリプションイベントをAppsFlyerに送信できます。これにより、AppsFlyerのダッシュボード内でこれらのイベントを追跡できるようになります。この連携は、広告キャンペーンの効果を評価するのに役立ちます。

## 設定のセットアップ \{#set-up-configuration\}

### AdaptyをAppsFlyerに接続する \{#connect-adapty-to-appsflyer\}

AppsFlyerとの連携をセットアップするには：

1. Adapty ダッシュボードで [**Integrations** -> **AppsFlyer**](https://app.adapty.io/integrations/appsflyer) を開きます。

2. トグルをオンにして連携を有効にします。

3. 次のステップは認証情報の設定です。  
   iOSの場合、App Store Connectで **Apple ID** を確認します（[App Store Connect](https://appstoreconnect.apple.com/) でアプリページを開き、**General** セクションの **App Information** ページに移動して、画面左下の **Apple ID** を確認してください）。

  <img src="/assets/shared/img/43a5cc6-apple_id.webp"
  style={{
    border: '1px solid #727272', /* border width and color */
    width: '700px', /* image width */
    display: 'block', /* for alignment */
    margin: '0 auto' /* center alignment */
  }}
/>

3.2. コピーした **Apple ID** を、Adapty ダッシュボードの **iOS App ID** フィールドに貼り付けます。

  <img src="/assets/shared/img/61bff5a-appsflyer_iOS_app_id.webp"
  style={{
    border: '1px solid #727272', /* border width and color */
    width: '700px', /* image width */
    display: 'block', /* for alignment */
    margin: '0 auto' /* center alignment */
  }}
/>

:::warning

AppsFlyer API 2を使用している場合は、AppsFlyerが旧バージョンを間もなく廃止するため、API 3に切り替える必要があります。切り替えるには、**AppsFlyer S2S API** リストで **API 3** を選択してください。

:::

5. iOSとAndroidの両方について、[AppsFlyerサイト](https://www.appsflyer.com/home)を開いてログインします。

6. ダッシュボード右上の **Your account name** -> **Security Center** をクリックします。

  <img src="/assets/shared/img/1c18c50-appsflyer_security_center.webp"
  style={{
    border: '1px solid #727272', /* border width and color */
    width: '700px', /* image width */
    display: 'block', /* for alignment */
    margin: '0 auto' /* center alignment */
  }}
/>

7. **Manage your account security** ウィンドウで、**Manage your AppsFlyer API and S2S tokens** ボタンをクリックします。

8. S2Sトークンがある場合はステップ12に進んでください。ない場合は、**New token** ボタンをクリックします。

  <img src="/assets/shared/img/7934920-appsflyer_new_token.webp"
  style={{
    border: '1px solid #727272', /* border width and color */
    width: '700px', /* image width */
    display: 'block', /* for alignment */
    margin: '0 auto' /* center alignment */
  }}
/>

9. **New token** ウィンドウで、トークンの名前を入力します。この名前は自分の参照用のみです。

10. **Choose type** リストで **S2S** を選択します。

11. **Create new token** ボタンをクリックして新しいトークンを保存します。

12. **Tokens** ウィンドウで、S2Sトークンをコピーします。

13. Adapty ダッシュボードで、コピーしたS2Sキーを **Dev key for iOS** と **Dev key for Android** フィールドに貼り付けます。

  <img src="/assets/shared/img/a7d1c31-appsflyer_dev_keys.webp"
  style={{
    border: '1px solid #727272', /* border width and color */
    width: '700px', /* image width */
    display: 'block', /* for alignment */
    margin: '0 auto' /* center alignment */
  }}
/>

14. **Save** ボタンをクリックして変更を保存します。

    :::info
    
    AppsFlyerにはサーバー間連携用のサンドボックスモードがありません。そのため、サンドボックスの Dev Key にはAppsFlyer内で別のアプリ/アカウントが必要です。サンドボックスイベントを同じアプリに送信したい場合は、本番環境とサンドボックスで同じキーを使用してください。
    :::

Adaptyはデフォルトで一部のイベントをAppsFlyerの[標準イベント](https://support.appsflyer.com/hc/en-us/articles/115005544169-Rich-in-app-events-for-Android-and-iOS#event-types)にマッピングします。この設定により、AppsFlyerは追加設定なしで使用している各広告ネットワークにイベントを転送できます。

もう一つ重要な点として、AppsFlyerは26時間以上古いイベントをサポートしていません。そのため、26時間以上前のイベントはAdaptyからAppsFlyerに送信されますが、イベントの日時は現在のタイムスタンプに置き換えられます。

### イベントとタグの設定 \{#configure-events-and-tags\}

認証情報の下には、AdaptyからAppsFlyerに送信できる3つのイベントグループがあります。必要なものをオンにするだけです。Adaptyが提供するイベントの完全なリストは[こちら](events)で確認できます。

  <img src="/assets/shared/img/1b0c777-CleanShot_2023-08-11_at_14.56.362x.webp"
  style={{
    border: '1px solid #727272', /* border width and color */
    width: '700px', /* image width */
    display: 'block', /* for alignment */
    margin: '0 auto' /* center alignment */
  }}
/>

Adaptyが提供するデフォルトのイベント名を使用することを推奨します。ただし、必要に応じてイベント名を変更することも可能です。

Adaptyはサーバー間連携を使用してサブスクリプションイベントをAppsFlyerに送信します。これにより、AppsFlyerのダッシュボードですべてのサブスクリプションイベントを確認し、獲得キャンペーンと紐付けることができます。

### アプリをAppsFlyerに接続する \{#connect-your-app-to-appsflyer\}

上記の手順を完了したら、`updateAttribution` メソッドを呼び出してアトリビューションデータを保存し、`Adapty.setIntegrationIdentifier()` を使用して連携識別子を設定します。

AppsFlyerのSDKを初期化し、AdaptyでユーザーのIDを設定する前にUIDコールバックを待ってください。そうしないと、`appsflyer_id` がSDKのアクティベーション時に一時的に作成される匿名のAdaptyプロファイルに紐付けられてしまい、識別済みのプロファイルに常には引き継がれません。この状態になると、AppsFlyerへの収益の転送がサイレントに失敗します。

<Tabs groupId="current-os" queryString>
<TabItem value="swift" label="iOS (Swift)" default>

```swift showLineNumbers
class YourAppsFlyerLibDelegateImplementation {
    // Find your implementation of AppsFlyerLibDelegate 
    // and update onConversionDataSuccess method:
    func onConversionDataSuccess(_ conversionInfo: [AnyHashable : Any]) {
        let uid = AppsFlyerLib.shared().getAppsFlyerUID()
        // Adapty SDK 4.x
        Adapty.setIntegrationIdentifier(.appsflyerId(uid))
        Adapty.updateAttribution(conversionInfo, source: .appsflyer)
        // Adapty SDK 3.x
        Adapty.setIntegrationIdentifier(key: "appsflyer_id", value: uid)
        Adapty.updateAttribution(conversionInfo, source: "appsflyer")
    }
}
```
</TabItem>

<TabItem value="kotlin" label="Android (Kotlin)" default>

```kotlin showLineNumbers
val conversionListener: AppsFlyerConversionListener = object : AppsFlyerConversionListener {
    override fun onConversionDataSuccess(conversionData: Map<String, Any>) {
        val uid = AppsFlyerLib.getInstance().getAppsFlyerUID(context)
        Adapty.setIntegrationIdentifier("appsflyer_id", uid) { error ->
            if (error != null) {
                // handle the error
            }
        }
        Adapty.updateAttribution(conversionData, "appsflyer") { error ->
            if (error != null) {
                //handle the error
            }
        }
    }
}
```
</TabItem>
<TabItem value="rn" label="React Native (TS)" default>

```typescript showLineNumbers

appsFlyer.onInstallConversionData(installData => {
    appsFlyer.getAppsFlyerUID((error, networkUserId) => {
        if (error) {
            // handle the error
        }
        try {
            adapty.updateAttribution(installData, AttributionSource.AppsFlyer, networkUserId);
        } catch (error) {
            // handle the error
        }
    });
});

// ...
appsFlyer.initSdk(/*...*/);
```
</TabItem>
<TabItem value="flutter" label="Flutter (Dart)" default>

```javascript showLineNumbers

AppsflyerSdk appsflyerSdk = AppsflyerSdk(<YOUR_OPTIONS>);

appsflyerSdk.onInstallConversionData((data) async {
    try {
        final appsFlyerUID = await appsFlyerSdk.getAppsFlyerUID();
        
        await Adapty().setIntegrationIdentifier(
          key: "appsflyer_id", 
          value: appsFlyerUID,
        );
        
        await Adapty().updateAttribution(data, source: "appsflyer");
    } on AdaptyError catch (adaptyError) {
        // handle the error
    } catch (e) {
        // handle the error
    }
});

appsflyerSdk.initSdk(
    registerConversionDataCallback: true,
    registerOnAppOpenAttributionCallback: true,
    registerOnDeepLinkingCallback: true,
);
```
</TabItem>
<TabItem value="unity" label="Unity (C#)" default>

```csharp showLineNumbers
using AdaptySDK;
using AppsFlyerSDK;

// before SDK initialization
AppsFlyer.getConversionData(this.name);

// in your IAppsFlyerConversionData
void onConversionDataSuccess(string conversionData) {
    string appsFlyerId = AppsFlyer.getAppsFlyerId();
    
    Adapty.SetIntegrationIdentifier(
      "appsflyer_id", 
      appsFlyerId, 
      (error) => {
        // handle the error
    });
    
    Adapty.UpdateAttribution(
      conversionData, 
      "appsflyer",
      (error) => {
        // handle the error
    });
}
```
</TabItem>
</Tabs>

## イベント構造 \{#event-structure\}

AdaptyはPOSTリクエストのJSONボディを使用して、選択されたイベントをAppsFlyerに送信します。送信先は以下のとおりです：
- API v2: `https://api2.appsflyer.com/inappevent/{app_id}`
- API v3: `https://api3.appsflyer.com/inappevent/{app_id}`（推奨）

各イベントの構造は次のとおりです：

```json
{
  "appsflyer_id": "1699887556000-6192770",
  "eventName": "subscription_renewed",
  "eventTime": "2024-03-01 12:00:00",
  "eventValue": "{\"af_content_id\":\"yearly.premium.6999\",\"af_order_id\":\"GPA.3383-4699-1373-07113\",\"store_country\":\"US\",\"profile_country\":\"US\",\"af_content_type\":\"in_app\",\"af_revenue\":\"9.9900\",\"af_currency\":\"USD\",\"af_quantity\":\"1\"}",
  "os": "17.0.1",
  "bundleIdentifier": "com.example.app",
  "customer_user_id": "user_12345",
  "eventCurrency": "USD",
  "ip": "192.168.100.1",
  "advertising_id": "00000000-0000-0000-0000-000000000000",
  "idfa": "00000000-0000-0000-0000-000000000000",
  "idfv": "00000000-0000-0000-0000-000000000000",
  "att": "3"
}
```

各パラメータの説明：

| パラメータ           | 型      | 説明                                                                        |
|:-------------------|:-------|:---------------------------------------------------------------------------|
| `appsflyer_id`     | String | AppsFlyerのID（SDK経由で収集）。                                              |
| `eventName`        | String | AppsFlyerのイベント名（Adaptyイベントからマッピング）。                           |
| `eventTime`        | String | イベントの日時（UTC、`YYYY-MM-DD HH:MM:SS` 形式）。                             |
| `eventValue`       | String | イベント詳細を含むJSON文字列（下記参照）。                                        |
| `os`               | String | OSバージョン。                                                               |
| `bundleIdentifier` | String | アプリのバンドルID / パッケージ名。                                             |
| `customer_user_id` | String | ユーザーのCustomer User ID。                                                 |
| `eventCurrency`    | String | 通貨コード（例："USD"）。                                                      |
| `ip`               | String | ユーザーのIPアドレス。                                                         |
| `advertising_id`   | String | **Androidのみ**。Google Advertising ID。                                     |
| `idfa`             | String | **iOSのみ**。ID for Advertisers。                                            |
| `idfv`             | String | **iOSのみ**。ID for Vendors。                                                |
| `att`              | String | **iOSのみ**。App Tracking Transparencyのステータス（例："3" は authorized）。   |

`eventValue` パラメータは、以下のフィールドを含むJSONエンコードされた文字列です：

| パラメータ          | 型      | 説明                                     |
|:------------------|:-------|:----------------------------------------|
| `af_content_id`   | String | ストアのプロダクトID。                        |
| `af_order_id`     | String | 元のトランザクションID。                       |
| `store_country`   | String | ストアユーザーの国コード。                      |
| `profile_country` | String | ユーザーのIPに基づく国コード。                   |
| `af_content_type` | String | 収益がある場合は常に `in_app`。               |
| `af_revenue`      | String | 小数点以下4桁にフォーマットされた収益金額。          |
| `af_currency`     | String | 通貨コード。                                |
| `af_quantity`     | String | 収益がある場合は常に `1`。                    |

## トラブルシューティング \{#troubleshooting\}

### 収益の不一致 \{#revenue-discrepancy\}

AdaptyとAppsFlyerの間で収益に差異がある場合、Adapty SDKが組み込まれたアプリバージョンを使用していないユーザーが存在することが原因の可能性があります。データの整合性を確保するために、ユーザーにAdapty SDKが組み込まれたバージョンへのアップデートを強制することができます。

### 連携データの欠落 \{#missing-integration-data\}

イベントの送信が失敗する場合、通常は連携データの欠落が原因です。この問題を解決するには、以下を確認してください：
- アプリにAppsFlyer SDKがインストールされていること。
- `getAppsFlyerUID` メソッドを呼び出していること。

### 認証エラー \{#authentication-failure\}

コンソールで `Failed to authenticate` エラーが発生している場合、AppsFlyerのバージョンと認証情報のバージョンが一致していないことが原因の可能性があります。

[移行ガイド](switch-from-appsflyer-s2s-api-2-to-3)を参照するか、[こちら](https://hq1.appsflyer.com/security-center/api-tokens)から有効な認証情報に差し替えてください。