Creating keyword performace report usind adwords API

374 views
Skip to first unread message

Дамян Станчев

unread,
Mar 19, 2012, 3:47:48 AM3/19/12
to adwor...@googlegroups.com
Hi guys,
I had the following code, that I was using to create reports and they appeared in my client center. Now when the old API is deprecated I have problems doing the same thing. I need to be able to create keyword performance reports from a PHP script and they must appear in the client center. Any ideas how to do this with the new API?

P.S Until now I managed to create a ReportDefinition, but what is the way to use the created ReportDefinition object after that?

OLD CODE:
$reportDefinitionService = $user->GetReportDefinitionService('v201008');
$adGroupId = (float) $_GET['id'];
$adGroupName = $_GET['name'];

# Create ad group predicate.
$adGroupPredicate = new Predicate();
$adGroupPredicate->field = 'AdGroupId';
$adGroupPredicate->operator = 'EQUALS';
$adGroupPredicate->values = array($adGroupId);

# Create selector.
$selector = new Selector();
$selector->fields = array("AdGroupName", "KeywordText", "Impressions", "Ctr", "AveragePosition");
$selector->predicates = array($adGroupPredicate);

# Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->reportName = 'NEW Keywords performance report '.$adGroupName.' for adgroup #' . $adGroupId . ' @' . time();
$reportDefinition->reportType = 'KEYWORDS_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSVFOREXCEL';
$reportDefinition->dateRangeType = 'LAST_7_DAYS';
$reportDefinition->selector = $selector;

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

# Add report definition and download.
$result = $reportDefinitionService->mutate(array($operation));

Ewan Heming

unread,
Mar 19, 2012, 4:16:41 AM3/19/12
to adwor...@googlegroups.com
It's actually quite easy as the main difference is that you don't need to create a report before downloading it anymore. Something like the following should work (although I haven't tested it):

$adGroupId = (float) $_GET['id'];
$adGroupName = $_GET['name'];

# Create ad group predicate.
$adGroupPredicate = new Predicate();
$adGroupPredicate->field = 'AdGroupId';
$adGroupPredicate->operator = 'EQUALS';
$adGroupPredicate->values = array($adGroupId);

# Create selector.
$selector = new Selector();
$selector->fields = array("AdGroupName", "KeywordText", "Impressions", "Ctr", "AveragePosition");
$selector->predicates = array($adGroupPredicate);

# Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->reportName = 'NEW Keywords performance report '.$adGroupName.' for adgroup #' . $adGroupId . ' @' . time();
$reportDefinition->reportType = 'KEYWORDS_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSVFOREXCEL';
$reportDefinition->dateRangeType = 'LAST_7_DAYS';
$reportDefinition->selector = $selector;

// You don't need to create a report, just download it:
$fileName = 'INSERT_OUTPUT_FILE_NAME_HERE';
$path = dirname(__FILE__) . '/' . $fileName;
  $options = array('version' => 'v201109', 'returnMoneyInMicros' => TRUE);
  ReportUtils::DownloadReport($reportDefinition, $path, $user, $options);

David Torres

unread,
Mar 22, 2012, 9:53:12 AM3/22/12
to adwor...@googlegroups.com
Hi,

Aside from the great response from Ewan, I got to add that API reports were never intended to appear in the UI, so what you describe is not longer possible via the API.

Best,

-David Torres - AdWords API Team
Reply all
Reply to author
Forward
0 new messages