Search code examples
ruby-on-railsruby-on-rails-3garb-gem

Using Garb with GA Management API v3


I installed Sija's fork of garb and am having some issues. The documentation appears to be a bit outdated as some things have been deprecated.

I have the following code (ignore the fact that it's horribly unsecure):

extend Garb::Model
metrics :pageviews
dimensions :page_path

Garb::Session.login('[email protected]', 'mypassword')
profile = Garb::Management::Profile.all.detect { |p| p.web_property_id == 'UA-XXXXX-1' }
puts profile.visits

When I run this, I get undefined method visits. I also tried this code on StackOverview, and it returned undefined method results. I'm guessing these are due to the new GA Management API v3 changes, but does anyone know the new way to access pageviews/visits?

I'm trying to query pageviews by date in the end.

Thanks for any help!


Solution

  • You need to create a class extending Garb::Model (https://github.com/Sija/garb#define-a-report-class). Btw, documentation has been updated to work with the newest version of the gem.