Attribution Modeling in SQL: First-Touch, Last-Touch & Linear Multi-Touch
Overview & Learning Objectives
A customer discovers your app from an Instagram ad on Monday, reads a tech review on Google Search on Wednesday, clicks an email newsletter on Friday, and finally purchases a $100 subscription on Sunday! Which marketing channel gets credit for the sale: Instagram, Google, or Email? This is Attribution Modeling. In this lesson, you will master the 3 essential attribution models in SQL: First-Touch, Last-Touch, and Linear Multi-Touch.
- Understand the business trade-offs of First-Touch (Top-of-Funnel Brand Discovery) vs Last-Touch (Final Conversion Push).
- Implement Linear Multi-Touch Attribution in SQL where every touchpoint receives equal fractional credit ($1/N$).
- Use SQL Window Functions (`ROW_NUMBER()`, `COUNT() OVER`) to assign conversion revenue across channels.
Real-World Example: Passing the Soccer Ball to Score a Winning Goal
- Scenario: Scoring a winning soccer goal: who intercepted the ball, who crossed it, and who kicked it into the net?
- First-Touch: Credits the initial discovery channel (e.g. Google Search).
- Multi-Touch (MTA): Shares credit proportionally across blog reads, retargeting ads, and email newsletters.
Visual Infographic: Comparing the 3 Core Attribution Models
ATTRIBUTION INFOGRAPHICInstagram Ad gets 100% credit ($100). Best for top-of-funnel brand awareness.
Instagram ($33.33), Google Search ($33.33), Email ($33.33). Fair ecosystem view.
Email Newsletter gets 100% credit ($100). Biased toward bottom-of-funnel retargeting.
Industry Standard & Framework
Standard: IAB Digital Attribution Standards & Multi-Channel Marketing Analytics.
Real-World Business Application: LensKart Eyewear Multi-Touch Marketing Attribution Audit
LensKart analyzes INR 10,00,000 in monthly digital ad spend across Instagram Ads, Google Search, and In-App Push Notifications.
| Marketing Channel | First-Touch Revenue Credit | Last-Touch Revenue Credit | Linear Multi-Touch Credit | Strategic Recommendation |
|---|---|---|---|---|
| Instagram Sponsored Video | INR 5,40,000 (54%) | INR 1,20,000 (12%) | INR 3,40,000 (34%) | Vital top-of-funnel discovery engine; DO NOT CUT BUDGET! |
| Google Brand Search ("Lenskart") | INR 1,80,000 (18%) | INR 6,10,000 (61%) | INR 3,90,000 (39%) | Captures high-intent users; heavily overcredited by Last-Touch |
| Email / SMS Discount Notification | INR 80,000 (8%) | INR 2,10,000 (21%) | INR 1,60,000 (16%) | Great closing mechanism for warm leads |
| Direct / Organic Type-in | INR 2,00,000 (20%) | INR 60,000 (6%) | INR 1,10,000 (11%) | Word-of-mouth baseline |
Step-by-Step UI Tutorial & Visual Workflow Guide
Below is the practical, non-technical walkthrough showing how Product Analysts design, review, and execute this capability inside real-world tools like Mixpanel, Google Analytics 4, BigQuery, and Google Tag Manager.
Step-by-Step Execution Workflow
EXECUTION PHASESPull all session touchpoints with `utm_source` and `timestamp` prior to order.
Set standard 30-day lookback window: Touchpoints older than 30 days get zero credit.
Use `ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY touch_time ASC)` to find touch #1.
Use `ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY touch_time DESC)` to find the final touch.
Use `COUNT(*) OVER (PARTITION BY user_id)` to calculate total touches $N$, then assign weight $1.0 / N$.
Step-by-Step UI Tutorial: Executing Linear Multi-Touch Attribution in SQL
Filter touchpoints where `touch_time <= purchase_time AND touch_time >= purchase_time - INTERVAL 30 DAY`.
Add column: `COUNT(*) OVER (PARTITION BY order_id) AS total_touches`.
Add column: `order_revenue * (1.0 / total_touches) AS attributed_revenue`.
`SELECT utm_source, SUM(attributed_revenue) FROM touchpoints GROUP BY 1 ORDER BY 2 DESC`.
Attribution Model Trade-Off Matrix
MODEL COMPARISON| model | bias | best Use |
|---|---|---|
| First-Touch | Favors Top-of-Funnel discovery | Allocating brand awareness and influencer marketing budgets |
| Last-Touch (Default) | Favors Bottom-of-Funnel converters | Evaluating closing mechanisms (branded search, discount emails) |
| Linear Multi-Touch | Balanced equal weighting | Holistic multi-channel marketing budget allocation |
Implementation Guidelines for Product Analysts
- Always set an explicit Lookback Window (typically 30 days) to prevent ad clicks from 6 months ago from stealing credit.
- Exclude self-referrals (like payment gateway redirect URLs `paypal.com` or `paytm.com`) from your attribution touchpoints.
- Present both First-Touch and Last-Touch side-by-side to marketing leadership to avoid underfunding discovery channels.
Practical Hands-On Exercises
- A user clicks a Facebook ad, then an Email link, then a Google Search ad, and buys a $90 product. Under Linear Multi-Touch, how much revenue is credited to Facebook?
- Explain why Google Search often claims 70% of revenue under Last-Touch attribution even when social media drove the initial awareness.