Sie können Berichte über die Google Display & Video 360-Benutzeroberfläche oder die API erstellen und planen. Endnutzer können beispielsweise einen täglichen Bericht mit den gestrigen Impressionen oder einen monatlichen Bericht mit den Gesamtausgaben einrichten.
Geplante Berichte erstellen
Erstellen Sie über die Berichterstellungsoberfläche von Display & Video 360 oder mit der API-Methode queries.create
einen neuen geplanten Bericht. Ausführliche Informationen zu den Berichtsfunktionen von Display & Video 360 und zum Erstellen neuer Berichte finden Sie auf der Supportwebsite von Display & Video 360.
Berichte können bei der Erstellung mit dem Feld Repeats
in der Benutzeroberfläche und dem Feld schedule
in der API geplant werden. Für diese Felder sollte ein geeignetes Zeitintervall festgelegt werden.
Nachdem das richtige Feld festgelegt wurde, wird dieser Bericht nach diesem Zeitplan ausgeführt und die generierten Berichte stehen dann zum Download zur Verfügung.
Auf geplante Berichte zugreifen
Geplante Berichte werden als einfache CSV-Dateien generiert und automatisch und sicher in Google Cloud Storage gespeichert. Es ist jedoch nicht möglich, direkt auf die Google Cloud Storage-Buckets zuzugreifen, die diese Dateien enthalten. Stattdessen können die Dateien manuell über die Benutzeroberfläche von Display & Video 360 heruntergeladen oder programmatisch mithilfe von vorautorisierten URLs aus der API abgerufen werden.
Im Folgenden finden Sie ein Beispiel für die Verwendung der API zum Herunterladen einer Berichtsdatei. In diesem Beispiel wird queries.reports.list
mit dem Parameter orderBy
verwendet, um den neuesten Bericht unter einer Abfrage abzurufen. Anschließend wird mithilfe des Felds Report.reportMetadata.googleCloudStoragePath
die Berichtsdatei gesucht und ihr Inhalt in eine lokale CSV-Datei heruntergeladen.
Java
Erforderliche Importe:
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;
Codebeispiel:
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
Erforderliche Importe:
from contextlib import closing from six.moves.urllib.request import urlopen
Codebeispiel:
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); }