Reputation: 11
I have been trying to add a custom date range to the selector of my adwords report and cannot get the dates to take. I'm getting back undefined function call 'DateRange'.
Has anyone been able to figure this out?
class ParallelReportDownload {
// Timeout between retries in seconds.
const BACKOFF_FACTOR = 5;
// Maximum number of retries for 500 errors.
const MAX_RETRIES = 5;
// The number of entries per page of the results.
const PAGE_LIMIT = 500;
public static function runExample(AdWordsServices $adWordsServices,
AdWordsSessionBuilder $sessionBuilder, $reportDir) {
// Construct an API session for the client customer ID specified in the
// configuration file.
$session = $sessionBuilder->build();
// Create selector.
$selector = new Selector();
$selector->setFields(['Month', 'Impressions', 'Clicks', 'Ctr', 'AverageCpc', 'AveragePosition', 'Cost', 'Conversions', 'CostPerConversion', 'ConversionRate', 'SearchImpressionShare']);
//THIS CODE WAS FOUND ON GOOGLE API FORUM
$selector->dateRange = new DateRange();
$selector->dateRange->min = date('Ymd', strtotime('2017/06/01'));
$selector->dateRange->max = date('Ymd', strtotime('2017/06/09'));
// Use a predicate to filter out paused criteria (this is optional).
//$selector->setPredicates([
//new Predicate('Impressions', PredicateOperator::GREATER_THAN, [1000]),
//new Predicate('CampaignName', PredicateOperator::CONTAINS, ['Branded'])
//]);
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->setSelector($selector);
$reportDefinition->setReportName('LAST_MONTH ACCOUNT_PERFORMANCE_REPORT');
$reportDefinition->setDateRangeType(
ReportDefinitionDateRangeType::CUSTOM_DATE);
$reportDefinition->setReportType(
ReportDefinitionReportType::ACCOUNT_PERFORMANCE_REPORT);
$reportDefinition->setDownloadFormat(DownloadFormat::CSV);
$customerIds = self::getAllManagedCustomerIds($adWordsServices, $session);
printf("Downloading reports for %d managed customers.\n",
count($customerIds));
$successfulReports = [];
$failedReports = [];
foreach ($customerIds as $customerId) {
$filePath = "../../../../../../clients/client_reports/accounts/" . $customerId . "_LAST_MONTH___account.csv";
I am getting error message: Fatal error: Class 'Google\AdsApi\Examples\AdWords\v201705\Reporting\DateRange' not found in /home/mtrant/public_html/clients/backend/api/adwords/production/paidsearch/reports/selector/all_MOM_ACCOUNT_PERFORMANCE_REPORT.php on line 69
Any help would be greatly appreciated.
Upvotes: 0
Views: 1270
Reputation: 392
First of all include this in the top of your code :
use Google\AdsApi\AdWords\v201705\cm\DateRange;
Then add Date Range to your selector like below :
$selector->setDateRange(new DateRange($FromDate, $ToDate));
This should solve your issue. Solved it for me. Update me if you get any errors even after making these changes.
Upvotes: 3