jorgegorka edited this page May 6, 2012 · 5 revisions


Google Analytics API wrapper.

It uses Oauth2 as authorization


Add this line to your application's Gemfile:

gem 'ariadna'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ariadna


Create a new connexion with your Oauth2 access token

  analytics = Ariadna::Analytics.new(access_token)

Get a list of all accounts available

  accounts    = analytics.accounts.all

Get a list of all web properties available for an account

  properties = accounts.first.properties.all

Get a list of all profiles available for a web property

  profiles    = properties.first.profiles.all

Create a query with metrics and dimensions

  results  = profile.results.select(
        :metrics    => [:visits, :bounces, :timeOnSite],
        :dimensions => [:country]
        :start_date => Date.today,
        :end_date   => 2.months.ago,
        :browser    => "==Firefox"
      .order([:visits, :bounces])

All the metrics and dimensions returned by the query are mapped into attributes.

  results.each do |result|
    puts result.visits
    puts result.bounces
    puts result.timeOnSite
    puts result.country

More info

Table of Contents

How to test

Using rspec to test Ariadna