# Retargeting / Segment Targeting

Segment targeting allows you to show ads only to users who belong to a specific audience. One common use case is **retargeting**—reaching users who previously visited a webpage or took a defined action elsewhere.

Kevel supports two approaches to segment-based targeting:

| Type | Use Case | How It Works |
| --- | --- | --- |
| **Segment Targeting (Recommended)** | Target users based on centrally managed segments from Kevel Audience or synced CDPs | Define segments externally (via Kevel Audience or an integrated system) and reference them directly when setting up targeting in your campaign. |
| **Retargeting Segments (Legacy)** | Track user actions on your site or advertiser’s site to build ad-hoc segments via UserDB | Use Ados.js pixels or the UserDB API to manually add users to segments. Then use reserved keys to target users based on stored `retargetingSegments` in their user profile.

### Recommended: Use Segment Targeting

[Segment targeting](https://dev.kevel.com/docs/segment-targeting) using [Kevel Audience](https://docs.audience.kevel.com/) or a synced external system is the preferred method. It enables centralized audience management, better reuse across campaigns, and a cleaner setup.

## Legacy Retargeting Segment Setup

If you're not using Audience, you can still set up retargeting segments using the JavaScript pixel method or the API. These segments are stored in the user’s [UserDB](https://dev.kevel.com/docs/userdb-1) record under `retargetingSegments`, tied to a persistent `userKey`.

### Retargeting via Ados.js (Pixel Method)

This method allows advertisers to retarget users who visited **their** site when those users later visit **your** site.

1. Create a pixel using the format below.
2. Provide it to the advertiser to place on their website.
3. When a user visits that page, the pixel fires and updates the user's UserDB record.
4. You can then target users in that segment.

**Pixel format:**

```undefined
https://e-{networkId}.adzerk.net/udb/{networkId}/rt/{advertiserID}/{segment}/i.gif
```

**Parameters:**

| Field | Description |
| --- | --- |
| `networkId` | Your Kevel network ID |
| `advertiserID` | The advertiser’s ID in your network |
| `segment` | An integer segment ID (e.g. `1`). You can assign multiple if needed. |

**Example:**

```undefined
https://e-123.adzerk.net/udb/123/rt/6700/1/i.gif
```

### Retargeting via API

You can also add users to a retargeting segment programmatically by calling the [Add to Retargeting Segment endpoint](https://dev.kevel.co/v1.0/reference/userdb#add-user-to-retargeting-segment).

This requires:

- The `userKey` for the user
- A numeric `segment` ID
- The `advertiserId` that owns the segment

This is useful if you want to create custom segments based on user activity across your properties (e.g., cart views, product pages, video views).

### Alternative: Interest Targeting

If you'd prefer more control or transparency, you can use [Interest Targeting](https://dev.kevel.com/docs/interest-targeting) instead. Both approaches let you build custom segments, but they differ in expiration behavior:

| Method | Persistence | Example Use Case |
| --- | --- | --- |
| Retargeting Segment | Auto-expires (~90d) | Target recent site visitors |
| Interest Targeting | Persistent unless removed manually | Track recurring behaviors or interest over time |

## Targeting These Segments

When creating a Flight or Ad via the UI or API, you can target users in specific retargeting segments using [Reserved Keys](https://dev.kevel.com/docs/reserved-keys).

Use the format:

```undefined
$user.retargetingSegments.b[AdvertiserID] = [SegmentID]
```

**Example JSON:**

```json
{
  "CampaignId": 1234,
  "PriorityId": 1325,
  "Name": "Retargeting - Homepage",
  "StartDateISO": "2017-05-01T00:00:00.00.0000000",
  "GoalType": 1,
  "CustomTargeting": "$user.retargetingSegments.b42 = 1"
}
```

## Viewing Retargeting Segments for a User

To inspect what segments a user belongs to, you can use the [Read User endpoint](https://dev.kevel.co/v1.0/reference/userdb#read-a-users-record). Look for the `retargetingSegments` object in the response.
