Skip to content

Multi-Touch Attribution (MTA)

Find out which marketing channels actually drive conversions, not just which ones happened to come first or last.

Overview and Use Cases

Multi-Touch Attribution (MTA) AI Signals gives each marketing channel a share of the credit for conversions, based on how customers really move through their journeys. Rule-based attribution models such as First Touch, Last Touch, Linear, and U-Shaped give credit by position in the journey. They are easy to explain, but they ignore how channels work together. MTA AI Signals learns from your data instead:

  • Markov models journeys as a chain of channel-to-channel steps. It measures how much each channel contributes by checking what happens to conversions when that channel is removed from the chain. It also produces a transition matrix that shows how customers move from one channel to the next.
  • Shapley treats the channels in a journey as a team. It measures each channel's average contribution to the conversion rate across every combination of channels it appears in, so channels that often appear together share credit fairly.

Common use cases

  • Budget allocation: split marketing spend across channels based on their measured contribution
  • Channel what-if analysis: estimate how important a channel is before you cut or scale it
  • Journey flow analysis: build Sankey or flow views from the Markov transition matrix to see which channel usually comes next
  • Last-touch influence: use Shapley's lookback sizes to see which channels matter most in the last few touches before a conversion
  • Model comparison: compare data-driven credit with your rule-based models. A big difference between them is worth investigating

Who benefits most: Marketing analysts, data engineers, and data scientists who already have touchpoint data (web, email, ads, or other channels) and conversion events in Treasure AI.

How It Fits with the Other AI Signals

Question you're asking Use
Who matters, based on past purchasing?RFM AI Signals: descriptive segments, no modeling required
How likely is this customer to do X?Propensity Scoring AI Signals: a probability per event you define
How much will this customer be worth?CLTV AI Signals: a value forecast and percentile rank
Which product should I recommend next?NBP AI Signals: a ranked list of products, services, or content
Which action should I take for this customer?NBA AI Signals: a learned per-user policy across candidate actions
Which marketing channels deserve credit for conversions?MTA AI Signals (you are here): data-driven credit per channel

MTA or the per-customer signals? The other AI Signals score or recommend something for each customer. MTA works at the channel level: it explains past conversions across all customers instead of predicting what one customer will do.

Markov and Shapley answer slightly different questions. Markov tells you which channels are hard to replace and how customers move between them. Shapley tells you how to split credit fairly between channels that often appear together. We recommend running both. For details, see Choosing a Model.

Quick Start

This example runs both models in parallel from one touchpoint table. Each row in the table is one touch, with these columns: user_id, touch_time, channel, and converted. For this workflow, store converted as integer 0 or 1 in the source touch table.

Before you start:

  • MTA must be enabled for your account. If it is not, contact your Treasure AI account team.
  • The API key you use must be able to read the input database and write to the output database.
Security

Store your API key in a Workflow secret named td.apikey, never as a literal value in the workflow definition. This keeps the key out of version control. See Setting Workflow Secrets from Treasure Console.

Markov needs one row per journey, so the workflow first builds a journey table from the touch table. Shapley reads the touch table directly.

# mta_ai_signals.dig
timezone: UTC

_export:
  ml_batch_endpoint: "https://ml-batch-api.treasuredata.com"
  db: "my_mta_db"
  touch_table: "mta_touches"              # one row per touch
  markov_input_table: "mta_markov_input"  # one row per journey (built below)

+build_markov_input:
  td>: queries/build_markov_input.sql     # see "mta_markov > Data Preparation"
  database: ${db}
  create_table: ${markov_input_table}

+attribution:
  _parallel: true

  +markov:
    +submit:
      http>: ${ml_batch_endpoint}/v1/runs/
      method: POST
      headers:
        - authorization: "TD1 ${secret:td.apikey}"
        - X-TD-ML-SESSION-ID: ${session_id}
        - X-TD-ML-ATTEMPT-ID: ${attempt_id}
      content_format: json
      content:
        solution_name: "mta_markov"
        input_table: "${db}.${markov_input_table}"
        output_table: "${db}.mta_markov_attribution"
        solution_arguments:
          user_id_col: "journey_id"
          time_col: "touch_time"
          channel_colname: "journey"
          conversion_col_name: "converted"
          transition_output_table: "${db}.mta_markov_transition"
      store_content: true
    +print:
      echo>: ${http.last_content}
    +poll:
      http>: ${ml_batch_endpoint}/v1/runs/${JSON.parse(http.last_content)['id']}/status
      method: GET
      headers:
        - authorization: "TD1 ${secret:td.apikey}"

  +shapley:
    +submit:
      http>: ${ml_batch_endpoint}/v1/runs/
      method: POST
      headers:
        - authorization: "TD1 ${secret:td.apikey}"
        - X-TD-ML-SESSION-ID: ${session_id}
        - X-TD-ML-ATTEMPT-ID: ${attempt_id}
      content_format: json
      content:
        solution_name: "mta_shapley"
        input_table: "${db}.${touch_table}"
        output_table: "${db}.mta_shapley_attribution"
        solution_arguments:
          user_id_col: "user_id"
          time_col: "touch_time"
          channel_colname: "channel"
          conversion_col_name: "converted"
          shapley_lookback_window: 4
          shapley_order: true
      store_content: true
    +print:
      echo>: ${http.last_content}
    +poll:
      http>: ${ml_batch_endpoint}/v1/runs/${JSON.parse(http.last_content)['id']}/status
      method: GET
      headers:
        - authorization: "TD1 ${secret:td.apikey}"

Each branch keeps its own submit and poll steps in one group, so http.last_content always refers to that branch's own run, even though the branches run in parallel. The status endpoint returns HTTP 408 while the run is in progress. The http> operator keeps retrying until the run finishes, and then returns the final status and any error_messages.

Expected output: when the workflow finishes, you have three tables.

mta_markov_attribution: credit for each channel

channels  attribution_markov_algorithmic  removal_effect
email     1.358                           0.750
social    1.132                           0.625
organic   1.509                           0.833
display   0.000                           0.000

mta_markov_transition: the probability of moving from one channel to the next

channels  email   social  organic  _conversion_
email     0.000   0.400   0.200    0.400
social    0.250   0.000   0.500    0.250
organic   0.000   0.000   0.000    1.000

mta_shapley_attribution: credit for each channel, for each lookback size

channels  variable                                              value  size
email     attribution_shapley_size0_conv_rate_order_algorithmic  1.42   0
organic   attribution_shapley_size0_conv_rate_order_algorithmic  1.61   0
email     attribution_shapley_size2_conv_rate_order_algorithmic  1.18   2
organic   attribution_shapley_size2_conv_rate_order_algorithmic  1.87   2

The values above are examples. Your results depend on your data.

To create and schedule this workflow, see Getting Started with Treasure Workflow.

Model Configuration

Both solutions use the same four column parameters: user_id_col, time_col, channel_colname, and conversion_col_name. You choose the column names, because nothing is hardcoded. However, the two solutions read different table shapes and you can't swap their inputs:

  • mta_markov reads one row per journey, with the whole channel path in one column.
  • mta_shapley reads one row per touch.

You can build both inputs from the same touchpoint data.

The following fields are set at the top level of the run request for both solutions, not inside solution_arguments:

Parameter Type Default Required Description
solution_namestring—Yesmta_markov or mta_shapley.
input_tablestring—YesInput table, in database.table format.
output_tablestring—YesTable for the attribution result, in database.table format.
solution_argumentsobject—YesSolution-specific settings. See the sections below.
versionstringstableNoSolution version. Use stable.

mta_markov

Markov-chain attribution treats each journey as a walk from a start state, through a sequence of channels, to either a conversion or the end of the journey. From all converting journeys it estimates how likely customers are to move from each channel to each next channel. It then measures each channel's removal effect, which is how much the paths to conversion depend on that channel.

Data Preparation

The input table has one row per journey. Each journey must already be split at conversions, so that a journey ends at its conversion touch. This keeps touches that happen after a conversion out of the path that led to it.

Field Type Required Description
Journey ID (user_id_col)varcharYesA unique ID for each journey. One customer can have several journeys.
Path (channel_colname)varcharYesThe channels in the journey, in order, joined with ' > ' (space, greater-than, space). For example: email > social > organic.
Converted (conversion_col_name)intYes1 if the journey ends in a conversion, otherwise 0. The preparation SQL below produces integer flags.
Time (time_col)timestamp / varcharYesThe time of the journey's last touch. Markov does not use it to calculate attribution. It is only used to choose which journeys to load first when you set max_load_rows.

Example rows:

journey_id  journey                           converted  touch_time
cust_001-0  email > paid_search > organic     1          2026-08-02 10:15:00
cust_001-1  social > email                    0          2026-08-20 18:40:00
cust_002-0  display                           0          2026-08-11 09:02:00
cust_003-0  paid_search > paid_search > email 1          2026-08-14 21:30:00

You can build this table from the workflow's touch_table with a window function. The query below starts a new journey after each conversion and joins the channels in time order.

The source converted column must contain integer 0 or 1 because the query uses SUM(converted). Normalize text flags to these values before running the query; directly casting 'true' or 'false' to an integer does not work. Reject unrecognized values during preparation instead of converting them to NULL.

-- queries/build_markov_input.sql
WITH segmented AS (
  SELECT
    user_id,
    touch_time,
    channel,
    converted,
    COALESCE(SUM(converted) OVER (
      PARTITION BY user_id ORDER BY touch_time, channel
      ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING), 0) AS journey_index
  FROM ${touch_table}
  WHERE user_id IS NOT NULL AND channel IS NOT NULL
)
SELECT
  CONCAT(user_id, '-', CAST(journey_index AS VARCHAR))                 AS journey_id,
  MAX(touch_time)                                                      AS touch_time,
  ARRAY_JOIN(ARRAY_AGG(channel ORDER BY touch_time, channel), ' > ')   AS journey,
  CAST(MAX(converted) AS BIGINT)                                       AS converted
FROM segmented
GROUP BY user_id, journey_index
Data requirements
  • Don't pass touch-level rows to Markov. If no row in the table contains the ' > ' separator, the run is rejected, because that means each row is a single touch rather than a journey. Single-touch journeys are fine, as long as some journeys have more than one touch.
  • The input must contain at least one conversion.
  • Rows where the journey ID or path is NULL are skipped.

Workflow Parameters

Set these inside solution_arguments:

Parameter Type Default Required Description
user_id_colstring—YesJourney ID column.
time_colstring—YesJourney timestamp column (the last touch). Only used to order a capped load.
channel_colnamestring—YesColumn that holds the ' > '-joined channel path.
conversion_col_namestring—YesConversion flag column.
transition_output_tablestring—NoTable for the transition matrix, in database.table format. If you leave it out, the transition matrix isn't written.
max_load_rowsinteger0NoMaximum number of journeys to load. 0 means no limit. Converting journeys are loaded first, then the most recent ones. See Controlling Input Size.
output_modestringoverwriteNooverwrite or append. See Output Modes.

Output

Attribution table (output_table)

Field Type Description
channelsvarcharChannel label.
attribution_markov_algorithmicdoubleConversions credited to the channel. The column adds up to the total number of converting journeys, not to 100%. Rounded to 3 decimal places.
removal_effectdoubleHow much the paths to conversion depend on the channel, from 0 to 1. Rounded to 3 decimal places.

To get each channel's share of credit, divide attribution_markov_algorithmic by its total across all channels. A channel that appears only in non-converting journeys is still listed, with 0 credit and 0 removal effect. This is expected.

Transition matrix (transition_output_table)

A wide table. The channels column is the channel a customer is moving from. There is one column for each channel a customer can move to, plus a column for the conversion state (_conversion_). Each value is a probability, rounded to 3 decimal places. Because the columns come from your channel labels, the set of columns depends on your data. For tips on labels, see Channel Label Hygiene.

The channels rows can also include the synthetic absorbing state (conversion), which represents the end of a converting path.

Use the transition matrix to build Sankey diagrams and flow views, or to find the most likely next channel after a given one.

mta_shapley

Shapley-value attribution comes from cooperative game theory. The set of channels in a journey is a coalition, and each coalition is scored by the conversion rate of the journeys that contain it. A channel's Shapley value is its average contribution to that conversion rate across every coalition it can join. A channel that appears in almost every journey doesn't get credit just for being there. It only gets credit for the conversions it adds.

Data Preparation

The input table has one row per touch. The solution groups touches into journeys by user, orders them by time, and starts a new journey after each conversion. This means one customer can contribute a converting journey followed by a non-converting one.

Field Type Required Description
User (user_id_col)varcharYesCustomer or user ID. You can also pass a journey ID. If the journeys are already split at conversions, the result is the same.
Time (time_col)timestamp / varcharYesTouch timestamp, as a timestamp or as text in YYYY-MM-DD HH:MM:SS format. Don't use Unix epoch integers. They are read as the wrong dates.
Channel (channel_colname)varcharYesOne channel label per row.
Converted (conversion_col_name)int / booleanYes1 on the converting touch, otherwise 0.

Example rows:

user_id   touch_time           channel      converted
cust_001  2026-08-01 09:00:00  email        0
cust_001  2026-08-01 12:30:00  paid_search  0
cust_001  2026-08-02 10:15:00  organic      1
cust_001  2026-08-19 08:00:00  social       0
cust_001  2026-08-20 18:40:00  email        0
cust_002  2026-08-11 09:02:00  display      0

In this example, cust_001 has two journeys: a converting journey that ends at organic, and a non-converting journey (social > email).

Data requirements
  • Include non-converting journeys. Shapley scores each coalition by its conversion rate, so it needs the journeys that didn't convert to calculate that rate. If you only supply converting journeys, every coalition has a conversion rate of 100% and the results aren't meaningful.
  • The input must contain at least one conversion.
  • Rows where the user ID or channel is NULL are skipped.
  • If two touches have the same timestamp, they are ordered by channel name, so results are the same from run to run.

Workflow Parameters

Set these inside solution_arguments:

Parameter Type Default Required Description
user_id_colstring—YesUser (or journey) ID column.
time_colstring—YesTouch timestamp column.
channel_colnamestring—YesChannel column.
conversion_col_namestring—YesConversion flag column.
shapley_lookback_windowinteger4NoLargest lookback size to score, from 1 to 10. One model runs for each size from 0 up to this value. See Shapley Lookback Window and Order.
shapley_orderbooleantrueNoWhether channel order matters in a coalition. With true, email > social and social > email are different coalitions.
max_load_rowsinteger0NoMaximum number of rows to load. 0 means no limit. Whole journeys are loaded, starting with converting journeys, so the limit can be exceeded by at most one journey. See Controlling Input Size.
output_modestringoverwriteNooverwrite or append. See Output Modes.

Workflow variables such as ${...} are passed as text. Both solutions accept numbers and booleans as strings, so "4" and "false" work.

Output

Field Type Description
channelsvarcharChannel label.
variablevarcharThe model that produced the row, for example attribution_shapley_size2_conv_rate_order_algorithmic. When shapley_order is false, the name doesn't include _order.
valuedoubleShapley attribution value for the channel at this size.
sizeintegerLookback size, from 0 to shapley_lookback_window. 0 is the whole journey. N means only the last N unique channels of each journey are scored.

The table is in long format: one row per channel per size. Always filter or group by size before you compare channels. To turn values into percentages, see Converting Shapley Output to Percentages.

Choosing a Model

Aspect Markov (mta_markov) Shapley (mta_shapley)
InputOne row per journey, with the path joined by ' > 'One row per touch
What drives creditChannel-to-channel transitions and the removal effectConversion rate of channel combinations
Uses non-converting journeys?No. They don't change the result.Yes. They're required to calculate conversion rates.
Order-sensitive?AlwaysConfigurable (shapley_order)
Recent-touch viewNo (whole path)Yes (sizes 1 to N = last N channels)
Extra outputTransition matrix (optional)One result set per lookback size
Main cost driverNumber of journeys and channelsUnique channels per journey × lookback window
If your question is… Use Why
Which channels are hardest to replace? What if we turn off channel X?mta_markovThe removal effect is a direct what-if on the channel graph.
How do customers move between channels?mta_markov with transition_output_tableOnly Markov produces the transition matrix.
How should we split budget between channels that usually appear together?mta_shapleyShapley shares credit fairly between channels that appear together.
Which channels matter most right before a conversion?mta_shapley (sizes 1 to 3)Small sizes look only at the last few channels.
What should we show executives?Both, plus your rule-based modelsComparing several models shows where they agree and where they don't.

Recommendation: run both models in parallel, as in the Quick Start. They are independent runs and don't share any state.

Relevant Topics

Interpreting Markov Results

Markov estimates the transitions only from journeys that convert. Non-converting journeys don't affect the result, even if you include them. Because of this:

  • removal_effect shows how much a channel sits on the paths that lead to conversion: roughly, the chance that a walk along those paths passes through the channel. A channel with a high removal effect is hard to replace. Removal effects don't add up to 1, because one journey can pass through several channels.
  • attribution_markov_algorithmic is the removal effects scaled to add up to the total number of conversions. Use it to say "channel X is credited with about N conversions."
  • Markov doesn't tell you how often journeys through a channel fail. To see the impact of channels on conversion rate, use Shapley.

When you build a transition report or Sankey view, you can leave out channels with a very small removal effect (for example, below 0.005) to keep the view readable.

Shapley Lookback Window and Order

shapley_lookback_window controls how many models Shapley runs. With the default of 4, Shapley runs five models: sizes 0, 1, 2, 3, and 4.

  • Size 0 scores the whole journey.
  • Size N keeps only the last N unique channels of each journey. The unit is channels, not days.

Lower the window to 2 or 3 if most journeys have fewer than 3 unique channels, or if runs take too long. Each step lower removes one model. Raise it (up to 10) only when journeys often have more than 4 unique channels and a longer window answers a real business question.

Set shapley_order to false when:

  • You have many channels and not much data, so ordered coalitions are sparse.
  • Touch order isn't reliable, for example because many touches share the same timestamp.
  • You want credit by channel set, regardless of order.

Order-free coalitions combine more journeys, so their estimates are more stable.

Converting Shapley Output to Percentages

To get each channel's share of credit for each size, divide its value by the total for that size. To keep a history, add the run time:

SELECT
  ${session_unixtime}                          AS time,
  '${session_local_time}'                      AS run_time,
  size,
  channels,
  ROUND(value, 4)                              AS value,
  value / SUM(value) OVER (PARTITION BY size)  AS percentage
FROM my_mta_db.mta_shapley_attribution

Controlling Input Size

By default (max_load_rows = 0), all rows are loaded. We recommend keeping the default and limiting the volume in your preparation SQL instead, for example by using a lookback period such as the last 180 days, or by mapping rare channels to other.

If you set max_load_rows as a safety limit, check the run statistics afterward. The run reports input_total_records, loaded_rows, output_rows, and truncated. If truncated is true, the limit cut part of the input.

The two models handle a limit differently:

  • Markov loads converting journeys first. Because non-converting journeys don't affect Markov, the result is the same as an uncapped run as long as every converting journey fits under the limit.
  • Shapley also loads converting journeys first, and it always loads whole journeys. Because fewer non-converting journeys are loaded, conversion rates go up and the attribution is biased. For Shapley, use a deliberate sampling strategy in your preparation SQL rather than max_load_rows.

Output Modes

MTA recalculates attribution from your full input each time, so keep the default output_mode: overwrite. The output tables have no run ID column, so append would mix results from different runs.

To keep a history, copy each run's output into a separate table and add the run time, as in Converting Shapley Output to Percentages.

Channel Label Hygiene

Channel labels appear in reports, and in the Markov transition matrix they become column names. To keep results clean:

  • Use short, lowercase labels without punctuation, for example paid_search rather than Paid Search (Google).
  • Make sure no two labels become the same column name after normalization. For example, Paid-Search and paid_search could collide.
  • Keep to about 15 distinct channels or fewer by mapping rare sources to other. This keeps Shapley coalitions well populated and the transition matrix readable.
  • Handle NULL channels the same way in both inputs, either by dropping them or by mapping them to a label such as direct.

FAQs

Getting Started

What data do I need? Touchpoint data with a user ID, a timestamp, a channel label, and a conversion flag. Web events, email engagement, ad clicks, and orders can all be combined into one touch table. Markov needs that data grouped into journeys first. Shapley reads it as is.

Do I have to run both models? No. Each solution runs on its own. We recommend running both, because they answer different questions and comparing them helps you trust the results.

The run was rejected because the solution isn't enabled. What do I do? MTA must be enabled for your account. Contact your Treasure AI account team.

Data and Quality

What values does the conversion flag accept? The ML Batch API accepts boolean, any number (non-zero means converted), or text: true/false, t/f, yes/no, y/n, or 1/0. Text is not case-sensitive and spaces are trimmed. NULL counts as not converted. Any other value fails the run, and the error message lists the values it couldn't read.

The quick-start workflow has a stricter requirement: its source touch table must store converted as integer 0 or 1 because the Markov preparation SQL uses SUM(converted). Normalize text flags before that step, as described in Data Preparation. Shapley reads touch-level input directly without this SQL step.

Why did my run fail with "no conversions"? The input must contain at least one conversion. A run without conversions fails on purpose, so that it doesn't overwrite your previous results with an empty table. Check your conversion flag column and the date range of your preparation SQL.

Why did my Markov run fail even though the table has data? Markov needs one row per journey with the channels joined by ' > '. If no row contains the separator, the input looks like touch-level data and the run is rejected. Build the journey table first, as shown in mta_markov Data Preparation.

My Shapley results look wrong, and the timestamps are numbers. Why? Unix epoch integers are read as the wrong dates, which breaks the order of touches. Pass a timestamp or text in YYYY-MM-DD HH:MM:SS format instead.

Why does a channel have zero credit in Markov? The channel only appears in non-converting journeys. Markov only uses converting journeys, so the channel gets no credit. This is expected and isn't a data quality problem.

Choosing a Model

Markov and Shapley give different numbers. Which one is right? Both are valid. They measure different things. Markov shows which channels the paths to conversion depend on. Shapley shows each channel's contribution to the conversion rate. Look for where they agree. Where they disagree, compare them with your rule-based models and investigate.

Which Shapley size should I report? Use size 0 (the whole journey) for an overall view. Use sizes 1 to 3 when you care about the touches closest to the conversion. Don't add values across sizes, because each size is a separate model.

Scale and Limits

How much data can MTA handle? Each solution runs on a single node, because attribution depends on every journey and can't be split up. MTA is designed for model inputs of up to about 20 million rows. Runs with larger inputs have completed in testing, but run time and memory increase with input size.

What makes Shapley slow? The number of channel combinations grows quickly with the number of unique channels per journey, and Shapley runs one model per lookback size. To speed it up, lower shapley_lookback_window, set shapley_order to false, or map rare channels to other.

Is MTA real-time? No. MTA is a batch solution. Schedule the workflow (for example, weekly or monthly) to refresh attribution.

Glossary

Term Definition
Touchpoint (touch)One interaction between a customer and a channel, such as an email click or a site visit.
JourneyThe ordered touches of one customer, up to and including a conversion, or up to the end of the data if they didn't convert.
Conversion journeyA journey that ends in a conversion. A new journey starts after each conversion.
ChannelThe marketing source of a touch, such as email, paid_search, or organic.
Markov chainA model in which the next step depends only on the current step. MTA uses it to model channel-to-channel moves.
Transition matrixA table of probabilities that a customer moves from one channel to another, or to conversion.
Removal effectHow much the paths to conversion depend on a channel, from 0 to 1.
CoalitionA set (or ordered sequence) of channels that appear together in a journey.
Shapley valueA channel's average contribution to the conversion rate across all coalitions it can join.
Lookback sizeThe number of unique channels Shapley scores, counting back from the end of the journey. Size 0 means the whole journey.
Rule-based attributionModels that give credit by position, such as First Touch, Last Touch, Linear, and U-Shaped.