Attribute Conversions to the Last Ad Click Within Seven Days

Last updated: November 29, 2026

Quick Overview

Given ad click and conversion tables, assign each conversion to the user's most recent ad click in the 7 days before it, then report attributed conversions and value per campaign.

Google
Data Manipulation (SQL/Python)
Data Scientist
Google
November 29, 2026
Data Scientist
Onsite
Data Manipulation (SQL/Python)
Hard

0

0

0 solved


Given ad click and conversion tables, assign each conversion to the user's most recent ad click in the 7 days before it, then report attributed conversions and value per campaign.

Attribution is central to Google Ads reporting, and last-click within a lookback window is the baseline model every analyst should be able to write. Interviewers check the range join, picking the latest click, tie-breaking, and what happens to unattributed conversions.

What the Interviewer Expects
  • Join conversions to clicks by user with a time-bounded range condition
  • Pick the latest qualifying click per conversion with ROW_NUMBER
  • Break ties deterministically
  • Aggregate count and value per campaign
  • Account for unattributed conversions
Key Topics to Cover
Attribution
Range joins
ROW_NUMBER
Lookback window
Ads reporting
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you implement a position-based (40/20/40) model instead?
  • How would you make this efficient when the clicks table is billions of rows?
  • What changes if conversions can be reported before the click due to clock skew?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

ad_clicks(click_id, user_id, campaign_id, click_ts) and conversions(conversion_id, user_id, conv_ts, value_usd). A click qualifies if it is at or before the conversion and no more than 7 days earl...

Approach

Range-join each conversion to that user's clicks in the window, rank candidate clicks per conversion by recency, keep rank 1, then aggregate. Use a LEFT JOIN so unattributed conversions survive....


Submit Your Answer
Markdown supported