ReportUtils::DownloadReport PHP Method

DownloadReport() public method

Downloads a new instance of an existing report definition. If the path parameter is specified it will be downloaded to the file at that path, otherwise it will be downloaded to memory and be returned as a string.
public DownloadReport ( mixed $reportDefinition, string $path = null, AdWordsUser $user, array $options = null ) : mixed
$reportDefinition mixed the ReportDefinition to download or the id of a stored report definition
$path string an optional path of the file to download the report to
$user AdWordsUser the user that created the ReportDefinition
$options array the option to use when downloading the report: {boolean} skipReportHeader: if report responses should skip the header row containing the report name and date range {boolean} skipColumnHeader: if report responses should skip the header row containing column names {boolean} skipReportSummary: if report responses should skip the summary row containing totals {boolean} includeZeroImpressions: if report responses should include zero impression rows {boolean} useRawEnumValues: if report responses should return enum values instead of enum display values {string} server: the server to make the request to. If null, then the default server will be used {string} version: the version to make the request against. If null, then the default version will be used
return mixed if path isn't specified the contents of the report, otherwise the size in bytes of the downloaded report
    public function DownloadReport($reportDefinition, $path = null, AdWordsUser $user, array $options = null)
    {
        if ($path === null || $path === '') {
            $this->adsUtilityRegistry->addUtility(AdsUtility::REPORT_UTILS_STRING);
        } else {
            $this->adsUtilityRegistry->addUtility(AdsUtility::REPORT_UTILS_FILE);
        }
        return ReportUtilsDelegate::DownloadReport($reportDefinition, $path, $user, $options);
    }

Same methods

ReportUtils::DownloadReport ( mixed $reportDefinition, string $path = null, AdWordsUser $user, array $options = null, array $customCurlOptions = null ) : mixed

Usage Example

/**
 * 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);
}
All Usage Examples Of ReportUtils::DownloadReport