Project

gareadonly

0.01
No commit activity in last 3 years
No release in over 3 years
Simple read-only wrapper for the Google Analytics API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 0

Runtime

 Project Readme

Google Analytics API Read-only

GAReadOnly is a simple wrapper to get the data out of google analytics using the API.

In order to make the gem works, you'll have few configuration steps to do in your Google API Console.

Installation

Add this line to your application's Gemfile:

gem 'gareadonly'

And then execute:

$ bundle

Or install it yourself as:

$ gem install gareadonly

Configuration

To install the initializer file execute:

$ rails g gareadonly

Usage

GAReadonly.connect
pageviews = GAReadonly.get_analytics_data({'start-date' => '2014-01-01', 'end-date' => 'yesterday', 'metrics' => 'ga:pageviews', 'dimensions' => 'ga:date'})
puts "We had #{pageviews.totalsForAllResults['ga:pageviews']} since the 2014-01-01'

To connect to the Google API, you'll need to run GAReadonly.connect. In therory you only need to run it ounce. The connection is persistant.

Currently the only query available is get_analytics_data. It takes an hash as argument. The following hash will retrieve all the page views since the begining of the year 2014 GAReadonly.get_analytics_data({'start-date' => '2014-01-01', 'end-date' => 'yesterday', 'metrics' => 'ga:pageviews', 'dimensions' => 'ga:date'})

Contributing

If You want more features, please let me know. Thanks.

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