# Targeting

Target an AppLovin campaign by country, and narrow the US to states or metro areas, on create or later.

import { Tab, Tabs } from 'fumadocs-ui/components/tabs';

Targeting sits on the AppLovin campaign, so it applies to every creative set in it.

## Targeting fields

| Field | Values |
|-------|--------|
| `countries` | ISO 3166-1 alpha-2 codes, at least one, required on every new campaign |
| `regions` | US state codes, as `[{ "key": "CA" }]` or `"US-CA"`. Only with `US` in `countries` |
| `metros` | AppLovin metro names, as `[{ "key": "New York-Newark-Jersey City, NY-NJ-PA" }]`. Only with `US` in `countries` |

This creates a campaign that serves in Canada, and in California and Texas in the US:

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">
```typescript
const { data: created } = await zernio.adcampaigns.createStandaloneAd({
  body: {
    accountId: '6507a1b2c3d4e5f6a7b8c9d0',
    adAccountId: '184520',
    name: 'Trail guide West',
    goal: 'lead_generation',
    budgetAmount: 30,
    budgetType: 'daily',
    linkUrl: 'https://example.com/trial',
    countries: ['US', 'CA'],
    regions: [{ key: 'CA' }, { key: 'TX' }],
    platformSpecificData: {
      campaignType: 'WEB',
      goalValue: 12,
      eventTarget: 'GENERATE_LEAD',
      assets: [{ type: 'HOSTED_HTML', url: 'https://cdn.example.com/trial-playable.html' }]
    }
  }
});
```
</Tab>
<Tab value="Python">
```python
created = client.ad_campaigns.create_standalone_ad(
    account_id="6507a1b2c3d4e5f6a7b8c9d0",
    ad_account_id="184520",
    name="Trail guide West",
    goal="lead_generation",
    budget_amount=30,
    budget_type="daily",
    link_url="https://example.com/trial",
    countries=["US", "CA"],
    regions=[{"key": "CA"}, {"key": "TX"}],
    platform_specific_data={
        "campaignType": "WEB",
        "goalValue": 12,
        "eventTarget": "GENERATE_LEAD",
        "assets": [{"type": "HOSTED_HTML", "url": "https://cdn.example.com/trial-playable.html"}],
    },
)
```
</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": "6507a1b2c3d4e5f6a7b8c9d0",
    "adAccountId": "184520",
    "name": "Trail guide West",
    "goal": "lead_generation",
    "budgetAmount": 30,
    "budgetType": "daily",
    "linkUrl": "https://example.com/trial",
    "countries": ["US", "CA"],
    "regions": [{ "key": "CA" }, { "key": "TX" }],
    "platformSpecificData": {
      "campaignType": "WEB",
      "goalValue": 12,
      "eventTarget": "GENERATE_LEAD",
      "assets": [{ "type": "HOSTED_HTML", "url": "https://cdn.example.com/trial-playable.html" }]
    }
  }'
```
</Tab>
</Tabs>

The response is the created ad, as in [Create ads](/platforms/applovin/create-ads#create-a-campaign). Zernio sends AppLovin one targeting entry per country.

## Change the targeting

Send `targeting` with `countries`, and `regions` or `metros`, to `PUT /v1/ads/{adId}` with any creative set of the campaign:

```bash
curl -X PUT "https://zernio.com/api/v1/ads/6ae0968fa23091cc35b72188" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "targeting": { "countries": ["US"], "metros": [{ "key": "New York-Newark-Jersey City, NY-NJ-PA" }] } }'
```

The change applies to the whole campaign, so every creative set in it serves where the new targeting says.

## How it behaves

- `regions` and `metros` cannot go together, and both are US only.
- The keys of `countryBudgets` and `countryGoalValues` must be countries the campaign targets.
- Age, gender, interests, devices and audiences are not available.

## If it fails

| Error | Cause | Fix |
|-------|-------|-----|
| `422` on `countries` | No countries sent | Send at least one country. |
| `422` on `regions` or `metros` | `US` is not in `countries`, or both were sent | Add `US`, and send only one of them. |
| `422` on `countryBudgets` or `countryGoalValues` | A key that is not a targeted country | Target the country, or remove the key. |

## Related

- [Create ads](/platforms/applovin/create-ads): the rest of the create request.
- [Update ad](/ad-campaigns/update-ad): every field of the update.
- [Limits & errors](/platforms/applovin/reference): what AppLovin does not support yet.