Webclat / Martech Practice
Webclat / Martech Practice  /  qa  /  attribution

How do I build a Markov-chain removal-effect attribution model on top of exported GA/BigQuery channel data?

Answer in brief

A Markov-chain attribution model treats each marketing channel as a state in a graph built from observed customer paths, then measures each channel's "removal effect" - how much overall conversion probability drops when that channel is removed from every path - and normalizes those removal effects into attribution percentages. Building it on GA/BigQuery data means extracting per-user channel-touch sequences from the raw export tables first, since GA4's own UI reports do not expose the sequence-level data this model needs.

Why this happens

Rule-based attribution models - first-touch, last-touch, linear - assign credit using a fixed, arbitrary formula that ignores how channels actually interact. A Markov model instead estimates each channel's causal contribution empirically, from probability theory applied to the real paths your own users took.

This needs BigQuery export specifically, rather than the GA4 UI, because the model requires the ordered sequence of channels a user touched before converting (or not converting) - a graph-structure input the UI's pre-aggregated reports do not provide, but which is present in the raw, unsampled, event-level export tables if you reconstruct it yourself.

Fix it

  1. Confirm GA4-to-BigQuery export is live and has accumulated enough history to build meaningful paths.
  2. Write a query that, per user, extracts the ordered sequence of session-level channel or source values leading up to each conversion event, plus equivalent sequences for users who never converted - both are required, since the model needs "failure" paths to compute a meaningful removal effect, not just successful ones.
  3. Build a transition-probability graph from these sequences: for each pair of consecutive channels, including "Start" and "Conversion"/"Null" as special states, compute the probability of moving from one to the next across all paths.
  4. Compute the baseline overall conversion probability across the full graph, then recompute it once per channel with that channel's transitions removed - the drop in conversion probability is that channel's removal effect.
  5. Normalize the removal effects across all channels so they sum to your total conversion count, producing the final attributed value per channel.
  6. Use an existing library (Python's ChannelAttribution/markov_model packages, or R's ChannelAttribution) rather than hand-rolling the linear algebra, unless you have a specific reason to implement it from scratch.

How to verify it worked

Sum the model's attributed conversions or revenue across all channels and confirm it equals your total observed conversions from the same BigQuery dataset - a Markov model should conserve total conversions, only redistributing credit. If the sums do not reconcile, the graph construction likely double-counted or dropped some paths. Spot-check one specific, well-understood conversion path manually against the graph's transition probabilities before trusting the aggregate output.

Still Seeing This After Trying the Fix?

Send us what you are seeing - the console error, the Network tab, the Live View output. We trace tracking implementations for a living and can usually tell you what is actually happening in one look.

Ask An Engineer