This site is intended to provide a (hopefully growing) list of standalone examples of using Google Analytics with R.

Target user: primarily, analysts who are using Google Analytics and starting to dip their toe into the R waters and, along the way, are wishing they had some standalone examples that they can quickly get to work, after which they can then start tinkering with them to meet their specific needs.

This site is not a tutorial on how to use R. There IS a great site for that, though – the parent site of this site!

Key Tenets of the Site

These are partly to drive consistency (“Once I’ve gotten one example to work, I can totally get any of these examples to work.”), but also, admittedly, are driven by the personal preferences of the site owner:

Example Structure

Unless it just makes no sense, each example follows the same structure:

  1. Setup/Config – loading of packages, configuring of variables, authorization of Google Analytics; this is pretty redundant across many of the examples, but it’s required to make each page a standalone example
  2. Data Pulling – the actual call(s) to pull in Google Analytics data
  3. Data Munging – manipulation of the data as warranted
  4. Data Visualization – (usually) one visualization of the resulting data

Initial Setup

The steps listed on the Initial Setup page are required in order for the example code to work. Don’t skip that!

Using the Code

Each page has blocks of code that are shaded gray. If you copy each of the blocks of code – one after the other – into an R script, the example should then run.

Making Requests or Reporting Bugs

To request an example or report an issue with one of the existing examples, log an issue on the Github repository for this site.


This site is a sub-site to dartistics.com