Monday, 8 February 2016

How to set date range in Bid Landscapes - Adwords API

I am playing with Bid Landscapes, and as the official documentation describes:

Bid landscapes are a way for you to research information about estimated performance for your ad groups and criteria.

I am testing the API in AdGroup level, and the following piece of code has been written:

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";      }  }

This code works fine, and the output is similar to:

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.

By default, the API always picks up the previous week range ending two days from now. For instance, if today is 2016/02/08, the API will get the range between 2016/01/31 and 2016/02/06. My problem is how to set the specific date range in the code. I have commented out this part

// $selector->dateRange = new DateRange();  // $selector->dateRange->min = date('Ymd', strtotime('2016/01/01'));  // $selector->dateRange->max = date('Ymd', strtotime('2016/01/31'));

because it doesn't work. If I uncomment this part, the code won't give me any results. Any knowledge of how to set a date range for the bid landscapes in Adwords API?

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups "AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/3c36ee6f-51b7-4939-b0dc-9ce09d5e139a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment