Google Analytics提供MCF data。我想使用这些数据来解释转换之前介质与R之间的相互作用。
为了简化,假设我有2行中间路径和与每条路径相关的转换总数:
直接> cpc>有机> cpc>推荐>直接| 3次转换
有机>直接> cpc>推荐> cpc>直接| 1次转换
使用R,您将如何管理数据框以获取此信息:
问题在于,当我继续时,最终数据帧的列数很大(每个通道组合1个)。
感谢。
西尔
答案 0 :(得分:1)
以下是一个例子:
df <- read.table(sep="|", stringsAsFactors = F, text="
direct > cpc > organic | 3 conversions
organic > direct > cpc > email | 1 conversion
cpc > email | 10 conversion")
df[,1] <- trimws(df[,1])
df[,2] <- as.integer(gsub("\\D","",df[,2]))
lst <- strsplit(df[,1], " > ", T)
lst <- lapply(lst, function(x) matrix(embed(x, 2)[, 2:1], ncol=2))
res <- as.data.frame(do.call(rbind, lst))
res$V3 <- rep(df[,2], sapply(lst, nrow))
(res <- aggregate(V3~V1+V2, res, sum))
# V1 V2 V3
# 1 direct cpc 4
# 2 organic direct 1
# 3 cpc email 11
# 4 cpc organic 3
library(igraph)
g <- graph_from_data_frame(setNames(res, c("source", "target", "weight")))
plot(
g,
edge.width = plotrix::rescale(E(g)$weight, c(1,5)),
edge.label = E(g)$weight
)
您可能还想查看包channelAttribution
以了解归因建模。