# Audience StudioからのFacebook Conversion Export

このドキュメントでは、Audience StudioのFacebook Conversionコネクタを使用して、Facebook上でアクティベーションを作成する方法について説明します。

Treasure コンソールは、電話番号、メールアドレス、アイテムリスト、通貨などの情報を含むリクエストペイロードとともに、FacebookへのAPI呼び出しを送信することで、Facebook上でアクティベーションを開始します。以下はAPI呼び出しの例です。追加情報については、Metaのドキュメント[Sending Offline Events Using the Conversions API](https://developers.facebook.com/docs/marketing-api/conversions-api/offline-events#2--sending-events)を参照してください。


```bash
curl -X POST -F 'data=[{"event_name": "Purchase",  "event_time": 1674000041,  "user_data": {"em":["309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd"],    "ph": ["254aa248acb47dd654ca3ea53f48c2c26d641d23d7e2e93a1ec56258df7674c4","6f4fcb9deaeadc8f9746ae76d97ce1239e98b404efe5da3ee0b7149740f89ad6"]}, "custom_data": {"currency": "usd","value": 123.45,"contents": [{"id": "product123","quantity": 1}]},"action_source": "physical_store"}]' -F 'access_token=ACCESS_TOKEN' https://graph.facebook.com/v15.0/DATASET_ID/events
```

## Treasure Dataでのアクティベーションの作成

Treasure Data Audience StudioからFacebookにイベントを送信するには:

1. Facebook Pixel IDとAccess Tokenを取得し、Treasure コンソールでFacebookの認証を作成します。(このステップの詳細な手順は[こちら](/ja/int/facebook-conversions-api-export-integration#create-a-new-connection)を参照してください。)
2. Treasure コンソールでバッチセグメントを作成します。


以下は、オフラインイベントを含むセグメントの例です。

![](/assets/segment.34bebc5db0ef2ed5ab7054ba95e00465013d246bec5853ee281c85c8b72c29c1.c13ed41d.png)
3. アクティベーションの詳細を入力します。
入力が必要な詳細は以下の通りです:

- Name
- Facebookコネクタの認証
- Custom Fieldsエントリ—JSON形式でFacebookに送信されるリクエストペイロードを作成するために、カスタムフィールドエントリが必要です。ステップ5では、カスタムフィールドの設定方法を示します。
![](/assets/act1.71e1c98c306eac04e73b853a4c9df06c04bbddf75a1550840242df4f0b9b4915.c13ed41d.png)


1. 出力マッピングの詳細を入力します。
![](/assets/act2.9be43aa702a51359baf59b5f8c46020990b0219c76feab5fbe9162bff9aa404c.c13ed41d.png)
2. Custom Fieldsを設定します。
Custom Fieldsは、出力カラムマッピングと整合するように設定する必要があります。これを実現するには2つのオプションがあります:
  - オプションA: カスタムクエリを使用し、custom_fieldsを使用してcustom_dataを定義します。
  - オプションB: すべて選択し、custom_fieldsを使用してcustom_dataを定義します。


オプションA
- カスタムクエリの例



```sql
SELECT
   usd_currency as currency,
   usd_amount as value,
   ctype as content_type,
   c1_id as "contents[0].id",
   c1_pr as "contents[0].item_price",
   c1_qt as "contents[0].quantity"
FROM
 table_name;
```

- Custom Fields (ステップ3用)



```
custom_fields=
currency,
value,
content_type,
contents[0].id,
contents[0].item_price,
contents[0].quantity
```

オプションB
すべて選択し、custom_fieldsを使用してcustom_dataを定義します。

- クエリ



```sql
SELECT
　*
FROM
 table_name;
```

- Custom Fields (ステップ3用)



```
custom_fields=
usd_currency as currency,
usd_amount as value,
ctype as content_type,
c1_id as contents[0].id,
c1_pr as contents[0].item_price,
c1_qt as contents[0].quantity
```

idとquantity以外に追加の属性が必要な場合は、それに応じて追加してください。


```
usd_currency as currency,
usd_amount as value,
c1_id as contents[0].id,
c1_qt as contents[0].quantity,
c1_id as contents[1].id,
c1_qt as contents[1].quantity
```

リストサイズについては、リストサイズ以上のインデックスを設定する必要があります。例えば、最大のアイテムリストに10個のアイテムがある場合は、contents[9].attributeまでリストを設定してください。

1. アクティベーションをスケジュールして実行します。


## Facebookでの結果

イベントがFacebookデータセットに表示されると、以下のようになります:

![](/assets/result.42a38a07bec73c913808dcd0b06882ea93186c42a088daf0b860793ceb781b88.c13ed41d.png)