Skip to content

Page Attribution

Overview

Our clients are interested in understanding the impact of their page content during a customers journey. This is important for understanding the value of their content and how it contributes to the overall conversion rate. Page attribution is a method of assigning a value to each page in a customers journey. This value can then be used to understand the impact of each page on the overall conversion rate.

We utilise a deep neural network with attention multi-touch page attribution model. We leverage a Long Short Term Memory (LSTM) based deep sequential model, which is well known for capturing the long time dependency of sequence observations. Furthermore, the sequence of touchpoints is important in a customer journey, order matters! Additionally, the same touchpoint may be differentially important at different touchpoints in the journey. To capture this, we introduce an attention mechanism to learn the importance of each touchpoint in the journey. The model is largely based on the following paper: Deep Neural Net with Attention for Multi-channel Multi-touch Attribution.

The model is trained on thousands of converting and non-converting customer journeys. If the model can accurately predict the outcome of a customer journey, we can be sure that the attention mechanism has captured a relationship between the touchpoint sequence and a journey outcome. Given a converting journey, the attention layer will optimise its weights to assign a higher value to the touchpoints that are considered to be more important in the converting journey. This means that the weights themselves can be extracted and used to understand the importance of each page in that conversion.

Model Architecture

The model architecture is shown below. The model is trained on a sequence of touchpoints, where each touchpoint is represented by a vector of features (pages). The model is trained to predict the outcome of a journey, which is represented by a binary variable. The attention layer is used to learn the importance of each touchpoint in the journey. The attention weights can then be used to understand the importance of each page in the journey. Model

Code Infrastructure

train.py

The main entrypoint, and will be called from the backend monthly. To call the main script the following flags are available:

Flag Required Description
--connection Yes Connection string to the client database.
--startdate Yes Start date of the training data.
--enddate Yes End date of the training data. This must be the same date as startdate
--limit-journey-length No The maximum number of touchpoints in a journey. Default: the length of the longest journey

The main script iterates through all active products inside attrib_product and creates journey data for each product. The journey data is then used to train a model for each product. Currently the model, attention model, and tokenizer are saved to disk as hd5 files and JSON files. The save path follows the structure: /src/models/page_attribution/{client}/{product_id}/{filename}

settings.py

Global variables and settings for the tool to run. The settings are split into three sections: data, model and path settings. The variables/constants should be self explanatory and require no further explanation.

data

data.py

Home to the data pipeline. The data pipeline is responsible for creating the journey data for each product. The pipeline is initialised with a connection string to the client database. As client conversion data comes in various sizes we have to stream the data sequentially. After the data has been streamed, the pipeline is responsible for removing any sales pages present in a customers journey. This is an important step as we do not want the model to learn that a sale page is important for a conversion. Finally, the converting and non-converting journeys are balanced to ensure the model does not learn to predict the majority class.

queries.py

A helper class that holds all the SQL queries used in the data pipeline.The queries are stored as class attributes.

attribution

model.py

Home to the page attribution model: class PageAttributionModel. The model is a wrapper around the Keras model. The model is initialised with paramaters defined in Config, see Config. This class contains some static methods relevant to the models functionality. See below for a brief description.

Method Description
tokenize Converts a list of journeys into a list of tokenized journeys.
handle_train_test_split Splits the data into train and test sets.
save_tokenizer Saves the tokenizer to disk.

attention.py

A class that loads and handles attention model related functionality. The class is initialised with a path to the attention model. The class contains some static methods relevant to the models functionality.

config.py

A configuration class for PageAttributionModel. The class contains the following attributes: max_features, sequence_length, batch_size, embedding_size, epochs, and hidden_units. Some of these paramaters are defined inside Settings while others are constrained by the data and have to be defined at runtime.

Attribute Description
max_features The maximum number of pages (touchpoints) to be included in the model.
sequence_length The maximum number of touchpoints in a journey.
batch_size The number of journeys to be included in each batch.
embedding_size The size of the embedding layer.
epochs The number of epochs to train the model for.
hidden_units The number of hidden units in the LSTM layer.

products

products.py

Contains a Product dataclass that is used to store product information. The dataclass is initialised with a product id, name, and the associated client. We also define a factory class that is used to create a Product object from all active products in the client database.