Setting Custom Date Range on Report with Selector (PHP Lib v201705)

1,398 views
Skip to first unread message

goo...@searchintegrations.com

unread,
Jun 12, 2017, 5:07:13 PM6/12/17
to AdWords API Forum
I am confused on where to add the min and max data ranges. If anyone could assist that would be great.

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']);
// 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";


Shwetha Vastrad (AdWords API Team)

unread,
Jun 12, 2017, 5:34:07 PM6/12/17
to AdWords API Forum
Hi, 

You can set the custom date range in the selector as shown below:

use Google\AdsApi\AdWords\v201705\cm\DateRange;
.
.
.
$selector
->setDateRange(new DateRange(min, max));

Regards,
Shwetha, AdWords API Team.

goo...@searchintegrations.com

unread,
Jun 13, 2017, 5:21:39 AM6/13/17
to AdWords API Forum
Thank you this worked great.

Could you assist in adding an orderby in the selector (i.e. order by month)? I have recently switched over some reports to the selector and am having a difficult time with some simple items.

Any further help would be greatly appreciated.


Thanks.

Shwetha Vastrad (AdWords API Team)

unread,
Jun 13, 2017, 11:46:48 AM6/13/17
to AdWords API Forum
Hi, 

Sorting is not supported for AdWords API reports at the moment. You'll not be able to specify a sorting order for report downloads. If you would like to specify the sort order for other API services, you can use the following example code snippet:

use Google\AdsApi\AdWords\v201705\cm\SortOrder;
use Google\AdsApi\AdWords\v201705\cm\OrderBy;
.
.
$selector
->setOrdering([new OrderBy('Name', SortOrder::ASCENDING)]); //sort by Name

prreportin...@gmail.com

unread,
Feb 4, 2019, 10:16:07 AM2/4/19
to AdWords API and Google Ads API Forum
Hi,

How can i sync Adwords campaign performance report Api data with my local database so that i don't need to download ALL_TIME data from report definition and avoid processing time.

googleadsapi...@google.com

unread,
Feb 4, 2019, 5:02:10 PM2/4/19
to prreportin...@gmail.com, AdWords API and Google Ads API Forum
Hi there,

You can run the report end of the week or end of the month using the date ranges available here or use custom date ranges. You can then use this data to update your local database. This Help center article may be helpful.

Regards,
Dhanya, AdWords API Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Reply all
Reply to author
Forward
0 new messages