First-Touch Attribution with a 14-Day Lookback

Credit each conversion to the campaign of the user's earliest ad click within the 14 days before the conversion. Ignore conversions with no click in that window. Report attributed conversions and revenue per campaign.

Expected output

name, conversions, revenue (rounded to 2 decimals). Sorted by revenue descending, then name.

Row order is checked. Column names are not checked; numbers are compared to 2 decimals.

Dataset: Digital ads performance

A retailer's paid campaigns across search, social, display and video in February 2026: daily delivery, individual ad clicks and purchases.

campaigns

One row per campaign.

campaign_idINTEGERprimary key
nameTEXT
channelTEXTsearch, social, display or video
start_dateTEXTYYYY-MM-DD
end_dateTEXTYYYY-MM-DD inclusive, NULL if still running
daily_budgetREALUSD
ad_daily

Delivery per campaign per day it ran, as reported by the ad platform. clicks is the platform's count, which may differ from our own click log.

campaign_idINTEGER
dayTEXTYYYY-MM-DD
impressionsINTEGER
clicksINTEGER
spendREALUSD
ad_clicks

Our own click log: one row per ad click that reached the site and was tracked.

click_idINTEGERprimary key, increases with clicked_at
campaign_idINTEGER
user_idINTEGER
clicked_atTEXTYYYY-MM-DD HH:MM:SS (UTC)
conversions

One row per purchase. Some purchases come from users who never clicked an ad.

conversion_idINTEGERprimary key
user_idINTEGER
converted_atTEXTYYYY-MM-DD HH:MM:SS (UTC)
revenueREALUSD

Engine: SQLite. Dates are text (YYYY-MM-DD); use strftime(), date() and julianday() for date math.

Related problems

SQLite · runs in your browser
Ctrl/⌘ + Enter to run
Expected output preview (12 rows, order matters)
nameconversionsrevenue
Brand Search192559.88
Social Retargeting162220.12
Display Remarketing121741.99

Showing 3 of 12 rows.

Hints

Worked solution

Run at least one query to unlock it.