Telemetry
Product analytics SQL recipe

Compare Experiment Conversion and Revenue Lift

Measure conversion, revenue per participant, and relative lift by experiment variant without double-counting repeated events.

Advancedexperiment_eventsReviewed 2026-07-28Tested with Apache DataFusion 45.2.0

Question answered

Did the experiment improve conversion and revenue per assigned participant?

An experiment result needs one assignment per participant, a fixed outcome window, and both conversion and value. This pattern collapses repeated events to a participant-level record before comparing each variant with control.

Event contract

Fields the query expects

FieldTypeWhy it exists
timestamp_utcTimestampAssignment or outcome event time in UTC.
experiment_nameUtf8Stable experiment identifier.
variantUtf8control or a named treatment.
user_idUtf8Stable participant identifier.
event_nameUtf8experiment_assigned or purchase_completed.
revenue_usdFloat64Normalized revenue on a completed purchase.
DataFusion SQL

Copy the query

sql
WITH participant_outcomes AS (
  SELECT
    experiment_name,
    variant,
    user_id,
    MAX(CASE WHEN event_name = 'experiment_assigned' THEN 1 ELSE 0 END)
      AS was_assigned,
    MAX(CASE WHEN event_name = 'purchase_completed' THEN 1 ELSE 0 END)
      AS converted,
    SUM(CASE
      WHEN event_name = 'purchase_completed' THEN revenue_usd
      ELSE 0.0
    END) AS revenue_usd
  FROM experiment_events
  WHERE timestamp_utc >= now() - INTERVAL '60 days'
  GROUP BY experiment_name, variant, user_id
),
variant_summary AS (
  SELECT
    experiment_name,
    variant,
    COUNT(*) AS participants,
    SUM(converted) AS converted_participants,
    100.0 * SUM(converted) / NULLIF(COUNT(*), 0) AS conversion_rate_pct,
    SUM(revenue_usd) / NULLIF(COUNT(*), 0) AS revenue_per_participant_usd
  FROM participant_outcomes
  WHERE was_assigned = 1
  GROUP BY experiment_name, variant
),
control AS (
  SELECT
    experiment_name,
    conversion_rate_pct AS control_conversion_rate_pct
  FROM variant_summary
  WHERE variant = 'control'
)
SELECT
  summary.experiment_name,
  summary.variant,
  summary.participants,
  summary.converted_participants,
  summary.conversion_rate_pct,
  summary.revenue_per_participant_usd,
  100.0 * (
    summary.conversion_rate_pct - control.control_conversion_rate_pct
  ) / NULLIF(control.control_conversion_rate_pct, 0) AS relative_lift_pct
FROM variant_summary AS summary
JOIN control
  ON control.experiment_name = summary.experiment_name
ORDER BY summary.experiment_name, summary.variant;

This read-only query is planned and executed against an empty typed table with Apache DataFusion 45.2.0. The deterministic sample output is synthetic and reviewed separately; validate field types, thresholds, and business definitions against your own data. Read the testing methodology.

Query result

Conversion lift by experiment variant

The treatment has higher observed conversion and revenue per participant; statistical uncertainty still needs review before rollout.

experiment_namevariantparticipantsconverted_participantsconversion_rate_pctrevenue_per_participant_usdrelative_lift_pct
annual_plan_checkoutcontrol2,14027812.9918.420
annual_plan_checkoutproof_near_cta2,18732614.9121.7614.78

Synthetic example output. Run the query against your own event schema and thresholds before using it for operational decisions.

How the SQL works

  1. 1The first CTE creates one outcome record per assigned participant, preventing repeated purchase or tracking events from inflating the denominator.
  2. 2Variant summaries preserve participant volume, conversion, and revenue so a higher conversion rate is not evaluated without commercial value.
  3. 3The final join compares every variant with the control rate and reports relative rather than percentage-point lift.

Edge cases to decide

  • Exclude participants exposed to multiple variants or assign them according to a documented intent-to-treat rule.
  • Apply a mature outcome window so recently assigned participants are not treated as non-converters.
  • Calculate confidence intervals or a pre-agreed statistical test before declaring a winner.

Recommended dashboard

  • Bars: conversion_rate_pct by variant
  • Table: participants, revenue per participant, and relative lift
  • Trend: mature cohort conversion by assignment week

Alert guidance

Do not page on normal experiment variation; alert only when assignment balance, event delivery, or a guardrail metric breaks.

Read alert setup

Put the recipe to work

Related instrumentation and guides

Continue the analysis

Run it on real events

Create a table, adapt the fields, and save the result

Start free, send structured events, and use the query result as a chart, shared dashboard widget, or alert input.

Get an API key