Complete client report in a single API call (PHP)

185 views
Skip to first unread message

federico ulfo

unread,
Oct 23, 2010, 10:02:06 AM10/23/10
to AdWords API Forum
Hi,
is it possible to get the complete client report (as follow) in a
single API call?
CLIENT clicks, impression, avg CPC, avg CPM...
-- CAMPAIGNS
-- GROUPS
-- KEYWORDS

Thanks,
Federico

AdWords API Advisor

unread,
Oct 25, 2010, 7:26:18 AM10/25/10
to AdWords API Forum
HI Federico,

You can't get the whole account details in a single call, you will
need at least 4 API calls (a CampaignService.get(),
AdGroupService.get(), AdGroupAdService.get() and
AdGroupCriterionService.get()), and a reasonable amount of code to
organize the objects in the required hierarchical order.

Another alternative is to run 1 performance report each for Campaign,
AdGroups, Keywords and Ads, but still you need code to parse and put
the stats in the desired hierarchical form.

Cheers,
Anash P. Oommen,
AdWords API Advisor.

Federico Ulfo

unread,
Oct 25, 2010, 1:32:28 PM10/25/10
to AdWords API Forum
Hi Anash,

thanks, 1st solution works well for me!
How can I get the tot. report of the selected client? It looks like is
not always the sum of all campaign reports.

Do you think is it possible to do a single report using
scheduleRerportJob?
http://code.google.com/apis/adwords/docs/developer/ReportService.html#scheduleReportJob

When completed I'll share my PHP code.

Best,
Federico
www.federicoulfo.it




On Oct 25, 1:26 pm, AdWords API Advisor <adwordsapiadvi...@google.com>
wrote:
> HI Federico,
>
> You can't get the whole account details in a single call, you will
> need at least 4 API calls (a CampaignService.get(),
> AdGroupService.get(), AdGroupAdService.get() and
> AdGroupCriterionService.get()), and a reasonable amount of code to
> organize the objects in the required hierarchical order.
>
> Another alternative is to run 1 performancereporteach for Campaign,
> AdGroups, Keywords and Ads, but still you need code to parse and put
> the stats in the desired hierarchical form.
>
> Cheers,
> Anash P. Oommen,
> AdWords API Advisor.
>
> On Oct 23, 7:02 pm, federico ulfo <rainelemen...@gmail.com> wrote:
>
> > Hi,
> > is it possible to get the complete clientreport(as follow) in a

AdWords API Advisor

unread,
Oct 26, 2010, 6:12:41 AM10/26/10
to AdWords API Forum
Hi Federico,

Can you please clarify your question? What do you mean by "tot. report
of the selected client"?

Cheers,
Anash P. Oommen,
AdWords API Advisor.

On Oct 25, 10:32 pm, Federico Ulfo <federicotest...@gmail.com> wrote:
> Hi Anash,
>
> thanks, 1st solution works well for me!
> How can I get the tot. report of the selected client? It looks like is
> not always the sum of all campaign reports.
>
> Do you think is it possible to do a single report using
> scheduleRerportJob?http://code.google.com/apis/adwords/docs/developer/ReportService.html...

federico ulfo

unread,
Oct 26, 2010, 8:15:34 AM10/26/10
to AdWords API Forum
Hey Anash,

I mean the stats of a selected client (client_id: xxx-xxx-xxxx)
so clicks, impression, avg cpc, avg cpm, ctr, avg position ...

thanks
Federico
www.federicoulfo.it

On Oct 26, 12:12 pm, AdWords API Advisor

AdWords API Advisor

unread,
Oct 27, 2010, 12:01:35 AM10/27/10
to AdWords API Forum
Hi Federico,

Try Account Performance report which was newly added in v201008. See
http://code.google.com/apis/adwords/docs/appendix/reports.html#account
for more details.

Cheers,
Anash P. Oommen,
AdWords API Advisor.

federico ulfo

unread,
Oct 27, 2010, 4:48:38 PM10/27/10
to AdWords API Forum
Hi Anash,
I tried to modify AddKeywordsPerformanceReportDefinition.php,
I receive INVALID_FIELD_NAME_FOR_REPORT error,
what's the correct Predicate::field for get the Customer stats?
---
$user = new AdWordsUser();
$user->LogDefaults();

// Get the GetReportDefinitionService.
$reportDefinitionService = $user-
>GetReportDefinitionService('v201008');

// Create ad group predicate.
$customer = new Predicate();
$customer->field = 'clientCustomerId';
$customer->operator = 'EQUALS';
$customer->values = array("209-212-1229");

// Create selector.
$selector = new Selector();
$selector->fields = array( 'Impressions', 'Clicks' );
$selector->predicates = array($customer);

// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->reportName = 'Account Stats#' . time();
$reportDefinition->dateRangeType = 'YESTERDAY';
$reportDefinition->reportType = 'ACCOUNT_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'XML';
$reportDefinition->selector = $selector;

// Create operations.
$operation = new ReportDefinitionOperation();
$operation->operand = $reportDefinition;
$operation->operator = 'ADD';

$operations = array($operation);

// Add report definition.
$result = $reportDefinitionService->mutate($operations);
---


Thanks,
Federico



On Oct 27, 6:01 am, AdWords API Advisor <adwordsapiadvi...@google.com>
wrote:
> Hi Federico,
>
> Try Account Performance report which was newly added in v201008. Seehttp://code.google.com/apis/adwords/docs/appendix/reports.html#account

AdWords API Advisor

unread,
Oct 29, 2010, 8:39:11 PM10/29/10
to AdWords API Forum
Hi Frederico,

There is no field called "clientCustomerId" that is available for the
report type ACCOUNT_PERFORMANCE_REPORT:

http://code.google.com/apis/adwords/docs/appendix/reports.html#account

v201008 reports cannot target multiple client account, so ensure that
the report definition is created in the account you wish to report on
(set the clientCustomerId header in the request).

Best,
- Eric Koleda, AdWords API Tea,

federico ulfo

unread,
Oct 31, 2010, 7:03:09 AM10/31/10
to AdWords API Forum
Hi and thanks, it finally works!
Here the PHP code to Get the Keywords Stats for a selected client with
ReportDefinitionService and downloadReport as Array:

<?php

date_default_timezone_set( "Europe/Rome" );
error_reporting(E_STRICT | E_ALL);

require_once dirname(__FILE__) . '/../../src/Google/Api/Ads/AdWords/
Lib/AdWordsUser.php';
require_once dirname(__FILE__) . '/../../src/Google/Api/Ads/AdWords/
Util/ReportUtils.php';


$user = new AdWordsUser();
$user->SetClientId('123-123-1234'); // select the client with
clientId

$reportDefinitionService = $user-
>GetReportDefinitionService('v201008');

// Create selector.
$selector = new Selector();
$selector->fields = array('Id', 'AdGroupId', 'KeywordText',
'KeywordMatchType', 'Impressions', 'Clicks', 'Cost');

// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->reportName = 'Keywords performance report #' .
time();
$reportDefinition->dateRangeType = 'YESTERDAY';
$reportDefinition->reportType = 'ACCOUNT_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';
$reportDefinition->selector = $selector;

// Create operations.
$operation = new ReportDefinitionOperation();
$operation->operand = $reportDefinition;
$operation->operator = 'ADD';

$operations = array($operation);

// Add report definition.
$result = $reportDefinitionService->mutate($operations);

// Display report definitions.
if ($result != null)
foreach ($result as $reportDefinition) {

$csv = ReportUtils::DownloadReport($reportDefinition->id, $path
= null, $user); // get the Report in $csv

// Get the result in Array
$rows = explode( "\n", $csv );
for($i=2;$i<count($rows)-1;$i++)
$array[]=explode( "," , $rows[$i] );
}

?>


Best,
Federico
www.federicoulfo.it




On Oct 30, 1:39 am, AdWords API Advisor <adwordsapiadvi...@google.com>
Reply all
Reply to author
Forward
0 new messages