So, here is how I found to use it: You create a class that defines the “model” of your request (and, like the return relationship to the active model, you can also concatenate here). In this example:
- Model / query validation for pageviews and unique pageviews in the ga: pagePathLevel1 dimension.
- There is an additional filter that you can use, looking for an “index” within pagePathLevel1 (and, as you can see, you can use it or not, add additional filters, combine them, etc.
Also note that the filter and the result simply return a “query” (like ActiveModel :: Relation), where execution is performed by calling something on it, for example, “each” or “to_a”, etc.
class Pageviews extend Legato::Model metrics :pageviews, :uniquePageviews dimensions :pagePathLevel1 filter(:by_index_in_path_level_1) {|page_path_level1| contains(:pagePathLevel1, 'index')} def self.query(profile, start_date, end_date) Pageviews.results(profile, :start_date => start_date, :end_date => end_date )
Once this is ready, you can do something like:
Pageviews.query(profile, start_date, end_date).each do |result| # Just print the pageviews & unique-pageviews, for example puts result.try(:pageviews) puts result.try(:uniquePageviews) end
Finally, I recommend that you first explore the Google Analytics Query Explorer .
Hope this example is useful
source share