視認性と無効なトラフィックに関する指標をクエリする

概要

API を使用して、有効な視認性トラフィックと無効なトラフィックの両方をクエリする方法の例を以下に示します。この指標は、Google 広告、ディスプレイ&ビデオ 360、YouTube Reserve で購入した広告枠に限定されています。

TrueView ビューの視聴に関する MRC 認定の指標には、関連するテンプレート化されたクエリがないため、ADH API を使用する必要があります。なお、TrueView ビューの視聴に関する指標を視認性の指標と混同しないでください。

視認性の指標をクエリする購入プラットフォームを以下から選択してください。

管理画面を使って視認性の指標をクエリする

テンプレート化された視認性クエリでは、MRC 認定の指標を取得できます。

MRC 認定では、その結果が認定されるかされないかのいずれかです。また、この認定は結果テーブル全体に適用されます。BigQuery では、MRC 認定を受けたすべての結果にラベル adh-mrc-accredited が適用されます。指標が MRC 認定を受けるには、テンプレートを使ってクエリを実行する必要があります。

テンプレートを使用して MRC 認定クエリを実行する方法は次のとおりです。

  1. クエリの作成方法の手順に沿って、購入プラットフォームとして [YouTube Reserve]、クエリ テンプレートとして [動画の視認性] を選択します。
  2. [テンプレートを使用] の横にある [実行] ボタンをクリックします。

API を使用して、無効なトラフィックと視認性の指標をクエリする

無効なトラフィックと視認性の指標は、エンドポイント generateIvtReportstartAnalysis を使用して ADH API から取得できます。無効なトラフィックの場合、adh-mrc-accredited ラベルが適用され、指標が MRC 認定を受けるには、generateIvtReport で指標を取得する必要があります。同様に、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))