Demand-to-Revenue Attribution Sanity Check with Lift Tests
As Sherlock, I've deduced this request calls for a rigorous, data-driven framework to validate your demand generation (demand gen) attribution model—ensuring marketing/sales efforts are correctly linked to revenue—while incorporating lift tests for empirical proof of incrementality. This prevents "garbage in, garbage out" pitfalls like over-attribution or illusory causality.
This framework is plug-and-play:
- Assumptions: You have data in a warehouse (e.g., Snowflake/BigQuery) with tables for
leads (MQLs), opportunities, deals (closed-won), campaigns, and spend. Key fields: lead_created_date, opp_created_date, close_date, revenue, campaign_id, geo (e.g., DMA/zip), user_id (for audience matching).
- Tools: SQL for queries + Python (Pandas/Statsmodels) for analysis/lift calcs.
- Success Criteria: Attribution model predicts experimental lift within ±10-20% (tune per your tolerance).
1. Pre-Lift Baseline Sanity Checks
Run these weekly/monthly on historical data to flag issues before experiments.
SQL Queries (Generic; adapt to your schema)
-- 1. Attribution Coverage & Leakage
WITH attributed_revenue AS (
SELECT
SUM(CASE WHEN attribution_source = 'demand_gen' THEN revenue ELSE 0 END) as attributed_rev,
SUM(revenue) as total_rev
FROM deals d
LEFT JOIN attribution_model a ON d.opp_id = a.opp_id
WHERE close_date >= '2024-01-01'
)
SELECT
attributed_rev / total_rev as coverage_pct,
(1 - attributed_rev / total_rev) as leakage_pct
FROM attributed_revenue;
-- 2. No Negative/Impossible Attribution (Sanity Flag)
SELECT
COUNT(*) as bad_attributions,
attribution_source
FROM attribution_model
WHERE attribution_weight < 0 OR attribution_weight > 1
GROUP BY attribution_source
HAVING COUNT(*) > 0;
-- 3. Time Decay Check (Revenue shouldn't precede demand >90 days)
SELECT
AVG(DATEDIFF(close_date, lead_created_date)) as avg_lag_days,
PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY DATEDIFF(close_date, lead_created_date)) as p95_lag_days
FROM leads l JOIN opportunities o ON l.lead_id = o.lead_id JOIN deals d ON o.opp_id = d.opp_id;
-- 4. Spend-to-Attributed Revenue Ratio (Should be stable, e.g., 1:3-5 ROAS)
SELECT
DATE_TRUNC('month', spend_date) as month,
SUM(spend) as tot_spend,
SUM(attributed_revenue) as att_rev,
SUM(attributed_revenue) / NULLIF(SUM(spend), 0) as roas
FROM campaigns c JOIN attribution_model a ON c.campaign_id = a.campaign_id
GROUP BY 1 ORDER BY 1;
Pass Criteria:
| Metric | Green (Pass) | Yellow (Watch) | Red (Fail) |
|---|
| Coverage % | >90% | 70-90% | <70% |
| Leakage % | <10% | 10-30% | >30% |
| Avg Lag Days | 30-180 | 0-30 or >180 | Negative |
| ROAS Stability | CV <20% MoM | CV 20-50% | CV >50% or declining |
2. Lift Test Design: Geo-Holdout (Recommended for B2B Scale)
Why Geo? Controls for seasonality/competition; easy to run parallel campaigns.
Step-by-Step Setup (2-4 Week Test)
-
Select Markets (N=20-50 DMAs/Zips):
- Target: High-potential, similar baseline demand/revenue (match on hist. MQLs/opps/rev).
- Holdout: Matched non-target (use propensity score matching).
# Python: Match markets (install: pip install scikit-learn)
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
# Load hist data: df with ['dma', 'hist_mqls', 'hist_opps', 'hist_rev', 'pop_size']
scaler = StandardScaler()
X = scaler.fit_transform(df[['hist_mqls', 'hist_opps', 'hist_rev', 'pop_size']])
model = LogisticRegression().fit(X, df['treatment_eligible']) # 1=target candidates
df['match_score'] = model.predict_proba(X)[:,1]
targets = df.nlargest(25, 'match_score')['dma'].tolist() # Top 25 targets
holdouts = df.nsmallest(25, 'match_score')['dma'].tolist()
-
Run Experiment:
| Group | Campaigns | Budget | Duration |
|---|
| Target | Full demand gen (ads/email) | $X | 2-4wks |
| Holdout | None (business-as-usual organic) | $0 | Same |
-
Measure Outcomes (SQL + Python):
-- Incremental Metrics by Group (post-test)
WITH metrics AS (
SELECT
CASE WHEN dma IN ('target1','target2',...) THEN 'target' ELSE 'holdout' END as group,
COUNT(DISTINCT lead_id) as mqls,
COUNT(DISTINCT opp_id) as opps,
SUM(CASE WHEN is_won THEN revenue ELSE 0 END) as rev
FROM leads l
LEFT JOIN opps o ON l.lead_id = o.lead_id
LEFT JOIN deals d ON o.opp_id = d.opp_id
WHERE activity_date BETWEEN '2024-10-01' AND '2024-10-31' -- Test window
AND dma IN (targets + holdouts)
GROUP BY 1
)
SELECT * FROM metrics;
# Lift Calc (Statistical Significance)
import statsmodels.stats.api as sms
from scipy import stats
test_data = pd.read_sql(query, con=engine) # From above SQL
lift_mql = (test_data.loc[test_data.group=='target', 'mqls'].iloc[0] / len(targets) -
test_data.loc[test_data.group=='holdout', 'mqls'].iloc[0] / len(holdouts)) / baseline_mql_per_market
lift_rev = (test_data.loc[test_data.group=='target', 'rev'].iloc[0] / len(targets) -
test_data.loc[test_data.group=='holdout', 'rev'].iloc[0] / len(holdouts)) / baseline_rev_per_market
# t-test p-value
t_stat, p_val_mql = stats.ttest_ind(target_mqls_per_market, holdout_mqls_per_market)
print(f"MQL Lift: {lift_mql:.1%} (p={p_val_mql:.3f}) | Rev Lift: {lift_rev:.1%} (p={p_val_rev:.3f})")
Expected Lifts (Benchmarks):
| Funnel Stage | Typical Lift | Stat Sig (p<0.05) |
|---|
| MQLs | 20-100% | Required |
| Opportunities | 10-50% | Required |
| Revenue | 5-30% | Required (lag 30-90d) |
3. Attribution Model Validation (The Ultimate Sanity Check)
Run your attribution model (e.g., Markov, data-driven) on test data only.
# Pseudo-code: Compare Model vs Experiment
modeled_lift_mql = model.predict(test_spend)['attributed_mqls'] / baseline_mql
modeled_lift_rev = model.predict(test_spend)['attributed_rev'] / baseline_rev
error_mql = abs(modeled_lift_mql - experimental_lift_mql) / experimental_lift_mql
error_rev = abs(modeled_lift_rev - experimental_lift_rev) / experimental_lift_rev
print(f"Model Error: MQL {error_mql:.1%} | Rev {error_rev:.1%}")
Final Pass Criteria:
| Validation | Green | Yellow | Red |
|---|
| Model vs. Exp Lift Error | <10% | 10-20% | >20% |
| Overall Sanity Score (Weighted Avg) | >90% | 70-90% | <70% |
4. Automation & Dashboard
- dbt/Sigma: Schedule SQL tests as alerts.
- Looker/G Sheets: Viz lifts + errors (e.g., waterfall chart: Modeled vs. Actual).
- Edge Cases: Run quarterly; scale to audience-holdout for digital channels.
Elementary, my dear analyst: If your model passes, trust it for optimization. If not, retrain (e.g., add lag features). Share your schema/data sample for a custom Sherlock tweak. 🔍