public
Description: A Ruby wrapper for the Google Analytics API
Home | Edit | New

Building a Report

Report On-The-Fly

report = Garb::Report.new(profile)
report.metrics :exits, :exit_rate
report.dimensions :request_uri

This will define a simple report that returns exits and exit rate for each request uri. This information will be for the time in the last month (roughly) and for the profile given. See Profiles for info on getting a profile.

Add Filters and Sort to the Report

report.filter :request_uri.contains => 'fun', :exits.gte => 1000
report.sort :exit_rate.desc

This will filter results that have a request uri which contains (a Regex, so you can anchor the string) AND where exits are greater than or equal to 1000 (for any given page).

In addition, it will sort the results by the exit rate, in descending order.

Options such as limit, offset and the start/end dates are set in Getting Results

Defining a Report Class

class Exits
  include Garb::Resource

  metrics :exits, :exit_rate
  dimensions :request_uri
end

This is useful if you have a class that you would like to use, and define methods, or maybe use with a database. With a defined class, we’ll specify filters and sorting as part of Getting Results, (along with all the other options).

Last edited by tpitale, Mon May 04 10:04:42 -0700 2009
Home | Edit | New
Versions: