Ringkasan
Petunjuk di bawah memberikan contoh cara membuat kueri traffic keterlihatan yang valid dan traffic tidak valid menggunakan API. Metrik ini terbatas pada inventaris yang dibeli menggunakan Google Ads, Display & Video 360, dan YouTube Reserve.
Perhatikan bahwa metrik penayangan penayangan TrueView yang terakreditasi MRC memerlukan penggunaan ADH API, karena tidak ada kueri yang terkait. Selain itu, metrik penayangan TrueView tidak boleh disamakan dengan metrik visibilitas.
Pilih pintu masuk pembelian yang ingin Anda kueri metrik keaktifan iklannya:
Mengkueri metrik visibilitas menggunakan UI
Kueri visibilitas yang dibuat dengan template memberikan metrik yang diakreditasi MRC.
Akreditasi MRC bersifat biner—hasil Anda dapat diakreditasi, atau tidak—dan berlaku untuk seluruh tabel hasil Anda. Di BigQuery, label adh-mrc-accredited diterapkan ke semua hasil yang terakreditasi MRC. Anda harus menjalankan kueri melalui template agar metrik Anda terakreditasi MRC.
Untuk menjalankan kueri terakreditasi MRC melalui template:
- Ikuti petunjuk tentang cara membuat kueri, pastikan Anda memilih Google Ads sebagai pintu pembelian dan Keterlihatan Video sebagai template kueri.
- Klik tombol Run di samping Use template.
Membuat kueri metrik traffic tidak valid dan metrik viewability menggunakan API
Metrik traffic tidak valid dan visibilitas dapat diambil dari ADH API menggunakan endpoint generateIvtReport , dan startAnalysis. Untuk traffic tidak valid, metrik Anda harus diambil melalui generateIvtReport agar label adh-mrc-accredited dapat diterapkan dan metrik Anda dapat diakreditasi MRC. Demikian pula, kueri global yang ditentukan di bawah harus digunakan untuk metrik visibilitas melalui ADH API untuk akreditasi MRC. Bagian ini membahas cara mengirim permintaan ke endpoint ini menggunakan library klien Python.
Ikuti petunjuk penyiapan dan otorisasi/autentikasi di mulai cepat API.
Setelah mengganti kolom berikut dengan informasi yang relevan dengan akun Anda, Anda dapat menjalankan kueri di bawah untuk mengambil laporan traffic tidak valid untuk kampanye Google Ads :
- File rahasia klien
- ID Pelanggan
- Kunci API
- Campaign IDs
- Zona waktu
Kode contoh
Traffic tidak valid
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',
'google_ads_dimensions': {
'campaign_ids': [YOUR_CAMPAIGN_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))
Metrik visibilitas
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/f41320e7296d49158e572aba662f35b1'
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': {
'campaign_ids': {
'array_value': {
'values': [
{
'value': 'YOUR_CAMPAIGN_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))
Menghitung metrik kevisibilitasan setelah dikurangi traffic tidak valid umum
Gunakan formula berikut untuk mendapatkan metrik visibilitas yang diakreditasi MRC setelah dikurangi traffic tidak valid umum (GIVT):
- Total Tayangan Iklan (Bersih dari GIVT): Total Tayangan Iklan - Tayangan Iklan Tidak Valid Umum
- Tayangan Iklan Terlihat (Bersih dari GIVT): Tayangan Iklan Terlihat + Tayangan Iklan Terlihat Tidak Valid - Tayangan Iklan Terlihat GIVT
- Tayangan Iklan Terukur (Bersih dari GIVT): Tayangan Iklan Terukur + Tayangan Iklan Terukur Tidak Valid - Tayangan Iklan Terukur GIVT
- Tayangan Valid (Setelah GIVT): Tayangan Valid + Tayangan Valid Tidak Valid - Tayangan Valid GIVT
- Tayangan Iklan Tidak Terlihat (Setelah GIVT) : Tayangan Iklan Terukur (Setelah GIVT) - Tayangan Iklan Terlihat (Setelah GIVT)
- Tayangan Iklan yang Tidak Terukur (Setelah GIVT): Tayangan Iklan yang Valid (Setelah GIVT) - Tayangan Iklan yang Terukur (Setelah GIVT)
- % Tayangan Iklan Terukur (Nilai bersih GIVT): Tayangan Iklan Terukur (Nilai bersih GIVT) / Tayangan Iklan Valid (Nilai bersih GIVT)
- % Tayangan Iklan Terlihat (Setelah GIVT): Tayangan Iklan Terlihat (Setelah GIVT) / Tayangan Iklan Terukur (Setelah GIVT)