How to get Adgroup CPC,cost,CTR ,impressions etc ...using google adword api

445 views
Skip to first unread message

Kiran Kumar

unread,
Jan 8, 2015, 8:44:32 AM1/8/15
to adwor...@googlegroups.com


Hi , 

I am trying to get the CPC,cost,CTR ,impressions using GetTextAds ,but it's only giving like adtext ,headline and urls but not the others 

How do I retrieve this values using API ?

Thank you ?


Code:


function GetTextAdsExample(AdWordsUser $user, $adGroupId) {
// Get the service, which loads the required classes.
$adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);

 // Create selector.
 $selector = new Selector();
 $selector->fields = array('Headline', 'Id');
 $selector->ordering[] = new OrderBy('Headline', 'ASCENDING');

 // Create predicates.
 $selector->predicates[] = new Predicate('AdGroupId', 'IN', array($adGroupId));
 $selector->predicates[] = new Predicate('AdType', 'IN', array('TEXT_AD'));
 // By default disabled ads aren't returned by the selector. To return them
 // include the DISABLED status in a predicate.
 $selector->predicates[] =
 new Predicate('Status', 'IN', array('ENABLED', 'PAUSED', 'DISABLED'));

 // Create paging controls.
 $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

 do {
// Make the get request.
$page = $adGroupAdService->get($selector);

// Display results.
if (isset($page->entries)) {
 foreach ($page->entries as $adGroupAd) {
 global $retval;
 $head=$adGroupAd->ad->headline;
 $adid=$adGroupAd->ad->id;
 $des1=$adGroupAd->ad->description1;
 $des2=$adGroupAd->ad->description2;
 $url=$adGroupAd->ad->displayUrl;
 $clicks=$adGroupAd->stats->clicks;
 $cpc=$adGroupAd->stats->averageCpc->microAmount / 1000000;
 $conversions=$adGroupAd->stats->conversions;
 $cost=$adGroupAd->stats->cost->microAmount / 1000000;
 $ctr=$adGroupAd->stats->ctr;
 $imp=$adGroupAd->stats->impressions;
 $ap=$adGroupAd->stats->averagePosition;
//printf("Text ad with headline '%s' and ID '%s' was found.\n",
//$adGroupAd->ad->headline, $adGroupAd->ad->id);
array_push($retval,array("hea"=>$head,"id"=>$adid ,"desc"=>$des1 ,"desc2"=>$des2,"url"=>$url,
"cli"=>$clicks,"cpc"=>$cpc,"con"=>$conversions,"cost"=>$cost,"ctr"=>$ctr,"imp"=>$imp,"ap"=>$ap
));
}
echo json_encode($retval); 
} else {
 //print "No text ads were found.\n";
}

// Advance the paging index.
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
 } while ($page->totalNumEntries > $selector->paging->startIndex);
}


try {
 // Get AdWordsUser from credentials in "../auth.ini"
 // relative to the AdWordsUser.php file's directory.
 $user = new AdWordsUser();

 // Log every SOAP XML request and response.
 $user->LogAll();

 // Run the example.
 GetTextAdsExample($user, $adGroupId);
} catch (Exception $e) {
 printf("An error has occurred: %s\n", $e->getMessage());
}

Stacie Waleyko

unread,
Jan 8, 2015, 4:42:04 PM1/8/15
to adwor...@googlegroups.com
Hello,

AdGroupAdService.get only returns ads (or, in your case TextAds). If you look at the TextAd API you will notice that CPC, cost, CTR, impressions, etc. are not available. To get these performance values I recommend downloading an ad performance report.

Stacie

Kiran Kumar

unread,
Jan 8, 2015, 11:57:28 PM1/8/15
to adwor...@googlegroups.com
 

 Is there any method available to call ads statistics like  CPC, cost, CTR, impressions, etc,I don't want to download the reports rather I want to display these values in the website .

Michael Cloonan (AdWords API Team)

unread,
Jan 9, 2015, 9:10:52 AM1/9/15
to adwor...@googlegroups.com
Hello,

Stacie is correct; the only way to get these statistics via the API is through reports. You can still display the values programmatically in the website you're developing, but you'll have to parse the report to get them.

Regards,
Mike, AdWords API Team

webmast...@gmail.com

unread,
Feb 23, 2018, 3:02:10 AM2/23/18
to AdWords API Forum
Could you tell me what parse means?

webmast...@gmail.com

unread,
Feb 23, 2018, 3:02:56 AM2/23/18
to AdWords API Forum


On Friday, February 23, 2018 at 3:02:10 PM UTC+7, webmast...@gmail.com wrote:
Could you tell me what parse means?

I am getting same issue, and I need to display them in website.
But not idea how I can display them in website
 

Milind Sankeshware (AdWords API Team)

unread,
Feb 23, 2018, 3:03:44 PM2/23/18
to AdWords API Forum
Hi,

To get performance stats for ads via the API, you could use the Ad Performance Report. You will be able to download them in any of the supported formats listed here. You could also refer sample code in java to get performance stats. Let me know if you have further questions.

Thanks,
Milind, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages