Skip to content

Quick Start

Tony Pitale edited this page Jan 2, 2014 · 14 revisions
  1. Install gems

     > gem install legato
    
  2. Start irb

     > irb
    
  3. Require gems

     require 'legato'
    
  4. Get an OAuth2 Token. Make sure to use the scope https://www.googleapis.com/auth/analytics.readonly.

  5. Create a Model

     class Exit
       extend Legato::Model
    
       metrics :exits, :pageviews
       dimensions :browser
     end
    
  6. Create a User

     user = Legato::User.new(access_token) # access_token from step #4
    
  7. Select a Profile

     profile = user.profiles.first
    
  8. Query for Results

     Exit.results(profile).each {|result| p result}
     profile.exit.each {|result| p result}
    

It's important to note that the method name exit comes from the model name Exit above. This is a shortcut. It's preferable to use the model class directly.

  1. Options

The results method accepts a number of options:

  • start_date
  • end_date
  • limit
  • offset
  • sort, for reverse sort, pass a string value with a - as the first character e.g., '-pageviews'.
Clone this wiki locally