No one loves client reporting and everyone wants a better way of doing it. What would my perfect client reporting tool look like?
I've never found anything that fitted all of these criteria but now I'm starting to think I might have found something.
Org-babel is an extension to org-mode which lets you run code as you write documents. I can combine this with the amazing graph drawing capabilities of R and the Google Analytics API to start producing pretty sweet reports without tiresome data munging.
Matt Clarke over at TechPad has a good guide to getting started with R and the Google Analytics API. One part of the article is out of date (unless Matt has updated the post); the Google Analytics library he links to is out of date after the latest API changes. Instead you can use the one at https://github.com/JerryWho/rgoogleanalytics (works for me anyway). You'll also need an GA API key too.
Putting the following code in an org file will get the visits and pageviews per day for a site and then draw a fancy graph of them:
#+name: visits-pageviews-graph #+begin_src R :file /files/2012-09-24-pageviews.png :exports results :results output graphics :width 700 :height 400 library(rgoogleanalytics) library(ggplot2) ga <- RGoogleAnalytics() ga$SetCredentials("LOGIN_EMAIL", "PASSWORD", "API_KEY") query <- QueryBuilder("API_KEY") query$Init(start.date=Sys.Date()-30, end.date=Sys.Date()-1, dimensions="ga:date", metrics="ga:visits,ga:pageviews", sort="ga:date", table.id="PROFILE_ID") ga.data <- ga$GetReportData(query) d<-data.frame(ga.data$data) d$ga.date <- as.Date(d$ga.date,"%Y%m%d") pageviews <- d$ga.pageviews qplot(d$ga.date, d$ga.visits,xlab="Date",ylab="Visits", size=pageviews, color=pageviews)
It is then quite simple to write the insightful commentary that should be the most time consuming part of reporting.
The resulting report can then be exported to PDF directly. In order to get a stylish and good looking result at the end you'll have to style the template using LaTeX - this might be a bit much! I haven't got this far yet; I might try my hand at some templates in the future.
If you don't want to use org-mode there is an R package called knitr that can do the same thing. I prefer org-mode for the ease of editing text, but knitr integrates more closely with R.