如何在 Bid Landscapes 中设置日期范围 - Adwords API
How to set date range in Bid Landscapes - Adwords API
我正在玩 Bid Landscapes,正如官方文档所述:
Bid landscapes are a way for you to research information about estimated performance for your ad groups and criteria.
我正在测试AdGroup级别的API,已经编写了以下代码:
public function test_bid_simulator() {
$user = new AdWordsUser();
$user->SetClientCustomerId('*******');
$dataService = $user->GetService('DataService', 'v201509');
$selector = new Selector();
$selector->fields = array('AdGroupId', 'StartDate', 'EndDate',
'Bid', 'LocalClicks', 'LocalCost', 'LocalImpressions');
// Create predicates.
$selector->predicates[] = new Predicate('CampaignId', 'IN', array('****', '****', '****', '****'));
// $selector->dateRange = new DateRange();
// $selector->dateRange->min = date('Ymd', strtotime('2016/01/28'));
// $selector->dateRange->max = date('Ymd', strtotime('2016/02/03'));
do {
// Make the getAdGroupBidLandscape request.
$page = $dataService->getAdGroupBidLandscape($selector);
// Display results.
if (isset($page->entries)) {
foreach ($page->entries as $bidLandscape) {
printf("Found adgroup bid landscape with id '%s' for start "
. "date '%s', end date '%s', and landscape points:\n",
$bidLandscape->adGroupId,
$bidLandscape->startDate,
$bidLandscape->endDate);
foreach ($bidLandscape->landscapePoints as $bidLandscapePoint) {
printf(" bid: %.0f => clicks: %d, cost: %.0f, impressions: %d\n",
$bidLandscapePoint->bid->microAmount,
$bidLandscapePoint->clicks,
$bidLandscapePoint->cost->microAmount,
$bidLandscapePoint->impressions);
}
print "\n";
}
}
// Advance the paging index.
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while (isset($page->entries) && count($page->entries) > 0);
if ($selector->paging->startIndex === 0) {
print "No adgroup bid landscapes were found.\n";
}
}
此代码运行良好,输出类似于:
Found adgroup bid landscape with id '****' for start date '20160131', end date '20160206', and landscape points:
bid: 60000 => clicks: 0, cost: 0, impressions: 38
bid: 110000 => clicks: 0, cost: 0, impressions: 70
bid: 150000 => clicks: 0, cost: 0, impressions: 97
bid: 210000 => clicks: 0, cost: 0, impressions: 116
bid: 280000 => clicks: 0, cost: 0, impressions: 126
bid: 470000 => clicks: 0, cost: 0, impressions: 136
Found adgroup bid landscape with id '****' for start date '20160131', end date '20160206', and landscape points:
bid: 20000 => clicks: 0, cost: 0, impressions: 16
bid: 40000 => clicks: 0, cost: 0, impressions: 89
bid: 60000 => clicks: 0, cost: 0, impressions: 138
bid: 100000 => clicks: 0, cost: 0, impressions: 183
bid: 160000 => clicks: 0, cost: 0, impressions: 218
bid: 240000 => clicks: 0, cost: 0, impressions: 234
bid: 390000 => clicks: 0, cost: 0, impressions: 256
etc.
默认情况下,API 始终选取从现在起两天后结束的前一周范围。例如,如果今天是 2016/02/08,则 API 将获得 2016/01/31 和 2016/02/06 之间的范围。我的问题是如何在代码中设置具体的日期范围。这部分我已经注释掉了
// $selector->dateRange = new DateRange();
// $selector->dateRange->min = date('Ymd', strtotime('2016/01/01'));
// $selector->dateRange->max = date('Ymd', strtotime('2016/01/31'));
因为它不起作用。如果我取消注释这部分,代码将不会给我任何结果。了解如何在 Adwords API 中设置出价环境的日期范围吗?
我在 Google Groups 中发布了完全相同的问题。 Google AdWords API 团队是这样回应的:
You cannot set date range for BidLandScape. The system does the calculation based on the latest data, generally last 7 days, depending on data availability. BidLandscape is similiar to the Bid Simulator in UI. You can take a look at this thread which discussed about BidLandScape.
我正在玩 Bid Landscapes,正如官方文档所述:
Bid landscapes are a way for you to research information about estimated performance for your ad groups and criteria.
我正在测试AdGroup级别的API,已经编写了以下代码:
public function test_bid_simulator() {
$user = new AdWordsUser();
$user->SetClientCustomerId('*******');
$dataService = $user->GetService('DataService', 'v201509');
$selector = new Selector();
$selector->fields = array('AdGroupId', 'StartDate', 'EndDate',
'Bid', 'LocalClicks', 'LocalCost', 'LocalImpressions');
// Create predicates.
$selector->predicates[] = new Predicate('CampaignId', 'IN', array('****', '****', '****', '****'));
// $selector->dateRange = new DateRange();
// $selector->dateRange->min = date('Ymd', strtotime('2016/01/28'));
// $selector->dateRange->max = date('Ymd', strtotime('2016/02/03'));
do {
// Make the getAdGroupBidLandscape request.
$page = $dataService->getAdGroupBidLandscape($selector);
// Display results.
if (isset($page->entries)) {
foreach ($page->entries as $bidLandscape) {
printf("Found adgroup bid landscape with id '%s' for start "
. "date '%s', end date '%s', and landscape points:\n",
$bidLandscape->adGroupId,
$bidLandscape->startDate,
$bidLandscape->endDate);
foreach ($bidLandscape->landscapePoints as $bidLandscapePoint) {
printf(" bid: %.0f => clicks: %d, cost: %.0f, impressions: %d\n",
$bidLandscapePoint->bid->microAmount,
$bidLandscapePoint->clicks,
$bidLandscapePoint->cost->microAmount,
$bidLandscapePoint->impressions);
}
print "\n";
}
}
// Advance the paging index.
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while (isset($page->entries) && count($page->entries) > 0);
if ($selector->paging->startIndex === 0) {
print "No adgroup bid landscapes were found.\n";
}
}
此代码运行良好,输出类似于:
Found adgroup bid landscape with id '****' for start date '20160131', end date '20160206', and landscape points:
bid: 60000 => clicks: 0, cost: 0, impressions: 38
bid: 110000 => clicks: 0, cost: 0, impressions: 70
bid: 150000 => clicks: 0, cost: 0, impressions: 97
bid: 210000 => clicks: 0, cost: 0, impressions: 116
bid: 280000 => clicks: 0, cost: 0, impressions: 126
bid: 470000 => clicks: 0, cost: 0, impressions: 136
Found adgroup bid landscape with id '****' for start date '20160131', end date '20160206', and landscape points:
bid: 20000 => clicks: 0, cost: 0, impressions: 16
bid: 40000 => clicks: 0, cost: 0, impressions: 89
bid: 60000 => clicks: 0, cost: 0, impressions: 138
bid: 100000 => clicks: 0, cost: 0, impressions: 183
bid: 160000 => clicks: 0, cost: 0, impressions: 218
bid: 240000 => clicks: 0, cost: 0, impressions: 234
bid: 390000 => clicks: 0, cost: 0, impressions: 256
etc.
默认情况下,API 始终选取从现在起两天后结束的前一周范围。例如,如果今天是 2016/02/08,则 API 将获得 2016/01/31 和 2016/02/06 之间的范围。我的问题是如何在代码中设置具体的日期范围。这部分我已经注释掉了
// $selector->dateRange = new DateRange();
// $selector->dateRange->min = date('Ymd', strtotime('2016/01/01'));
// $selector->dateRange->max = date('Ymd', strtotime('2016/01/31'));
因为它不起作用。如果我取消注释这部分,代码将不会给我任何结果。了解如何在 Adwords API 中设置出价环境的日期范围吗?
我在 Google Groups 中发布了完全相同的问题。 Google AdWords API 团队是这样回应的:
You cannot set date range for BidLandScape. The system does the calculation based on the latest data, generally last 7 days, depending on data availability. BidLandscape is similiar to the Bid Simulator in UI. You can take a look at this thread which discussed about BidLandScape.