Php SDK get campaign spent budget (daily)

66 views
Skip to first unread message

nicolò Cozzani

unread,
Dec 5, 2018, 3:31:28 AM12/5/18
to AdWords API and Google Ads API Forum
Hi, would i'd like to achieve is to know everyday how much of the budget was spent the day before.
Thas my code :

$selector = new Selector();
$yesterday = date('Ymd',strtotime("-2days"));
$today  = $yesterday = date('Ymd',strtotime("-1days"));

$selector->setFields(["Amount","Cost"]);
$selector->setDateRange(new DateRange($yesterday, $today));

$selector->setPredicates([
       new Predicate('AssociatedCampaignId', PredicateOperator::IN, [$idcampagna])]);

$reportDefinition = new ReportDefinition();
$reportDefinition->setSelector($selector);
$reportDefinition->setReportName('Report per la campagna #' . $idcampagna);
  $reportDefinition->setDateRangeType(ReportDefinitionDateRangeType::CUSTOM_DATE);

$reportDefinition->setReportType(ReportDefinitionReportType::BUDGET_PERFORMANCE_REPORT);
$reportDefinition->setDownloadFormat(DownloadFormat::CSV);
$reportDownloader = new ReportDownloader($session);
$reportSettingsOverride = (new ReportSettingsBuilder())
    ->includeZeroImpressions(false)
    ->build();
    $reportDownloadResult = $reportDownloader->downloadReport($reportDefinition, $reportSettingsOverride);

    $result = $reportDownloadResult->getAsString();
    $result2 = array_filter(explode("\n",$result));

The problem is that the Cost is  greater than the ammount, how that's possibile? any help would be apreciated, thanks

Dhanya Sundararaju (AdWords API Team)

unread,
Dec 5, 2018, 10:20:46 AM12/5/18
to AdWords API and Google Ads API Forum
Hi Nicolò,

For yesterday's data, you can use ReportDefinitionDateRangeType::YESTERDAY. I was unable to replicate this on my test account. Could you reply back with a client customer id and AssociatedCampaignId where you see this? Also, do you see the same data via Budgets report in the UI? For your reference, this Help Center article may be useful.

Regards,
Dhanya, AdWords API Team
Reply all
Reply to author
Forward
0 new messages