The Two-Stage Pipeline

The ConversionFlow library is built around a two-stage pipeline designed to first understand the customer journey and then use that understanding to make optimal decisions.

Stage 1: Estimation

The first stage is all about learning from the data. In this stage, we take the raw user interaction data and use it to build a probabilistic model of the customer journey.

Key Steps

  1. Data Loading and Preprocessing: The raw data from GA4 and backend systems is loaded, cleaned, and transformed into a format suitable for modeling. This includes creating a binary feature for each touchpoint (node) for each user.

  2. Model Building: A Bayesian Network is constructed based on the structure defined in the config.yml file. This involves defining the nodes, edges, and prior distributions for the model parameters.

  3. MCMC Inference: We use Markov Chain Monte Carlo (MCMC) sampling (specifically, the NUTS sampler in PyMC) to estimate the posterior distribution of the model’s parameters. This is the core of the estimation process, where the model learns the relationships between the different touchpoints from the data.

Output

The primary output of the estimation stage is the posterior distribution of the model’s parameters (alpha and beta coefficients). This tells us the strength and uncertainty of the causal relationships in our customer journey model.

Stage 2: Optimization

The second stage is all about making decisions based on what we’ve learned. In this stage, we use the model parameters estimated in Stage 1 to find the optimal allocation of a marketing budget.

Key Steps

  1. Parameter Loading: The mean values of the beta coefficients from the posterior distribution are loaded into the optimizer.

  2. Objective Function: The optimizer’s goal is to maximize the total expected conversion value. This is a function of the beta coefficients (how much each touchpoint influences the final conversion) and the budget allocated to each touchpoint.

  3. Genetic Algorithm: A genetic algorithm is used to search for the optimal budget allocation. This is a powerful optimization technique that is well-suited for complex, non-linear problems like this one.

Output

The output of the optimization stage is a recommended budget allocation. This provides a clear, data-driven recommendation for how to distribute marketing spend to achieve the highest return on investment.