Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
87 lines (61 sloc) 2.96 KB

Google Analytics Feeds

Allows access to Google Analytics feeds from Ruby.

Does not support any of the OAuth-related authentication methods, only session login.

It tries to be really simple, returning rows as Hashes rather than specific objects, and provides flexibility as to how you want to make HTTP calls via Faraday.

Tested on 1.9, 1.8 & Rubinus; depends on Ox, which has C dependencies so not tested on JRuby.


gem install google_analytics_feeds


require 'google_analytics_feeds'

# Define your report. Reports are built up like an ActiveRecord or 
# Sequel::Dataset query.
report =

# Create a session and login. You can optionally pass a
# Faraday::Connection to +new+ to use a different adapter, deal 
# with proxies etc.
session =
session.login("username", "password")

# Fetch a report. Rows are handled with a 
# GoogleAnalyticsFeeds::RowHandler - this may just be an anonymous
# block as demonstrated here.
session.fetch_report(report) do
  def row(r)
    puts r.inspect # => outputs the row as a hash.

# Or you can pass a RowHandler class
class StdoutRowHandler < GoogleAnalyticsFeeds::RowHandler
  def row(r)
    puts r.inspect

# Either takes the class
session.fetch_report(report, StdoutRowHandler)

# Or an instance (if you needed to pass things to the constructor)

For detailed documentation on how to use the Google Analytics Data Feeds, see Google's documentation:


  • More tests, documentation.

  • Access to the management data feed.

  • Auto-follow of paginated result sets.


Patch-level releases will not change the API. Minor releases may make breaking changes to the API until a 1.0 release.

Contributing to google_analytics_feeds

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.

  • Fork the project.

  • Start a feature/bugfix branch.

  • Commit and push until you are happy with your contribution.

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright © 2012 Roland Swingler. See LICENSE.txt for further details.