Giter VIP home page Giter VIP logo

analytics-reporter's Introduction

Analytics Reporter

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.

Installing

  • Install through npm:
npm install -g analytics-reporter
  • 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, and transform it into a .pem file:

openssl pkcs12 -in <name of your p12 key>.p12 -out secret_key.pem -nocerts -nodes
  • Set the following environment variables:
export ANALYTICS_REPORT_EMAIL="[email protected]"
export ANALYTICS_REPORT_IDS="ga:XXXXXX"
export ANALYTICS_KEY_PATH="/path/to/secret_key.pem"

You may wish to manage these using autoenv.

  • Test your configuration by printing a report to STDOUT:
./bin/report users

If you see a nicely formatted JSON file, you are all set.

  • (Optional) Authorize yourself for S3 publishing.

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

Use

Reports are created and published using the analytics command.

analytics

This 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 .gov sites tracked by the U.S. federal government's Digital Analytics Program."
  },
  "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"
  }
}

Options

  • --output - Output to a directory.
analytics --output /path/to/data
  • --publish - Publish to an S3 bucket. Requires AWS environment variables set as described above.
analytics --publish
  • --only - only run one report.
analytics --only devices
  • --slim -Where supported, use totals only (omit the data array). Only applies to JSON, and reports where "slim": true.
analytics --only devices --slim
  • --csv - Gives you CSV instead of JSON.
analytics --csv
  • --frequency - Limit to reports with this 'frequency' value.
analytics --frequency=realtime
  • --debug - Print debug details on STDOUT.
analytics --publish --debug

Public domain

This 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.

analytics-reporter's People

Contributors

konklone avatar ramirezg avatar geramirez avatar

Watchers

James Cloos avatar MK Tantum avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.