Google Analytics superProxy

This page demonstrates the Google superProxy in action, showing live data from Google Analytics for this site, on this page.

What is the Google superProxy and why is it useful, how does it work?

  • Allows Public access to your Google Analytics data
  • The superProxy can be used to power custom dashboards (like this simple one below!)
  • Convert to Google Analytics data to CSV, Data Tables for graphing or TSV files for export
  • Relative dates are supported (e.g. last 7 days) in the query URI
  • Automatically refreshing of the reported data
  • Intelligent Caching – for fast worldwide responses and efficient quota usage

The superProxy code is written in Python and can be obtained from GitHub. Don’t worry there’s nothing you need to do other than download a few files (the code, Python itself so you can run the code, and the App Engine SDK so you can create the web application later on), register your application/service in the Google API Console and fire up the Google App Engine launcher.

You’ll need to get the latest Python distribution – and install it – and if it goes wrong you may need to reboot Windows 8 a few times…

Then get the Google App Engine SDK for Python (there’s an experimental version of the App Engine for PHP coders too… but as the superProxy code is written in Python, best get that one 🙂 )

What we are aiming for, is to run the superProxy web application locally to start with, to test it before deploying it to Google’s App Engine service.

So, next, go to the Google API Console to create a new project – and give your newly created project access to the Google Analytics API. You’ll also need to create an OAuth2 Client ID for the web application, then copy the secret keys and app name to the superProxy configuration files. This lets your superProxy use your project OAuth2 authentication to connect to Google Analytics accounts later…

You need to copy the clientID, clientSecret and the redirection URI entry that comes from the console into the file in the /src directory of the superProxy code.

Now you can add the superProxy project to the Google App Engine Launcher and run it! Once running, you can use the service locally by visiting /localhost:8080/admin in a browser.

If all is well, when you run the superProxy code locally, you will be asked to connect to your GA account, then be taken to the administration page. It is here that you create the URIs which are then used to interrogate the Google Analytics account.

Google superProxy interface

Once you have devised a URI call to get the data you need from GA, it can be saved for future use – where ‘future use’ means the call can be used to service a published endpoint (URI) for use in other applications (such as this WordPress site).

The advantage of using the superProxy is that the underlying call to GA is hidden, the details are hidden away inside the superProxy. The URI request is a call to the superProxy instead, and the superProxy takes the decision whether to make the call to Google Analytics or provide the data it already has from it’s cache.

To make your superProxy a public service, you next need to create an application ID (which gives you a hostname on ). The Google App Engine application ID can then be added to the superProxy config file app.yaml

application: your-application-id

Once this is done, the console redirection URLs can be changed from /localhost (the local test environment) to the now publically available location:

Finally… use the Google App Engine Launcher to help deploy the superProxy code to the web.

The pie chart above is updated hourly, with actual referrer statistics to this site, pulled from Google Analytics via the superProxy running in the Google App Engine world… and breathe.

One thought on “Google Analytics superProxy

Leave a Reply

Your email address will not be published. Required fields are marked *