Google Campaign Manager 運算子 (Operators)¶
Google Campaign Manager 運算子允許您插入、執行、獲取或刪除報告。有關 Campaign Manager 報告 API 的更多資訊,請參閱官方文件。
先決條件任務¶
要使用這些運算子,您必須完成以下幾件事
使用Cloud Console選擇或建立 Cloud Platform 專案。
為您的專案啟用結算功能,詳見Google Cloud 文件。
啟用 API,詳見Cloud Console 文件。
透過 pip 安裝 API 庫。
pip install 'apache-airflow[google]'有關安裝的詳細資訊。
刪除報告¶
要刪除 Campaign Manager 報告,您可以使用GoogleCampaignManagerDeleteReportOperator。它會根據報告的唯一 ID 刪除報告。
tests/system/google/marketing_platform/example_campaign_manager.py
delete_report = GoogleCampaignManagerDeleteReportOperator(
profile_id=USER_PROFILE_ID,
report_name=REPORT_NAME,
task_id="delete_report",
trigger_rule=TriggerRule.ALL_DONE,
gcp_conn_id=CONNECTION_ID,
)
您可以將Jinja 模板與profile_id、report_id、report_name、api_version、gcp_conn_id、impersonation_chain引數一起使用,以便動態確定值。
下載報告¶
GoogleCampaignManagerDownloadReportOperator 允許您將 Campaign Manager 報告下載到 Google Cloud Storage 儲存桶。
tests/system/google/marketing_platform/example_campaign_manager.py
report_name = f"reports/report_{str(uuid.uuid1())}"
get_report = GoogleCampaignManagerDownloadReportOperator(
task_id="get_report",
profile_id=USER_PROFILE_ID,
report_id=report_id,
file_id=file_id,
report_name=report_name,
bucket_name=BUCKET_NAME,
gcp_conn_id=CONNECTION_ID,
)
您可以將Jinja 模板與profile_id、report_id、file_id、bucket_name、report_name、chunk_size、api_version、gcp_conn_id、impersonation_chain引數一起使用,以便動態確定值。
等待報告¶
報告是非同步生成的。要等待報告準備好下載,您可以使用GoogleCampaignManagerReportSensor。
tests/system/google/marketing_platform/example_campaign_manager.py
wait_for_report = GoogleCampaignManagerReportSensor(
task_id="wait_for_report",
profile_id=USER_PROFILE_ID,
report_id=report_id,
file_id=file_id,
gcp_conn_id=CONNECTION_ID,
)
您可以將Jinja 模板與profile_id、report_id、file_id、impersonation_chain引數一起使用,以便動態確定值。
插入新報告¶
要插入 Campaign Manager 報告,您可以使用GoogleCampaignManagerInsertReportOperator。執行此運算子會建立一個新報告。
tests/system/google/marketing_platform/example_campaign_manager.py
create_report = GoogleCampaignManagerInsertReportOperator(
profile_id=USER_PROFILE_ID,
report=REPORT,
task_id="create_report",
gcp_conn_id=CONNECTION_ID,
)
report_id = cast("str", XComArg(create_report, key="report_id"))
您可以將Jinja 模板與profile_id、report、api_version、gcp_conn_id、impersonation_chain引數一起使用,以便動態確定值。由於此運算子支援此模板擴充套件,您可以使用 .json 檔案提供報告定義。結果會儲存到 XCom,以便其他運算子使用。
執行報告¶
要執行 Campaign Manager 報告,您可以使用GoogleCampaignManagerRunReportOperator。
tests/system/google/marketing_platform/example_campaign_manager.py
run_report = GoogleCampaignManagerRunReportOperator(
profile_id=USER_PROFILE_ID,
report_id=report_id,
task_id="run_report",
gcp_conn_id=CONNECTION_ID,
)
file_id = cast("str", XComArg(run_report, key="file_id"))
您可以將Jinja 模板與profile_id、report_id、synchronous、api_version、gcp_conn_id、impersonation_chain引數一起使用,以便動態確定值。結果會儲存到 XCom,以便其他運算子使用。
插入轉化次數¶
要插入 Campaign Manager 轉化次數,您可以使用GoogleCampaignManagerBatchInsertConversionsOperator。
tests/system/google/marketing_platform/example_campaign_manager.py
insert_conversion = GoogleCampaignManagerBatchInsertConversionsOperator(
task_id="insert_conversion",
profile_id=USER_PROFILE_ID,
conversions=[CONVERSION],
encryption_source="AD_SERVING",
encryption_entity_type="DCM_ADVERTISER",
encryption_entity_id=ENCRYPTION_ENTITY_ID, # type: ignore[arg-type]
gcp_conn_id=CONNECTION_ID,
)
您可以將Jinja 模板與profile_id、conversions、encryption_entity_type、encryption_entity_id、encryption_source、impersonation_chain引數一起使用,以便動態確定值。結果會儲存到 XCom,以便其他運算子使用。
更新轉化次數¶
要更新 Campaign Manager 轉化次數,您可以使用GoogleCampaignManagerBatchUpdateConversionsOperator。
tests/system/google/marketing_platform/example_campaign_manager.py
update_conversion = GoogleCampaignManagerBatchUpdateConversionsOperator(
task_id="update_conversion",
profile_id=USER_PROFILE_ID,
conversions=[CONVERSION_UPDATE],
encryption_source="AD_SERVING",
encryption_entity_type="DCM_ADVERTISER",
encryption_entity_id=ENCRYPTION_ENTITY_ID, # type: ignore[arg-type]
max_failed_updates=1,
gcp_conn_id=CONNECTION_ID,
)
您可以將Jinja 模板與profile_id、conversions、encryption_entity_type、encryption_entity_id、encryption_source、impersonation_chain引數一起使用,以便動態確定值。結果會儲存到 XCom,以便其他運算子使用。