/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { ReportService reportService = (ReportService) user.GetService( DfpService.v201505.ReportService); // Set the file path where the report will be saved. String filePath = _T("INSERT_FILE_PATH_HERE"); long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE")); // Create statement object to filter for an order. StatementBuilder statementBuilder = new StatementBuilder() .Where("ORDER_ID = :id") .AddValue("id", orderId); // Create report job. ReportJob reportJob = new ReportJob(); reportJob.reportQuery = new ReportQuery(); reportJob.reportQuery.dimensions = new Dimension[] {Dimension.ORDER_ID, Dimension.ORDER_NAME}; reportJob.reportQuery.dimensionAttributes = new DimensionAttribute[] { DimensionAttribute.ORDER_TRAFFICKER, DimensionAttribute.ORDER_START_DATE_TIME, DimensionAttribute.ORDER_END_DATE_TIME}; reportJob.reportQuery.columns = new Column[] {Column.AD_SERVER_IMPRESSIONS, Column.AD_SERVER_CLICKS, Column.AD_SERVER_CTR, Column.AD_SERVER_CPM_AND_CPC_REVENUE, Column.AD_SERVER_WITHOUT_CPD_AVERAGE_ECPM}; reportJob.reportQuery.dateRangeType = DateRangeType.LAST_MONTH; reportJob.reportQuery.statement = statementBuilder.ToStatement(); try { // Run report job. reportJob = reportService.runReportJob(reportJob); ReportUtilities reportUtilities = new ReportUtilities(reportService, reportJob.id); // Set download options. ReportDownloadOptions options = new ReportDownloadOptions(); options.exportFormat = ExportFormat.CSV_DUMP; options.useGzipCompression = true; reportUtilities.reportDownloadOptions = options; // Download the report. using (ReportResponse reportResponse = reportUtilities.GetResponse()) { reportResponse.Save(filePath); } Console.WriteLine("Report saved to \"{0}\".", filePath); } catch (Exception e) { Console.WriteLine("Failed to run delivery report. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { ReportService reportService = (ReportService) user.GetService( DfpService.v201505.ReportService); // Set the file path where the report will be saved. String filePath = _T("INSERT_FILE_PATH_HERE"); // Create report job. ReportJob reportJob = new ReportJob(); reportJob.reportQuery = new ReportQuery(); reportJob.reportQuery.dimensions = new Dimension[] {Dimension.SALESPERSON_ID, Dimension.SALESPERSON_NAME}; reportJob.reportQuery.columns = new Column[] { Column.AD_SERVER_IMPRESSIONS, Column.AD_SERVER_CPM_AND_CPC_REVENUE, Column.AD_SERVER_WITHOUT_CPD_AVERAGE_ECPM }; reportJob.reportQuery.dateRangeType = DateRangeType.LAST_MONTH; try { // Run report. reportJob = reportService.runReportJob(reportJob); ReportUtilities reportUtilities = new ReportUtilities(reportService, reportJob.id); // Set download options. ReportDownloadOptions options = new ReportDownloadOptions(); options.exportFormat = ExportFormat.CSV_DUMP; options.useGzipCompression = true; reportUtilities.reportDownloadOptions = options; // Download the report. using (ReportResponse reportResponse = reportUtilities.GetResponse()) { reportResponse.Save(filePath); } Console.WriteLine("Report saved to \"{0}\".", filePath); } catch (Exception e) { Console.WriteLine("Failed to run sales report. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { ReportService reportService = (ReportService) user.GetService( DfpService.v201505.ReportService); // Set the file path where the report will be saved. String filePath = _T("INSERT_FILE_PATH_HERE"); // Create report job. ReportJob reportJob = new ReportJob(); // Create report query. ReportQuery reportQuery = new ReportQuery(); reportQuery.dateRangeType = DateRangeType.REACH_LIFETIME; reportQuery.dimensions = new Dimension[] {Dimension.LINE_ITEM_ID, Dimension.LINE_ITEM_NAME}; reportQuery.columns = new Column[] {Column.REACH_FREQUENCY, Column.REACH_AVERAGE_REVENUE, Column.REACH}; reportJob.reportQuery = reportQuery; try { // Run report. reportJob = reportService.runReportJob(reportJob); ReportUtilities reportUtilities = new ReportUtilities(reportService, reportJob.id); // Set download options. ReportDownloadOptions options = new ReportDownloadOptions(); options.exportFormat = ExportFormat.CSV_DUMP; options.useGzipCompression = true; reportUtilities.reportDownloadOptions = options; // Download the report. using (ReportResponse reportResponse = reportUtilities.GetResponse()) { reportResponse.Save(filePath); } Console.WriteLine("Report saved to \"{0}\".", filePath); } catch (Exception e) { Console.WriteLine("Failed to run delivery report. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { ReportService reportService = (ReportService) user.GetService( DfpService.v201505.ReportService); // Get the NetworkService. NetworkService networkService = (NetworkService) user.GetService( DfpService.v201505.NetworkService); // Set the file path where the report will be saved. String filePath = _T("INSERT_FILE_PATH_HERE"); // Get the root ad unit ID to filter on. String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId; // Create statement to filter on an ancestor ad unit with the root ad unit ID to include all // ad units in the network. StatementBuilder statementBuilder = new StatementBuilder() .Where("PARENT_AD_UNIT_ID = :parentAdUnitId") .AddValue("parentAdUnitId", long.Parse(rootAdUnitId)); // Create report query. ReportQuery reportQuery = new ReportQuery(); reportQuery.dimensions = new Dimension[] {Dimension.AD_UNIT_ID, Dimension.AD_UNIT_NAME}; reportQuery.columns = new Column[] {Column.AD_SERVER_IMPRESSIONS, Column.AD_SERVER_CLICKS, Column.DYNAMIC_ALLOCATION_INVENTORY_LEVEL_IMPRESSIONS, Column.DYNAMIC_ALLOCATION_INVENTORY_LEVEL_CLICKS, Column.TOTAL_INVENTORY_LEVEL_IMPRESSIONS, Column.TOTAL_INVENTORY_LEVEL_CPM_AND_CPC_REVENUE}; // Set the filter statement. reportQuery.statement = statementBuilder.ToStatement(); reportQuery.adUnitView = ReportQueryAdUnitView.HIERARCHICAL; reportQuery.dateRangeType = DateRangeType.LAST_WEEK; // Create report job. ReportJob reportJob = new ReportJob(); reportJob.reportQuery = reportQuery; try { // Run report. reportJob = reportService.runReportJob(reportJob); ReportUtilities reportUtilities = new ReportUtilities(reportService, reportJob.id); // Set download options. ReportDownloadOptions options = new ReportDownloadOptions(); options.exportFormat = ExportFormat.CSV_DUMP; options.useGzipCompression = true; reportUtilities.reportDownloadOptions = options; // Download the report. using (ReportResponse reportResponse = reportUtilities.GetResponse()) { reportResponse.Save(filePath); } Console.WriteLine("Report saved to \"{0}\".", filePath); } catch (Exception e) { Console.WriteLine("Failed to run inventory report. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Handles the Click event of the btnDownloadReport control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="eventArgs">The <see cref="System.EventArgs"/> instance containing /// the event data.</param> protected void OnDownloadReportButtonClick(object sender, EventArgs eventArgs) { ConfigureUserForOAuth(); ReportService reportService = (ReportService) user.GetService( DfpService.v201505.ReportService); ReportQuery reportQuery = new ReportQuery(); reportQuery.dimensions = new Dimension[] { Dimension.AD_UNIT_ID, Dimension.AD_UNIT_NAME }; reportQuery.columns = new Column[] { Column.AD_SERVER_IMPRESSIONS, Column.AD_SERVER_CLICKS, Column.DYNAMIC_ALLOCATION_INVENTORY_LEVEL_IMPRESSIONS, Column.DYNAMIC_ALLOCATION_INVENTORY_LEVEL_CLICKS, Column.TOTAL_INVENTORY_LEVEL_IMPRESSIONS, Column.TOTAL_INVENTORY_LEVEL_CPM_AND_CPC_REVENUE }; reportQuery.adUnitView = ReportQueryAdUnitView.HIERARCHICAL; reportQuery.dateRangeType = DateRangeType.YESTERDAY; // Create report job. ReportJob reportJob = new ReportJob(); reportJob.reportQuery = reportQuery; string filePath = Path.GetTempFileName(); try { // Run report. reportJob = reportService.runReportJob(reportJob); ReportUtilities reportUtilities = new ReportUtilities(reportService, reportJob.id); // Set download options. ReportDownloadOptions options = new ReportDownloadOptions(); options.exportFormat = ExportFormat.CSV_DUMP; options.useGzipCompression = true; reportUtilities.reportDownloadOptions = options; // Download the report. using (ReportResponse reportResponse = reportUtilities.GetResponse()) { reportResponse.Save(filePath); } } catch (Exception e) { throw new System.ApplicationException("Failed to download report.", e); } Response.AddHeader("content-disposition", "attachment;filename=report.csv.gzip"); Response.WriteFile(filePath); Response.End(); }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the LineItemService. LineItemService lineItemService = (LineItemService) user.GetService(DfpService.v201505.LineItemService); // Get the ReportService. ReportService reportService = (ReportService) user.GetService(DfpService.v201505.ReportService); try { // Set the ID of the order to get line items from. long orderId = long.Parse(_T("INSERT_ORDER_ID_HERE")); // Set the file path where the report will be saved. String filePath = _T("INSERT_FILE_PATH_HERE"); // Sets default for page. LineItemPage page = new LineItemPage(); // Create a statement to only select line items from a given order. StatementBuilder statementBuilder = new StatementBuilder() .Where("orderId = :orderId") .Limit(StatementBuilder.SUGGESTED_PAGE_LIMIT) .AddValue("orderId", orderId); // Collect all line item custom field IDs for an order. List<long> customFieldIds = new List<long>(); do { // Get line items by statement. page = lineItemService.getLineItemsByStatement(statementBuilder.ToStatement()); // Get custom field IDs from the line items of an order. if (page.results != null) { foreach (LineItem lineItem in page.results) { if (lineItem.customFieldValues != null) { foreach (BaseCustomFieldValue customFieldValue in lineItem.customFieldValues) { if (!customFieldIds.Contains(customFieldValue.customFieldId)) { customFieldIds.Add(customFieldValue.customFieldId); } } } } } statementBuilder.IncreaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT); } while (statementBuilder.GetOffset() < page.totalResultSetSize); // Create statement to filter for an order. statementBuilder.RemoveLimitAndOffset(); // Create report job. ReportJob reportJob = new ReportJob(); // Create report query. ReportQuery reportQuery = new ReportQuery(); reportQuery.dateRangeType = DateRangeType.LAST_MONTH; reportQuery.dimensions = new Dimension[] {Dimension.LINE_ITEM_ID, Dimension.LINE_ITEM_NAME}; reportQuery.statement = statementBuilder.ToStatement(); reportQuery.customFieldIds = customFieldIds.ToArray(); reportQuery.columns = new Column[] {Column.AD_SERVER_IMPRESSIONS}; reportJob.reportQuery = reportQuery; // Run report job. reportJob = reportService.runReportJob(reportJob); ReportUtilities reportUtilities = new ReportUtilities(reportService, reportJob.id); // Set download options. ReportDownloadOptions options = new ReportDownloadOptions(); options.exportFormat = ExportFormat.CSV_DUMP; options.useGzipCompression = true; reportUtilities.reportDownloadOptions = options; // Download the report. using (ReportResponse reportResponse = reportUtilities.GetResponse()) { reportResponse.Save(filePath); } Console.WriteLine("Report saved to \"{0}\".", filePath); } catch (Exception e) { Console.WriteLine("Failed to run cusom fields report. Exception says \"{0}\"", e.Message); } }