Skip to content
rodrigoalvesvieira edited this page Aug 10, 2011 · 18 revisions

With a Class and Filters and Sorting

First, get a profile:

profile = Garb::Management::Profile.all.first

You can also get an exact profile by passing its Web Property id:

profile = Garb::Management::Profile.all.detect {|p| p.web_property_id == 'UA-00000000-0'}

Then define an Exits class, extending Garb::Model and gathering metrics for pageviews:

class Exits
  extend Garb::Model
  metrics :pageviews
end

Then fetch the results:

Exits.results(profile, :limit => 10,
                       :offset => 20,
                       :start_date => (Date.today - 30),
                       :end_date => Date.today,
                       :filters => {:pageviews.gte => 200},
                       :sort => :pageviews)

The shorthand with a given profile is also nice:

profile.exits(:limit => 10, :offset => 20)

This can be done with any class which extends Garb::Model

Filtering with :contains and a regular expression

Note that contains accepts a regex notation but as a string rather than a actual regex literal. For example, to get results for all pages with a path containing “blog/posts/any-post-title” use this:

Exits.results(profile, :filters => {:page_path.contains => "^\/blog\/posts\/.+" })

Instead of:

Exits.results(profile, :filters => {:page_path.contains => /^\/blog\/posts\/.+/ })
Clone this wiki locally