How to specify a date range for the Google Adwords CLICK_PERFORMANCE_REPORT

4.2k Views Asked by At

I am trying to query the adwords api (v201603) and am using/extending the Java examples provided.

The problem I am encountering is being able to specify a specific date to download the report data for the CLICK_PERFORMANCE_REPORT report. This report is restricted to returning a single days worth of data at a time (for up to the last 90 days).

I can get todays and yesterdays data using the specifiers : ReportDefinitionDateRangeType.TODAY and ReportDefinitionDateRangeType.YESTERDAY, but what I really need to do is be able to specify a specific date within the last 90 days in order to get as much historical data as possible.

I have tried the following:

    DateRange dr = new DateRange();
    dr.setMin("20160401");
    dr.setMax("20160402");
    selector.setDateRange(dr);

    reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.CUSTOM_DATE);
    reportDefinition.setReportType(ReportDefinitionReportType.CLICK_PERFORMANCE_REPORT);
    reportDefinition.setDownloadFormat(DownloadFormat.CSV);

Both with and without the custom date specifier - and either gives the following error:

Report was not downloaded due to: HTTP Response Code: 400, Trigger: A single day DateRange is required for reportType: CLICK_PERFORMANCE_REPORT, Type: ReportDefinitionError.INVALID_DATE_RANGE_FOR_REPORT

Any help much appreciated, thanks in advance

2

There are 2 best solutions below

0
On

Single Day Iterator for AdWords Scripts CLICK_PERFORMANCE_REPORT:

var start = new Date("12/01/2016");
var end = new Date("12/18/2016");

while(start < end){

   var newDate = start.setDate(start.getDate() + 1);
   start = new Date(newDate);
   singleDay = start.toISOString().substring(0, 10).replace(/-/g,"");
   console.log(singleDay);

}

Utilities.formatDate(start, timeZone, "yyyyMMdd"); formats date object as an 8-digit integer, so:

singleDay = Utilities.formatDate(start, timeZone, "yyyyMMdd");

Use singleDay in 'DURING ' + singleDay + ',' + singleDay);

Working with Dates and Times #Reporting — AdWords Scripts

0
On

You're going to have to use DURING and the same date string.

... + 'DURING 20161004,20161004';