Google Analytics superProxy
The Google Analytics superProxy allows you to publicly share your Google Analytics reporting data. Use it to power your own custom dashboards and widgets, transform responses to various formats, manage your quota efficiently, test, and more. It handles authentication, caching, and response-formatting for you.
It works with the following Google Analytics APIs: Core Reporting API, Real Time Reporting API, and Multi-Channel Funnels Reporting API
Quick Links
- Video demo of the Google Analytics superProxy
- Google Analytics superProxy on the Google Analytics Developers site.
- Quota Considerations
- Google Analytics superProxy Forum (Ask questions, share Ideas, and get feedback)
Feature Highlights
- Public access to your Google Analytics data
- Use the proxy to power your own custom dashboards
- Convert to CSV, Data Table, TSV
- Relative dates are supported (e.g. last 7 days)
- Automatically refreshes report data
- Caching - fast responses and efficient quota usage
The Google Analytics superProxy is a web application that runs in the Google App Engine python environment.
Setting up a local development environment
- If necessary, download and install Python 2.7
- Download and install the App Engine SDK for Python
- Create an APIs Console Project.
- Go to the Services pane
to activate the Analytics API service.
- Go to the API Access pane
and create an OAuth 2.0 Client. For Client ID settings select
Web Application. For the hostname click more options and then add
the following to the Authorized Redirect URIs field:
http://localhost:8080/admin/auth
. Note: you may use a different port, but you need to use that port consistently throughout your project. Click on Create client ID.
- Go to the API Access pane
and create an OAuth 2.0 Client. For Client ID settings select
Web Application. For the hostname click more options and then add
the following to the Authorized Redirect URIs field:
- Edit
config.py
in the Google Analytics superProxysrc
directory. UpdateOAUTH_CLIENT_ID
,OAUTH_CLIENT_SECRET
, andOAUTH_REDIRECT_URI
with the corresponding values from the OAuth 2.0 Client you created in the previous step. The redirect URI does not need to include/admin/auth
, this will be added for you. - (Optional): The default the timezone for resolving relative dates is the
Pacific timezone. The default setting for "anonymizing" Core Reporting API
responses is set to
False
. Both of these options can be configured insrc/controllers/util/co.py
. - Add the Google Analytics superProxy app to the Google App Engine Launcher
(File->Add Existing Application) or start the app using
dev_appserver.py
. For additional details see The Development Environment. Make sure to serve the application using the same port as set in the list of Authorized Redirect URIs for your APIs Console Project, and inconfig.py
. - View the app by visiting http://localhost:8080/admin
(replace
8080
with the correct port number).
Hosting the application on App Engine
- Setup the local development environment as described above.
- Register an application ID for your application using the
App Engine Administration Console. This
will give you a free hostname on
appspot.com
. - Edit the
app.yaml
file in thesrc
directory of the Google Analytics superProxy and set the first line to the application ID you registered in the previous step. E.g.application: your-application-id
. - Edit or create a new
APIs Console Project and
add the full URL of your application +
/admin/auth
as an Authorized Redirect URI for the OAuth 2.0 Client. If using the free appspot.com domain, the redirect URI will look something likehttps://your-applciation-id.appspot.com/admin/auth
. - Edit
config.py
in the Google Analytics superProxysrc
directory and updateOAUTH_CLIENT_ID
,OAUTH_CLIENT_SECRET
, andOAUTH_REDIRECT_URI
if necessary. - Using the Google App Engine Launcher or
appcfg.py
deploy the application. For details see Uploading Your Application. - View the app by visiting the
/admin
page of your application. E.g. https://your-application-id.appspot.com/admin.
Creating your first public query
- See instructions above to get up and running, either with a local dev environment or on App Engine.
- View the application by visiting the
/admin
page. E.g. https://your-application-id.appspot.com/admin. - Follow the instructions to authenticate and authorize the application to access your Google Analytics account.
- Create a new query (a Core Reporting API query URI) and specify:
- A name for the query (e.g. Top 10 Browsers for last 7 days)
- Refresh interval - how often to update the report, in seconds (e.g. 3600 to refresh this once an hour.)
- The Query URI (e.g. https://www.googleapis.com/analytics/v3/data/ga?ids=ga:XXXX&dimensions=ga:browser;metrics=ga:visits;sort=-ga:visits&max-results=10&start-date={6daysago}&end-date={today})
- Tip: Use the Google Analytics Query Explorer to get a valid Query URI.
- Click Save & Schedule Query to save the query and start scheduling the query for automatic refresh. A new Public Request Endpoint (URL) will be created for this report.
Requests to the public endpoint URL will return the API response for the specific report created. Authorization will not be required to access the report data and it will automatically refresh.
Features
- OAuth 2.0 for authentication and it's all handled for you server side
- Multiple users - each with their own set of queries
- Automatic scheduling to refresh data at a configurable time interval
- Caching of responses (saves on quota and it's fast)
- API Query stats (last request time and number public requests)
- Transform responses to CSV, Data Table, or TSV.
- Relative dates are supported for reporting queries (e.g. last 7 days).
- Timezone for relative dates can be configured (North American timezones and UTC).
- Auto-scheduling. Scheduling for an "abandoned" API query (i.e. hasn't been publicly requested for a long time) will be automatically paused, resuming only if is subsequently requested.
- Responses can "anonymized". If enabled, then Google Analytics profile IDs and other account information is removed from the public response.
- Error logging. Errors for scheduled API queries are logged. After an API Query
(default) has 10 error responses, scheduling for the query is paused.
- The Google Analytics superProxy will not publicly return error responses. Instead the last successful response will be returned.
- Public endpoints can be enabled/disabled if you want to stop sharing.
- Queries can be be refreshed on an adhoc basis instead of waiting for the next scheduled refresh.
- JSONP (add a
callback
parameter to the Public Endpoint request URL).
Changelog
2013-07-19
- Initial launch...super sweet!
2013-08-06
- Multiple Google Charts on a single page works again! (Fixes Issue #3)
- Added a sample Google Charts HTML/JS demo.