Skip to main content
Version: 3.20.1

uam

R​

This example shows how to use uam with aggregate marketing data and, optionally, customer journey paths. The aggregate dataset includes both digital signals and a TV signal. TV is useful in this example because it is available in aggregate data but is usually not observed inside user-level journeys. The aggregate baseline uses prior-weighted and saturated signals before computing attribution.

D_variables defines how raw input variables are mapped to final attribution channels. It must include prior_weight, which converts each raw signal into a more comparable business-weighted signal before saturation and scoring. prior_weight: business weight assigned to each raw signal. A common way to estimate it is conversions / touchpoints, but it can also be set from domain knowledge or historical benchmarks. Several variables can map to the same channel: for example, Facebook impressions and Facebook clicks are both assigned to facebook_ads.

library(ChannelAttributionPro)

token <- "yourtoken"

# data_mmm_3.csv includes a TV signal in addition to digital aggregate signals.
df_aggr <- read.csv("https://app.channelattribution.io/data/data_mmm_3.csv")

D_variables <- data.frame(
variable = c(
"direct_searches",
"facebook_impressions",
"facebook_clicks",
"google_impressions",
"google_clicks",
"tv"
),
channel = c(
"direct",
"facebook_ads",
"facebook_ads",
"google_ads",
"google_ads",
"tv"
),
measure = c(
"direct_searches",
"impressions",
"clicks",
"impressions",
"clicks",
"views"
),
prior_weight = c(
0.50, # direct search
0.015, # Facebook impressions
0.21, # Facebook clicks
0.015, # Google impressions
0.25, # Google clicks
0.02 # TV views / GRP-like signal
),
stringsAsFactors = FALSE
)

target <- "conversions"

Aggregated-data attribution without customer journey paths​

Use this mode when you only have aggregate time-series data. In this case, uam estimates channel attribution directly from the aggregate signals and the target variable.

res <- uam(
df_aggr = df_aggr,
D_variables = D_variables,
target = target,
df_paths = NULL,
baseline_model = "linear", # "reward", "copula", or "linear"
max_p = 12,
nsim = 1000,
seed = 1234567,
verbose = 1,
password = token
)

attribution <- res$attribution
print(head(attribution))

UAM with already aggregated customer journey paths​

Use this mode when customer journeys are already represented as one row per path, with the number of conversions and null outcomes associated with each path.

df_paths_agg <- read.csv("https://app.channelattribution.io/data/data_uam_paths_t.csv")

res <- uam(
df_aggr = df_aggr,
D_variables = D_variables,
target = target,
df_paths = df_paths_agg,
baseline_model = "linear", # "reward", "copula", or "linear"
var_path = "path",
var_conv = "total_conversions",
var_null = "total_null",
order = 1,
sep = ">",
verbose = 1,
password = token
)

attribution <- res$attribution
print(head(attribution))

UAM with event-level customer journey paths​

Use this mode when each row is a single touchpoint event. The conversion event is identified by channel_conv and the path is reconstructed internally.

df_paths_events <- read.csv("https://app.channelattribution.io/data/data_uam_paths.csv")

res <- uam(
df_aggr = df_aggr,
D_variables = D_variables,
target = target,
df_paths = df_paths_events,
baseline_model = "linear",
channel_conv = "((CONV))",
order = 1,
sep = ">",
verbose = 1,
password = token
)

attribution <- res$attribution
print(head(attribution))