Average Position for keywords

75 views
Skip to first unread message

Farid

unread,
Nov 1, 2010, 5:59:52 PM11/1/10
to AdWords API Forum
Is there anyway that I can find the average positon for a keyword.
Message has been deleted

Federico Ulfo

unread,
Nov 2, 2010, 9:50:46 AM11/2/10
to AdWords API Forum
Hi Farid,

that's easy, with PHP API you can do as follow:

<?php

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

$user = new AdWordsUser();
$user->SetClientId( $client_id ); // Select the client
$user->LogDefaults();
$reportDefinitionService = $user-
>GetReportDefinitionService('v201008');

$operations = array();

// Create ad group predicate.
$statusPredicate = new Predicate();
$statusPredicate->field = 'Id
$statusPredicate->operator = 'EQUALS';
$statusPredicate->values = array('YOUR KEYWORD ID HERE');

// Create selector.
$selector = new Selector();
$selector->predicates = array( $statusPredicate );
$selector->fields = $keywordsFields =
array('AveragePosition'); //Get Avg. position
/* If you want other field, see here:
http://code.google.com/apis/adwords/docs/appendix/reports.html#keywords.
An example it could be $selector->fields = $keywordsFields =
array('Id', 'AdGroupId', 'KeywordText', 'Status', 'Clicks',
'Impressions', 'AverageCpc', 'AverageCpm', 'Ctr', 'AveragePosition' );
*/

// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->reportName = "Keywords";
$reportDefinition->dateRangeType = $dateRangeType;
$reportDefinition->reportType = 'KEYWORDS_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';
$reportDefinition->selector = $selector;

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

$operations[] = $operation;

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

// Display report definitions.
if ($result != null)

// Download the report
foreach ($result as $reportDefinition) {
$csv = ReportUtils::DownloadReport($reportDefinition->id,
$path = null, $user);
$rows = explode( "\n", $csv );
for($i=2;$i<count($rows)-1;$i++)
$array[]=explode( "," , $rows[$i] );

// $array contain your keyword info
echo "<pre>";
print_r( $array );
}

?>

Best,
Federico
http://www.federicoulfo.it
Reply all
Reply to author
Forward
0 new messages