Class: Orange::AnalyticsResource
- Inherits:
-
Resource
- Object
- Resource
- Orange::AnalyticsResource
- Defined in:
- lib/orange-more/analytics/resources/analytics_resource.rb
Instance Method Summary collapse
Instance Method Details
#gattica ⇒ Object
12 13 14 15 |
# File 'lib/orange-more/analytics/resources/analytics_resource.rb', line 12 def gattica return false unless [:email] @gattica ||= Gattica.new() end |
#pageviews(route, opts = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/orange-more/analytics/resources/analytics_resource.rb', line 17 def pageviews(route, opts = {}) return "No GA" unless gattica r = route.to_s # Strip trailing slash if present. GA doesn't like it. if r.rindex('/') > 0 r[r.rindex('/')] = '' end # authenticate with the API via email/password ga = gattica accounts = ga.accounts ga.profile_id = [:profile] || accounts.first.profile_id views = "" data = ga.get({ :start_date => '2009-01-01', :end_date => Time.now.localtime.strftime("%Y-%m-%d"), :dimensions => ['pagePath'], :metrics => ['pageviews'], :filters => ['pagePath == '+route.to_s[0..-1]] }.merge(opts)) unless data.points.length == 0 views = data.points[0].metrics[0][:pageviews] views else 0 end end |
#stack_init ⇒ Object
6 7 8 9 10 |
# File 'lib/orange-more/analytics/resources/analytics_resource.rb', line 6 def stack_init [:email] = orange.['ga_email'] [:password] = orange.['ga_password'] [:profile] = orange.['ga_profile'] end |