AdGroupAdService is not giving the statistics of ads

343 views
Skip to first unread message

sho...@multipliersolutions.in

unread,
Jan 9, 2015, 6:04:30 AM1/9/15
to adwor...@googlegroups.com

Hi I am using AdgroupAdservice method retrieve the cost,cpc,impression,ctr,conversion etc by using the following code.

Code:


require_once dirname(__FILE__).'/adwordsAPI/src/Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
//require_once dirname(__FILE__).'/adwordsAPI/src/Google/Api/Ads/AdWords/v201406/AdGroupCriterionService.php';
require_once dirname(__FILE__).'/adwordsAPI/examples/AdWords/v201406/init.php';
//echo "values is :".$var;
$adGroupId = $var;
$retval=array();
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','Description1', 'Description2', 'DisplayUrl', 'Url', 'Status', 'AverageCpc', 'AveragePosition', 'Clicks', 'Conversions', 'Cost','Ctr', 'Impressions');
 $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);
}


ERROR:


An error has occurred: [SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'AverageCpc', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'AveragePosition', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'Clicks', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'Conversions', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'Cost', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'Ctr', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'Impressions']

Michael Cloonan (AdWords API Team)

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

You cannot fetch statistics via the AdGroupAdService. In order to get statistics for ad groups, you will need to run an ADGROUP_PERFORMANCE_REPORT.

You can look up which fields are selectable at the documentation for that field. For example, here's the documentation for AdGroupAd.

Regards,
Mike, AdWords API Team

Shobhan Babu

unread,
Jan 11, 2015, 11:45:39 PM1/11/15
to adwor...@googlegroups.com

How can we get the one ad group performance report rather than entire ad groups performance report ?

if it is available please let me know the procedure to get the  specific ad group performance report. 

Michael Cloonan (AdWords API Team)

unread,
Jan 12, 2015, 9:56:55 AM1/12/15
to adwor...@googlegroups.com
Hello,

You can filter the report on the AdGroupId. Please see this documentation for a list of valid fields in the ad group performance report.

For example, if you were using AWQL to run your report, you could make a query like this:

SELECT [whatever fields you want]
WHERE AdGroupID = [some ad group id]
DURING 20150101,20150112

The WHERE clause limits which rows are returned so it only shows the AdGroup you want. If you want more than one ad group at a time, you can use the IN operator and provide all the IDs you're interested in.

Regards,
Mike, AdWords API Team 
 

webmast...@gmail.com

unread,
Feb 22, 2018, 5:00:33 PM2/22/18
to AdWords API Forum
Hi, I have question
How can I run you will ADGROUP_PERFORMANCE_REPORT this report,
I had tried to this run with AWQL, but they show me invalid from class error

Please help me and let me know 

thanks

Dhanya Sundararaju (AdWords API Team)

unread,
Feb 23, 2018, 1:33:52 PM2/23/18
to AdWords API Forum
Hi,

You can refer this code sample in java to run any report. Code samples in other languages are given here. You would just need to specify the report name as ADGROUP_PERFORMANCE_REPORT and the report fields that you need. If this does not help you, could you create a new thread giving details of your report definition and the error that you are getting, as this would help us to keep track of issues?

Regards,
Dhanya, AdWords API Team

webmast...@gmail.com

unread,
Feb 24, 2018, 4:29:56 PM2/24/18
to AdWords API Forum
Thanks for your help.
So i had used this code to get these field values

        $selector->setFields(array(//'AdGroupId', 'CriterionUse', 'Status',
            'CriteriaType', 'KeywordMatchType', 'KeywordText'));
        if ($doStats) {
            $selector->setFields(array_merge($selector->getFields(),
                array('AveragePosition ', 'Impressions', 'Clicks',
                    'Ctr', 'AverageCpc', 'Cost ')));
        }
 $result = $adGroupCriterionService->get($selector);
but this code show me error "Invalid field name : "AveragePosition  , Clicks, Impressions" and so on.
So I read this discussion and tried to understood, implement this.
But not luck yet.
So if you would like to help me and show me some example code, I will be very happy.
PS: I had migrated v201609 into v201710 version.

thanks

Regards
 

Dhanya Sundararaju (AdWords API Team)

unread,
Feb 26, 2018, 1:37:32 PM2/26/18
to AdWords API Forum
Hi,

The error "Invalid field name : "AveragePosition, Clicks, Impressions" is being thrown because these fields are metrics in the ADGROUP_PERFORMANCE_REPORT. You will be able to get fields only which are attributes of the AdGroup if you are calling the AdGroupCriterionService. Instead, if you create a reportdefinition, you will be able to get these fields in your report. Please refer the guide for a sample code. If you have further questions, could you please create a new thread as this would help us to keep track of issues?

webmast...@gmail.com

unread,
Feb 27, 2018, 2:51:53 AM2/27/18
to AdWords API Forum
Thanks for your reply
So I have one question, When I use Report, I can  set pagination function?
For example,$selector->setPaging(new Paging(0,10)); code line.
But I got error also like this "Paging is not supported "
Hope this will solved soon.

Thanks

Regards

Dhanya Sundararaju (AdWords API Team)

unread,
Feb 27, 2018, 1:19:52 PM2/27/18
to AdWords API Forum
Hi,

Sorting and Paging are not supported in reports. Please refer here for better clarity.
Reply all
Reply to author
Forward
0 new messages