| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This project is still under construction.
A lightweight system for publishing analytics data from Google Analytics profiles.
Available reports are named and described in reports.json. For now, they're hardcoded into the repository.
npm install -g analytics-reporterIf you're developing locally inside the repo, npm install is sufficient.
Create an API service account in the Google developer dashboard.
Take the generated client email address (ends with gserviceaccount.com) and grant it Read & Analyze permissions to the Google Analytics profile(s) whose data you wish to publish.
Download the .p12 private key file from the dashboard. Copy the password Google shows you (you will only need it once).
Transform the p12 file into a .pem file, entering the password when asked:
openssl pkcs12 -in <name of your p12 key>.p12 -out secret_key.pem -nocerts -nodesVisit the "APIs" section of the Google Developer Dashboard for your project, and enable it for the "Analytics API".
Set environment variables for your app's generated email address, and for the profile you authorized it to:
export ANALYTICS_REPORT_EMAIL="YYYYYYY@developer.gserviceaccount.com"
export ANALYTICS_REPORT_IDS="ga:XXXXXX"You may wish to manage these using autoenv. If you do, there is an example.env file you can copy to .env to get started.
To find your Google Analytics view ID:
To specify a file path:
export ANALYTICS_KEY_PATH="/path/to/secret_key.pem"
To specify the key directly, paste in the contents of the .pem directly and exactly, in quotes (below example has been sanitized):
export ANALYTICS_KEY="Bag Attributes
friendlyName: privatekey
localKeyID: [your key id]
Key Attributes: <No Attributes>
-----BEGIN PRIVATE KEY-----
[contents of your key]
-----END PRIVATE KEY-----"
Make sure your computer or server is syncing its time with the world over NTP. Your computer's time will need to match those on Google's servers for the authentication to work.
Test your configuration by printing a report to STDOUT:
./bin/analytics usersIf you see a nicely formatted JSON file, you are all set.
If you plan to use this project's lightweight S3 publishing system, you'll need to add 6 more environment variables:
export AWS_REGION=us-east-1 export AWS_ACCESS_KEY_ID=[your-key] export AWS_SECRET_ACCESS_KEY=[your-secret-key] export AWS_BUCKET=[your-bucket] export AWS_BUCKET_PATH=[your-path] export AWS_CACHE_TIME=0
If you use a single domain for all of your analytics data, then your profile is likely set to return relative paths (e.g. /faq) and not absolute paths when accessing real-time reports.
You can set a default domain, to be returned as data in all real-time data point:
export ANALYTICS_HOSTNAME=https://konklone.com
This will produce points similar to the following:
{
"page": "/post/why-google-is-hurrying-the-web-to-kill-sha-1",
"page_title": "Why Google is Hurrying the Web to Kill SHA-1",
"active_visitors": "1",
"domain": "https://konklone.com"
}Reports are created and published using the analytics command.
analyticsThis will run every report, in sequence, and print out the resulting JSON to STDOUT. There will be two newlines between each report.
A report might look something like this:
{
"name": "devices",
"query": {
"dimensions": [
"ga:date",
"ga:deviceCategory"
],
"metrics": [
"ga:sessions"
],
"start-date": "90daysAgo",
"end-date": "yesterday",
"sort": "ga:date"
},
"meta": {
"name": "Devices",
"description": "Weekly desktop/mobile/tablet visits by day for all sites."
},
"data": [
{
"date": "2014-10-14",
"device": "desktop",
"visits": "11495462"
},
{
"date": "2014-10-14",
"device": "mobile",
"visits": "2499586"
},
{
"date": "2014-10-14",
"device": "tablet",
"visits": "976396"
},
// ...
],
"totals": {
"devices": {
"mobile": 213920363,
"desktop": 755511646,
"tablet": 81874189
},
"start_date": "2014-10-14",
"end_date": "2015-01-11"
}
}analytics --output /path/to/dataanalytics --publishanalytics --only devices
analytics --only devices,todayanalytics --only devices --slimanalytics --csvanalytics --frequency=realtimeanalytics --publish --debugThis project is in the worldwide public domain. As stated in CONTRIBUTING:
This project is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the CC0 1.0 Universal public domain dedication.
All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest.
| Back | FazBrowse Home | New Git URL |