|
Project Information
Featured
Downloads
|
OverviewThis project provides access to Google Analytics data natively from the R Statistical Computing programming language. You can use this library to retrieve an R data.frame with Google Analytics data. Then perform advanced statistical analysis, like time series analysis and regressions. Supported Features
Get The LibraryGet the latest library from the download section or checkout the source In the R folder, there are 2 files, QueryBuilder.R and RGoogleAnalytics.R. These are the main library files. To load the libraries within your application use: source("./RGoogleAnalytics.R")
source("./QueryBuilder.R")where the parameter to source is the location of each file on your machine. Before You BeginIf you haven't already, download a version of R from the R project home page. This projects depends on 2 libraries. They can both be downloaded from http://www.omegahat.org/R.
install.packages("RCurl", repos = "http://www.omegahat.org/R")
install.packages("XML", repos = "http://www.omegahat.org/R")If errors occur when downloading/installing Rcurl or XML packages, ensure the libcurl and libxml libraries are up to date. On a Linux machine, you can run:
Getting StartedOnce everything is configured it's a snap to get Google Analytics Data! Here's an Example: # 1. Create a new Google Analytics API object
ga <- RGoogleAnalytics()
# 2. Authorize the object with your Google Analytics Account Credentials
ga$SetCredentials("INSERT_USER_NAME", "INSERT_PASSWORD")
# 3. Get the list of different profiles, to help build the query
profiles <- ga$GetProfileData()
# 4. Build the Data Export API query
query <- QueryBuilder()
query$Init(start.date = "2010-05-01",
end.date = "2010-08-20",
dimensions = "ga:date",
metrics = "ga:visitors",
sort = "ga:date",
table.id = profiles[1])
#5. Make a request to get the data from the API
ga.data <- ga$GetReportData(query)
#6. Look at the returned data
head(ga.data$data)Additional Reference InformationGoogle Analytics provides over 170 dimensions and metrics which you can access through the API. See the:
|