Google Campaign Manager Operators

Google Campaign Manager operators allow you to insert, run, get or delete reports. For more information about the Campaign Manager API check official documentation.

Prerequisite Tasks

Deleting a report

To delete Campaign Manager report you can use the GoogleCampaignManagerDeleteReportOperator. It deletes a report by its unique ID.

airflow/providers/google/marketing_platform/example_dags/example_campaign_manager.py[source]

delete_report = GoogleCampaignManagerDeleteReportOperator(
    profile_id=PROFILE_ID, report_name=REPORT_NAME, task_id="delete_report"
)

You can use Jinja templating with profile_id, report_id, report_name, api_version, gcp_conn_id, delegate_to, impersonation_chain parameters which allows you to dynamically determine values.

Downloading a report

The GoogleCampaignManagerDownloadReportOperator. allows you to download a Campaign Manager to Google Cloud Storage bucket.

airflow/providers/google/marketing_platform/example_dags/example_campaign_manager.py[source]

get_report = GoogleCampaignManagerDownloadReportOperator(
    task_id="get_report",
    profile_id=PROFILE_ID,
    report_id=report_id,
    file_id=file_id,
    report_name="test_report.csv",
    bucket_name=BUCKET,
)

You can use Jinja templating with profile_id, report_id, file_id, bucket_name, report_name, chunk_size, api_version, gcp_conn_id, delegate_to, impersonation_chain parameters which allows you to dynamically determine values.

Waiting for a report

Report are generated asynchronously. To wait for report to be ready for downloading you can use GoogleCampaignManagerReportSensor.

airflow/providers/google/marketing_platform/example_dags/example_campaign_manager.py[source]

wait_for_report = GoogleCampaignManagerReportSensor(
    task_id="wait_for_report",
    profile_id=PROFILE_ID,
    report_id=report_id,
    file_id=file_id,
)

You can use Jinja templating with profile_id, report_id, file_id, impersonation_chain parameters which allows you to dynamically determine values.

Inserting a new report

To insert a Campaign Manager report you can use the GoogleCampaignManagerInsertReportOperator. Running this operator creates a new report.

airflow/providers/google/marketing_platform/example_dags/example_campaign_manager.py[source]

create_report = GoogleCampaignManagerInsertReportOperator(
    profile_id=PROFILE_ID, report=REPORT, task_id="create_report"
)
report_id = create_report.output["report_id"]

You can use Jinja templating with profile_id, report, api_version, gcp_conn_id, delegate_to, impersonation_chain parameters which allows you to dynamically determine values. You can provide report definition using .json file as this operator supports this template extension. The result is saved to XCom, which allows it to be used by other operators.

Running a report

To run Campaign Manager report you can use the GoogleCampaignManagerRunReportOperator.

airflow/providers/google/marketing_platform/example_dags/example_campaign_manager.py[source]

run_report = GoogleCampaignManagerRunReportOperator(
    profile_id=PROFILE_ID, report_id=report_id, task_id="run_report"
)
file_id = run_report.output["file_id"]

You can use Jinja templating with profile_id, report_id, synchronous, api_version, gcp_conn_id, delegate_to, impersonation_chain parameters which allows you to dynamically determine values. The result is saved to XCom, which allows it to be used by other operators.

Inserting a conversions

To insert Campaign Manager conversions you can use the GoogleCampaignManagerBatchInsertConversionsOperator.

airflow/providers/google/marketing_platform/example_dags/example_campaign_manager.py[source]

insert_conversion = GoogleCampaignManagerBatchInsertConversionsOperator(
    task_id="insert_conversion",
    profile_id=PROFILE_ID,
    conversions=[CONVERSION],
    encryption_source="AD_SERVING",
    encryption_entity_type="DCM_ADVERTISER",
    encryption_entity_id=ENCRYPTION_ENTITY_ID,
)

You can use Jinja templating with profile_id, conversions, encryption_entity_type, encryption_entity_id, encryption_source, impersonation_chain parameters which allows you to dynamically determine values. The result is saved to XCom, which allows it to be used by other operators.

Updating a conversions

To update Campaign Manager conversions you can use the GoogleCampaignManagerBatchUpdateConversionsOperator.

airflow/providers/google/marketing_platform/example_dags/example_campaign_manager.py[source]

update_conversion = GoogleCampaignManagerBatchUpdateConversionsOperator(
    task_id="update_conversion",
    profile_id=PROFILE_ID,
    conversions=[CONVERSION_UPDATE],
    encryption_source="AD_SERVING",
    encryption_entity_type="DCM_ADVERTISER",
    encryption_entity_id=ENCRYPTION_ENTITY_ID,
    max_failed_updates=1,
)

You can use Jinja templating with profile_id, conversions, encryption_entity_type, encryption_entity_id, encryption_source, impersonation_chain parameters which allows you to dynamically determine values. The result is saved to XCom, which allows it to be used by other operators.

Was this entry helpful?