GA Effect is a webapp that uses Bayesian structural time-series to judge if events happening in your Google Analytics account are statistically significant. Its been well received on Twitter and how to use it is detailed in this guest post on Online Behaviour, but this blog will be about how to build your own or similar.
Update 18th March: I've made a package that holds a lot of the functions below, shinyga. That may be easiest to work with.
What R can do
Now is a golden time for the R community, as it gains popularity outside of its traditional academic background and hits business. Microsoft has recently bought Revolution Analytics, an enterprise solution of R so we can expect a lot more integration with them soon, such as the machine learning in their Azure platform.
For the GA Effect app, the key components were these R packages:
- Shiny, ShinyDashboard and ShinyApps for the web interaction and themes
- Dygraphs for the nice plots
- rga() for the Google Analytics connection
- CausalImpact for the statistics
Putting them together
Web InteractionFirst off, using RStudio makes this all a lot easier as they have a lot of integration with their products.
The Shiny code then creates the UI for the app, and creates reactive versions of the datatables needed for the plots.
The Google authentication flow uses OAuth2 and could be used for any Google API in the console, such as BigQuery, Gmail, Google Drive etc. I include the code used for the authentication dance below so you can use it in your own apps:
Fetching Google Analytics Data
Once a user has authenticated with Google, the user token is then passed to rga() to fetch the GA data, according to which metric and segment the user has selected.
This is done reactively, so each time you update the options a new data fetch to the API is made. Shiny apps are on a per user basis and work in RAM, so the data is forgotten once the app closes down.
Doing the StatisticsYou can now manipulate the data however you wish. I put it through the CausalImpact package as that was the application goal, but you have a wealth of other R packages that could be used such as machine learning, text analysis, and all the other statistical packages available in the R universe. It really is only limited by your imagination.
Here is a link to the CausalImpact paper, if you really want to get in-depth with the methods used. It includes some nice examples of predicting the impact of search campaign clicks.
Here is how CausalImpact was implemented as a function in GA Effect: