Google Display & Video 360 Operators

Google Display & Video 360 has the end-to-end campaign management features you need.

Prerequisite Tasks

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

Creating a Query

To create Display&Video 360 query use GoogleDisplayVideo360CreateQueryOperator.

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

create_query_v2 = GoogleDisplayVideo360CreateQueryOperator(body=REPORT_V2, task_id="create_query")

query_id = cast(str, XComArg(create_query_v2, key="query_id"))

Use Jinja templating with body, impersonation_chain parameters which allow you to dynamically determine values. You can provide body definition using `` .json`` file as this operator supports this template extension. The result is saved to XCom, which allows the result to be used by other operators.

Run Query

GoogleDisplayVideo360RunQueryOperator.

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

run_query_v2 = GoogleDisplayVideo360RunQueryOperator(
    query_id=query_id, parameters=PARAMETERS, task_id="run_report"
)

query_id = cast(str, XComArg(run_query_v2, key="query_id"))
report_id = cast(str, XComArg(run_query_v2, key="report_id"))

You can use Jinja templating with query_id, parameters, impersonation_chain parameters which allow you to dynamically determine values. The result is saved to XCom, which allows the result to be used by other operators.

Deleting a report

To delete Display&Video 360 report use GoogleDisplayVideo360DeleteReportOperator.

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

delete_report_v2 = GoogleDisplayVideo360DeleteReportOperator(report_id=report_id, task_id="delete_report")

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

Waiting for query

To wait for the report use GoogleDisplayVideo360RunQuerySensor.

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

wait_for_query = GoogleDisplayVideo360RunQuerySensor(
    task_id="wait_for_query",
    query_id=query_id,
    report_id=report_id,
)

Use Jinja templating with query_id, report_id, impersonation_chain parameters which allow you to dynamically determine values.

Downloading a report

To download a report to GCS bucket use GoogleDisplayVideo360DownloadReportV2Operator.

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

get_report_v2 = GoogleDisplayVideo360DownloadReportV2Operator(
    query_id=query_id,
    report_id=report_id,
    task_id="get_report",
    bucket_name=BUCKET,
    report_name="test1.csv",
)

Use Jinja templating with query_id, report_id, bucket_name, report_name, impersonation_chain parameters which allow you to dynamically determine values.

Downloading Line Items

The operator accepts body request:

  • consistent with Google API

    REQUEST_BODY = {
    "filterType": ADVERTISER_ID,
    "format": "CSV",
    "fileSpec": "EWF"
    }
    

To download line items in CSV format report use GoogleDisplayVideo360DownloadLineItemsOperator.

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

download_line_items = GoogleDisplayVideo360DownloadLineItemsOperator(
    task_id="download_line_items",
    request_body=DOWNLOAD_LINE_ITEMS_REQUEST,
    bucket_name=BUCKET,
    object_name=OBJECT_NAME,
    gzip=False,
)

Use Jinja templating with request_body, bucket_name, object_name, impersonation_chain parameters which allow you to dynamically determine values.

Upload line items

To run Display&Video 360 uploading line items use GoogleDisplayVideo360UploadLineItemsOperator.

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

upload_line_items = GoogleDisplayVideo360UploadLineItemsOperator(
    task_id="upload_line_items",
    bucket_name=BUCKET,
    object_name=BUCKET_FILE_LOCATION,
)

Use Jinja templating with bucket_name, object_name, impersonation_chain parameters which allow you to dynamically determine values.

Create SDF download task

To create SDF download task use GoogleDisplayVideo360CreateSDFDownloadTaskOperator.

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

create_sdf_download_task = GoogleDisplayVideo360CreateSDFDownloadTaskOperator(
    task_id="create_sdf_download_task", body_request=CREATE_SDF_DOWNLOAD_TASK_BODY_REQUEST
)
operation_name = '{{ task_instance.xcom_pull("create_sdf_download_task")["name"] }}'

Use Jinja templating with body_request, impersonation_chain parameters which allow you to dynamically determine values.

Save SDF files in the Google Cloud Storage

To save SDF files and save them in the Google Cloud Storage use GoogleDisplayVideo360SDFtoGCSOperator.

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

save_sdf_in_gcs = GoogleDisplayVideo360SDFtoGCSOperator(
    task_id="save_sdf_in_gcs",
    operation_name=operation_name,
    bucket_name=BUCKET,
    object_name=BUCKET_FILE_LOCATION,
    gzip=False,
)

Use Jinja templating with operation_name, bucket_name, object_name, impersonation_chain parameters which allow you to dynamically determine values.

Waiting for SDF operation

Wait for SDF operation is executed by: GoogleDisplayVideo360GetSDFDownloadOperationSensor.

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

wait_for_operation = GoogleDisplayVideo360GetSDFDownloadOperationSensor(
    task_id="wait_for_operation",
    operation_name=operation_name,
)

Use Jinja templating with operation_name, impersonation_chain parameters which allow you to dynamically determine values.

Was this entry helpful?