Translation of Using Google Analytics with R (Michal Brys)

  • Tutorial
The “Using Google Analytics with R” (Michal Brys) e-book is a practical guide to analyzing data from Google Analytics in R. It was written by a data scientist in 2014, but does not lose its relevance today.


We are currently swimming in a “data lake”. Only if you know how to use this data will you stay on the surface. The first step is to regularly check the standard reports in the web analytics tool (Google Analytics).

But to stay competitive, you need something more. Everyone is talking about data collection. But only a few know what to do with the data after it is collected. I will try to describe this process and give you some ideas on how to work with data from Google Analytics using R.

R is a programming language for statistical data processing and graphics, as well as a free open-source computing environment within the GNU project. It was developed by Ross Ihaka and Robert Gentleman of the University of Auckland University of Statistics .


The main advantages of the R language:

  • free;
  • many libraries are available for various statistical calculations;
  • current list of packages. A lot of training materials (study guides, MOOCs, blogs) are available for free on the Internet;
  • Has a large community of specialists (Russian-speaking is still small);
  • ready to run on different platforms (Windows, Mac, Unix). A server installation version is also available;
  • fast because it works in memory mode.

The author of the article has been working in the Internet industry since 2009, is an expert in the field of web analytics in e-commerce, especially using Google Analytics and Google Tag Manager, and is also a member of the Google development team in Krakow (Poland).


Thanks to this book, I met R. It is written for marketers who have worked with Google Analytics and know the basic metrics included in this tool and know the web interface.

The book uses R Studio (a free open source software development environment for the R programming language), as well as various packages, such as googleAnalyticsR, googleAuthR, RGoogleAnalytics, ggplot2, plotly, tidyverse, forecast, reshape2 .


Book's contents:

  • Introduction
  • What for?
  • About Google Analytics
  • About R
  • about the author
  • Environment preparation
  • Data sources
  • Create a Google Analytics Account
  • Retrieve credentials for the Google Analytics API
  • Installing a Google Analytics Counter on a Website
  • Install R Studio
  • First steps
  • Introduction to R
  • Link to Google Analytics
  • GoogleAnalyticsR package
  • Import and export data in .CSV
  • Code repository
  • Exploration Data Analysis (EDA)
  • Data visualization in R
  • Traffic Heatmap
  • Device comparison
  • Machine learning
  • Clustering (k-means method)
  • Report Building
  • Introduction to R Markdown
  • Report Creation
  • Additional analysis
  • Anomaly Detection
  • Forecasting
  • Resources (blogs, documentation, online training, books)

Download the book in .pdf format

Since the book was written in 2014, some things have changed over the past 5 years. For example, the Google Analytics code (gtag.js) was updated, the interface, some commands in the R libraries were changed. During the translation process, I myself checked the code, ran the programs, and made corrections where necessary. Therefore, the data from the original book may be slightly different from my translation.

If you find errors and have comments on the translation, write to me at . Thanks also possible =)

Also popular now: