查询可见度和无效流量指标

概览

本文举例说明了如何通过 API 查询有效的可见流量及无效流量。这些指标仅适用于通过 Google Ads、Display & Video 360 和 YouTube 预订型广告资源购买的广告资源。

请注意,已获 MRC 认证的观看次数指标“TrueView 观看次数”需要使用 ADH API,因为没有相关的模板化查询。此外,请勿将 TrueView 观看次数指标与可见度指标相混淆。

请选择要查询可见度指标的购买渠道:

通过界面查询可见度指标

模板化可见度查询提供已获 MRC 认证的指标。

MRC 认证结果分为两种(已获认证或未获认证),且适用于整个结果表。在 BigQuery 中,标签 adh-mrc-accredited 会应用于已获 MRC 认证的所有结果。您必须通过模板运行查询,指标才能获得 MRC 认证。

如要通过模板运行已获 MRC 认证的查询,请执行以下操作:

  1. 按照有关如何创建查询的说明进行操作,确保选择 YouTube Reserve 作为购买渠道,同时选择视频广告可见度作为查询模板。
  2. 点击使用模板旁边的运行按钮。

通过 API 查询无效流量和可见度指标

您可以通过 ADH API 使用 generateIvtReportstartAnalysis 端点来检索无效流量和可见度指标。对于无效流量,您必须通过 generateIvtReport 检索指标,才能应用 adh-mrc-accredited 标签,您的指标也才能获得 MRC 认证。同样,必须通过 ADH API 使用下方指定的全局查询检索可见度指标,以获得 MRC 认证。本部分介绍了如何使用 Python 客户端库向此端点发送请求。

按照 API 快速入门中的设置和授权/身份验证说明进行操作。

将以下字段替换为与您的账号相关的信息后,您可以运行下方的查询来检索您的 YouTube Reserve 广告系列的无效流量报告:

  • 客户端密钥文件
  • 客户 ID
  • API 密钥
  • Order IDs
  • 时区

代码示例

无效流量

from __future__ import print_function
import json
import os.path
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

# If modifying these scopes, delete the file `token.json`.
SCOPES = ['https://www.googleapis.com/auth/adsdatahub']
TOKEN_FILE = 'token.json'

creds = None

# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists(TOKEN_FILE):
    creds = Credentials.from_authorized_user_file(TOKEN_FILE, SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        creds.refresh(Request())
    else:
        flow = InstalledAppFlow.from_client_secrets_file(
            'YOUR_CLIENT_SECRETS.json', SCOPES)
        creds = flow.run_local_server(port=0)
    # Save the credentials for the next run.
    with open(TOKEN_FILE, 'w') as token:
        token.write(creds.to_json())

service = build('adsdatahub', 'v1', credentials=creds,
                developerKey='YOUR_API_KEY',
                discoveryServiceUrl='https://adsdatahub.googleapis.com/$discovery/rest?version=v1&labels=')

body = {
    'ads_data_customer_id': YOUR_CUSTOMER_ID,
    'start_date': {
        'year': 2019,
        'month': 12,
        'day': 15
    },
    'end_date': {
        'year': 2019,
        'month': 12,
        'day': 20
    },
    'time_zone': 'YOUR_TIMEZONE',
    'yt_reserve_dimensions': {
        'order_ids': [YOUR_ORDER_IDS],
        'metric_type': 'METRIC_TYPE_IMPRESSION'
    },
    'dest_table': 'YOUR_DESTINATION_TABLE'
}

resp = service.customers().generateIvtReport(name='customers/YOUR_CUSTOMER_ID,
                                             body=body).execute()
print(json.dumps(resp))

可见度指标

from __future__ import print_function
import json
import os.path
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

# If modifying these scopes, delete the file `token.json`.
SCOPES = ['https://www.googleapis.com/auth/adsdatahub']
TOKEN_FILE = 'token.json'

creds = None

# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists(TOKEN_FILE):
    creds = Credentials.from_authorized_user_file(TOKEN_FILE, SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        creds.refresh(Request())
    else:
        flow = InstalledAppFlow.from_client_secrets_file(
            'YOUR_CLIENT_SECRETS.json', SCOPES)
        creds = flow.run_local_server(port=0)
    # Save the credentials for the next run.
    with open(TOKEN_FILE, 'w') as token:
        token.write(creds.to_json())

service = build('adsdatahub', 'v1', credentials=creds,
                developerKey='YOUR_API_KEY',
                discoveryServiceUrl='https://adsdatahub.googleapis.com/$discovery/rest?version=v1&labels=')

name = 'customers/global/analysisQueries/ad88e8562a8f4baa9c8522945fe95522'
body = {
  'spec': {
    'ads_data_customer_id': YOUR_CUSTOMER_ID,
    'start_date': {
      'year': 2019,
      'month': 12,
      'day': 15
    },
    'end_date': {
      'year': 2019,
      'month': 12,
      'day': 20
    },
    'time_zone': 'YOUR_TIMEZONE',
    'parameter_values': {
      'line_item_ids': {
        'array_value': {
          'values': [
            {
              'value': 'YOUR_LINE_ITEM_ID'
            },
          ]
        }
      }
    }
  },
  'dest_table': 'YOUR_DESTINATION_TABLE',
  'customer_id': YOUR_CUSTOMER_ID
}

resp = service.customers().analysisQueries().start(name=name,body=body).execute()
print(json.dumps(resp))