> Documentation index: https://docs.zernio.com/llms.txt. Every page is also Markdown: add .md to its URL.

# 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](/platforms/google-ads#connect) and the create call from [Create a campaign](/platforms/google-ads/create-ads).

## 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.

| Field | What it targets on Google |
|---|---|
| `countries` | ISO 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](#look-up-google-ids) |
| `customLocations` | A `latitude`, `longitude`, `radius` and `distanceUnit` pin. Google has no city radius, so use a pin instead. |
| `excludedLocations` | Countries, regions, cities and zips the campaign never serves in. Demand Gen returns `400`. |
| `languages` | Google's language codes (ISO 639-1, plus variants such as `zh_CN`). An unknown code returns `400`. |
| `ageMin`, `ageMax` | Search and Display. Google excludes the age ranges outside the request and only targets 18 and older. |
| `gender` | Search and Display. Google excludes the other gender. |
| `incomeTier` | `top_10` only. Other tiers return `400`. |
| `interests` | Affinity and in-market segments, on the Search and Display ad groups the request creates |
| `audienceInclude`, `audienceExclude` | Google user list ids, such as a [Customer Match list](/platforms/google-ads/audiences) |

Performance Max and Demand Gen accept only geo and language fields (plus `excludedLocations` on Performance Max). Demand Gen takes its audience in `demandGen` instead ([Demand Gen](/platforms/google-ads/demand-gen)).

Every other field returns `400`, including `customLocations`, `incomeTier`, `audienceInclude`, `audienceExclude` and top-level `audienceId`.

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

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">
```typescript
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
    }
  }
});
```
</Tab>
<Tab value="Python">
```python
from zernio import Zernio

client = Zernio()

created = client.ad_campaigns.create_standalone_ad(
    account_id="66b2e19d8c3f5a7e9d0b1c2d",
    ad_account_id="1234567890",
    name="US DevOps Search",
    campaign_type="search",
    goal="traffic",
    budget_amount=50,
    budget_type="daily",
    headline="Internal Developer Platforms",
    body="Spec-driven platform engineering.",
    link_url="https://example.com/platform",
    keywords=["internal developer platform"],
    location_targeting_type="presence",
    targeting={
        "countries": ["US"],
        "excludedLocations": {"countries": ["CA"]},
        "languages": ["en"],
        "ageMin": 25,
        "ageMax": 54,
    },
)
```
</Tab>
<Tab value="curl">
```bash
curl -X POST "https://zernio.com/api/v1/ads/create" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "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
    }
  }'
```
</Tab>
</Tabs>

Response (`201`), the same shape as any [create](/platforms/google-ads/create-ads#create-a-campaign):

```json
{
  "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`.

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">
```typescript
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');
```
</Tab>
<Tab value="Python">
```python
search = client.ad_targeting.search_ad_targeting(
    account_id="66b2e19d8c3f5a7e9d0b1c2d",
    q="Austin",
    dimension="geo",
    country_code="US",
)

cities = [r for r in search["results"] if r["type"] == "city"]
```
</Tab>
<Tab value="curl">
```bash
curl "https://zernio.com/api/v1/ads/targeting/search?accountId=66b2e19d8c3f5a7e9d0b1c2d&q=Austin&dimension=geo&countryCode=US" \
  -H "Authorization: Bearer $ZERNIO_API_KEY"
```
</Tab>
</Tabs>

Response (`200`):

```json
{
  "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:

| Value | Reaches |
|---|---|
| `presence` | People in, or regularly in, the targeted locations |
| `presence_or_interest` | Also 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.

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">
```typescript
const { data: retargeted } = await zernio.adcampaigns.updateCampaignTargeting({
  path: { campaignId: '21874563210' },
  body: {
    platform: 'google',
    targeting: {
      locations: { countries: ['US'], cities: ['1026201'] },
      languages: ['en', 'es'],
      locationTargetingType: 'presence'
    }
  }
});
```
</Tab>
<Tab value="Python">
```python
retargeted = client.ad_campaigns.update_campaign_targeting(
    campaign_id="21874563210",
    platform="google",
    targeting={
        "locations": {"countries": ["US"], "cities": ["1026201"]},
        "languages": ["en", "es"],
        "locationTargetingType": "presence",
    },
)
```
</Tab>
<Tab value="curl">
```bash
curl -X PUT "https://zernio.com/api/v1/ads/campaigns/21874563210/targeting" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "google",
    "targeting": {
      "locations": { "countries": ["US"], "cities": ["1026201"] },
      "languages": ["en", "es"],
      "locationTargetingType": "presence"
    }
  }'
```
</Tab>
</Tabs>

Response (`200`), trimmed:

```json
{
  "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](/platforms/google-ads/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}`](/ad-campaigns/update-ad), on an ad of that ad group.

## If it fails

| Error | Cause | Fix |
|---|---|---|
| `400` on `ageMin`, `gender` or `interests` | The campaign is Performance Max or Demand Gen, or `interests` joins an existing ad group | Drop the field, or use the Demand Gen `audience` |
| `400` on `ageMax` | `ageMax` is under 18, and Google only targets 18 and older | Send 18 or more |
| `400` on `languages` | Google has no language for that code | Look the code up with `dimension=language` |
| `400` on `locationTargetingType` | The request joins an existing campaign, or the platform is not Google | Change it with `PUT /v1/ads/campaigns/{campaignId}/targeting` |
| `400` on an empty `locations` list | A Google campaign with no locations targets every country | Omit `locations` to keep the current set |
| `400` when a place is both targeted and excluded | The result would put one place on both sides | Move it in one request, or drop it from one side |
| `422` on `devices` | The campaign's channel does not carry that device, or the set switches every device off | Send the devices the channel supports, with at least one on |
| `501` on a targeting update | The campaign is not on Google | Use the platform's own targeting page |

## Related

- [Create a campaign](/platforms/google-ads/create-ads): the create call these fields ride on.
- [Customer Match](/platforms/google-ads/audiences): build the user list for `audienceInclude`.
- [Keywords](/platforms/google-ads/keywords): keyword targeting on Search ad groups.
- [Search targeting options](/ad-targeting/search-ad-targeting) and [Edit campaign targeting](/ad-campaigns/update-campaign-targeting): every parameter.