#### Let's begin by installing and loading the necessary packages and libraries #### install.packages("ChannelAttribution") library(ChannelAttribution) #### Attribution models in R #### # Begin by loading Google Analytics Data (Data for July 2019 from the demo account) # ga_data.csv. Make sure you specify that rows are separated by semi-colons # Run attribution modeling for the simple rules (first, last, and linear interaction) model <- heuristic_models(ga_data,"path", "conversions", "conversion_value") #### Add data on marketing expenditure to calculate ROAS AND CPA #### # Create marketing expenditure vector based on data in Google Analytics demo account spend_vector<-c(156, 1365, 2675, 323, 98, 135, 762, 853) # Add the spend vector to the attribution model results model$spend <- spend_vector model # Calculate MROI and ROAS using the respective formulas for each model $ first_touch_MROI <- (model $ first_touch_value - model $ spend ) / model $ spend model$first_touch_ROAS <- ( model$first_touch_value) / model$spend model$first_touch_CPA <- (model$spend / model$first_touch_conversions)