How to get the top performing ad for a campaign?

254 views
Skip to first unread message

Jake Wilson

unread,
May 28, 2014, 6:51:47 PM5/28/14
to adwor...@googlegroups.com
I'm looking at all the ads for a campaign.  I want to fetch the top performing ad from the campaign.  By top performing I guess I would choose the ad with the highest CTR maybe?  Or maybe the Conversion rate.  Anyways, I'm doing this kind of thing:

$user = new AdWordsUser();
$user->setClientCustomerId($accountId);
$user->LoadService('ReportDefinitionService', ADWORDS_VERSION);

$selector = new Selector();
$selector->fields = array(.....);
$selector->predicates[] = new Predicate('CampaignId', 'IN', $campaignIds);

$reportDefinition = new ReportDefinition();
$reportDefinition->selector = $selector;
$reportDefinition->reportName = 'Ad performance report #' . uniqid();
$reportDefinition->dateRangeType = "LAST_30_DAYS";
$reportDefinition->reportType = 'AD_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'XML';
$reportDefinition->includeZeroImpressions = FALSE;

The problem with this API call is that it returns ALL the ads (218 ads for this particular campaign I'm testing on).  And I don't think the ads are sorted in any logical way that I can see.  Maybe by adID ascending.

Anyways, I tried to add two things to my selector:

$selector->ordering[] = new OrderBy('Ctr', 'DESCENDING');

Gives the error:

Report download failed. Underlying errors are Type = 'ReportDefinitionError.SORTING_NOT_SUPPORTED', Trigger = 'Sorting is not supported for reports', FieldPath = ''.


Also, in order to just return the first result only (which work work if I could get ordering to work), I tried using paging:

$selector->paging = new Paging(0,1);

But I get 

Report download failed. Underlying errors are Type = 'ReportDefinitionError.PAGING_NOT_SUPPORTED', Trigger = 'Paging is not supported for reports', FieldPath = ''.

Okay so downloading reports supports neight ordering or paging/limiting?  Am I only able to just fetch ALL the ads and I need to manually sort through them myself?  That doesn't seem right...

Am I missing something here?

Michael Cloonan (AdWords API Team)

unread,
May 29, 2014, 9:32:40 AM5/29/14
to adwor...@googlegroups.com
Hello,

The ReportDefinitionService is not meant for running reports, but rather for fetching information about what fields are supported in different reports. We also make all this information on our Report Types page, so you can avoid using this service altogether by referencing this page.

In order to actually run a report, please see our Reporting Basics guide. You can also look at any of our PHP Reporting examples.

I recommend using AWQL to fetch reports, which is a SQL-like language specifically for AdWords. For example, you could do something like this:

SELECT Id, Ctr
FROM AD_PERFORMANCE_REPORT
WHERE CampaignId IN (...)
DURING 20140501,20140529
ORDER BY Ctr DESC
LIMIT 0,50

You can add whatever fields/predicates/timeframe you like. Both ordering and paging do work when running the report, just not when fetching report definitions.

Regards,
Mike, AdWords API Team

Jake Wilson

unread,
May 29, 2014, 10:56:23 AM5/29/14
to adwor...@googlegroups.com
Ah okay that wasn't clear to me.  Thank you!

Jake Wilson

unread,
May 29, 2014, 12:52:33 PM5/29/14
to adwor...@googlegroups.com
One more question about this.  I have the following AWQL query:

SELECT Id,Clicks,Headline,Description1,Description2,DisplayUrl,Impressions,Clicks,Cost,Conversions,ConversionRate,Ctr
FROM AD_PERFORMANCE_REPORT
WHERE Status IN [ENABLED,PAUSED]
DURING 20140522,20140528
ORDER BY Clicks ASC

I get:

Report download failed. Underlying errors are Type = 'QueryError.INVALID_ORDER_BY_CLAUSE', Trigger = '', FieldPath = ''.

It doesn't like that ORDER BY syntax apparently.  What am I doing wrong here?  The order and syntax appears to match examples that I'm referencing.   The query works just fine without the ORDER BY clause.

Jake Wilson

unread,
May 29, 2014, 1:07:28 PM5/29/14
to adwor...@googlegroups.com
I also get a similar error when using LIMIT...

Any clues?

Michael Cloonan (AdWords API Team)

unread,
May 29, 2014, 2:16:05 PM5/29/14
to adwor...@googlegroups.com
Hi Jake,

That is strange. I just confirmed that I'm seeing the same error here. I filed a bug internally with the team, and I'll update here when I hear back about what's going wrong.

Regards,
Mike, AdWords API Team

Jake Wilson

unread,
May 29, 2014, 3:23:15 PM5/29/14
to adwor...@googlegroups.com
Thank you for looking into this Michael.  If you could reply to this post when you discover the answer or if/when it's fixed I would appreciate it.  In the meantime I will run my query to grab everything and then sort it locally.

Thanks,

Anash P. Oommen (AdWords API Team)

unread,
May 30, 2014, 1:14:26 PM5/30/14
to adwor...@googlegroups.com
Hi Jake,

Reports do not support order by or limit clauses. They work only when used with query() method on various campaign management services, so you need to sort the results on your own.

Cheers,
Anash P. Oommen,
AdWords API Advisor.
Reply all
Reply to author
Forward
0 new messages