Markov Chain Attribution Modeling
Modeling the Customer Journey as a State Machine
Markov chain attribution represents the customer journey as a sequence of transitions between states, where each state is a channel (or touchpoint type) and the chain also includes two absorbing states: Conversion and Null (the path ends without converting). Each user's path through channels becomes a sequence of state transitions, and from historical path data you estimate the transition probability between every pair of states — the probability of moving from 'Email' to 'Paid Search,' or from 'Paid Search' directly to 'Conversion.' This gives you a full probabilistic model of how customers move between channels on their way to converting or dropping off.
The Removal Effect: How Credit Gets Assigned
Once the transition matrix is built, Markov attribution computes each channel's importance via the removal effect: recompute the overall conversion probability of the entire graph with that channel's node removed (its incoming traffic redistributed to the Null state, since those paths can no longer flow through it), and compare against the baseline conversion probability with all channels present. The percentage drop in conversion probability when a channel is removed becomes that channel's relative importance, and total conversion value is then allocated across channels proportional to their removal effect.
import numpy as np
# Transition matrix built from historical path data: rows/cols are
# states (channels + Conversion + Null), values are transition probabilities.
states = ["Start", "Paid Search", "Email", "Retargeting", "Conversion", "Null"]
def total_conversion_probability(transition_matrix, states):
# Simplified: solve for probability of reaching "Conversion" from "Start"
# via absorbing Markov chain fundamental matrix math.
idx = {s: i for i, s in enumerate(states)}
# ... fundamental matrix computation omitted for brevity ...
return 0.0 # placeholder for actual absorption probability calc
def removal_effect(transition_matrix, states, channel_to_remove):
baseline = total_conversion_probability(transition_matrix, states)
modified = transition_matrix.copy()
idx = states.index(channel_to_remove)
modified[:, idx] = 0 # no transitions INTO the removed channel
modified[idx, states.index("Null")] = 1.0 # paths through it now go to Null
without_channel = total_conversion_probability(modified, states)
return (baseline - without_channel) / baseline # % drop in conversion probabilityMarkov Attribution Naturally Handles Loops and Repeated Touches
Markov vs Shapley: Practical Tradeoffs
Both are data-driven, both move beyond fixed-rule attribution, but they differ in computational approach and what they capture. Markov chains scale more gracefully to larger channel sets (the transition matrix grows quadratically with channel count, not exponentially like exact Shapley), and naturally represent sequence/order effects. Shapley value attribution more rigorously captures combinatorial interaction effects between channels regardless of order, at higher computational cost. In practice, many teams use Markov chain models as their primary in-house, warehouse-native attribution method (since it's tractable to build in SQL/Python against BigQuery event data) while treating Google's Shapley-based DDA as a secondary cross-check within Google's own ecosystem.
First-Order vs Higher-Order Markov Assumptions
A first-order Markov model assumes the next state depends only on the current state, not the full history — a simplifying assumption that's often wrong in practice (whether a visitor converts after seeing 'Retargeting' depends partly on what got them there in the first place, not just the immediately preceding touch). Higher-order models (considering the last 2-3 states instead of just 1) capture more of this path-dependency but require substantially more data to estimate reliably, since the state space grows multiplicatively with order. Most practical implementations stick to first-order for data-volume reasons, accepting the simplification.
Transition Matrices Need Regular Refreshing
What's Next?
Attribution models estimate contribution from individual-level path data; a complementary approach that works even without user-level tracking — Media Mix Modeling — is the natural next topic.
I build these systems professionally.
Whether it's a RAG pipeline, analytics migration, or AI workflow — let's talk.