Question

I am developing a reporting tool using Google Analytics API. I am using Garb I am able to pull the data. The challenge I am facing is how do I specif icy the start_date and end_date to fetch the between two dates.

   class Exits

  extend Garb::Model

  metrics :visits,:percentNewVisits
  dimensions :visitorType
end


  def registration
puts "entering the registration method"  
Garb::Session.login("email@email.com", "password")

profile = Garb::Management::Profile.all.detect {|p| p.web_property_id == 'UA-xxxxxxxx-x'} 
report = Exits.results(profile, {:start_date =>2.day.ago, :end_date =>1.day.ago, :metrics =>[:visits]})
#report = Garb::Report.new(profile, {:start_date => 2.day.ago, :end_date => Time.now})
puts "entering the loop" 
 report = profile.exits()
  report.each do |re| 
  puts re
#puts "#{report.visits}"
#puts "#{profile.percent_new_visits}"
#puts "#{profile.visitorType}"
  end 

end 

end

Kindly help to fetch the page view and any other metrics between two dates.

Was it helpful?

Solution

Try this:

    profile = Garb::Management::Profile.all.detect {|p| p.web_property_id == web_profile}
    options =  {
                    :start_date     => (Date.today - 2),
                    :end_date       => (Date.today - 1),
                }

    result = Report.results(profile, options)

OTHER TIPS

In regard of documentation in the README :

Other Parameters
start_date: The date of the period you would like this report to start
end_date: The date to end, inclusive
limit: The maximum number of results to be returned
offset: The starting index

So you can do what you want by :

report = Garb::Report.results(profile, {:start_date => 2.day.ago, :end_date => 1.day.ago})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top