Last-Touch Attribution of TikTok Shop Orders to Product Clicks

Last updated: November 29, 2026

Quick Overview

Given a clicks DataFrame (click_id, user_id, product_id, click_ts, source) and an orders DataFrame (order_id, user_id, product_id, order_ts, amount), attribute each order to the most recent click on the same product by the same user within the prior 24 hours, then summarize orders and GMV by click source.

TikTok
Data Manipulation (SQL/Python)
Data Scientist
TikTok
November 29, 2026
Data Scientist
Take-home Project
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given a clicks DataFrame (click_id, user_id, product_id, click_ts, source) and an orders DataFrame (order_id, user_id, product_id, order_ts, amount), attribute each order to the most recent click on the same product by the same user within the prior 24 hours, then summarize orders and GMV by click source.

TikTok Shop sells through short videos, LIVE streams, search and the Shop tab, and the commerce team needs to know which surface drives GMV. This pandas exercise checks whether you can do a time-bounded as-of join correctly and keep unattributed orders in the total.

What the Interviewer Expects
  • Use merge_asof with by keys, backward direction and a tolerance
  • Sort both frames by their time keys before the as-of merge
  • Keep unattributed orders as their own row in the summary
  • Avoid double counting when a user clicks many times
  • Discuss last-touch bias against upper-funnel surfaces
Key Topics to Cover
merge_asof
attribution window
joins
pandas groupby
e-commerce GMV
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 switch to a linear multi-touch model across all clicks in the window?
  • An order contains several products. How does the join key change?
  • How would you validate the 24-hour window choice?
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
  • One row per click and one row per order (single-product orders for now).
  • Attribution key is (user_id, product_id): a click on product A should not get credit for buying product B.
  • Window: clic...
Approach

A plain merge on user and product followed by filtering would explode rows for heavy clickers and then need a groupby to pick the latest. pd.merge_asof does exactly "latest click at or before the or...


Submit Your Answer
Markdown supported