Créer des rapports planifiés et y accéder

Vous pouvez créer et planifier des rapports à l'aide de l'interface utilisateur Google Display &Video 360 ou de l'API. Par exemple, les utilisateurs finaux peuvent configurer un rapport quotidien affichant les impressions de la veille ou un rapport mensuel indiquant les dépenses totales.

Créer des rapports planifiés

Créez un rapport planifié dans l'interface de création de rapports Display & Video 360 ou à l'aide de la méthode d'API queries.create. Pour en savoir plus sur la fonctionnalité de création de rapports de Display & Video 360 et sur la création de rapports, consultez le site d'assistance Display & Video 360.

Vous pouvez planifier des rapports lors de leur création à l'aide du Repeats champ dans l'interface utilisateur et du schedule champ dans l'API. Ces champs doivent être définis sur un intervalle de temps approprié.

Une fois le champ approprié défini, ce rapport s'exécutera selon cette planification, et les rapports générés seront disponibles au téléchargement.

Accéder aux rapports planifiés

Les rapports planifiés sont générés sous forme de fichiers CSV simples et stockés automatiquement et de manière sécurisée dans Google Cloud Storage. Toutefois, il n'est pas possible d'accéder directement aux buckets Google Cloud Storage contenant ces fichiers. Vous pouvez télécharger manuellement les fichiers à partir de l'interface utilisateur Display & Video 360 ou les récupérer par programmation à l'aide d'URL préautorisées obtenues à partir de l'API.

Vous trouverez ci-dessous un exemple d'utilisation de l'API pour télécharger un fichier de rapport. Dans cet exemple, queries.reports.list est utilisé avec le orderBy paramètre pour récupérer le rapport le plus récent sous une requête. Le champ Report.reportMetadata.googleCloudStoragePath est ensuite utilisé pour localiser le fichier de rapport et télécharger son contenu dans un fichier CSV local.

Java

Importations requises :

import com.google.api.client.googleapis.media.MediaHttpDownloader;
import com.google.api.client.googleapis.util.Utils;
import com.google.api.client.http.GenericUrl;
import com.google.api.services.doubleclickbidmanager.DoubleClickBidManager;
import com.google.api.services.doubleclickbidmanager.model.ListReportsResponse;
import com.google.api.services.doubleclickbidmanager.model.Report;
import java.io.FileOutputStream;
import java.io.OutputStream;

Exemple de code :

long queryId = query-id;

// Call the API, listing the reports under the given queryId from most to
// least recent.
ListReportsResponse reportListResponse =
    service
        .queries()
        .reports()
        .list(queryId)
        .setOrderBy("key.reportId desc")
        .execute();

// Iterate over returned reports, stopping once finding a report that
// finished generating successfully.
Report mostRecentReport = null;
if (reportListResponse.getReports() != null) {
  for (Report report : reportListResponse.getReports()) {
    if (report.getMetadata().getStatus().getState().equals("DONE")) {
      mostRecentReport = report;
      break;
    }
  }
} else {
  System.out.format("No reports exist for query Id %s.\n", queryId);
}

// Download report file of most recent finished report found.
if (mostRecentReport != null) {
  // Retrieve GCS URL from report object.
  GenericUrl reportUrl =
      new GenericUrl(mostRecentReport.getMetadata().getGoogleCloudStoragePath());

  // Build filename.
  String filename =
      mostRecentReport.getKey().getQueryId() + "_"
          + mostRecentReport.getKey().getReportId() + ".csv";

  // Download the report file.
  try (OutputStream output = new FileOutputStream(filename)) {
    MediaHttpDownloader downloader =
        new MediaHttpDownloader(Utils.getDefaultTransport(), null);
    downloader.download(reportUrl, output);
  }
  System.out.format("Download of file %s complete.\n", filename);
} else {
  System.out.format(
      "There are no completed report files to download for query Id %s.\n",
      queryId);
}

Python

Importations requises :

from contextlib import closing
from six.moves.urllib.request import urlopen

Exemple de code :

query_id = query-id

# Call the API, listing the reports under the given queryId from most to
# least recent.
response = service.queries().reports().list(queryId=query_id, orderBy="key.reportId desc").execute()

# Iterate over returned reports, stopping once finding a report that
# finished generating successfully.
most_recent_report = None
if response['reports']:
  for report in response['reports']:
    if report['metadata']['status']['state'] == 'DONE':
      most_recent_report = report
      break
else:
  print('No reports exist for query Id %s.' % query_id)

# Download report file of most recent finished report found.
if most_recent_report != None:
  # Retrieve GCS URL from report object.
  report_url = most_recent_report['metadata']['googleCloudStoragePath']

  # Build filename.
  output_file = '%s_%s.csv' % (report['key']['queryId'], report['key']['reportId'])

  # Download the report file.
  with open(output_file, 'wb') as output:
    with closing(urlopen(report_url)) as url:
      output.write(url.read())
  print('Download of file %s complete.' % output_file)
else:
  print('There are no completed report files to download for query Id %s.' % query_id)

PHP

$queryId = query-id;

// Call the API, listing the reports under the given queryId from most to
// least recent.
$optParams = array('orderBy' => "key.reportId desc");
$response = $service->queries_reports->listQueriesReports($queryId, $optParams);

// Iterate over returned reports, stopping once finding a report that
// finished generating successfully.
$mostRecentReport = null;
if (!empty($response->getReports())) {
  foreach ($response->getReports() as $report) {
    if ($report->metadata->status->state == "DONE") {
      $mostRecentReport = $report;
      break;
    }
  }
} else {
  printf('<p>No reports exist for query ID %s.</p>', $queryId);
}

// Download report file of most recent finished report found.
if ($mostRecentReport != null) {
  // Build filename.
  $filename = $mostRecentReport->key->queryId . '_' . $mostRecentReport->key->reportId . '.csv';

  // Download the report file.
  file_put_contents($filename, fopen($mostRecentReport->metadata->googleCloudStoragePath, 'r'));
  printf('<p>Download of file %s complete.</p>', $filename);
} else {
  printf('<p>There are no completed report files to download for query Id %s.</p>', $queryId);
}