My Google Analytics Time Series Shiny App (Alpha)

There are many Google Analytics dashboards like it, but this one is mine:

My Google Analytics Time Series App

Its a bare bones framework where I can start to publish publicly some of the R work I have been learning over the past couple of years. 

It takes advantage of an Alpha of Shinyapps, which is a public offering of R Shiny, that I love and adore. 

At the moment the app has just been made to authenticate and show some generic output, but I plan to create a lot more interesting plots/graphs from it in the future.

How To Use It

  1. You need a Google Analytics account.  
  2. Go to
  3. You'll see this screen.  Pardon the over heavy legal disclaimers, I'm just covering my arse.  I have no intention of using this app to mine data, but other's GA apps might, so I would be wary giving access to Google Analytics for other webapps, especially now its possible to add users via the management API.
  4. Click the "GA Authentication" link.  It'll take you to the Google account screen, where you say its ok to use the data (if it is), and copy-paste the token it then displays.
  5. This token allows the app (but not me) process your data.  Go back to the app and paste the token in the box.
  6. Wait about 10 seconds, depending on how many accounts you have in your Google Analytics.
  7. Sometimes you may see "Bad Request" which means the app is bad, and the GA call has errored.  If you hard reload the page (on Firefox this is SHIFT + RELOAD), you need to reauthenticate starting from step 2 above. Sorry.
  8. You should now see a table of your GA Views on the "GA View Table" tab.  You can search and browse the table, and choose the account and profile ID you want to work with via the left hand drop downs. Example using Sanne's Copenhagenish blog:
  9. If you click on "Charts" tab in the middle, you should see some Google Charts of your Visits and PageViews. Just place holders for now.
  10. If you click on the "Forecasts" tab you should see some forecasting of your visits data.  If it doesn't show, make sure the date range to the far left covers 70 days (say 1st Dec 2013 to 20th Feb 2014). 
  11. The Forecast is based on Holt-Winters exponential smoothing to try and model seasonality.  The red line is your actual data, the blue the model's guess including 70 days into the future. The green area is the margin of error to 50% confidence, and the Time axis shows number of months.  To be improved.
  12. Under the forecast model is a decomposition of the visits time series. Top graph is the actual data, second is the trend without seasonal, third graph the 31 data seasonal trend and the forth graph is the random everything else.
  13. In the last "Data Table" tab you can see the top 1000 rows of data.

That's it for now, but I'll be doing more in the future with some more exciting uses of GA data, including clustering, unsupervised learning, multinomial regression and sexy stuff like that.

Update 24th Feb

I've now added a bit of segmentation, with SEO and Referral data available trended, forecasted and decomposed.

6 responses
I've been doing a very similar project to this and love web app setup. Would you mind sharing your code for the creation of ggplot2 graphics using Holt-Winters forecasting? I've been unable to get ggplot2 to interface with ts or Holt-Winter objects.
Hi LinMod - sure I found it on the web myself from somewhere, but here is a Gist of it for your own use. ggplot doesn't handle time series, so you have to turn the dates into characters or numeric. I changed the function to add some config options at the top, and to return a list of things you may need, so the plot itself is found by: myHWplot
This is amazing work on how Shiny can leverage the GA API to pull data. Any chance you putting this project on Github? I am building a similar project and curious on how you are pulling the data (i am using rga from Skardhamar). Thanks
Dear Chris, thank you for your kind words. I have toyed with putting at least the GA connector to Shiny up on github, the problem is its a very messy hacked version as I needed to tweak the rga functions to support authentication through the browser. It also involved stripping out the nice method style of rga functions and making them all Shiny reactive functions, so as soon as you update rga it all breaks. I'll take another look and see if it can be made upgrade friendly. In the meantime though I have met up with rga's author, Bror, as we are both living in Copenhagen, and perhaps with his support we can add a fork to rga to support Shiny? I'll mention it next time we have a coffee. I look back at this app now and see it as very alpha, once my current project is done I plan to come back and move this to using ggvis, improve the stats etc, so watch this space! Yours sincerely, Mark
Hi, I am unable to found the GA authentication code link on the landing page. Its showing the Please visit the link but the link is not there. Can you please help me on the same? Thanks
Dear Ritesh, thanks for dropping by :) I just tried the app and it was working ok for me, perhaps send a screenshot to one of my accounts above? And we're talking about this one, right? - not the one I just did: I'm going to upgrade the authentication method soon as I've learnt a much smoother way as used in the new app since this older app 12 months ago :)