Zernio
APIFor you
Zernio
APIFor you
Platforms

Google Ads

Overview

Build

Create adsPerformance MaxDemand Gen

Target

TargetingKeywordsCustomer Match

Measure

Insights & GAQLConversionsGoogle TagURL tracking tags

Operate

Manage adsRecommendationsAccounts & labels

Reference

Limits and errors
Dashboard
OverviewPlatformsAPI ReferenceResources
Google Ads

Targeting

Target Google campaigns by location, language, age, gender, income, interests and Customer Match lists, look up Google's ids, and change a live campaign's locations, languages and devices.


By the end of this page, a new Google campaign reaches the places, languages and people you choose, and you can change that targeting once it runs.

Before you start

You need a googleads account and the create call from Create a campaign.

Targeting fields

Send the fields in the targeting object of POST /v1/ads/create. The same names also work flat on the request body, and a flat field replaces its nested value.

FieldWhat it targets on Google
countriesISO 3166-1 alpha-2 codes. On Search and Display, US when the request has no other geo. Performance Max and Demand Gen with no geo run worldwide.
regions, cities, zips, metros{ key } entries, where key is Google's geo target constant id from the search
customLocationsA latitude, longitude, radius and distanceUnit pin. Google has no city radius, so use a pin instead.
excludedLocationsCountries, regions, cities and zips the campaign never serves in. Demand Gen returns 400.
languagesGoogle's language codes (ISO 639-1, plus variants such as zh_CN). An unknown code returns 400.
ageMin, ageMaxSearch and Display. Google excludes the age ranges outside the request and only targets 18 and older.
genderSearch and Display. Google excludes the other gender.
incomeTiertop_10 only. Other tiers return 400.
interestsAffinity and in-market segments, on the Search and Display ad groups the request creates
audienceInclude, audienceExcludeGoogle user list ids, such as a Customer Match list

Performance Max and Demand Gen accept only geo and language fields (plus excludedLocations on Performance Max). Every other field, including customLocations, incomeTier, audienceInclude, audienceExclude and top-level audienceId, returns 400. Demand Gen takes its audience in demandGen instead (Demand Gen).

Interests are create-only, and they return 400 when the request joins an existing ad group with adSetId.

import Zernio from '@zernio/node';

const zernio = new Zernio();

const { data: created } = await zernio.adcampaigns.createStandaloneAd({
  body: {
    accountId: '66b2e19d8c3f5a7e9d0b1c2d',
    adAccountId: '1234567890',
    name: 'US DevOps Search',
    campaignType: 'search',
    goal: 'traffic',
    budgetAmount: 50,
    budgetType: 'daily',
    headline: 'Internal Developer Platforms',
    body: 'Spec-driven platform engineering.',
    linkUrl: 'https://example.com/platform',
    keywords: ['internal developer platform'],
    locationTargetingType: 'presence',
    targeting: {
      countries: ['US'],
      excludedLocations: { countries: ['CA'] },
      languages: ['en'],
      ageMin: 25,
      ageMax: 54
    }
  }
});

Response (201), the same shape as any create:

{
  "ad": {
    "_id": "66f0a1b2c3d4e5f6a7b8c9d0",
    "name": "US DevOps Search",
    "platform": "google",
    "status": "pending_review",
    "adType": "standalone",
    "goal": "traffic",
    "budget": { "amount": 50, "type": "daily" },
    "platformAdId": "735198246013",
    "platformCampaignId": "21874563210",
    "platformAdSetId": "165489732105"
  },
  "message": "Ad created"
}

Look up Google ids

Call GET /v1/ads/targeting/search with accountId, q and dimension. On Google, dimension takes geo, interest, language and income.

const { data: search } = await zernio.adtargeting.searchAdTargeting({
  query: {
    accountId: '66b2e19d8c3f5a7e9d0b1c2d',
    q: 'Austin',
    dimension: 'geo',
    countryCode: 'US'
  }
});

const cities = search.results.filter((result) => result.type === 'city');

Response (200):

{
  "results": [
    { "id": "1026201", "name": "Austin", "type": "city", "path": ["Texas", "United States"] }
  ]
}

A geo search returns every matching level in one list, because Google ignores geoType. Filter on each result's type (country, region, city, zip, metro). countryCode scopes the search to one country.

A country result's id is its ISO code, for countries. Every other id is Google's numeric id, for the key of regions, cities, zips or metros.

  • interest returns Google's affinity and in-market segments. Google has no separate behavior catalog.
  • language reads Google's language table without calling Google. It returns 20 results by default, and limit (up to 100) overrides that.
  • income returns the one tier Google targets, top_10.

Location targeting type

locationTargetingType is a top-level field that sets who a new campaign's locations reach:

ValueReaches
presencePeople in, or regularly in, the targeted locations
presence_or_interestAlso people searching for or showing interest in them. Google's default when you omit it.

Excluded locations always use presence.

It is set on the new campaign only. A request that joins an existing campaign (existingCampaignId or adSetId) returns 400. It is Google-only and returns 400 on other platforms.

Change a running campaign

PUT /v1/ads/campaigns/{campaignId}/targeting changes a Google campaign's devices, locations, excludedLocations, languages and locationTargetingType. campaignId is Google's numeric campaign id.

const { data: retargeted } = await zernio.adcampaigns.updateCampaignTargeting({
  path: { campaignId: '21874563210' },
  body: {
    platform: 'google',
    targeting: {
      locations: { countries: ['US'], cities: ['1026201'] },
      languages: ['en', 'es'],
      locationTargetingType: 'presence'
    }
  }
});

Response (200), trimmed:

{
  "campaignId": "21874563210",
  "updated": ["locations", "languages", "locationTargetingType"],
  "locationTargetingType": "presence",
  "locations": [
    { "geoTargetId": "2840", "negative": false, "name": "United States", "type": "Country", "countryCode": "US" },
    { "geoTargetId": "1026201", "negative": false, "name": "Austin", "type": "City", "countryCode": "US" }
  ],
  "languages": [
    { "code": "en", "id": "1000", "name": "English" },
    { "code": "es", "id": "1003", "name": "Spanish" }
  ]
}

Each field you send replaces that whole set on the campaign. A field you leave out stays as it is.

  • locations takes a bare array of ISO codes, or countries, regions, cities, zips and metros lists. It leaves excluded locations alone.
  • excludedLocations takes the same shapes. An empty list removes every exclusion.
  • devices is the full set of MOBILE, DESKTOP, TABLET and CONNECTED_TV, with an optional bidModifier each. A device you leave out is switched off with a bid modifier of 0, because Google cannot remove a device.

Locations, languages and devices are campaign-level on Google, so the change applies to every ad group and ad in the campaign. Each set's removes and creates go out in one Google request. locationTargetingType, devices, locations, radius and languages go as separate calls, so a failure part-way leaves earlier fields applied.

GET /v1/ads/campaigns/{campaignId}/targeting reads the current set. Keyword edits are on Keywords.

Demand Gen. Google keeps a Demand Gen campaign's locations and languages on its ad group. excludedLocations returns 400. With one ad group they are written there and the response carries its adGroupId.

With several ad groups the call returns 400 naming them. Edit each one with targeting on PUT /v1/ads/{adId}, on an ad of that ad group.

If it fails

ErrorCauseFix
400 on ageMin, gender or interestsThe campaign is Performance Max or Demand Gen, or interests joins an existing ad groupDrop the field, or use the Demand Gen audience
400 on ageMaxageMax is under 18, and Google only targets 18 and olderSend 18 or more
400 on languagesGoogle has no language for that codeLook the code up with dimension=language
400 on locationTargetingTypeThe request joins an existing campaign, or the platform is not GoogleChange it with PUT /v1/ads/campaigns/{campaignId}/targeting
400 on an empty locations listA Google campaign with no locations targets every countryOmit locations to keep the current set
400 when a place is both targeted and excludedThe result would put one place on both sidesMove it in one request, or drop it from one side
422 on devicesThe campaign's channel does not carry that device, or the set switches every device offSend the devices the channel supports, with at least one on
501 on a targeting updateThe campaign is not on GoogleUse the platform's own targeting page

Related

  • Create a campaign: the create call these fields ride on.
  • Customer Match: build the user list for audienceInclude.
  • Keywords: keyword targeting on Search ad groups.
  • Search targeting options and Edit campaign targeting: every parameter.
Was this page helpful?

Demand Gen

Create Google Demand Gen campaigns with image, video or carousel ads across YouTube, Discover and Gmail, add ad groups and ads, and edit creative, channels, audiences and targeting.

Keywords

Read the Search keywords your Google campaigns run, add keywords to an ad group, and research new ones with the Keyword Planner.

On this page

Before you startTargeting fieldsLook up Google idsLocation targeting typeChange a running campaignIf it failsRelated