Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ruby client library for accessing google analytics feeds

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 .yardopts
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 google_analytics_feeds.gemspec
README.rdoc

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.

Installation

gem install google_analytics_feeds

Usage

require 'google_analytics_feeds'

# Define your report. Reports are built up like an ActiveRecord or 
# Sequel::Dataset query.
report = GoogleAnalyticsFeeds::DataFeed.new.
  profile(123456).
  dimensions(:visitor_type).
  metrics(:visits)

# Create a session and login. You can optionally pass a
# Faraday::Connection to +new+ to use a different adapter, deal 
# with proxies etc.
session = GoogleAnalyticsFeeds::Session.new
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.
  end
end

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

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

# Or an instance (if you needed to pass things to the constructor)
session.fetch_report(report, StdoutRowHandler.new)

For detailed documentation on how to use the Google Analytics Data Feeds, see Google's documentation: developers.google.com/analytics/devguides/reporting/core/v2/gdataReferenceDataFeed

TODO

  • More tests, documentation.

  • Access to the management data feed.

  • Auto-follow of paginated result sets.

Versioning

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

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

Something went wrong with that request. Please try again.