How many users who view a product go on to add it to the cart, and then check out? Build a funnel from raw events.
Events are (user_id, event_name, timestamp) tuples in any order. A user reaches step k if they did step 1, then step 2 at or after that time, and so on, in order. Each step must happen at or after the previous step's earliest qualifying time.
Implement funnel(events, steps) returning a list of dicts, one per step: {"step", "users", "conversion_from_previous", "conversion_from_start"}, with conversions as fractions (the first step has 1.0 for both, or 0.0 if nobody started).