The latest stable version of googleAnalyticsR is available on CRAN. CRAN

You also need the version > 0.3.0 of googleAuthR


Development version off github

You may prefer to use the latest development version is on github which you can install via the below.

Github check status: Travis-CI Build Status


Check out the NEWS to see whats currently available in each version.


## setup

## This should send you to your browser to authenticate your email.
## Authenticate with an email that has access to the Google Analytics View you want to use.

## get your accounts
account_list <- google_analytics_account_list()

## pick a profile with data to query
ga_id <- account_list[23,'viewId']

Should you need to authenticate under a new user, use ga_auth(new_user=TRUE)


From version 0.4 (currently on Github) you can choose to auto-authenticate by moving your .httr-oauth or by creating a Google OAuth service account JSON file.

Once you have set the environment variable GA_AUTH_FILE to a valid file location, the function will look there for authentication details upon loading the library meaning you will not need to call ga_auth() yourself as you would normally.

You can set environment variables using a .Renviron file or via the function Sys.setenv()

An example .Renviron file is below - this is placed in your root directory (~/ or C:\\)

GA_AUTH_FILE = "/Users/bob/auth/googleAnalyticsR.httr-oauth"

GA_AUTH_FILE can be either the file path to a .httr-oauth token generated by gar_auth() or your own Google Project’s service account JSON ending with file extension .json

If you use the service account JSON, you will also need to add the service account email via your Google Analytics admin as a user to see data e.g.

Meta data

To see what dimensions and metrics are available via the API, you can use this command:

## get a list of what metrics and dimensions you can use
meta <- google_analytics_meta()

If offline, from v0.2.0 this data is also available offline by typing meta, although it won’t be quite as up to date.

The meta data does not include multi-channel as they are not available to download, for those see the online version.

When using the library, you can call metrics and dimensions with or without the ga: prefix (mcf: for multi-channel metrics/dimensions.)

Multiple API authentication

If you are using more than one API for authentication (such as Search Console), then authenticate using googleAuthR::gar_auth() instead, to ensure you are authenticate with the correct scopes.

Using your own Google Developer Project API Key

With the amount of API calls possible with this library via batching and walking, its more likely the default shared Google API project will hit the 50,000 calls per day limit.

To mitigate that, use your own Google Developer Console Project key, so it is not shared across all users of this library.

Example adding your own Google Developer Console keys

Set the options before any call to ga_auth() or other data fetching calls.

options(googleAuthR.client_id = "")
options(googleAuthR.client_secret = "3JhLa_GxxxxxCQYLe31c64")
options(googleAuthR.scopes.selected = "")

In the next example, the scopes are also set so a user can authenticate with searchConsoleR at the same time, which is possible as they both use googleAuthR as a backend.

options(googleAuthR.client_id = "")
options(googleAuthR.client_secret = "3JhLa_GxxxxxCQYLe31c64")
options(googleAuthR.scopes.selected = c("",

If you want to use with Shiny, then set the webapp clientId/secrets.

options(googleAnalyticsR.webapp.client_id = "")
options(googleAnalyticsR.webapp.client_secret = "zcofxxxxxxElemXN5sf")

Copyright (c) 2016 Sunholo Ltd. Released under MIT license.