Only the Linux version of the updated package is here , but for Windows users (like say 80% of the USERs) you can just source the 2 R files within the package sub structure after unzipping the downloaded tar.z file TWICE. The package takes care of taking you to the correct link for authentication after the line access_token <- query$authorize(), you need to
1) sign in to your Google account
2) click grant access (blue button)
3) click exchange tokens (blue button)
4) paste the access token at the prompt specified within the R console
access tokens stay active for 3600 seconds !
query <- QueryBuilder()
access_token <- query$authorize()
ga <- RGoogleAnalytics()
ga.profiles <- ga$GetProfileData(access_token)
query$Init(start.date = "2012-06-18",
end.date = "2012-12-18",
dimensions = "ga:date,ga:pagePath",
metrics = "ga:visits,ga:pageviews,ga:timeOnPage",
sort = "ga:visits",
max.results = 99,
table.id = paste("ga:",ga.profiles$id,sep="",collapse=","),
# 4. Make a request to get the data from the API
ga.data <- ga$GetReportData(query)# 5. Look at the returned data
Created by Pretty R at inside-R.org
Interested in using R for Web Analytics? Use it from here http://code.google.com/p/r-google-analytics/
Great work by the Google team (Michael Pearmain et al) and Tatvic team working together!
Due to changes in Google APIs my earlier post on using Google Analytics in R is deprecated. Unfortunately it is still on top 10 results for Google results for Using Google Analytics with R.
That post is here https://decisionstats.com/2012/03/20/using-google-analytics-with-r/
A more updated R package on Google Analytics and R is here . https://github.com/skardhamar/rga
A better updated post on an easy to use tutorial on using Google Analytics with R using OAuth 2 playground is here.
- Set the Google analytics query parameters for preparing the request URI
- Get the access token from Oauth 2.0 Playground
- Retrieve and select the Profile
- Retrieving GA data
Note it is excellent for learning to use RJSON method as well. You can see the details on the Tatvic blog above.
Hat tip- Vignesh Prajapati
The awesome Hadley Wickham has just released the next version of httr package. Prof Hadley is currently on leave from Rice Univ and working with the tremendous geeks at R Studio . New things in the httr package-
httr, a package designed to make it easy to work with web APIs. Httr is a wrapper around RCurl, and provides:
- functions for the most important http verbs:
- support for OAuth 1.0 and 2.0. Use
oauth2.0_token to get user tokens, and
sign_oauth2.0to sign requests. The demos directory has six demos of using OAuth: three for 1.0 (linkedin, twitter and vimeo) and three for 2.0 (facebook, github, google).
I especially like the OAuth functionality as I occasionaly got flummoxed with existing R OAuth packages , and this should hopefully lead to awesome new social media analytics posts by the larger R blogger community. Also given the fact that unauthenticated API requests to Twitter are greatly expanded by OAuth authenticated requests- (see https://dev.twitter.com/docs/rate-limiting )
- Unauthenticated calls are permitted 150 requests per hour. Unauthenticated calls are measured against the public facing IP of the server or device making the request.
- OAuth calls are permitted 350 requests per hour and are measured against the oauth_token used in the request.
some creative use cases should see an incredible amount of cross social media analysis (not just one social media channel ) at a time.
R for Social Media Analytics ? Watch this space.. 😉