{
  "license": "CC BY 4.0",
  "licenseUrl": "https://creativecommons.org/licenses/by/4.0/",
  "recipe": {
    "slug": "experiment-revenue-lift",
    "title": "Compare Experiment Conversion and Revenue Lift",
    "testedWith": "Apache DataFusion 45.2.0",
    "lastReviewed": "2026-07-28"
  },
  "contract": {
    "tableName": "experiment_events",
    "schema": [
      {
        "name": "timestamp_utc",
        "type": "Timestamp",
        "description": "Assignment or outcome event time in UTC."
      },
      {
        "name": "experiment_name",
        "type": "Utf8",
        "description": "Stable experiment identifier."
      },
      {
        "name": "variant",
        "type": "Utf8",
        "description": "control or a named treatment."
      },
      {
        "name": "user_id",
        "type": "Utf8",
        "description": "Stable participant identifier."
      },
      {
        "name": "event_name",
        "type": "Utf8",
        "description": "experiment_assigned or purchase_completed."
      },
      {
        "name": "revenue_usd",
        "type": "Float64",
        "description": "Normalized revenue on a completed purchase."
      }
    ]
  },
  "query": "WITH participant_outcomes AS (\n  SELECT\n    experiment_name,\n    variant,\n    user_id,\n    MAX(CASE WHEN event_name = 'experiment_assigned' THEN 1 ELSE 0 END)\n      AS was_assigned,\n    MAX(CASE WHEN event_name = 'purchase_completed' THEN 1 ELSE 0 END)\n      AS converted,\n    SUM(CASE\n      WHEN event_name = 'purchase_completed' THEN revenue_usd\n      ELSE 0.0\n    END) AS revenue_usd\n  FROM experiment_events\n  WHERE timestamp_utc >= now() - INTERVAL '60 days'\n  GROUP BY experiment_name, variant, user_id\n),\nvariant_summary AS (\n  SELECT\n    experiment_name,\n    variant,\n    COUNT(*) AS participants,\n    SUM(converted) AS converted_participants,\n    100.0 * SUM(converted) / NULLIF(COUNT(*), 0) AS conversion_rate_pct,\n    SUM(revenue_usd) / NULLIF(COUNT(*), 0) AS revenue_per_participant_usd\n  FROM participant_outcomes\n  WHERE was_assigned = 1\n  GROUP BY experiment_name, variant\n),\ncontrol AS (\n  SELECT\n    experiment_name,\n    conversion_rate_pct AS control_conversion_rate_pct\n  FROM variant_summary\n  WHERE variant = 'control'\n)\nSELECT\n  summary.experiment_name,\n  summary.variant,\n  summary.participants,\n  summary.converted_participants,\n  summary.conversion_rate_pct,\n  summary.revenue_per_participant_usd,\n  100.0 * (\n    summary.conversion_rate_pct - control.control_conversion_rate_pct\n  ) / NULLIF(control.control_conversion_rate_pct, 0) AS relative_lift_pct\nFROM variant_summary AS summary\nJOIN control\n  ON control.experiment_name = summary.experiment_name\nORDER BY summary.experiment_name, summary.variant;",
  "fixtureKind": "schema-example",
  "inputRows": [
    {
      "timestamp_utc": "2026-07-28T10:00:00Z",
      "experiment_name": "experiment_name_example_1",
      "variant": "variant_example_1",
      "user_id": "user_1",
      "event_name": "workflow_completed",
      "revenue_usd": 12
    },
    {
      "timestamp_utc": "2026-07-28T11:00:00Z",
      "experiment_name": "experiment_name_example_2",
      "variant": "variant_example_2",
      "user_id": "user_2",
      "event_name": "workflow_completed",
      "revenue_usd": 37
    },
    {
      "timestamp_utc": "2026-07-28T12:00:00Z",
      "experiment_name": "experiment_name_example_3",
      "variant": "variant_example_3",
      "user_id": "user_3",
      "event_name": "workflow_completed",
      "revenue_usd": 24
    }
  ],
  "illustrativeInputRows": [
    {
      "timestamp_utc": "2026-07-28T10:00:00Z",
      "experiment_name": "experiment_name_example_1",
      "variant": "variant_example_1",
      "user_id": "user_1",
      "event_name": "workflow_completed",
      "revenue_usd": 12
    },
    {
      "timestamp_utc": "2026-07-28T11:00:00Z",
      "experiment_name": "experiment_name_example_2",
      "variant": "variant_example_2",
      "user_id": "user_2",
      "event_name": "workflow_completed",
      "revenue_usd": 37
    },
    {
      "timestamp_utc": "2026-07-28T12:00:00Z",
      "experiment_name": "experiment_name_example_3",
      "variant": "variant_example_3",
      "user_id": "user_3",
      "event_name": "workflow_completed",
      "revenue_usd": 24
    }
  ],
  "expectedOutput": {
    "columns": [
      "experiment_name",
      "variant",
      "participants",
      "converted_participants",
      "conversion_rate_pct",
      "revenue_per_participant_usd",
      "relative_lift_pct"
    ],
    "rows": [
      {
        "experiment_name": "annual_plan_checkout",
        "variant": "control",
        "participants": 2140,
        "converted_participants": 278,
        "conversion_rate_pct": 12.99,
        "revenue_per_participant_usd": 18.42,
        "relative_lift_pct": 0
      },
      {
        "experiment_name": "annual_plan_checkout",
        "variant": "proof_near_cta",
        "participants": 2187,
        "converted_participants": 326,
        "conversion_rate_pct": 14.91,
        "revenue_per_participant_usd": 21.76,
        "relative_lift_pct": 14.78
      }
    ]
  },
  "notes": [
    "The compact input rows demonstrate field names and JSON types; they are not claimed to generate the displayed aggregate by themselves.",
    "The expected output is deterministic synthetic review data for the documented output shape.",
    "Adapt time windows, thresholds, identities, and business definitions before operational use."
  ]
}