20

Is there an R package that connects to the Google Analytics API? Does anyone have any pointers otherwise?

11 Answers 11

17

http://code.google.com/p/r-google-analytics/

This package is now available

3
  • 4
    Great work, now submit it to CRAN.
    – Shane
    Nov 29, 2010 at 14:55
  • 1
    (Since there's not really any other way to say this, it looks like you have two different accounts setup - you may want to put in a request to have your accounts merged.) Jun 24, 2011 at 15:37
  • There is now a copy of CRAN Sep 22, 2014 at 14:37
7

Well, there's one option (that i am aware of) for explicitly connecting the two (Google Analytics & R).

This option requires R-DCOM (an interface to COM and DCOM to access R); you can get that here.

So i guess this is limited to Windows/.NET and C# (or any .NET language, i suppose).

I haven't used it (incompatible OS) but i have set it up for someone else; at least install & set-up are fairly straightforward:

  • install DCOM

  • then config--begin by executing the "dcomcnfg" in the console window

  • this launches a component mgr; search StatConnectorSrv in DCOM components for 'properties'

  • update the permissions--done.

There's a also complete tutorial, source code included (C#), for DCOM setup/install and building a small App that has programmatic access to Google Analytics and R, available here.

But if all you want to do is get the data into R, all the pieces you need are readily available, e.g., my workflow:

  1. export the data i need from the GA main panel. GA delivers your data in XML.

  2. parse the raw data using the XML library (not part of the base distro, but available on CRAN)

  3. (also pretty obvious) i store my data in an R dataframe (for analysis only, later it's broken up into tables and stored in a PostgreSQL database, using the RPostgreSQL package, which provides the drivers and R interface (DBI) to the pg database).

Lastly, it's not GA but another Google data resource with an R interface: the Omega Project has a fairly new R Package that provides an interface to GoogleTrends (called 'RGoogleTrends'), available here.

3
  • Doug, I think we spell it 'RPostgreSQL' not 'R-PostGreSQL' :) Apr 4, 2010 at 17:59
  • Yes, thanks Dirk, editing now. Perhaps because i am not a native English speaker, words which have capital letters in the middle are a constant source of confusion for me. In the future, if you find it quicker/easier, just edit my post.
    – doug
    Apr 4, 2010 at 20:16
  • so this is a correct answer but unfortunately i'm an os x user however i'll reward the thorough nature. I could export the data manual but I'd like to automate the workflow. It looks like I'll be building an R wrapper for the Google Analytics API.
    – Dan
    Apr 6, 2010 at 2:19
6

I've put an updated version of the original r-google-analytics package on github: https://github.com/JerryWho/rgoogleanalytics Here I've changed to version 2.4 of the API. The older version just used v2.3 which doesn't work since summer any more.

1
5

I'm actually building one now, i'll aim to get it onto CRAN as soon as possible

3
  • 1
    Wonderful! Once you'll get it ready, I'f be very glad to know about it (and maybe write about it on r-statistics.com): [email protected]
    – Tal Galili
    Jul 14, 2010 at 14:11
  • 1
    Very excited to see this as it develops!
    – Btibert3
    Jul 28, 2010 at 5:16
  • 1
    Thanks Tal, that will be fantastic! Aug 13, 2010 at 12:26
4

A new package has just been announced:

http://github.com/sorenmacbeth/googleanalytics4r

3

The Google Analytics API site has an example on how to retrieve analytics data using curl http://code.google.com/intl/fi-FI/apis/analytics/docs/gdata/2.0/gdataProtocol.html so supposedly you should be able to modify the examples and use Rcurl to retrieve the data.

There is a nice python package for getting data from GA that might give you some hints: http://github.com/clintecker/python-googleanalytics

3

There is a recently released R library on CRAN that enables Google Analytics Data extraction into R. It supports Google Analytics Core Reporting API v3 and uses OAuth2.0 under the hood for Authorization. You may be able to install the library via

install.packages("RGoogleAnalytics")

Or in case if you want the development version from Github you can try

require(devtools)
devtools::install_github("Tatvic/RGoogleAnalytics")
1
  • I've edited my response by excluding the link and providing specific information on the R library requested by the OP.
    – kushan_s
    Sep 7, 2014 at 6:14
2

It would be fairly simple to create a wrapper using the RCurl and XML packages (very similar to the nytR or RGoogleDocs packages).

1
  • 3
    " fairly simple " depends on who is creating the wrapper...
    – Tal Galili
    Jun 3, 2010 at 8:36
2

Just to give an update, i've now created the base script, which currently does the following:

Create a new export object. Authenticate with your Google Account. Return an account profile for an authorised Google Account. Create a new API query Use the query to return a data.frame populated with metrics.

I've also built in some low level error handling of the parameter types, but on some of the more complex parameters like segment, i've left the errors to the GA API.

I just need to build out the unit tests and package this up, and we should be good to go.

Mike

1
  • 1
    link to it when you can please.
    – erikvold
    Aug 13, 2010 at 1:31
2

I've found another R-package for Google Anayltics: http://skardhamar.github.com/rga/ It uses OAuth2 for authentication. I haven't tried it yet. But maybe that's the newest package out there.

1

There seems to be another Google Analytics-R package: https://github.com/jdeboer/ganalytics/blob/master/README.md I haven't tried it yet.

1
  • The ganalytics package is now available on CRAN and has interoperability with the googleAnalyticsR package which is also on CRAN. The former package makes it easy to dynamically define Google Analytics segments and filters. The latter offers the latest Google Analytics API features, including cohort analysis.
    – johannux
    Jan 12, 2019 at 8:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.