How Ad Conversion Rate Changes with the Attribution Window

Last updated: November 29, 2026

Quick Overview

Given ad click and purchase events, compute the click-to-purchase conversion rate under several attribution windows (1 hour, 1 day, 7 days) in one pass, counting a purchase only if it follows the user's first click.

Meta
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given ad click and purchase events, compute the click-to-purchase conversion rate under several attribution windows (1 hour, 1 day, 7 days) in one pass, counting a purchase only if it follows the user's first click.

A Python data manipulation question in the style of Meta's ads measurement screens, where attribution windows are a standing product decision. The interviewer checks that you compute lag once and reuse it for every window, and that you can explain why longer windows raise the number.

What the Interviewer Expects
  • Anchors on each user's first click
  • Takes the first purchase at or after that click
  • Computes the lag once and evaluates every window from it
  • Uses clickers as the denominator
  • Explains the trade-off between short and long windows
Key Topics to Cover
attribution window
conversion lag
cumulative distribution
dictionaries
ads measurement
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 plot the full cumulative conversion curve by lag?
  • How does view-through attribution change this analysis?
  • Why might a 7-day window overstate the ad's causal effect?
  • How would you do this in SQL with a single query?
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

Input is (user_id, event_name, ts) with ad_click and purchase, unsorted. The denominator is users with at least one click. A user converts within window w if their first purchase at or after the...

Approach

One pass finds each user's first click; a second pass finds the first qualifying purchase per user. The lag list is computed once. For each window, the converted count is the number of lags at most w....


Submit Your Answer
Markdown supported