https://github.com/andrewn/realtime-analytics-feed
Feed of Google Realtime Analytics data
https://github.com/andrewn/realtime-analytics-feed
Last synced: about 2 months ago
JSON representation
Feed of Google Realtime Analytics data
- Host: GitHub
- URL: https://github.com/andrewn/realtime-analytics-feed
- Owner: andrewn
- Created: 2016-05-16T13:52:33.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-06T09:55:00.000Z (about 10 years ago)
- Last Synced: 2025-01-13T14:53:01.206Z (over 1 year ago)
- Language: Go
- Size: 291 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
Polls the [Google Analytics Real Time Reporting API](https://developers.google.com/analytics/devguides/reporting/realtime/v3/) every 10s for active users on a website and pushes that data via Server Sent Events.
Configuration
---
Google Analytics API credentials are supplied by a JSON file that contains the private key for a Service Account.
0. Request beta access to the [Analytics Real Time Reporting API](https://developers.google.com/analytics/devguides/reporting/realtime/v3/).
1. [Create a Service Account](https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount) for this application. The end result is a JSON file that's downloaded to you local machine.
2. In the Google Analytics Admin interface, add the `client_email` email address as a user to your Analytics account. This will give this application access to the API.
3. The JSON file can either be added as `credentials.json` in this directory or supplied as an environment variables called `CREDENTIALS_JSON` when starting the app.
Authorization
---
Set the AUTH_BASIC_USER and AUTH_BASIC_PASS env vars to require a username and password to access the event stream.
Deploy to Heroku
---
You can deploy this app to Heroku.
heroku create
git push -i heroku master
heroku config:set GA_ID="ga:12345678"
heroku config:set CREDENTIALS_JSON="`cat credentials.json`"
Visiting your heroku app URL should show the data being pushed.
Subscribe to the data source
---
This app is designed to use [Server Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) which makes it very easy to use in a web browser.
```js
var source = new EventSource('http://your-app-name.herokuapp.com/')
source.onmessage = function (evt) {
var data = JSON.parse(evt.data);
console.log('New message: ', data);
}
```