Google DV360 API Reporting: How to fetch performance metrics such as impressions ,clicks

447 Views Asked by At

I am trying to extract reports from DV360 API using python.The only way I could find was to use sdfdownloadtask.Using sdfdownloadtask I was able to fetch the reports ,but the reports don't have performance metrics like impressions,clicks,revenue . As per the documentation those fields are not available for any of the filetype. < https://developers.google.com/display-video/api/structured-data-file/v6/Campaign > Is there a way to fetch these metrices using DV360 API.

1

There are 1 best solutions below

0
poppash On

I don't know if it's the way, but it's a way. Inspired by Fivetran's approach, I ended up fetching performance metrics in a similar fashion:

  • Create a ONE_TIME query in your Google Display & Video 360 account
  • Run this query to start report generation
  • Wait for the query to complete
  • Download the resulting CSV report file using the link provided
  • Delete the created query upon completion or in case of any errors

Potentially helpful code:

from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient import discovery

PARTNER_ID = "..."
SCOPES = [
    "https://www.googleapis.com/auth/display-video",
    "https://www.googleapis.com/auth/doubleclickbidmanager",
]

flow = InstalledAppFlow.from_client_secrets_file(
    "<path to secrets file>",
    scopes=SCOPES
)
credentials = flow.run_local_server()

query = {
    "metadata": {
        "title": "Default Offline Report",
        "dataRange": {"range": "LAST_7_DAYS"},
        "format": "CSV",
    },
    "params": {
        "type": "STANDARD",
        "groupBys": [
            "FILTER_ADVERTISER_NAME",
            "FILTER_ADVERTISER",
            "FILTER_ADVERTISER_CURRENCY",
            "FILTER_INSERTION_ORDER_NAME",
            "FILTER_INSERTION_ORDER",
            "FILTER_LINE_ITEM_NAME",
            "FILTER_LINE_ITEM",
        ],
        "filters": [{"type": "FILTER_PARTNER", "value": f"{PARTNER_ID}"}],
        "metrics": [
            "METRIC_IMPRESSIONS",
            "METRIC_BILLABLE_IMPRESSIONS",
            "METRIC_CLICKS",
            "METRIC_CTR",
            "METRIC_TOTAL_CONVERSIONS",
            "METRIC_LAST_CLICKS",
            "METRIC_LAST_IMPRESSIONS",
            "METRIC_REVENUE_ADVERTISER",
            "METRIC_MEDIA_COST_ADVERTISER",
        ],
        "options": {},
    },
    "schedule": {"frequency": "ONE_TIME"},
}

# create a query, fetch its id
response = service.queries().create(body=query).execute()
queryId = response.get("queryId")

try:
    # run a query (i.e., create a report)
    response = service.queries().run(queryId=queryId, synchronous=True).execute()
    
    # in case you set synchronous=False (which is done by default), implement polling logic here
    
    # print url to report
    print(response["metadata"]["googleCloudStoragePath"])
except Exception as e:
    print(e)

service.queries().delete(queryId=queryId).execute()

NB. I recommend to

  • Create a ONE_TIME query in your Google Display & Video 360 account

using the UI and then extract report definitions for use in subsequent coding endeavors: service.queries().list().execute()

Good luck!