[英]PHP Google Adwords Api v201406: get total clicks, total impressions by campaignId
[英]get Google AdWords API all campaign stats for total impressions and clicks
如何獲得Google AdWords API上所有廣告系列的總印象數和點擊數? 現在我正在這樣做
// Get the service, which loads the required classes.
$campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);
// Create selector.
$selector = new Selector();
$selector->fields =
array('Id', 'Name', 'Impressions', 'Clicks', 'Cost', 'Ctr');
$selector->predicates[] =
new Predicate('Impressions', 'GREATER_THAN', array(0));
// Set date range to request stats for.
$dateRange = new DateRange();
$dateRange->min = date('Ym01', time());
$dateRange->max = date('Ymd', time());
$selector->dateRange = $dateRange;
// Make the get request.
$page = $campaignService->get($selector);
// get results.
$impressions = 0;
$clicks = 0;
if (isset($page->entries)) {
foreach ($page->entries as $campaign) {
$impressions += $campaign->campaignStats->impressions;
$clicks += $campaign->campaignStats->clicks;
}
} else {
//print "No matching campaigns were found.\n";
}
return array('impressions'=>$impressions, 'clicks'=>$clicks);
我想知道是否可以不使用foreach就能獲得全部收益,並循環瀏覽這些活動。
要獲取帳戶一級的統計信息,您可以使用AdWords API的ACCOUNT_PERFORMANCE_REPORT
。 您可以CSV格式下載此報告。
我是Rubyist,但我認為這應該適用於PHP客戶端庫 :
// AdWordsUser credentials come from "../auth.ini"
$user = new AdWordsUser();
$filePath = YOUR_FILE_PATH;
$user->LoadService('ReportDefinitionService', ADWORDS_VERSION);
$selector = new Selector();
$selector->fields = array('AccountId', 'AccountDescriptiveName', 'Impressions', 'Clicks', 'Cost', 'Ctr');
// no predicate necessary - this report already excludes zero-impression lines;
// plus, there is only one line, because it's the whole account
$reportDefinition = new ReportDefinition();
$reportDefinition->selector = $selector;
$reportDefinition->reportName = WHATEVER_YOU_WANT_IT_TO_BE_NAMED;
$reportDefinition->dateRangeType = 'LAST_7_DAYS';
$reportDefinition->reportType = 'ACCOUNT_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';
$options = array('returnMoneyInMicros' => TRUE);
ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);
$startDate = date('Ymd', strtotime('2018-10-12'));
$endDate = date('Ymd', strtotime('2018-11-13'));
$query = (new ReportQueryBuilder())
->select([
'CampaignId',
'AdGroupId',
'Impressions',
'Clicks',
'Cost'
])
->from(ReportDefinitionReportType::CRITERIA_PERFORMANCE_REPORT)
->where('Status')->in(['ENABLED', 'PAUSED'])
->during($startDate, $endDate)
->build();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.