---
title: Targeting Rules and Filters
description: >-
  Learn how targeting rules, filters, and rollout types control which variants
  your application serves.
breadcrumbs: Docs > Feature Flags > Concepts > Targeting Rules and Filters
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Targeting Rules and Filters

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Overview{% #overview %}

**Targeting rules** define which variant to serve to which subjects. Each rule can include a **filter**, one or more variants, and an optional percentage rollout. Rules are evaluated in order until a match is found.

## Targeting rule types{% #targeting-rule-types %}

Datadog supports different targeting rule types depending on your rollout strategy:

| Type                    | Description                                                                                                                                                                                        |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Feature gate**        | Roll out to a percentage of subjects matching your filter (randomized or not), immediately or at a [scheduled start time](https://docs.datadoghq.com/feature_flags/concepts/scheduled_rollouts.md) |
| **Progressive rollout** | Randomized rollout over a schedule with multiple steps, started manually or at a [scheduled start time](https://docs.datadoghq.com/feature_flags/concepts/scheduled_rollouts.md)                   |
| **Experiment**          | Randomized allocation associated with an experiment                                                                                                                                                |

## Configure targeting rules{% #configure-targeting-rules %}

To configure targeting rules for a flag:

1. Navigate to **Feature Flags** and select your flag.
1. Select the environment whose rules you want to modify.
1. Click **Add Targeting Rule** (or click the targeting rule you want to modify).

{% image
   source="https://docs.dd-static.net/images/feature_flags/concepts/ff-targeting-rules-and-rollouts-2.8e7e8ef69dd99653ec0d81beba6455a0.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/feature_flags/concepts/ff-targeting-rules-and-rollouts-2.8e7e8ef69dd99653ec0d81beba6455a0.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="Targeting Rules and Rollouts section on a feature flag." /%}

For each targeting rule, configure the following:

- **Name your targeting rule**: Give your targeting rule a name to describe the group it targets.
- **Define a filter** (optional): If you do not define a filter, the rule matches all subjects in that environment. To reuse the same conditions across multiple flags, add a [saved filter](https://docs.datadoghq.com/feature_flags/concepts/saved_filters.md) instead of redefining them on each flag.
- **Select variants**: Choose which variants to serve to matching subjects. Click **Split Traffic** to randomize across multiple variants (see [Traffic Splitting and Randomization](https://docs.datadoghq.com/feature_flags/concepts/traffic_splitting.md)).
- **Set the traffic exposure** (optional): Serve the variant to a percentage of matching subjects (see [Traffic Splitting and Randomization](https://docs.datadoghq.com/feature_flags/concepts/traffic_splitting.md)).
- **Schedule a start time** (optional): Activate the rule automatically at a future date and time instead of immediately (see [Scheduled Rollouts](https://docs.datadoghq.com/feature_flags/concepts/scheduled_rollouts.md)).

{% image
   source="https://docs.dd-static.net/images/feature_flags/concepts/configure-targeting-rule-3.8c90712715169ae16dbe96a5bb2bcbfa.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/feature_flags/concepts/configure-targeting-rule-3.8c90712715169ae16dbe96a5bb2bcbfa.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="Targeting Rule editor side panel on a feature flag." /%}

After configuring your targeting rules, click **Save**, then enable the flag in the environment so SDKs can evaluate targeting rules.

{% alert level="info" %}
SDKs do not evaluate targeting rules when the flag is disabled or overridden in an environment. If the flag is overridden with a fixed variant, the SDK returns that variant instead. If the flag is disabled, the SDK returns the coded default variant.
{% /alert %}

## Filters and evaluation context{% #filters-and-evaluation-context %}

Filters use attributes from your SDK's [evaluation context](https://docs.datadoghq.com/feature_flags/concepts/evaluation_context.md). Define attributes when you set the evaluation context before evaluating flags. Attributes must be flat primitive values (strings, numbers, Booleans). Nested objects and arrays are not supported.

When you build a filter, the attribute field suggests attributes your organization has already defined or that your SDKs have sent recently. See [Targeting Attributes](https://docs.datadoghq.com/feature_flags/concepts/targeting_attributes.md) to define reusable attributes with a data type, which also determines the operators available for that attribute.

Given an evaluation context with `country`, `tier`, `user_role`, and `account_age_days` attributes, you can build filters with different operators, such as equality, **is one of**, **is not**, or numeric comparisons:

- `country` **is one of** `US`, `CA`
- `tier` **equals** `premium`
- `user_role` **is not** `guest`
- `account_age_days` **greater than** `90`

## Rule hierarchy{% #rule-hierarchy %}

Targeting rules are evaluated **in order** from top to bottom:

1. The SDK evaluates the first rule. If the subject matches the filter (or no filter is defined), the rule may serve a variant.
1. If the subject does not match, evaluation passes through to the next rule.
1. If no rule matches, the SDK serves the **default variant** for that environment.

## Further reading{% #further-reading %}

Additional helpful documentation, links, and articles:

- [Targeting Attributes](https://docs.datadoghq.com/feature_flags/concepts/targeting_attributes.md)
- [Scheduled Rollouts](https://docs.datadoghq.com/feature_flags/concepts/scheduled_rollouts.md)
- [Saved Filters](https://docs.datadoghq.com/feature_flags/concepts/saved_filters.md)
- [Traffic Splitting and Randomization](https://docs.datadoghq.com/feature_flags/concepts/traffic_splitting.md)
- [Evaluation Context](https://docs.datadoghq.com/feature_flags/concepts/evaluation_context.md)
- [Environments](https://docs.datadoghq.com/feature_flags/concepts/environments.md)
- [Client-Side SDKs](https://docs.datadoghq.com/feature_flags/client.md)
