Fosome / garb

A Ruby wrapper for the Google Analytics API
http://www.viget.com/extend/
654 stars 89 forks source link

Add the ability to dynamically change the metrics and dimensions #87

Closed timuckun closed 13 years ago

timuckun commented 13 years ago

Google analytics limits you to ten metrics per query. This means if you need more you need to create a new class for your metrics.

For me the ability to specify the metrics and the dimensions in the parameters I pass in would be very handy as I can chunk the array and pass it to garb in a loop using each_slice.

Also this would clean up my app as I would only have one class for querying which contains my login information and some other setup.

I think that overall I tend to favor instance methods rather than class methods for this type of thing so I can set everything up (logging, credentials, etc) on the initialize and then rely on the base class to do the heavy lifting. For me this seems cleaner but I realize it's a preference thing.

Ideally it would look like this.

class MyGarb < Garb def initialize @logger = blah @credentials =['username', 'password'] @defaults ={:start_date =>1.month.ago, :end_date => 1.day.ago, :limit => 1000, :offset => 1} super end def log(level, str) @logger level, str end

end

results = Mygarb.query :dimensions => [:date], :metrics => [:visits], :filters => [blah]

timuckun commented 13 years ago

Check this out...

ga = Class.new(GoogleAnalyticSearch) ga.metrics params.delete :metrics ga.dimensions params.delete :dimensions result = ga.query(params) result