Eseguire query sulle metriche di visibilità e traffico non valido

Panoramica

Le istruzioni riportate di seguito forniscono esempi di come eseguire query sia sul traffico di visibilità valido sia sul traffico non valido tramite l'API. Queste metriche si riferiscono solo all'inventario acquistato tramite Google Ads, Display & Video 360 e YouTube Reserve.

Tieni presente che le metriche relative alle visualizzazioni TrueView accreditate da MRC richiedono l'uso dell'API ADH, poiché non esistono query basate su modelli associate. Inoltre, le metriche relative alle visualizzazioni TrueView non devono essere confuse con le metriche di visibilità.

Seleziona il canale di acquisto per il quale vuoi eseguire query sulle metriche di visibilità:

Eseguire query sulle metriche di visibilità utilizzando l'UI

Le query sulla visibilità basate su modelli forniscono metriche accreditate da MRC.

L'accreditamento MRC è binario, ovvero i risultati possono essere accreditati o meno, e si applica all'intera tabella dei risultati. In BigQuery, viene applicata l'etichetta adh-mrc-accredited a tutti i risultati accreditati da MRC. Affinché le tue metriche siano accreditate da MRC, devi eseguire la query tramite il modello.

Per eseguire la query accreditata da MRC attraverso il modello:

  1. Segui le istruzioni su come creare una query, assicurandoti di selezionare YouTube Reserve come canale di acquisto e Visibilità video come modello di query.
  2. Fai clic sul pulsante Esegui accanto a Utilizza modello.

Eseguire query sulle metriche di traffico non valido e visibilità utilizzando l'API

Le metriche relative a traffico non valido e visibilità possono essere recuperate dall'API ADH utilizzando gli endpoint generateIvtReport e startAnalysis. Per quanto riguarda il traffico non valido, le metriche devono essere recuperate tramite generateIvtReport affinché l'etichetta adh-mrc-accredited venga applicata e le metriche ottengano l'accreditamento MRC. Allo stesso modo, la query globale specificata di seguito deve essere utilizzata per le metriche di visibilità tramite l'API ADH per ottenere l'accreditamento MRC. Questa sezione illustra come inviare una richiesta a questo endpoint utilizzando la libreria client Python.

Segui le istruzioni per la configurazione e l'autorizzazione/autenticazione riportate nella guida rapida dell'API.

Dopo aver sostituito i seguenti campi con informazioni pertinenti al tuo account, puoi eseguire la query seguente per recuperare un report sul traffico non valido per le campagne YouTube Reserve :

  • File client secret
  • ID cliente
  • Chiave API
  • Order IDs
  • Fuso orario

Codice campione

Traffico non valido

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

Metriche relative alla visibilità

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