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());
}
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at http://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/f3b16c69-8b85-4145-8c30-25702a2cac36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.