Get Targeted Locations with geo radius map against campaign ID

300 views
Skip to first unread message

SOHAIR AHMAD

unread,
Dec 28, 2016, 2:54:19 AM12/28/16
to AdWords API Forum
I am trying to retrieve the detail of campaign, but I am not able to find any solution of getting Targeted location against campaign id, with targeted location, radius map, and reach.

https://developers.google.com/adwords/api/docs/samples/ruby/targeting#get-all-campaign-targeting-criteria does not get me any result but ZERO entries. any help in this case will be appriciated.

Joyce Lava

unread,
Dec 28, 2016, 4:44:31 AM12/28/16
to AdWords API Forum
Hi Sohair,

You may refer to the below example SOAP request and response to get the targeted location and proximity:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <ns1:RequestHeader xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201609" soapenv:mustUnderstand="0">
            <ns1:clientCustomerId>YOUR_CLIENT_CUSTOMER_ID</ns1:clientCustomerId>
            <ns1:developerToken>YOUR_DEVELOPER_TOKEN</ns1:developerToken>
            <ns1:userAgent>YOUR_USER_AGENT</ns1:userAgent>
            <ns1:validateOnly>false</ns1:validateOnly>
            <ns1:partialFailure>false</ns1:partialFailure>
        </ns1:RequestHeader>
    </soapenv:Header>
    <soapenv:Body>
        <get xmlns="https://adwords.google.com/api/adwords/cm/v201609">
            <serviceSelector>
                <fields>CampaignId</fields>
                <fields>Id</fields>
                <fields>CriteriaType</fields>
                <fields>LocationName</fields>
                <fields>RadiusDistanceUnits</fields>
                <fields>RadiusInUnits</fields>
                <predicates>
                    <field>CriteriaType</field>
                    <operator>IN</operator>
                    <values>LOCATION</values>
                    <values>PROXIMITY</values>
                </predicates>
                <predicates>
                    <field>CampaignId</field>
                    <operator>EQUALS</operator>
                    <values>YOUR_CAMPAIGN_ID</values>
                </predicates>
                <paging>
                    <startIndex>0</startIndex>
                    <numberResults>100</numberResults>
                </paging>
            </serviceSelector>
        </get>
    </soapenv:Body>
</soapenv:Envelope>

[main] INFO com.google.api.ads.adwords.lib.client.AdWordsServiceClient.soapXmlLogger - SOAP Response:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
        <ResponseHeader xmlns="https://adwords.google.com/api/adwords/cm/v201609">
            <requestId>REQUEST_ID</requestId>
            <serviceName>CampaignCriterionService</serviceName>
            <methodName>get</methodName>
            <operations>1</operations>
            <responseTime>303</responseTime>
        </ResponseHeader>
    </soap:Header>
    <soap:Body>
        <getResponse xmlns="https://adwords.google.com/api/adwords/cm/v201609">
            <rval>
                <totalNumEntries>2</totalNumEntries>
                <Page.Type>CampaignCriterionPage</Page.Type>
                <entries>
                    <campaignId>YOUR_CAMPAIGN_ID</campaignId>
                    <isNegative>false</isNegative>
                    <criterion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Location">
                        <id>LOCATION_ID</id>
                        <type>LOCATION</type>
                        <Criterion.Type>Location</Criterion.Type>
                        <locationName>Mexico</locationName>
                        <displayType>Country</displayType>
                        <targetingStatus>ACTIVE</targetingStatus>
                    </criterion>
                    <CampaignCriterion.Type>CampaignCriterion</CampaignCriterion.Type>
                </entries>
                <entries>
                    <campaignId>YOUR_CAMPAIGN_ID</campaignId>
                    <isNegative>false</isNegative>
                    <criterion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Proximity">
                        <id>ID</id>
                        <type>PROXIMITY</type>
                        <Criterion.Type>Proximity</Criterion.Type>
                        <radiusDistanceUnits>MILES</radiusDistanceUnits>
                        <radiusInUnits>20.0</radiusInUnits>
                        <address>
                            <cityName>Dublin</cityName>
                            <provinceName>OH</provinceName>
                            <countryCode>US</countryCode>
                        </address>
                    </criterion>
                    <CampaignCriterion.Type>CampaignCriterion</CampaignCriterion.Type>
                </entries>
            </rval>
        </getResponse>
    </soap:Body>
</soap:Envelope>

If you still encounter zero results on your end with your campaignId, please send me (reply privately to author) the complete SOAP request and response so I could better check. 

Best,
Joyce, AdWords API Team

SOHAIR AHMAD

unread,
Dec 28, 2016, 5:06:12 AM12/28/16
to AdWords API Forum
Hi Joyce, 

I have tried that sample that worked without campaign ID, i.e, it gives me results of location names

When I updated my selector with Campaign ID predicate:

selector = {
      :fields => ['CampaignId', 'Id', 'LocationName', 'CanonicalName', 'DisplayType',
          'ParentLocations', 'Reach', 'TargetingStatus'],
      :predicates => [
          {:field => 'CampaignId', :operator => 'EQUALS', :values => ['716319721']},
          # Location names must match exactly, only EQUALS and IN are supported.
          {:field => 'LocationName',
           :operator => 'IN',
           :values => location_names},
          # Set the locale of the returned location names.
          {:field => 'Locale', :operator => 'EQUALS', :values => [locale]},
    ]
  }


It gives me the following ERROR

criteria = location_criterion_srv.get(selector)

AdwordsApi::V201607::LocationCriterionService::ApiException: [SelectorError.INVALID_FIELD_NAME @ selector; trigger:'CampaignId', SelectorError.INVALID_PREDICATE_FIELD_NAME @ selector; trigger:'CampaignId'] 

For the Obvious reason may be as according to this https://developers.google.com/adwords/api/docs/reference/v201609/LocationCriterionService.LocationCriterion we do not have any campaign id field in it or may be I am missing something ?

Joyce Lava

unread,
Dec 28, 2016, 6:11:24 AM12/28/16
to AdWords API Forum
Hi Sohair,

Based on your code, you are using LocationCriterionService instead of CampaignCriterionService. LocationCriterionService is normally used to get the locationCriterion constants and not the targeted location of a campaign. From the sample SOAP request and response I previously sent, I was using CampaignCriterionService.get operation with criterion as Location and Proximity. That way, you can get the location and proximity targeting based on CampaignId. You may want to double check the SOAP logs I sent, then let me know if you encounter any issues after trying that on your end.

SOHAIR AHMAD

unread,
Dec 28, 2016, 7:12:10 AM12/28/16
to AdWords API Forum

Thanks Joyce, 

Things worked for me :) 
If anyone needs help in ruby (ruby on rails) here is an example;

require 'adwords_api'
config = YAML.load_file(Rails.root.join('config/adwords_api_test.yml'))
API_VERSION = :v201607
adwords = AdwordsApi::Api.new(config)
campaign_criterion_srv = adwords.service(:CampaignCriterionService, API_VERSION)
selector = {
  :fields => ['Id', 'CriteriaType', 'LocationName', 'RadiusDistanceUnits', 'RadiusInUnits'],
  :predicates => [
    {:field => 'CriteriaType', :operator => 'IN', :values => ['LOCATION', 'PROXIMITY']},
    {:field => 'CampaignId', :operator => 'EQUALS', :values => [716393970]},
  ],
  :paging => {
    :start_index => 0,
    :number_results => 100
  }
}
campaign_criterion_srv.get(selector

Joyce Lava

unread,
Dec 28, 2016, 9:30:25 PM12/28/16
to AdWords API Forum
Hi Sohair,

Glad to hear that I was able to help!
Reply all
Reply to author
Forward
0 new messages