Google DV360 API 报告:如何获取展示次数、点击次数等绩效指标

问题描述 投票:0回答:1

我正在尝试使用 python 从 DV360 API 中提取报告。我能找到的唯一方法是使用 sdfdownloadtask。使用 sdfdownloadtask 我能够获取报告,但报告没有印象数、点击数、收入等性能指标。根据文档,这些字段不适用于任何文件类型。 < https://developers.google.com/display-video/api/structed-data-file/v6/Campaign > 有没有办法使用 DV360 API 获取这些指标。

google-api-client google-api-python-client dv360
1个回答
0
投票

我不知道这是否是the方式,但它是a方式。受到 Fivetran 方法的启发,我最终以类似的方式获取性能指标:

  • 在您的 Google Display & Video 360 帐号中创建
    ONE_TIME
    查询
  • 运行此查询以开始生成报告
  • 等待查询完成
  • 使用提供的链接下载生成的 CSV 报告文件
  • 完成后或出现任何错误时删除创建的查询

可能有用的代码:

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()

注意。我建议

  • 在您的 Google Display & Video 360 帐号中创建
    ONE_TIME
    查询

使用 UI,然后提取报告定义以供后续编码工作使用:

service.queries().list().execute()

祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.