How To filter CampaignCriterionService By Location

23 views
Skip to first unread message

Snayder Acero

unread,
Jul 25, 2019, 1:32:59 AM7/25/19
to AdWords API and Google Ads API Forum
Good Afternoon,



I'm trying to filter campaigns by location but I haven't made it work. I require is that you bring me all the campaigns of (Spain By example) I currently have the following code:


// Create a selector
                $selector        = new Selector();
                // instance Adwords Service
                $adwServices     = new AdWordsServices();
                // create Array Predicates
                $arrPredicates   = array(
                    new Predicate('CriteriaType', PredicateOperator::IN, ['LOCATION']),
                    // new Predicate('LocationName', PredicateOperator::IN, $arrLocations),
                    // new Predicate('KeywordText',  PredicateOperator::IN, $arrLocations)
                );
                // call Campaigns Service
                $campaignService = $adwServices->get($session, CampaignCriterionService::class);
                // set Selector Values
                $selector->setFields(['Id', 'CriteriaType','LocationName','ParentLocations']);
                $selector->setPredicates($arrPredicates);
                $selector->setPaging(new Paging(0, $this->itmByPage));
        


Google Ads API Forum Advisor Prod

unread,
Jul 25, 2019, 3:50:25 AM7/25/19
to adwor...@googlegroups.com
Hi Snayder,

Thank you for reaching out.

Could you confirm if you wish to retrieve all campaigns that have a specific location criterion? If yes, as I was checking the code you provided, you could try adding the CampaignId field first in your selected fields to get the campaigns that have the criterion specified in your predicate.

If you want to retrieve a country specific criteria, you may want to use the Id as a predicate instead and refer to this geotarget table to get the value of the location you wish to use.

Let me know if this helps.

Regards,
Dannison
Google Ads API Team

ref:_00D1U1174p._5001UEGLlW:ref

Snayder Acero

unread,
Jul 25, 2019, 11:39:45 AM7/25/19
to AdWords API and Google Ads API Forum
My code is running correctly 



And This Predicate:


$arrPredicates   = array(
                    new Predicate('CriteriaType', PredicateOperator::IN, ['LOCATION']),
                    new Predicate('Id',  PredicateOperator::IN, $arrLocations)
                );


Thank you, very much
Reply all
Reply to author
Forward
0 new messages