Search in sources :

Example 11 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202111.ReportDownloadOptions in project googleads-java-lib by googleads.

the class RunDeliveryReportForOrder method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param orderId the ID of the order to run the report for.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws IOException if unable to write the response to a file.
 * @throws InterruptedException if the thread is interrupted while waiting for the report to
 *     complete.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long orderId) throws IOException, InterruptedException {
    // Get the ReportService.
    ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
    // Create report query.
    ReportQuery reportQuery = new ReportQuery();
    reportQuery.setDimensions(new Dimension[] { Dimension.DATE, Dimension.ORDER_ID });
    reportQuery.setColumns(new Column[] { Column.AD_SERVER_IMPRESSIONS, Column.AD_SERVER_CLICKS, Column.AD_SERVER_CTR, Column.AD_SERVER_CPM_AND_CPC_REVENUE });
    reportQuery.setDimensionAttributes(new DimensionAttribute[] { DimensionAttribute.ORDER_TRAFFICKER, DimensionAttribute.ORDER_START_DATE_TIME, DimensionAttribute.ORDER_END_DATE_TIME });
    // Create statement to filter for an order.
    StatementBuilder statementBuilder = new StatementBuilder().where("ORDER_ID = :orderId").withBindVariableValue("orderId", orderId);
    // Set the filter statement.
    reportQuery.setStatement(statementBuilder.toStatement());
    // Set the start and end dates or choose a dynamic date range type.
    reportQuery.setDateRangeType(DateRangeType.CUSTOM_DATE);
    reportQuery.setStartDate(DateTimes.toDateTime("2013-05-01T00:00:00", "America/New_York").getDate());
    reportQuery.setEndDate(DateTimes.toDateTime("2013-05-31T00:00:00", "America/New_York").getDate());
    // Create report job.
    ReportJob reportJob = new ReportJob();
    reportJob.setReportQuery(reportQuery);
    // Run report job.
    reportJob = reportService.runReportJob(reportJob);
    // Create report downloader.
    ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
    // Wait for the report to be ready.
    reportDownloader.waitForReportReady();
    // Change to your file location.
    File file = File.createTempFile("delivery-report-", ".csv.gz");
    System.out.printf("Downloading report to %s ...", file.toString());
    // Download the report.
    ReportDownloadOptions options = new ReportDownloadOptions();
    options.setExportFormat(ExportFormat.CSV_DUMP);
    options.setUseGzipCompression(true);
    URL url = reportDownloader.getDownloadUrl(options);
    Resources.asByteSource(url).copyTo(Files.asByteSink(file));
    System.out.println("done.");
}
Also used : ReportDownloader(com.google.api.ads.admanager.axis.utils.v202108.ReportDownloader) ReportDownloadOptions(com.google.api.ads.admanager.axis.v202108.ReportDownloadOptions) ReportQuery(com.google.api.ads.admanager.axis.v202108.ReportQuery) ReportServiceInterface(com.google.api.ads.admanager.axis.v202108.ReportServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) ReportJob(com.google.api.ads.admanager.axis.v202108.ReportJob) File(java.io.File) URL(java.net.URL)

Example 12 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202111.ReportDownloadOptions in project googleads-java-lib by googleads.

the class RunReportWithCustomFields method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param customFieldId the ID of the custom field to include in the report.
 * @param customDimensionKeyId the ID of the custom key to include as a dimension in the report.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws IOException if unable to write the response to a file.
 * @throws InterruptedException if the thread is interrupted while waiting for the report to
 *     complete.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long customFieldId, long customDimensionKeyId) throws IOException, InterruptedException {
    // Get the ReportService.
    ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
    // Create report query.
    ReportQuery reportQuery = new ReportQuery();
    reportQuery.setDimensions(new Dimension[] { Dimension.DATE, Dimension.CUSTOM_DIMENSION, Dimension.LINE_ITEM_ID });
    reportQuery.setColumns(new Column[] { Column.AD_SERVER_IMPRESSIONS });
    // Set the dynamic date range type or a custom start and end date.
    reportQuery.setDateRangeType(DateRangeType.LAST_MONTH);
    // Set the custom field IDs.
    reportQuery.setCustomFieldIds(new long[] { customFieldId });
    // Set the custom dimension IDs.
    reportQuery.setCustomDimensionKeyIds(new long[] { customDimensionKeyId });
    // Create report job.
    ReportJob reportJob = new ReportJob();
    reportJob.setReportQuery(reportQuery);
    // Run report job.
    reportJob = reportService.runReportJob(reportJob);
    // Create report downloader.
    ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
    // Wait for the report to be ready.
    reportDownloader.waitForReportReady();
    // Change to your file location.
    File file = File.createTempFile("custom-field-report-", ".csv.gz");
    System.out.printf("Downloading report to %s ...", file.toString());
    // Download the report.
    ReportDownloadOptions options = new ReportDownloadOptions();
    options.setExportFormat(ExportFormat.CSV_DUMP);
    options.setUseGzipCompression(true);
    URL url = reportDownloader.getDownloadUrl(options);
    Resources.asByteSource(url).copyTo(Files.asByteSink(file));
    System.out.println("done.");
}
Also used : ReportDownloader(com.google.api.ads.admanager.axis.utils.v202108.ReportDownloader) ReportDownloadOptions(com.google.api.ads.admanager.axis.v202108.ReportDownloadOptions) ReportQuery(com.google.api.ads.admanager.axis.v202108.ReportQuery) ReportServiceInterface(com.google.api.ads.admanager.axis.v202108.ReportServiceInterface) ReportJob(com.google.api.ads.admanager.axis.v202108.ReportJob) File(java.io.File) URL(java.net.URL)

Example 13 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202111.ReportDownloadOptions in project googleads-java-lib by googleads.

the class RunDeliveryReportForOrder method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param orderId the ID of the order to run the report for.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws IOException if unable to write the response to a file.
 * @throws InterruptedException if the thread is interrupted while waiting for the report to
 *     complete.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long orderId) throws IOException, InterruptedException {
    // Get the ReportService.
    ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
    // Create report query.
    ReportQuery reportQuery = new ReportQuery();
    reportQuery.setDimensions(new Dimension[] { Dimension.DATE, Dimension.ORDER_ID });
    reportQuery.setColumns(new Column[] { Column.AD_SERVER_IMPRESSIONS, Column.AD_SERVER_CLICKS, Column.AD_SERVER_CTR, Column.AD_SERVER_CPM_AND_CPC_REVENUE });
    reportQuery.setDimensionAttributes(new DimensionAttribute[] { DimensionAttribute.ORDER_TRAFFICKER, DimensionAttribute.ORDER_START_DATE_TIME, DimensionAttribute.ORDER_END_DATE_TIME });
    // Create statement to filter for an order.
    StatementBuilder statementBuilder = new StatementBuilder().where("ORDER_ID = :orderId").withBindVariableValue("orderId", orderId);
    // Set the filter statement.
    reportQuery.setStatement(statementBuilder.toStatement());
    // Set the start and end dates or choose a dynamic date range type.
    reportQuery.setDateRangeType(DateRangeType.CUSTOM_DATE);
    reportQuery.setStartDate(DateTimes.toDateTime("2013-05-01T00:00:00", "America/New_York").getDate());
    reportQuery.setEndDate(DateTimes.toDateTime("2013-05-31T00:00:00", "America/New_York").getDate());
    // Create report job.
    ReportJob reportJob = new ReportJob();
    reportJob.setReportQuery(reportQuery);
    // Run report job.
    reportJob = reportService.runReportJob(reportJob);
    // Create report downloader.
    ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
    // Wait for the report to be ready.
    reportDownloader.waitForReportReady();
    // Change to your file location.
    File file = File.createTempFile("delivery-report-", ".csv.gz");
    System.out.printf("Downloading report to %s ...", file.toString());
    // Download the report.
    ReportDownloadOptions options = new ReportDownloadOptions();
    options.setExportFormat(ExportFormat.CSV_DUMP);
    options.setUseGzipCompression(true);
    URL url = reportDownloader.getDownloadUrl(options);
    Resources.asByteSource(url).copyTo(Files.asByteSink(file));
    System.out.println("done.");
}
Also used : ReportDownloader(com.google.api.ads.admanager.axis.utils.v202202.ReportDownloader) ReportDownloadOptions(com.google.api.ads.admanager.axis.v202202.ReportDownloadOptions) ReportQuery(com.google.api.ads.admanager.axis.v202202.ReportQuery) ReportServiceInterface(com.google.api.ads.admanager.axis.v202202.ReportServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) ReportJob(com.google.api.ads.admanager.axis.v202202.ReportJob) File(java.io.File) URL(java.net.URL)

Example 14 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202111.ReportDownloadOptions in project googleads-java-lib by googleads.

the class RunReachReport method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws IOException if unable to write the response to a file.
 * @throws InterruptedException if the thread is interrupted while waiting for the report to
 *     complete.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws IOException, InterruptedException {
    // Get the ReportService.
    ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
    // Create report query.
    ReportQuery reportQuery = new ReportQuery();
    reportQuery.setDimensions(new Dimension[] { Dimension.COUNTRY_NAME, Dimension.LINE_ITEM_ID, Dimension.LINE_ITEM_NAME });
    reportQuery.setColumns(new Column[] { Column.UNIQUE_REACH_FREQUENCY, Column.UNIQUE_REACH_IMPRESSIONS, Column.UNIQUE_REACH });
    // Set the dynamic date range type or a custom start and end date that is
    // the beginning of the week (Sunday) to the end of the week (Saturday), or
    // the first of the month to the end of the month.
    reportQuery.setDateRangeType(DateRangeType.REACH_LIFETIME);
    // Create report job.
    ReportJob reportJob = new ReportJob();
    reportJob.setReportQuery(reportQuery);
    // Run report job.
    reportJob = reportService.runReportJob(reportJob);
    // Create report downloader.
    ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
    // Wait for the report to be ready.
    reportDownloader.waitForReportReady();
    // Change to your file location.
    File file = File.createTempFile("reach-report-", ".csv.gz");
    System.out.printf("Downloading report to %s ...", file.toString());
    // Download the report.
    ReportDownloadOptions options = new ReportDownloadOptions();
    options.setExportFormat(ExportFormat.CSV_DUMP);
    options.setUseGzipCompression(true);
    URL url = reportDownloader.getDownloadUrl(options);
    Resources.asByteSource(url).copyTo(Files.asByteSink(file));
    System.out.println("done.");
}
Also used : ReportDownloader(com.google.api.ads.admanager.axis.utils.v202202.ReportDownloader) ReportDownloadOptions(com.google.api.ads.admanager.axis.v202202.ReportDownloadOptions) ReportQuery(com.google.api.ads.admanager.axis.v202202.ReportQuery) ReportServiceInterface(com.google.api.ads.admanager.axis.v202202.ReportServiceInterface) ReportJob(com.google.api.ads.admanager.axis.v202202.ReportJob) File(java.io.File) URL(java.net.URL)

Example 15 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202111.ReportDownloadOptions in project googleads-java-lib by googleads.

the class RunAdExchangeReport method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws IOException if the report's contents could not be written to a temp file.
 * @throws InterruptedException if the thread was interrupted while waiting for the report to be
 *     ready.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws IOException, InterruptedException {
    // Get the ReportService.
    ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
    // Create report query.
    ReportQuery reportQuery = new ReportQuery();
    reportQuery.setDimensions(new Dimension[] { Dimension.AD_EXCHANGE_DATE, Dimension.AD_EXCHANGE_COUNTRY_NAME });
    reportQuery.setColumns(new Column[] { Column.AD_EXCHANGE_AD_REQUESTS, Column.AD_EXCHANGE_IMPRESSIONS, Column.AD_EXCHANGE_ESTIMATED_REVENUE });
    // Run in pacific time.
    reportQuery.setTimeZoneType(TimeZoneType.AD_EXCHANGE);
    reportQuery.setAdxReportCurrency("EUR");
    // Set the dynamic date range type or a custom start and end date.
    reportQuery.setDateRangeType(DateRangeType.YESTERDAY);
    // Create report job.
    ReportJob reportJob = new ReportJob();
    reportJob.setReportQuery(reportQuery);
    // Run report job.
    reportJob = reportService.runReportJob(reportJob);
    // Create report downloader.
    ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
    // Wait for the report to be ready.
    reportDownloader.waitForReportReady();
    // Change to your file location.
    File file = File.createTempFile("adexchange-report-", ".csv.gz");
    System.out.printf("Downloading report to %s ...", file.toString());
    // Download the report.
    ReportDownloadOptions options = new ReportDownloadOptions();
    options.setExportFormat(ExportFormat.CSV_DUMP);
    options.setUseGzipCompression(true);
    URL url = reportDownloader.getDownloadUrl(options);
    Resources.asByteSource(url).copyTo(Files.asByteSink(file));
    System.out.println("done.");
}
Also used : ReportDownloader(com.google.api.ads.admanager.axis.utils.v202202.ReportDownloader) ReportDownloadOptions(com.google.api.ads.admanager.axis.v202202.ReportDownloadOptions) ReportQuery(com.google.api.ads.admanager.axis.v202202.ReportQuery) ReportServiceInterface(com.google.api.ads.admanager.axis.v202202.ReportServiceInterface) ReportJob(com.google.api.ads.admanager.axis.v202202.ReportJob) File(java.io.File) URL(java.net.URL)

Aggregations

URL (java.net.URL)33 File (java.io.File)24 ReportDownloadOptions (com.google.api.ads.admanager.axis.v202108.ReportDownloadOptions)10 ReportDownloadOptions (com.google.api.ads.admanager.axis.v202111.ReportDownloadOptions)10 ReportDownloadOptions (com.google.api.ads.admanager.axis.v202202.ReportDownloadOptions)10 ReportDownloader (com.google.api.ads.admanager.axis.utils.v202108.ReportDownloader)8 ReportDownloader (com.google.api.ads.admanager.axis.utils.v202111.ReportDownloader)8 ReportDownloader (com.google.api.ads.admanager.axis.utils.v202202.ReportDownloader)8 ReportJob (com.google.api.ads.admanager.axis.v202108.ReportJob)8 ReportQuery (com.google.api.ads.admanager.axis.v202108.ReportQuery)8 ReportServiceInterface (com.google.api.ads.admanager.axis.v202108.ReportServiceInterface)8 ReportJob (com.google.api.ads.admanager.axis.v202111.ReportJob)8 ReportQuery (com.google.api.ads.admanager.axis.v202111.ReportQuery)8 ReportServiceInterface (com.google.api.ads.admanager.axis.v202111.ReportServiceInterface)8 ReportJob (com.google.api.ads.admanager.axis.v202202.ReportJob)8 ReportQuery (com.google.api.ads.admanager.axis.v202202.ReportQuery)8 ReportServiceInterface (com.google.api.ads.admanager.axis.v202202.ReportServiceInterface)8 Test (org.junit.Test)8 CharSource (com.google.common.io.CharSource)4 ReportCallback (com.google.api.ads.admanager.lib.utils.ReportCallback)3