2

I am using ads API for getting the spends based on state names of USA.

The below query gives segments.geo_target_state will be returned as an ID instead of name How can I combine this query with

SELECT 
geo_target_constant.name, 
geo_target_constant.canonical_name 
FROM geo_target_constant 
WHERE geo_target_constant.id = <<OBTAINED ID FROM THE BELOW QUERY>>
curl "https://googleads.googleapis.com/v10/customers/${CUSTOMER_ID}/googleAds:searchStream" \
  --header "Content-Type: application/json" \
  --header "developer-token: ${DEVELOPER_TOKEN}" \
  --header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \
  --header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
  --data '{
    "query": "
      SELECT
        campaign.name,
        segments.geo_target_state,
        metrics.cost_micros
      FROM geographic_view
      WHERE
        geographic_view.location_type = LOCATION_OF_PRESENCE
        AND segments.date BETWEEN 20220101 AND 20220430
    "
  }'

That is geoTargetConstants/21136 must be decoded to "name": "New Jersey",

 "results": [
            {
                "campaign": {
                    "resourceName": "customers/1234/campaigns/1234",
                    "name": "Display - macines - Leads Display Campaign Test - AA"
                },
                "metrics": {
                    "costMicros": "66664821"
                },
                "segments": {
                    "geoTargetState": "**geoTargetConstants/21136**"
                },
                "geographicView": {
                    "resourceName": "customers/6383148790/geographicViews/2840~LOCATION_OF_PRESENCE"
                }
            },
aknosis
  • 3,602
  • 20
  • 33
Code Guy
  • 3,059
  • 2
  • 30
  • 74

1 Answers1

0

If you want to use the API to lookup the geo target constant name you will have to issue another search request using the query you provided.

This is likely okay in one off scenarios but breaks down quickly if you need to retrieve multiple geo target constants.

What I have do to resolve this is pull the list of geo targets, see: https://developers.google.com/google-ads/api/reference/data/geotargets, and store them locally in a database. Then I can pull the name from a must faster source.

aknosis
  • 3,602
  • 20
  • 33