Turning Clickstreams into Strategy: A Markov Chain View of E-commerce Decisions
In e-commerce, small nudges can create outsized impact. A smoother checkout flow, a more prominent “Add to Cart” button, or the right…
Turning Clickstreams into Strategy: A Markov Chain View of E-commerce Decisions

In e-commerce, small nudges can create outsized impact. A smoother checkout flow, a more prominent “Add to Cart” button, or the right recommendation at the right time can shift millions in revenue. But the challenge for decision-makers is knowing which interventions truly move the needle.
Think about your own online shopping. Maybe you browsed a few items, added one to your cart, and then closed the tab. Or maybe you clicked “buy now” right away. Multiply that across hundreds of thousands of shoppers, and you get the messy reality of clickstreams: unpredictable paths, most ending without purchase. Funnels can show where drop-offs happen, but they rarely answer the deeper questions: What’s the probability a user will eventually buy? How many steps will it take? Which actions matter most?
That’s where Markov chain modeling comes in. By treating browsing sessions as probabilistic journeys, we can quantify how states like “view” vs. “add to cart” change purchase likelihood, how quickly sessions resolve, and which segments are most responsive. In other words, we can turn raw click data into strategy.
Why Markov Chains for Clickstream Data?
Clickstream data can be messy. A shopper might move from the homepage to a category page, jump to a product, go back, add something to their cart, pause, and then either complete the purchase or leave the site. Traditional funnel analysis breaks this into neat stages, but actual behavior rarely follows a straight line.
Markov chains are useful here because they model the probability of moving between states, where the next step depends only on the current state. In this case, each step in the customer journey(such as “view product,” “add to cart,” or “checkout”) is a state, and we can estimate probabilities for transitioning from one state to the next.
Using Markov chains lets us capture the non-linear paths shoppers take, estimate the likelihood of a purchase from any state, measure how many steps it usually takes to convert, and create a framework for what-if analysis.
Preparing the Data
To model these journeys, I started with the RetailRocket E-commerce Dataset, which contains over 2.8 million events across nearly 140,000 users. The data required careful cleaning and preprocessing to ensure accurate modeling. Key steps included:
- Filtering for purchase-relevant sessions: I kept only sessions containing at least one event of
view,add_to_cart, orpurchase. Roughly 3.6% of sessions included a purchase. - Mapping events to transitions: Each user’s sequential actions were transformed into a row of transitions, resulting in 417,053 mapped transitions across 382,780 unique sessions and 315,640 unique visitors.
- Constructing the Markov chain: Sessions were converted into state sequences (
START,VIEW,ADD_TO_CART,PURCHASE,DROP) to estimate transition probabilities and expected steps to absorption (PURCHASEorDROP).
The cleaned data set a solid foundation for modeling shopper behavior, letting us quantify the probabilities of purchases and typical session lengths from each starting point.

One clear insight from the model is the importance of the ADD_TO_CART state. While only about 3–4% of sessions that start or just include views end in a purchase, the likelihood jumps to over 20% once a shopper adds an item to their cart. Adding to cart signals stronger intent, and shoppers at this stage are much closer to conversion, requiring fewer steps to reach a decision.
From New to Repeat: What User Segments Reveal
Markov chain modeling can uncover differences across user segments, revealing where interventions might be most effective. By splitting sessions into groups such as new vs. repeat users or frequent vs. non-frequent purchasers, we can measure how purchase probabilities, number of steps, and time to conversion vary.

Repeat users are much more likely to make a purchase than new users, but they often spend more time browsing before completing it. Frequent shoppers convert quickly and stay engaged even when they eventually leave a session. Examining these segments helps retailers tailor their approach, such as speeding up checkout for high-intent users, offering personalized recommendations for multi-category shoppers, or running engagement campaigns for first-time visitors. This makes marketing and user experience decisions more precise and grounded in real behavior.
Digging Deeper: Category and Item-Level Insights
Markov chain modeling also uncovers differences across categories and individual items, showing which products drive conversions, which require more consideration, and where drop-offs are most common. By analyzing sessions at the category and item level, we can measure purchase probabilities, number of steps, and time to conversion to guide targeted interventions.

These insights show that categories and items vary widely in purchase likelihood and effort. Some categories like cat_959 demonstrate strong intent and attract more deliberate buyers, while others like cat_491 tend to convert quickly when they do purchase. At the item level, certain products consistently attract decisive buyers, whereas others involve longer browsing or almost always drop. Understanding these patterns allows retailers to optimize merchandising, recommendation strategies, and user experience at both the category and item level.
Takeaway
Insights like these can be critical for anyone in e-commerce. From marketers and UX designers to product managers and merchandisers, understanding how users move through your site can provide a real competitive advantage. In a market that is constantly changing and highly competitive, knowing who converts, when, and how is not just useful but it can be the difference between driving growth and leaving revenue on the table.
If you’d like to recreate this analysis, then all my code is reproducible and available on GitHub.
For more real-world data experiments and insights, connect with me on LinkedIn!
메타데이터
- post_id
- a653fa86af5d
- slug
- turning-clickstreams-into-strategy-a-markov-chain-view-of-e-commerce-decisions-a653fa86af5d
- url
- https://medium.com/@ritu.bansalrb00/turning-clickstreams-into-strategy-a-markov-chain-view-of-e-commerce-decisions-a653fa86af5d
- canonical_url
- https://medium.com/@ritu.bansalrb00/turning-clickstreams-into-strategy-a-markov-chain-view-of-e-commerce-decisions-a653fa86af5d
- author_url
- https://medium.com/@ritu.bansalrb00
- status
- ok
- fetched_at
- 2026-08-21 04:27:45