how to get stats for location in google ads php api?

580 views
Skip to first unread message

silent_coder

unread,
Jun 22, 2017, 12:25:55 PM6/22/17
to AdWords API Forum
I want to get stats for a targeted location of a campaign such as:

var geostats = targetedLocation.getStatsFor(String(duration[0]),String(duration[1]));

This is in JS version, I am looking to recreate it php version. I can already traverse through accounts and campaigns of each account but I'm lost in getting stats for location.

Shwetha Vastrad (AdWords API Team)

unread,
Jun 22, 2017, 5:17:50 PM6/22/17
to AdWords API Forum
Hi, 

In AdWords API, you need to download a report to get the performance data of your account. You can use the following report types to get geo performance data:
Please see the location targeting guide and reporting basics guide for more details. You can follow this guide to get started with the AdWords API PHP client library.

Regards,
Shwetha, AdWords API Team.

silent_coder

unread,
Jul 3, 2017, 12:10:31 PM7/3/17
to AdWords API Forum
Hi,

Thanks for your reply. Basically, I want to get statistics for example for

New York = clicks, cost, conversions, etc
Canada = clicks, cost, conversions, etc
Alabama = clicks, cost, conversions, etc
Alaska = clicks, cost, conversions, etc

What I have so far is this:

                $campaignService = $adWordsServices->get($session, CampaignService::class);

                $selector = new Selector();
                $selector->setFields(array('Id', 'Name', 'Status'));
                $selector->setOrdering(array(new OrderBy('Name', 'ASCENDING')));

That's for getting the campaign. 

 $campaignId = $campaign->getId();
                            $campaignCriterionService = $adWordsServices->get($session, CampaignCriterionService::class);

                            $selector = new Selector();
                            $selector->setFields(['Id', 'CriteriaType', 'CampaignId','BidModifier', 'LocationName']);
                            $selector->setPredicates([
                              new Predicate('CampaignId', PredicateOperator::IN, [$campaignId]), 
                              new Predicate('CriteriaType', PredicateOperator::IN, ['LOCATION'])]);

                           $page = $campaignCriterionService->get($selector);

That's for getting location.

I used what you suggested CAMPAIGN_LOCATION_TARGET_REPORT:

$query = 'SELECT CampaignId,Clicks, Cost, Conversions, CostPerConversion, Ctr,CampaignName,ConversionRate, BidModifier
              FROM CAMPAIGN_LOCATION_TARGET_REPORT
              WHERE CampaignId = ' . $campaignId 

But I'm getting duplicate values. I'm confused on how to get stats for exact location. 

Peter Oliquino

unread,
Jul 4, 2017, 2:25:06 AM7/4/17
to AdWords API Forum
Hi,

I'm Shwetha's colleague and I will be providing support in the meantime. The Campaign Location Target Report currently does not return records specific only to a certain location, however, to further filter your results, you may add the Id field as a filter wherein you use the location criterion Id as its value.

You may also try and generate the Geo Performance Report which returns one row per country/territory. You may also try the Criteria Performance Report, as mentioned by my colleague, which returns one row per ad group and criteria combination.

Please note, however, that if you also use any of the Segment fields of the mentioned reports, you may get more than one row per country/territory or ad group/criteria combination.

Thanks and regards,
Peter
AdWords API Team
Reply all
Reply to author
Forward
0 new messages