Code Monkey home page Code Monkey logo

ga-dashboard-demo's Introduction

ga-dashboard-demo

A demo on how to build your own Google Analytics dashboard with R, Shiny and MySQL

A guide blogpost here: http://markedmondson.me/enhance-your-google-analytics-data-with-r-and-shiny-free-online-dashboard-template

Live demo version here: https://mark.shinyapps.io/GA-dashboard-demo

Intro

Whilst shinyga() lets you create Shiny dashboards that anyone can connect their own GA data with, the more common use case of creating a dashboard to use just your own data is better served by this example. This template lets you clone and enter your GA id to quick start your own Shiny dashboard.

Features

  • Interactive trend graph.
  • Auto-update of GA data for last 3 years.
  • Zoomable heatmap for Day of week analysis.
  • Year on Year, Month on Month and Last Month vs same Month Last Year.
  • MySQL persistant storage for data blending your data with GA data.
  • Upload option to update MySQL data stored.
  • Analysis of impact of events on your GA data via Google's CausalImpact
  • Detection of unusual timepoints using Twitter's AnomalyDetection

Screenshots

Trend Upload to MySQL Analysis of data

To Use

  1. Clone this repository to your own RStudio project.
  2. Get your MySQL setup with a user and IP location, and the GA View ID you want to pull data from. You will also probably need to whitelist the IP of your Shiny Server. Add your local IP for testing too. If you will use shinyapps.io their IPs are:
  • 54.204.29.251
  • 54.204.34.9
  • 54.204.36.75
  • 54.204.37.78
  1. Create another file called secrets.r file in the same directory with the below content filled in with your details. This file is called in functions.r

     # secrets.r
     options(mysql = list(
     "host" = "YOUR SQL IP",
     "port" = 3306,
     "user" = "YOUR SQL USER",
     "password" = "YOUR USER PW",
     "databaseName" = "onlinegashiny"),
     rga = list(
     "profile_id" = "YOUR GA ID",
     "daysBackToFetch" = 356*3
     ),
     shinyMulti = list(
     "max_plots" = 10
     ),
     myCausalImpact = list(
     'test_time' = 14,
     'season' = 7
     ),
     shiny.maxRequestSize = 0.5*1024^2 ## upload only 0.5 MB
     )
    
  2. Install rga() if you need to, then run the below once locally in the same folder to have the app remember your GA OAuth2 settings.

     ## Run this locally first, to store the auth token.
     library(rga)
     rga::rga.open(where="token.rga")
    
  3. Run locally with shiny::runApp() or upload to your shinyapps.io account or your own Shiny server.

  4. Customise your instance.

ga-dashboard-demo's People

Contributors

markedmondson1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ga-dashboard-demo's Issues

Question about MySQL persistent data and Analytics

Hi Mark,

Thanks for your great job!

I have a doubt, It's possible to save the data from GA to a MySQL database?
I say this, because I could want to save some data and consult on my own database without query the GA API. (I think this could be more useful with others APIs, who don't let you access data for more than 3 months past, I think Facebook do it)

You think this is possible, or would be much complex?

Thanks!!

Getting Error - using atomic vector where DataFrame expected

Using ga-dashboard-demo, I was getting an error in the server.R file of using an atomic object where a DataFrame was expected ('$ is invalid for atomic vector' error). Upon debugging, I discovered removing '$anoms' from lines 79 and 173 of server.R file fixes this.

Within the two functions renderDygraph() and renderDataTable(), we want object 'anomalies' to be a data.frame and not an atomic vector since, later in those functions, we call anomalies$timestamp and anomalies$anoms. If we define anomalies <- anomalyData2()$anoms, it will only keep the column 'anoms' in memory and we won't be able to retrieve $timestamp within the function.

AnomalyDetectionTs coercing POSIXct to POSIXlt

The AnomalyDetection package as installed directly from the Twitter GitHub repo (linked within the code) causes an error when plotting the result of AnomalyDetectionTs (line 86 of functions.R) on the UI.R side since ggplot2 expects POSIXct objects rather than POSIXlt. The coercion happens under the hood of the AnomalyDetectionTs function.

To avoid this, install the following fork to avoid the implicit conversion (worked for me, haven't noticed any impact from the fork on the rest of the code):
devtools::install_github("hrbrmstr/AnomalyDetection")

anomalyData2()$plot throwing plotting error

Unsure of the following issue's reproducibility, but line 74 of server.R file through an error when using anomalyData2()$plot.

Rewriting the plot functionality using base R plot() seemed to fix this (but unsure whether it changes the intended visualization formatting), i.e.:

anomalyData2()$plot to plot(anomalyData2())

Lag period month calculation incorrect?

From John:

Thanks for the clarification, I actually saw that the month function wasn't working correctly. I corrected it by modifying the "lag_one_total/lag_two_total" code.
Here's an example of the modified code below:

  lag_one_total <- sum(data[data$period == lag_one_period &
                              year(data$date) == year(lag_time(time_period, 1)),2], 
                       na.rm=T)

By the way does the "now_period" variable serve any function? I can't seem to find its use. Also the "diff_period" variable seems to have an incomplete formula for % difference. Personally I prefer to use the formula for % change.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.