/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
* @param string $filePath the path of the file to download the report to
*/
function DownloadCriteriaReportExample(AdWordsUser $user, $filePath)
{
// Load the service, so that the required classes are available.
$user->LoadService('ReportDefinitionService', ADWORDS_VERSION);
// Create selector.
$selector = new Selector();
$selector->fields = array('CampaignId', 'AdGroupId', 'Id', 'Criteria', 'CriteriaType', 'Impressions', 'Clicks', 'Cost');
// Optional: use predicate to filter out paused criteria.
$selector->predicates[] = new Predicate('Status', 'NOT_IN', array('PAUSED'));
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->selector = $selector;
$reportDefinition->reportName = 'Criteria performance report #' . uniqid();
$reportDefinition->dateRangeType = 'LAST_7_DAYS';
$reportDefinition->reportType = 'CRITERIA_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';
// Exclude criteria that haven't recieved any impressions over the date range.
$reportDefinition->includeZeroImpressions = false;
// Set additional options.
$options = array('version' => ADWORDS_VERSION);
// Optional: Set skipReportHeader, skipColumnHeader, skipReportSummary to
// suppress headers or summary rows.
// $options['skipReportHeader'] = true;
// $options['skipColumnHeader'] = true;
// $options['skipReportSummary'] = true;
// Optional: Set includeZeroImpressions to include zero impression rows in
// the report output.
// $options['includeZeroImpressions'] = true;
// Download report.
ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);
printf("Report with name '%s' was downloaded to '%s'.\n", $reportDefinition->reportName, $filePath);
}