Downloads a report with AWQL. 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 DownloadReportWithAwql ( string $reportQuery, string $path = null, AdWordsUser $user, $reportFormat, array $options = null ) : mixed | ||
$reportQuery | string | the query to use for the report |
$path | string | an optional path of the file to download the report to |
$user | AdWordsUser | the user to retrieve report with |
$options | array | the option to use when downloading the report: {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 |
/** * 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 DownloadCriteriaReportWithAwqlExample(AdWordsUser $user, $filePath, $reportFormat) { // Optional: Set clientCustomerId to get reports of your child accounts // $user->SetClientCustomerId('INSERT_CLIENT_CUSTOMER_ID_HERE'); // Prepare a date range for the last week. Instead you can use 'LAST_7_DAYS'. $dateRange = sprintf('%d,%d', date('Ymd', strtotime('-7 day')), date('Ymd', strtotime('-1 day'))); // Create report query. $reportQuery = 'SELECT CampaignId, AdGroupId, Id, Criteria, CriteriaType, ' . 'Impressions, Clicks, Cost FROM CRITERIA_PERFORMANCE_REPORT ' . 'WHERE Status IN [ENABLED, PAUSED] DURING ' . $dateRange; // 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 useRawEnumValues to return enum values instead of enum // display values. // $options['useRawEnumValues'] = false; // // Optional: Set includeZeroImpressions to include zero impression rows in // the report output. // $options['includeZeroImpressions'] = true; // Download report. $reportUtils = new ReportUtils(); $reportUtils->DownloadReportWithAwql($reportQuery, $filePath, $user, $reportFormat, $options); printf("Report was downloaded to '%s'.\n", $filePath); }
/** * 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 DownloadCriteriaReportWithAwqlExample(AdWordsUser $user, $filePath, $reportFormat) { // Prepare a date range for the last week. Instead you can use 'LAST_7_DAYS'. $dateRange = sprintf('%d,%d', date('Ymd', strtotime('-7 day')), date('Ymd', strtotime('-1 day'))); // Create report query. $reportQuery = 'SELECT CampaignId, AdGroupId, Id, Criteria, CriteriaType, ' . 'Impressions, Clicks, Cost FROM CRITERIA_PERFORMANCE_REPORT ' . 'WHERE Status IN [ACTIVE, PAUSED] DURING ' . $dateRange; // Set additional options. $options = array('version' => 'v201206'); // Download report. ReportUtils::DownloadReportWithAwql($reportQuery, $filePath, $user, $reportFormat, $options); printf("Report was downloaded to '%s'.\n", $filePath); }
/** * 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 DownloadCriteriaReportWithAwqlExample(AdWordsUser $user, $filePath, $reportFormat) { // Prepare a date range for the last week. Instead you can use 'LAST_7_DAYS'. $dateRange = sprintf('%d,%d', date('Ymd', strtotime('-7 day')), date('Ymd', strtotime('-1 day'))); // Create report query. $reportQuery = 'SELECT CampaignId, AdGroupId, Id, Criteria, CriteriaType, ' . 'Impressions, Clicks, Cost FROM CRITERIA_PERFORMANCE_REPORT ' . 'WHERE Status IN [ENABLED, PAUSED] DURING ' . $dateRange; // Set additional options. $options = array('version' => ADWORDS_VERSION); // Optional: Set skipReportHeader, skipColumnHeader or skipReportSummary to // suppress header or summary rows in the report output. // $options['skipReportHeader'] = true; // $options['skipColumnHeader'] = true; // $options['skipReportSummary'] = true; // Download report. ReportUtils::DownloadReportWithAwql($reportQuery, $filePath, $user, $reportFormat, $options); printf("Report was downloaded to '%s'.\n", $filePath); }
/** * @param $reportQuery * @param string $format * @param array $options * @return null|string|void */ public function downloadReportWithAwql($reportQuery, $format, $path = null, array $options = null) { $allowformats = array("CSV", "XML", "TSV", "GZIPPED_CSV", "GZIPPED_XML"); if (!in_array($format, $allowformats)) { return; } if (!$this->validateUser()) { return; } $report = null; try { $report = \ReportUtils::DownloadReportWithAwql($reportQuery, $path, $this->adwordsuser, $format, $options); if ("GZIPPED_CSV" == $format || "GZIPPED_XML" == $format) { $report = gzdecode($report); } } catch (\Exception $e) { $this->lastexception = $e; return; } return $report; }