Is there an R package that connects to the Google Analytics API? Does anyone have any pointers otherwise?
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:
export the data i need from the GA main panel. GA delivers your data in XML.
parse the raw data using the XML library (not part of the base distro, but available on CRAN)
(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.
It would be fairly simple to create a wrapper using the RCurl and XML packages (very similar to the nytR or RGoogleDocs packages).
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
I'm actually building one now, i'll aim to get it onto CRAN as soon as possible
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