private void DefineReportCriteria(Report report)
        {
            // Define a date range to report on. This example uses explicit start and
            // end dates to mimic the "LAST_30_DAYS" relative date range.
            DateRange dateRange = new DateRange();

            dateRange.EndDate   = DateTime.Now.ToString("yyyy-MM-dd");
            dateRange.StartDate = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd");

            // Create a report criteria.
            SortedDimension dimension = new SortedDimension();

            dimension.Name = "dfa:advertiser";

            Report.CriteriaData criteria = new Report.CriteriaData();
            criteria.DateRange  = dateRange;
            criteria.Dimensions = new List <SortedDimension>()
            {
                dimension
            };
            criteria.MetricNames = new List <string>()
            {
                "dfa:clicks",
                "dfa:impressions"
            };

            // Add the criteria to the report resource.
            report.Criteria = criteria;

            Console.WriteLine("\nAdded report criteria:\n{0}",
                              JsonConvert.SerializeObject(criteria));
        }
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="service">An initialized Dfa Reporting service object
    /// </param>
    public override void Run(DfareportingService service) {
      long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

      string reportName = _T("INSERT_REPORT_NAME_HERE");

      // Create a date range to report on.
      DateRange dateRange = new DateRange();
      dateRange.RelativeDateRange = "YESTERDAY";

      // Create a dimension to report on.
      SortedDimension dimension = new SortedDimension();
      dimension.Name = "dfa:campaign";

      // Create the criteria for the report.
      Report.CriteriaData criteria = new Report.CriteriaData();
      criteria.DateRange = dateRange;
      criteria.Dimensions = new List<SortedDimension>() { dimension };
      criteria.MetricNames = new List<string>() { "dfa:clicks" };

      // Create the report.
      Report report = new Report();
      report.Criteria = criteria;
      report.Name = reportName;
      report.Type = "STANDARD";

      // Insert the report.
      Report result = service.Reports.Insert(report, profileId).Execute();

      // Display the new report ID.
      Console.WriteLine("Standard report with ID {0} was created.", result.Id);
    }
        private void FindCompatibleFields(DfareportingService service,
                                          long profileId, Report report)
        {
            CompatibleFields fields =
                service.Reports.CompatibleFields.Query(report, profileId).Execute();

            ReportCompatibleFields reportFields = fields.ReportCompatibleFields;

            if (reportFields.Dimensions.Any())
            {
                // Add a compatible dimension to the report.
                Dimension       dimension       = reportFields.Dimensions[0];
                SortedDimension sortedDimension = new SortedDimension();
                sortedDimension.Name = dimension.Name;
                report.Criteria.Dimensions.Add(sortedDimension);
            }
            else if (reportFields.Metrics.Any())
            {
                // Add a compatible metric to the report.
                Metric metric = reportFields.Metrics[0];
                report.Criteria.MetricNames.Add(metric.Name);
            }

            Console.WriteLine(
                "\nUpdated report criteria (with compatible fields):\n{0}",
                JsonConvert.SerializeObject(report.Criteria));
        }
Esempio n. 4
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="service">An initialized Dfa Reporting service object
        /// </param>
        public override void Run(DfareportingService service)
        {
            long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

            string reportName = _T("INSERT_REPORT_NAME_HERE");

            // Create a date range to report on.
            DateRange dateRange = new DateRange();

            dateRange.RelativeDateRange = "YESTERDAY";

            // Create a dimension to report on.
            SortedDimension dimension = new SortedDimension();

            dimension.Name = "dfa:campaign";

            // Create the criteria for the report.
            Report.CriteriaData criteria = new Report.CriteriaData();
            criteria.DateRange  = dateRange;
            criteria.Dimensions = new List <SortedDimension>()
            {
                dimension
            };
            criteria.MetricNames = new List <string>()
            {
                "dfa:clicks"
            };

            // Create the report.
            Report report = new Report();

            report.Criteria = criteria;
            report.Name     = reportName;
            report.Type     = "STANDARD";

            // Insert the report.
            Report result = service.Reports.Insert(report, profileId).Execute();

            // Display the new report ID.
            Console.WriteLine("Standard report with ID {0} was created.", result.Id);
        }