---
title: "Facebook Ads"
description: "Facebook AdsをAdaptyと統合して、効果的なサブスクリプションマーケティングを実現します。"
---

Facebook Ads連携を利用すると、Meta Analyticsでアプリの統計情報を簡単に確認できます。AdaptyはMeta Ads Managerにイベントを送信し、サブスクリプションに基づいた類似オーディエンスの作成をサポートすることで、より高いリターンを実現します。これにより、広告がサブスクリプションからどれだけの収益を生み出しているかを正確に把握できます。

AdaptyとFacebook Adsの連携は次のように動作します。Adaptyは、連携で設定されたすべてのサブスクリプションイベントをFacebook Adsに送信します。この連携は、広告キャンペーンの効果を評価するのに役立ちます。

## 連携のセットアップ \{#set-up-integration\}

### AdaptyをFacebook Adsに接続する \{#connect-adapty-to-facebook-ads\}

Facebook Adsと連携してアプリの指標を分析するには、Meta Analyticsとの連携をセットアップします。Meta Ads Managerにイベントを送信することで、更新などのサブスクリプションイベントを基に類似オーディエンスを作成できます。この連携を設定するには、Adapty ダッシュボードの [Integrations > Facebook Ads](https://app.adapty.io/integrations/facebookanalytics) に移動し、必要な認証情報を入力してください。

:::note
Facebook Ads連携は、ATTの同意を得たユーザーに対してiOS 14.5以降でのみ動作します。
:::

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

1. App IDを確認するには、[App Store Connect](https://appstoreconnect.apple.com/) でアプリのページを開き、**General** セクションの **App Information** ページに移動して、画面左下の **Apple ID** を確認します。
2. [Meta for Developers](https://developers.facebook.com/) プラットフォームでアプリケーションが必要です。アプリにログインして詳細設定を開くと、ヘッダーに **App ID** が表示されます。

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

3. Meta Ads Managerでの収益の二重カウントを防ぐため、Meta SDKの設定でクライアントサイドのトラッキングを無効にしてください。この設定は、Meta Developer Consoleの **App Settings > Advanced Settings** にあります。**Log in-app events automatically** を「No」に設定してください。これにより、収益イベントはAdaptyの連携経由でのみトラッキングされます。

   インストールや使用状況のイベントをトラッキングするには、コード内でMeta SDKを有効化する必要があります。各プラットフォームのMeta SDKドキュメントで実装の詳細を確認できます：
   - [iOS SDK](https://developers.facebook.com/docs/ios/getting-started)
   - [Android SDK](https://developers.facebook.com/docs/android/getting-started)
   - [Unity SDK](https://developers.facebook.com/docs/unity/getting-started/canvas)

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

この連携はAndroidアプリでも利用できます。**App Settings** でAndroid SDKの設定を行っている場合は、**Facebook App ID** を設定するだけで十分です。

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

Facebook Ads連携は、Metaを広告キャンペーンに活用し、顧客行動に基づいて最適化している企業向けです。Metaの標準イベントを最適化目的でサポートしています。そのため、Meta Ads連携ではイベント名の変更はできません。Adaptyはお客様の顧客イベントを対応するMetaイベントに正確にマッピングします。

| Adaptyイベント                  | Meta Adsイベント          |
| :---------------------------- | :-------------------------- |
| Subscription initial purchase | Subscribe                   |
| Subscription renewed          | Subscribe                   |
| Subscription cancelled        | CancelSubscription          |
| Trial started                 | StartTrial                  |
| Trial converted               | Subscribe                   |
| Trial cancelled               | CancelTrial                 |
| Non subscription purchase     | fb_mobile_purchase          |
| Billing issue detected        | billing_issue_detected      |
| Entered grace period          | entered_grace_period        |
| Auto renew off                | auto_renew_off              |
| Auto renew on                 | auto_renew_on               |
| Auto renew off subscription   | auto_renew_off_subscription |
| Auto renew on subscription    | auto_renew_on_subscription  |

StartTrial、Subscribe、CancelSubscriptionは標準イベントです。

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

特定のイベントを有効にするには、必要なものをトグルでオンにするだけです。複数のイベント名が選択された場合、Adaptyはすべての選択されたイベントのデータを1つのAdaptyイベント名にまとめます。

### アプリをFacebook Adsに接続する \{#connect-your-app-to-facebook-ads\}

上記の手順を完了すると、FacebookはAdaptyからサブスクリプションデータを自動的に受信します。

iOS 14.5でのIDFAの変更を受け、ユーザーの`facebookAnonymousId`をFacebookからリクエストすることをお勧めします。これにより、ユーザーのIDFAが取得できない場合でも連携が継続して機能します。このパラメーターを設定するには、<InlineTooltip tooltip="ユーザー属性設定ガイド">[iOS](setting-user-attributes)、[Android](android-setting-user-attributes)、[React Native](react-native-setting-user-attributes)、[Flutter](flutter-setting-user-attributes)、[Unity](unity-setting-user-attributes)</InlineTooltip> をご参照ください。

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

```swift showLineNumbers

do {
    try await Adapty.setIntegrationIdentifier(
        key: "facebook_anonymous_id", 
        value: AppEvents.shared.anonymousID
    )
} catch {
    // handle the error
}
```
</TabItem>
<TabItem value="kotlin" label="Android (Kotlin)" default>

```kotlin showLineNumbers
Adapty.setIntegrationIdentifier(
    "facebook_anonymous_id",
    AppEventsLogger.getAnonymousAppDeviceGUID(context)
) { error ->
    if (error != null) {
        // handle the error
    }
}
```
</TabItem>
<TabItem value="rn" label="React Native (TS)" default>

```typescript showLineNumbers

try {
  const anonymousId = await AppEventsLogger.getAnonymousID();

  await adapty.setIntegrationIdentifier("facebook_anonymous_id", anonymousId);
} catch (error) {
  // handle `AdaptyError`
}
```
</TabItem>
<TabItem value="flutter" label="Flutter (Dart)" default>

```text
There is no official SDK for Flutter
```
</TabItem>
<TabItem value="unity" label="Unity (C#)" default>

```csharp
anonymousID is not available in the official SDK
https://github.com/facebook/facebook-sdk-for-unity/issues/676
```
</TabItem>
</Tabs>

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

AdaptyはGraph API経由でFacebook Ads（Meta）にイベントを送信します。各イベントは次のような構造になっています：

```json
{
  "event": "CUSTOM_APP_EVENTS",
  "app_user_id": "user_12345",
  "advertiser_id": "00000000-0000-0000-0000-000000000000",
  "advertiser_tracking_enabled": 1,
  "application_tracking_enabled": 1,
  "custom_events": "[{\"_eventName\":\"Subscribe\",\"_logTime\":1709294400,\"fb_num_items\":1,\"fb_content_type\":\"in_app\",\"fb_content_id\":\"yearly.premium.6999\",\"fb_currency\":\"USD\",\"fb_order_id\":\"GPA.3383...\",\"fb_transaction_id\":\"GPA.3383...\",\"_valueToSum\":9.99}]",
  "extinfo": "[\"i2\",\"com.example.app\",\"1.0.0\",\"100\",\"17.0.1\",\"iPhone14,3\",\"en_US\",\"GMT+3\",\"\",0,0,0,0,0,0,\"GMT+3\"]",
  "anon_id": "facebook_anon_id_123"
}
```

各パラメーターの説明：

| パラメーター | 型 | 説明 |
|:---|:---|:---|
| `event` | String | 常に「CUSTOM_APP_EVENTS」。 |
| `app_user_id` | String | ユーザーのCustomer User ID。 |
| `advertiser_id` | String | IDFA（iOS）またはAdvertising ID（Android）。 |
| `advertiser_tracking_enabled` | Integer | トラッキングが有効（ATT承認済み）の場合は`1`、それ以外は`0`。 |
| `application_tracking_enabled` | Integer | 常に`1`。 |
| `custom_events` | String | イベントオブジェクトのJSON形式の文字列（下記参照）。 |
| `extinfo` | String | アプリ・デバイス情報（バージョン、OS、ロケールなど）を含むJSON形式の文字列。 |
| `anon_id` | String | Facebook Anonymous ID（利用可能な場合）。 |

`custom_events` パラメーターはオブジェクトのJSON配列で、以下の情報を含みます：

| パラメーター | 型 | 説明 |
|:---|:---|:---|
| `_eventName` | String | Meta Adsのイベント名（例：「Subscribe」）。 |
| `_logTime` | Long | イベントのタイムスタンプ（秒単位）。 |
| `_valueToSum` | Float | 収益金額。 |
| `fb_content_id` | String | ストアのプロダクトID。 |
| `fb_currency` | String | 通貨コード（例：「USD」）。 |
| `fb_order_id` | String | オリジナルトランザクションID。 |
| `fb_transaction_id` | String | オリジナルトランザクションID。 |
| `fb_content_type` | String | 常に「in_app」。 |
| `fb_num_items` | Integer | 購入イベントでは常に1。 |