---
title: Feature Flags and Experiments
description: >-
  Learn how a feature flag's targeting rules randomize a Datadog Experiment and
  record exposures for analysis.
breadcrumbs: Docs > Feature Flags > Concepts > Feature Flags and Experiments
---

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

# Feature Flags and Experiments

{% 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 %}

Datadog Feature Flags is the default way to randomize a [Datadog Experiment](https://docs.datadoghq.com/experiments.md). When you link a flag to an experiment, Datadog adds an Experiment targeting rule to the flag. Evaluations of that rule assign subjects to a variant and record an exposure event that Datadog uses to analyze the experiment.

## Link a flag to an experiment{% #link-a-flag-to-an-experiment %}

Link a flag to an experiment from either side of the workflow:

- From [Product Analytics > Experiments](https://docs.datadoghq.com/experiments.md), create an experiment and [add an existing feature flag](https://docs.datadoghq.com/experiments/plan_and_launch_experiments.md#add-a-feature-flag) to it.
- From a flag's detail page, click Create New Experiment in the Targeting Rules & Rollouts section to create an experiment pre-filled with that flag.

## Experiment targeting rules{% #experiment-targeting-rules %}

An experiment targeting rule works like any other [targeting rule](https://docs.datadoghq.com/feature_flags/concepts/targeting_rules.md): it can include a filter, and it uses the same [deterministic randomization](https://docs.datadoghq.com/feature_flags/concepts/traffic_splitting.md) to assign subjects to a variant. Randomization is based on the `targetingKey` in your [evaluation context](https://docs.datadoghq.com/feature_flags/concepts/evaluation_context.md), so the same subject consistently receives the same variant for the life of the experiment.

If multiple experiments share the same flag, Datadog evaluates their targeting rules in order, top to bottom. Reorder the rules before you launch an experiment to control which one takes priority for a given subject.

## Exposures{% #exposures %}

Each time the SDK evaluates a flag's experiment targeting rule for a subject, Datadog records an *exposure*: the subject, the variant served, and a timestamp. Datadog joins exposures to metric events to calculate the lift between variants. Those metric events can come from Product Analytics, Real User Monitoring, or your data warehouse.

Datadog joins exposures and metrics by subject identifier. The `targetingKey` your SDK sets in the [evaluation context](https://docs.datadoghq.com/feature_flags/concepts/evaluation_context.md) must match the [subject type attribute](https://docs.datadoghq.com/experiments/concepts/subject_types.md) configured for the experiment, such as `@usr.id`, or Datadog can't associate metric events with the correct exposure.

## Bring your own randomization{% #bring-your-own-randomization %}

If you randomize subjects with a system other than Datadog Feature Flags, this flag-to-experiment integration doesn't apply. Datadog can still analyze the experiment: define an [Exposure SQL Model](https://docs.datadoghq.com/experiments/concepts/exposure_sql.md) that reads exposure records from your data warehouse instead.

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

Additional helpful documentation, links, and articles:

- [Learn about Datadog Experiments](https://docs.datadoghq.com/experiments.md)
- [Plan and Launch Experiments](https://docs.datadoghq.com/experiments/plan_and_launch_experiments.md)
- [Subject Types in Experiments](https://docs.datadoghq.com/experiments/concepts/subject_types.md)
- [Feature Flags Targeting Rules and Filters](https://docs.datadoghq.com/feature_flags/concepts/targeting_rules.md)
- [Feature Flags Evaluation Context](https://docs.datadoghq.com/feature_flags/concepts/evaluation_context.md)
