Create Exposure SQL Models
This product is not supported for your selected
Datadog site. (
).
Overview
Datadog Experiments analyzes experiments run with Datadog Feature Flags or an independent randomization system. If you randomize subjects outside of Datadog Feature Flags, create Exposure SQL Models to tell Datadog who was exposed to your experiment and when, by reading exposure records from your warehouse.
Similar to Metric SQL Models, Exposure SQL Models are SQL queries that describe exposure data in your warehouse. Exposure SQL Models return the following columns:
| Column | Required | Description |
|---|
| Subject Key | Yes | A unique identifier for the subject randomized into the experiment. This is typically a user_id. |
| Timestamp | Yes | The timestamp when the user was exposed to the experiment. |
| Experiment ID | Yes | The experiment that the user was exposed to. One Exposure SQL Model can track many experiments; this column filters records to a specific experiment. |
| Variant ID | Yes | The variant the user was assigned to (for example, treatment or control). |
| Split-by properties | No | Categorical data used to create dimensional split-by charts, such as customer tier, device type, or region. |
When you create an experiment, Datadog Feature Flags and warehouse exposures both appear during flag selection:
Metrics built on events from the Datadog SDK are not supported when exposures come from your warehouse instead of Datadog Feature Flags.
Datadog deduplicates exposure data for you. You do not need to deduplicate upstream:
- If multiple records exist for the same user-experiment pair, Datadog uses the first record.
- If one user was exposed to multiple variants in the same experiment, Datadog excludes that user from the analysis.
Prerequisites
Before you create Exposure SQL Models:
- Connect your warehouse to Datadog. Datadog supports BigQuery, Databricks, Redshift, and Snowflake.
- Create at least one Metric SQL Model and warehouse metric to measure experiment outcomes.
- Store exposure records in your warehouse with the columns listed above.
Create Exposure SQL Models
Write your SQL
Exposure SQL Models query exposure data in your warehouse. For example:
SELECT
user_id,
exposed_at,
experiment_id,
variant_id,
customer_tier
FROM analytics.experiment_exposures
To create an Exposure SQL Model:
- Navigate to Experiments > Settings > Exposure SQL Models in Datadog Product Analytics.
- Click Create Exposure SQL Model.
- Enter a SQL query that returns the required columns. Column names in your query do not need to match the Datadog field names.
- Click Run to preview your data.
Map columns to Datadog
- In the mapping panel on the right, map each query column to the corresponding Datadog field (Subject Key, Timestamp, Experiment ID, Variant ID, and optional split-by properties).
- Click Create Exposure SQL Model to save the model.
Create experiments using Exposure SQL Models
After you save an Exposure SQL Model, Datadog scans the model for distinct experiment and variant values. To create an experiment with warehouse exposures:
- On the experiment setup page, open the feature flag selector.
- Select a warehouse experiment ID from the list, or enter an experiment ID manually if it does not appear in the latest scan.
- Select the Exposure SQL Model that tracks the flag.
How Datadog computes results
After you create an experiment from an Exposure SQL Model, Datadog runs a data pipeline that:
- Filters exposures to the relevant experiment and time frame.
- Deduplicates by subject (user) and removes users exposed to multiple variants.
- Joins exposures to metric events that occurred after exposure, by user and timestamp.
- Aggregates to the user level and applies winsorization (caps extreme metric values to reduce variance).
- Aggregates to the variant level and computes summary statistics, including mean and variance.
Update schedule
Datadog updates experiment results nightly. To refresh results immediately, open the experiment overview page and click Run an update now.
To view a simplified version of the pipeline logic, click Copy SQL on any warehouse metric.
Further reading
Additional helpful documentation, links, and articles: