Google AdWords API – Part 4
The fourth part from my AdWords article series is about the TargetingIdeaService. For a project I needed to get search volume and competition for each keyword. This is not as simple as getting clicks or impressions for keywords.
The main problem is, that you can not get those values from AdGroupCriterionService like all other values. So we have to query another service only for this two missing values. This service is calles TargetingIdesService.
I wrote a function that gets the search volume and competition as text for the keyword which is set as param. Like all other services, I also need the AdWords user object and the used AdWords version as string. The function returns the requested values as array:
$values = GetTargetingIdea($user, $adwords_version, $keyword);
The function looks as follows:
function GetTargetingIdea(AdwordsUser $user, $adwords_version, $keyword)
// Load the service, so that the required classes are available.
$targetingIdeaService = $user->GetTargetingIdeaService($adwords_version);
// Create selector.
$selector = new TargetingIdeaSelector();
$selector->requestType = "STATS";
$selector->ideaType = 'KEYWORD';
$selector->requestedAttributeTypes = array('SEARCH_VOLUME','COMPETITION');
$relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
$relatedToQuerySearchParameter->queries = array($keyword);
$selector->searchParameters = $relatedToQuerySearchParameter;
// Create paging controls.
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
$ret = array();
// Make the get request.
$page = $targetingIdeaService->get($selector);
// Display results.
foreach ($page->entries as $adGroupAd)
$ret = array(
'searchvolume' => $adGroupAd->data->value->value,
'competition' => $adGroupAd->data->value->value
// Advance the paging index.
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while ($page->totalNumEntries > $selector->paging->startIndex);
This service is a bit different. It does not use a selector class. We set the requestType to STATS, because we only want data for existing keywords and the ideaType is KEYWORD. For the requestedAttributeTypes array we define all fields that we want from AdWords API. It is really important to use searchParameters array, so we only get values for the needed keywords.