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:
Select or create a Cloud Platform project using the Cloud Console.
Enable billing for your project, as described in the Google Cloud documentation.
Enable the API, as described in the Cloud Console documentation.
Install API libraries via pip.
pip install 'apache-airflow[google]'Detailed information is available for Installation.
Deleting a report¶
To delete Campaign Manager report you can use the
GoogleCampaignManagerDeleteReportOperator
.
It deletes a report by its unique ID.
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,
)
You can use Jinja templating with
profile_id
, report_id
, report_name
, api_version
, gcp_conn_id
, 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.
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,
)
You can use Jinja templating with
profile_id
, report_id
, file_id
, bucket_name
, report_name
, chunk_size
, api_version
, gcp_conn_id
, 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
.
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,
)
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.
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"))
You can use Jinja templating with
profile_id
, report
, api_version
, gcp_conn_id
, 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
.
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"))
You can use Jinja templating with
profile_id
, report_id
, synchronous
, api_version
, gcp_conn_id
, 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
.
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,
)
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
.
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,
)
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.