task Funnels & conversion · hard
Attribute session conversion to first touch
For each first-touch channel, count sessions and converted_sessions, then return conversion_pct rounded to two decimals. A converted session contains an ordered view → checkout → purchase of the same cart within that session.
what to return
- Columns
channelsessionsconverted_sessionsconversion_pctin this order- Rows
- 4 rows · in the order asked
- Watch for
- Deduplicate globally by event_key, keeping the smallest id; a retry may have a conflicting payload.
- Use (occurred_at, id) as the total event order; equal timestamps follow id order. All times are UTC.
- A shopper starts a session at the first canonical event or after a gap strictly greater than 30 minutes from their previous canonical event. Exactly 30 minutes stays in the same session; midnight alone does not split it.
- Session numbers start at 1 per shopper and include every event type, including heartbeat and purchase-only sessions.
- Attribute the whole session to the channel of its first event. Conversion is binary per session, regardless of how many carts convert. There is no additional view-to-purchase time limit. Include zero-conversion channels. Order by channel.
- Skill
- Measure session-level conversion using a deterministic acquisition channel. Refresher: Sessionize an event stream →
expected result
Your query should return exactly these columns and values. Run it and compare.
expected result4 rows · in this order
| channel | sessions | converted_sessions | conversion_pct |
|---|---|---|---|
| direct | 3 | 0 | 0 |
| 6 | 2 | 33.33 | |
| search | 3 | 2 | 66.67 |
first 3 of 4 rows
data you can query
Sample rows from each table. Each column shows its type underneath; → marks a link to another table.
market_web_events7 columns · 38 rows
| idinteger · key | event_keytext | shopper_idinteger → shoppers | occurred_attext | event_typetext | channeltext | cart_idtext |
|---|---|---|---|---|---|---|
| 1 | a1 | 1 | 2025-05-01 09:00:00 | view | A | |
| 2 | a2 | 1 | 2025-05-01 09:05:00 | checkout | direct | A |
| 3 | a3 | 1 | 2025-05-01 09:10:00 | purchase | direct | A |
| 4 | a3 | 1 | 2025-05-01 09:10:00 | purchase | direct | A |
| 5 | b1 | 1 | 2025-05-01 10:00:00 | view | search | B |
showing 5 of 38 rows
solution.sql
Hints and the answer are always available. Using them counts the question as solved with help.