Learn R Programming

RGA (version 0.4.2)

RGA-package: A Google Analytics API client for R

Description

A package for extracting data from Google Analytics API into R.

Arguments

Key features

  • Support for OAuth 2.0 authorization;
  • Access to the following Google Analytics APIs:
  • Access to all the accounts which the user has access to;
  • API responses is converted directly into R as a data.frame;
  • Auto-pagination to return more than 10,000 rows of the results by combining multiple data requests.
To report a bug please type: utils::bug.report(package = "RGA").

Useage

Once you have the package loaded, there are 3 steps you need to use to get data from Google Analytics:
  1. Authorize this package to access your Google Analytics data with the authorize function;
  2. Determine the profile ID which you want to get access to with the list_profiles function;
  3. Get the results from the API with one of these functions: get_ga, get_mcf or get_realtime.
For details about this steps please type into R: browseVignettes(package = "RGA")

Bug reports

Before posting a bug please try execute your code with the with_verbose wrapper. It will be useful if you attach verbose output to the bug report. For example: httr::with_verbose(list_profiles()) Post the traceback() output also may be helpful. To report a bug please type into R: utils::bug.report(package = "RGA")

Examples

Run this code
## Not run: 
# # load package
# library(RGA)
# # get access token
# authorize()
# # get a GA profiles
# ga_profiles <- list_profiles()
# # choose the profile ID by site URL
# id <- ga_profiles[grep("http://example.com", ga_profiles$website.url), "id"]
# # get date when GA tracking began
# first.date <- firstdate(id)
# # get GA report data
# ga_data <- get_ga(id, start.date = first.date, end.date = "today",
#                   metrics = "ga:users,ga:sessions",
#                   dimensions = "ga:userGender,ga:userAgeBracket")
# ## End(Not run)

Run the code above in your browser using DataLab