User Journey Analysis with PrefixSpan and Seq2Pat

Mikhail Stroganov11 Apr 2025

Problem

A product analyst in a grocery app wants to know how users really get from launch to payment. A classic funnel shows the path the team expects, not what users do. Counting every real path directly is infeasible: with seven events and paths of 3 to 10 steps, the naive list has 12 million combinations. Computing 12 million funnels is practically impossible even on good hardware.

Example from the article: in the Magnit app, users often entered and left the cart several times before checkout, and for some this happened up to 20 times.

Solution in brief

Mine frequent sequences instead of enumerating funnels. PrefixSpan finds frequent ordered patterns above a minimum support. Seq2Pat does the same and adds constraints such as max_span. On a synthetic clickstream, Seq2Pat took 6 seconds and PrefixSpan 35 minutes. Brute-force funnels over 128,000 candidates were estimated at 42 minutes to 7 hours.

Questions this case answers
  • How to find the most frequent event sequences leading to a target action when brute-force enumeration of candidate paths is computationally infeasible
  • How to detect harmful repeated-behavior patterns in long event sequences within a limited compute budget
  • How to find the most frequent real paths users take from app launch to payment instead of relying on a hand-drawn funnel?
  • How to count candidate user journeys when the number of possible event combinations runs into the millions?

Tools and methods

  • Funnel analysis — baseline: count users who pass an ordered list of events
  • NetworkX — build an event graph and enumerate only technically possible paths with DFS
  • Retentioneering — funnel function, used as the slow baseline
  • Polars — faster custom funnel counting
  • PrefixSpan — frequent-pattern mining by prefix projections
  • Seq2Pat — framework with constraints (max_span, gaps, attribute averages, median, spread)
Continue reading — it's free

Google or a one-time email code. No password.