Mastering Product Analytics with Mixpanel & GA4Lesson 28 of 32
Lesson 28 of 32

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.
Example

Real-World Example: Passing the Soccer Ball to Score a Winning Goal

PRACTICAL CONTEXT
  • 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.
Corporate / Tech Term Everyday / Practical Metaphor Operational Meaning
First-Touch Attribution Giving 100% credit to the Goalie who kicked the ball first Credits the channel that first introduced the customer to the brand.
Last-Touch Attribution Giving 100% credit to the Striker who kicked it into the net Credits the final link clicked immediately before purchasing.
Linear Multi-Touch Dividing the trophy equally among all 3 teammates Splits conversion value equally across all touchpoints ($1/N$).
U-Shaped (Position-Based) 40% to Goalie, 40% to Striker, 20% to Midfielder Emphasizes the first discovery and final closing touches.
Core Principle: Never rely solely on Last-Touch Attribution! If you do, you will shut off your top-of-funnel social media ads and your entire sales pipeline will starve 3 months later.

Visual Infographic: Comparing the 3 Core Attribution Models

ATTRIBUTION INFOGRAPHIC
Stage 1
1. First-Touch (100% Start)

Instagram Ad gets 100% credit ($100). Best for top-of-funnel brand awareness.

Stage 2
2. Linear Multi-Touch (Equal)

Instagram ($33.33), Google Search ($33.33), Email ($33.33). Fair ecosystem view.

Stage 3
3. Last-Touch (100% End)

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 ChannelFirst-Touch Revenue CreditLast-Touch Revenue CreditLinear Multi-Touch CreditStrategic Recommendation
Instagram Sponsored VideoINR 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 NotificationINR 80,000 (8%)INR 2,10,000 (21%)INR 1,60,000 (16%)Great closing mechanism for warm leads
Direct / Organic Type-inINR 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 PHASES
1 Product Analyst
Collect All Marketing Touchpoints

Pull all session touchpoints with `utm_source` and `timestamp` prior to order.

2 Product Analyst
Establish Attribution Window

Set standard 30-day lookback window: Touchpoints older than 30 days get zero credit.

3 Product Analyst
Assign First-Touch via Window Function

Use `ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY touch_time ASC)` to find touch #1.

4 Product Analyst
Assign Last-Touch via Window Function

Use `ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY touch_time DESC)` to find the final touch.

5 Product Analyst
Compute Linear Multi-Touch Weight

Use `COUNT(*) OVER (PARTITION BY user_id)` to calculate total touches $N$, then assign weight $1.0 / N$.

BigQuery / Snowflake SQL Console

Step-by-Step UI Tutorial: Executing Linear Multi-Touch Attribution in SQL

Step 1
Step 1: Build Touchpoint CTE

Filter touchpoints where `touch_time <= purchase_time AND touch_time >= purchase_time - INTERVAL 30 DAY`.

Step 2
Step 2: Calculate Total Touches per User

Add column: `COUNT(*) OVER (PARTITION BY order_id) AS total_touches`.

Step 3
Step 3: Assign Fractional Credit

Add column: `order_revenue * (1.0 / total_touches) AS attributed_revenue`.

Step 4
Step 4: Group by Channel

`SELECT utm_source, SUM(attributed_revenue) FROM touchpoints GROUP BY 1 ORDER BY 2 DESC`.

Attribution Model Trade-Off Matrix

MODEL COMPARISON
modelbiasbest Use
First-TouchFavors Top-of-Funnel discoveryAllocating brand awareness and influencer marketing budgets
Last-Touch (Default)Favors Bottom-of-Funnel convertersEvaluating closing mechanisms (branded search, discount emails)
Linear Multi-TouchBalanced equal weightingHolistic 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

  1. 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?
  2. Explain why Google Search often claims 70% of revenue under Last-Touch attribution even when social media drove the initial awareness.