Meta Adsからデータを取り込む
ベータ版
この機能はベータ版です。ワークスペース管理者は、 プレビュー ページからこの機能へのアクセスを制御できます。「Databricks プレビューの管理」を参照してください。
Meta Ads から Databricks にデータを取り込むための管理された取り込みパイプラインを作成する方法を学びます。サポートされているオブジェクトの一覧については、 「サポートされているオブジェクト」を参照してください。
要件
-
取り込み パイプラインを作成するには、次の要件を満たす必要があります。
-
ワークスペースでUnity Catalogが有効になっている必要があります。
-
ワークスペースでサーバレスコンピュートを有効にする必要があります。 「サーバレス コンピュート要件」を参照してください。
-
新しい接続を作成する場合:メタストアに対して
CREATE CONNECTION権限が必要です。Unity Catalogの「権限の管理」を参照してください。コネクタが UI ベースのパイプライン オーサリングをサポートしている場合、管理者はこのページのステップを完了することで、接続とパイプラインを同時に作成できます。 ただし、パイプラインを作成するユーザーが API ベースのパイプライン オーサリングを使用している場合、または管理者以外のユーザーである場合、管理者はまずカタログ エクスプローラーで接続を作成する必要があります。 「管理対象取り込みソースへの接続」を参照してください。
-
既存の接続を使用する場合: 接続オブジェクトに対する
USE CONNECTION権限またはALL PRIVILEGESが必要です。 -
ターゲット カタログに対する
USE CATALOG権限が必要です。 -
既存のスキーマに対する
USE SCHEMAおよびCREATE TABLE権限、またはターゲット カタログに対するCREATE SCHEMA権限が必要です。
-
-
メタ広告から取り込むには、 「メタ広告をデータソースとして設定する」のステップを完了する必要があります。
取り込みパイプラインを作成する
- Databricks Asset Bundles
- Databricks notebook
このタブでは、宣言型自動化バンドルを使用してデータ取り込みパイプラインをデプロイする方法について説明します。バンドルにはジョブとタスクの YAML 定義を含めることができ、 Databricks CLIを使用して管理でき、さまざまなターゲット ワークスペース (開発、ステージング、本番運用など) で共有して実行できます。 詳細については、 「宣言的オートメーション バンドルとは何ですか?」を参照してください。 。
-
Databricks CLI を使用して新しいバンドルを作成します。
Bashdatabricks bundle init -
バンドルに 2 つの新しいリソース ファイルを追加します。
- パイプライン定義ファイル (例:
resources/meta_ads_pipeline.yml)。パイプライン.ingestion_定義を参照してください。 および例。 - データ取り込みの頻度を制御するジョブ定義ファイル (例:
resources/meta_ads_job.yml)。宣言型自動化バンドルのジョブ定義ファイルを参照してください。
- パイプライン定義ファイル (例:
-
Databricks CLI を使用してパイプラインをデプロイします。
Bashdatabricks bundle deploy
- 次のノートブックを Databricks ワークスペースにインポートします。
-
セル 1 はそのままにしておきます。
-
パイプライン構成の詳細に合わせてセル 3 を変更します。パイプライン.ingestion_定義を参照してください。 および例。
-
「 すべて実行 」をクリックします。
ad_insights構成
ad_insightsから取り込む場合は、 metamarketing_parametersで次の設定を構成する必要があります。
Value | 説明 |
|---|---|
| 知識の粒度レベル: |
|
|
| オプション。内訳ディメンションのリスト (例: |
| オプション。アクション内訳ディメンションのリスト (例: |
例
これらの例を使用してパイプラインを構成します。
アカウントから現在および将来のすべてのテーブルを取り込む
- Databricks Asset Bundles
- Databricks notebook
以下はパイプライン定義ファイルの例です。
resources:
pipelines:
pipeline_meta_ads:
name: <pipeline-name>
catalog: <destination-catalog>
target: <destination-schema>
channel: PREVIEW
ingestion_definition:
connection_name: <connection-name>
objects:
- schema:
source_schema: <meta-ads-account-id>
destination_catalog: <destination-catalog>
destination_schema: <destination-schema>
table_configuration:
scd_type: SCD_TYPE_1
以下はパイプライン仕様の例です。
pipeline_spec = {
"name": "<pipeline-name>",
"catalog": "<destination-catalog>",
"schema": "<destination-schema>",
"channel": "PREVIEW",
"ingestion_definition": {
"connection_name": "<connection-name>",
"objects": [
{
"schema": {
"source_schema": "<meta-ads-account-id>",
"destination_catalog": "<destination-catalog>",
"destination_schema": "<destination-schema>",
"table_configuration": {
"scd_type": "SCD_TYPE_1"
}
}
}
]
}
}
json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
アカウントから特定のテーブルを選択して取り込む
- Databricks Asset Bundles
- Databricks notebook
以下はパイプライン定義ファイルの例です。
resources:
pipelines:
pipeline_meta_ads:
name: <pipeline-name>
catalog: <destination-catalog>
target: <destination-schema>
channel: PREVIEW
ingestion_definition:
connection_name: <connection-name>
objects:
- table:
source_schema: <meta-ads-account-id>
source_table: campaigns
destination_catalog: <destination-catalog>
destination_schema: <destination-schema>
table_configuration:
scd_type: SCD_TYPE_1
- table:
source_schema: <meta-ads-account-id>
source_table: ads
destination_catalog: <destination-catalog>
destination_schema: <destination-schema>
table_configuration:
scd_type: SCD_TYPE_1
以下はパイプライン仕様の例です。
pipeline_spec = {
"name": "<pipeline-name>",
"catalog": "<destination-catalog>",
"schema": "<destination-schema>",
"channel": "PREVIEW",
"ingestion_definition": {
"connection_name": "<connection-name>",
"objects": [
{
"table": {
"source_schema": "<meta-ads-account-id>",
"source_table": "campaigns",
"destination_catalog": "<destination-catalog>",
"destination_schema": "<destination-schema>",
"table_configuration": {
"scd_type": "SCD_TYPE_1"
}
}
},
{
"table": {
"source_schema": "<meta-ads-account-id>",
"source_table": "ads",
"destination_catalog": "<destination-catalog>",
"destination_schema": "<destination-schema>",
"table_configuration": {
"scd_type": "SCD_TYPE_1"
}
}
}
]
}
}
json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
ad_insights摂取する metamarketing_parameters
- Databricks Asset Bundles
- Databricks notebook
以下はresources/meta_ads_pipeline.ymlファイルの例です。
resources:
pipelines:
pipeline_meta_ads:
name: <pipeline-name>
catalog: <destination-catalog>
target: <destination-schema>
channel: PREVIEW
ingestion_definition:
connection_name: <connection-name>
objects:
- table:
source_schema: <meta-ads-account-id>
source_table: ad_insights
destination_catalog: <destination-catalog>
destination_schema: <destination-schema>
table_configuration:
scd_type: SCD_TYPE_1
metamarketing_parameters:
level: ad
start_date: '2024-01-01'
breakdowns:
- age
- gender
action_breakdowns:
- action_type
pipeline_spec = {
"name": "<pipeline-name>",
"catalog": "<destination-catalog>",
"schema": "<destination-schema>",
"channel": "PREVIEW",
"ingestion_definition": {
"connection_name": "<connection-name>",
"objects": [
{
"table": {
"source_schema": "<meta-ads-account-id>",
"source_table": "ad_insights",
"destination_catalog": "<destination-catalog>",
"destination_schema": "<destination-schema>",
"table_configuration": {
"scd_type": "SCD_TYPE_1",
"metamarketing_parameters": {
"level": "ad",
"start_date": "2024-01-01",
"breakdowns": ["age", "gender"],
"action_breakdowns": ["action_type"]
}
}
}
}
]
}
}
json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
宣言型自動化バンドルのジョブ定義ファイル
以下はresources/meta_ads_job.ymlファイルの例です。
resources:
jobs:
meta_ads_dab_job:
name: meta_ads_dab_job
trigger:
# Run this job every day, exactly one day from the last run
# See https://docs.databricks.com/api/workspace/jobs/create#trigger
periodic:
interval: 1
unit: DAYS
email_notifications:
on_failure:
- <email-address>
tasks:
- task_key: refresh_pipeline
pipeline_task:
pipeline_id: <pipeline-id>
一般的なパターン
高度なパイプライン構成については、 「管理された取り込みパイプラインの一般的なパターン」を参照してください。
次のステップ
パイプラインを開始、スケジュールし、アラートを設定します。一般的なパイプラインメンテナンスタスクを参照してください。