Google Campaign Manager Operators

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

Prerequisite Tasks

To use these operators, you must do a few things:

Deleting a report

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

tests/system/providers/google/marketing_platform/example_campaign_manager.py[source]

delete_report = GoogleCampaignManagerDeleteReportOperator(
    profile_id=PROFILE_ID,
    report_name=REPORT_NAME,
    task_id="delete_report",
    trigger_rule=TriggerRule.ALL_DONE,
)

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.

tests/system/providers/google/marketing_platform/example_campaign_manager.py[source]

report_name = f"reports/report_{str(uuid.uuid1())}"
get_report = GoogleCampaignManagerDownloadReportOperator(
    task_id="get_report",
    profile_id=PROFILE_ID,
    report_id=report_id,
    file_id=file_id,
    report_name=report_name,
    bucket_name=BUCKET_NAME,
)

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.

tests/system/providers/google/marketing_platform/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.

tests/system/providers/google/marketing_platform/example_campaign_manager.py[source]

create_report = GoogleCampaignManagerInsertReportOperator(
    profile_id=PROFILE_ID, report=REPORT, task_id="create_report"
)
report_id = cast(str, XComArg(create_report, key="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.

tests/system/providers/google/marketing_platform/example_campaign_manager.py[source]

run_report = GoogleCampaignManagerRunReportOperator(
    profile_id=PROFILE_ID, report_id=report_id, task_id="run_report"
)
file_id = cast(str, XComArg(run_report, key="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 conversions

To insert Campaign Manager conversions you can use the GoogleCampaignManagerBatchInsertConversionsOperator.

tests/system/providers/google/marketing_platform/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 conversions

To update Campaign Manager conversions you can use the GoogleCampaignManagerBatchUpdateConversionsOperator.

tests/system/providers/google/marketing_platform/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?