Coder Social home page Coder Social logo

analytics's Introduction

Analytics

Build Status Code Climate githalytics.com alpha

A Ruby interface to the Google Analytics API.

Installation

Add this line to your application's Gemfile:

gem 'analytics-ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install analytics-ruby

Usage

Authentification

To make calls to the Google Analytics API, you have to authenticate via an API key (which you can get from the Google APIs Console. To set your API key and get started, use:

Analytics.consumer_key    = 'your key'
Analytics.consumer_secret = 'your secret'

Then you have to provide an access token ( OAuth or OAuth2 ) to manage or visualize statistics.

client = Analytics::Client.new(Analytics::OAuth.access_token('my token', 'my secret')) # With OAuth 1.x 
client = Analytics::Client.new(Analytics::OAuth.access_token('my token'))              # With OAuth 2.x 

Management

You can access to the accounts, web properties and profile from an Analytics::Client

client.accounts        # returns an array of Analytics::Account
client.web_properties  # returns an array of Analytics::WebProperty
client.profiles        # returns an array of Analytics::Profile

Reporting

You can access the report object from an Analytics::Profile

profile.report
# or 
Analytics::Report.new('profile_id', access_token) # access_token is a OAuth::AccessToken or  OAuth2::AccessToken

You can grab data with a simple DSL

report.visits(0, Time.now) # it should grab all visits from Jan 1st 1970 to now
# you can provide all metrics from google analytics ( visitors, new_visits, percent_new_visits, ... )

# you can provide a metric and a dimension
report.visits_by_month(0, Time.now)

# you can provide multiple metrics and dimensions as well
report.visists_and_visitors_by_month_and_city(0, Time.now)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

analytics's People

Contributors

alexismontagne avatar andrehjr avatar fluxusfrequency avatar

Watchers

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