Last-Click Attribution of Checkouts to Promoted Pins Within Seven Days
Last updated: November 29, 2026
Quick Overview
Given clicks(user_id, pin_id, advertiser_id, click_ts) on promoted Pins and checkouts(order_id, user_id, advertiser_id, checkout_ts, amount) that can contain duplicate events per order, attribute each unique order to the user's most recent click on the same advertiser's Pins in the 7 days before checkout, leaving unattributed orders null.
0
0
0 solved
Given clicks(user_id, pin_id, advertiser_id, click_ts) on promoted Pins and checkouts(order_id, user_id, advertiser_id, checkout_ts, amount) that can contain duplicate events per order, attribute each unique order to the user's most recent click on the same advertiser's Pins in the 7 days before checkout, leaving unattributed orders null.
Advertisers judge Pinterest ads by conversions, so attribution logic directly drives reported ROAS and billing trust. The interviewer checks deduplication of conversion events, a correct lookback window, last-touch selection, and that unattributed orders remain in the denominator.
What the Interviewer Expects
- Deduplicates checkout events by order_id before joining
- Restricts clicks to the same user and advertiser and to the window before checkout
- Selects the last click with ROW_NUMBER and a deterministic tie-break
- Keeps unattributed orders with a LEFT JOIN
- Discusses view-through versus click-through and multi-touch alternatives
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you report attributed revenue per Pin and per campaign?
- How would you change this to a 1-day view, 30-day click window?
- How would you handle cross-device users where the click and checkout have different user ids?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
- Checkout events can fire twice from the advertiser's pixel and API (same order_id), so dedupe on order_id.
- Window: click_ts in (checkout_ts - 7 days, checkout_ts]. Clicks after the checkout never ...
Approach
First keep one row per order (earliest event). Then range-join clicks on user, advertiser and the lookback window, and rank candidate clicks per order by recency. Finally left join the top candidate b...