查詢可視度和無效流量指標

總覽

下方操作說明舉例說明,如何透過 API 同時查詢有效可視度流量和無效流量。這些指標僅適用於透過 Google Ads、Display & Video 360 和 YouTube Reserve 購買的廣告空間。

請注意,如要查詢 MRC 認證的 TrueView 觀看指標,由於沒有相關聯的查詢範本,您必須使用 ADH API。此外,TrueView 觀看指標不應與可視度指標混為一談。

選取您要查詢可視度指標的購買平台:

透過使用者介面查詢可視度指標

可視度查詢範本提供 MRC 認證指標。

MRC 認證結果分為兩種 (已獲認證或未獲認證),且適用於整個結果資料表。在 BigQuery 中,標籤 adh-mrc-accredited 會套用至所有 MRC 認證結果。您必須透過範本執行查詢,指標才能獲得 MRC 認證。

如要透過範本執行 MRC 認證查詢:

  1. 按照「如何建立查詢」一文的說明操作,確認您已選取 YouTube Reserve 做為購買平台,並選取「影片可視度」做為查詢範本。
  2. 點選「使用範本」旁的「執行」按鈕。

使用 API 查詢無效流量和可視度指標

您可以使用 generateIvtReportstartAnalysis 端點,從 ADH API 擷取無效流量和可視度指標。如果是無效流量,必須透過 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))