Sessionize Checkout Events Into an Ordered Payment Funnel in Pandas
Last updated: November 29, 2026
Quick Overview
Given raw browser events from a hosted checkout page, split each browser's events into sessions using a 30 minute inactivity gap, then compute how many sessions reach each funnel step in order (loaded, details entered, submitted, payment succeeded) and the step-to-step conversion.
Stripe
November 29, 20260
0
0 solved
Given raw browser events from a hosted checkout page, split each browser's events into sessions using a 30 minute inactivity gap, then compute how many sessions reach each funnel step in order (loaded, details entered, submitted, payment succeeded) and the step-to-step conversion.
Stripe Checkout and Payment Links teams live on funnel analysis, and Python data rounds or take-homes often hand you raw clickstream to turn into a funnel. Interviewers check vectorized sessionization with groupby and cumsum, a strict definition of in-order step completion, and sensible handling of noise events and out-of-order logs.
What the Interviewer Expects
- Sorts by browser and timestamp before computing gaps
- Builds session ids with groupby diff plus cumsum rather than Python loops over rows
- Counts a step only when all earlier steps happened earlier in the same session
- Filters irrelevant events without breaking session boundaries unintentionally
- Reports conversion both from the previous step and from the top of the funnel
- Explains choices like gap length and how they change the numbers
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
- Should irrelevant events such as page_scrolled extend a session? How does your code treat them?
- How would you attribute a session to the merchant and the payment method shown?
- How would you make this run on a billion events per day?
- What changes if a buyer refreshes and gets a new checkout session id mid-flow?
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
events(browser_id, ts, event). Funnel events are checkout_loaded, payment_details_entered, submit_clicked, payment_succeeded; others are noise. A session ends after 30 minutes without a funn...
Approach
- Filter to funnel events and sort by browser and time.
diff()within browser; a new session starts on the first event or a gap above 30 minutes;cumsum()of that boolean per browser is the se...