Exposures and Rewards
How Levered reads exposures and rewards from the data warehouse and joins them into the observations that the model trains on.
Levered learns from two types of events. An exposure is recorded when a user sees a variant. A reward is recorded when a user does something of value, for example signs up. Both types of events are stored in the data warehouse. Levered reads them, joins them and trains the model on the result.
Exposures
An exposure records that a variant was shown to a user. It contains the variant and the attributes of the user.
The app passes an onExposure callback to the Levered SDK. The SDK calls it each time a variant is served to a user. In the callback, log the exposure to the warehouse (BigQuery or Snowflake).
A typical exposure record has the following fields:
| Field | Description |
|---|---|
anonymous_id | A unique identifier of the user or session |
optimization_id | The optimization that the exposure belongs to |
variant | The combination of design factor levels that was served, as JSON with design factor values, for example {"headline":"Ship faster","layout":"grid"} |
timestamp | The time of the exposure |
| Context values | The context factor values, for example country and device type |
The tables can have any schema. The metric query and the assignment source tell Levered which columns to read.
Rewards
A reward is the success event that the optimization maximizes. A reward has one of the following types:
- Boolean. Success or failure. Examples: signed up, completed checkout, clicked a CTA.
- Discrete. One of several degrees of success or failure, each with its own reward value. Example: chose one of multiple plans.
- Numeric. A continuous value. Examples: revenue amount, time on page, number of items purchased.
The existing analytics pipeline of the app logs reward events to the warehouse. Rewards need no SDK call. Levered reads them with the SQL query that is defined as the metric.
A typical reward record has the following fields:
| Field | Description |
|---|---|
anonymous_id | The same user identifier used in exposures |
value | The reward value (1/0 for boolean, or a numeric amount) |
timestamp | The time of the reward event |
Attribution
Attribution connects a reward to the variant that the user saw. Levered credits a reward to the first exposure of the user, within a configurable conversion window. The default conversion window is 24 hours.
- Levered takes the first exposure of each user to the optimization.
- Levered credits the first reward of the user at or after that exposure, and within the conversion window measured from it, to the variant of that exposure.
- If no reward falls within the window, the user counts as not converted.
- Levered leaves users whose window has not closed yet out of training until it closes. With no conversion window, any later reward counts.
Example: a user first sees variant A at 10:00 AM and converts at 2:00 PM the same day. Levered credits the conversion to variant A. If the user converts 3 days later, which is outside the default 24-hour window, the user counts as not converted. This also applies if the user saw the optimization again in between.
Set the conversion window to the typical time between exposure and conversion in the product. For example, a checkout optimization can use a 1-hour window and a subscription decision can use a 7-day window.
Observations
Observations are the joined dataset of exposures and rewards. The model trains on the observations.
For each user, Levered takes the first exposure and determines whether a reward occurred within the conversion window. The result is a table in which each row contains the first exposure of one user and its outcome:
| anonymous_id | variant | reward | context |
|---|---|---|---|
| user_abc | {"headline": "Start free", "cta": "Sign up"} | 1 | {"country": "US"} |
| user_def | {"headline": "Boost revenue", "cta": "Get started"} | 0 | {"country": "DE"} |
| user_ghi | {"headline": "Start free", "cta": "Get started"} | 1 | {"country": "US"} |
The model learns from this table which variants produce rewards. If the optimization has context factors, the model also learns which variants perform best for which context values.
The data flow
The following steps lead from a user visit to model training:
1. User visits your site
|
2. SDK requests a variant from Levered API
|
3. Levered returns the optimal variant
|
4. Your app renders the variant
|
5. onExposure callback fires -> you log to your warehouse
|
6. User converts (or doesn't)
|
7. Your analytics pipeline logs the reward to your warehouse
|
8. Levered queries your warehouse, joins exposures + rewards
|
9. Model trains on the joined observations
|
10. Next user gets a better variant selectionWith data warehouse native, Levered reads from the customer's warehouse, and the customer operates the data pipeline. Levered does not store the raw event data. It queries the warehouse with the metric SQL, builds the observations and trains the model. On the Managed Warehouse, steps 5 and 7 send the events to Levered's ingestion API instead, and Levered stores them in a warehouse it hosts. See Choose a warehouse.
Defining metrics
A metric is a SQL query that returns the rewards from the warehouse. Write standard SQL that returns rows with at least an anonymous_id, a reward value and a timestamp.
Example of a sign-up conversion metric:
SELECT
anonymous_id,
1 AS value,
created_at AS timestamp
FROM your_schema.sign_ups
WHERE created_at >= CURRENT_DATE - INTERVAL '30 days'Include a time filter so that a training run does not scan the full history. Levered runs the query against the warehouse, joins the results with the exposure data and produces the observations table that the model trains on.