Class: Spotlight::Analytics::Ga
- Inherits:
-
Object
- Object
- Spotlight::Analytics::Ga
- Extended by:
- Legato::Model
- Defined in:
- app/models/spotlight/analytics/ga.rb
Overview
Google Analytics data provider for the Exhibit dashboard
Instance Method Summary collapse
- #enabled? ⇒ Boolean
- #exhibit_data(exhibit, options) ⇒ Object
- #page_data(exhibit, options) ⇒ Object
- #site ⇒ Object
- #user(scope = 'https://www.googleapis.com/auth/analytics.readonly') ⇒ Object
Instance Method Details
#enabled? ⇒ Boolean
13 14 15 |
# File 'app/models/spotlight/analytics/ga.rb', line 13 def enabled? user && site end |
#exhibit_data(exhibit, options) ⇒ Object
19 20 21 |
# File 'app/models/spotlight/analytics/ga.rb', line 19 def exhibit_data(exhibit, ) model.context(exhibit).results(site, Spotlight::Engine.config..merge()).to_a.first || exhibit_data_unavailable end |
#page_data(exhibit, options) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'app/models/spotlight/analytics/ga.rb', line 23 def page_data(exhibit, ) [:sort] ||= '-pageviews' query = model.context(exhibit).results(site, Spotlight::Engine.config..merge()) query.dimensions << :page_path query.dimensions << :page_title query.to_a end |
#site ⇒ Object
41 42 43 |
# File 'app/models/spotlight/analytics/ga.rb', line 41 def site @site ||= user.accounts.first.profiles.find { |x| x.web_property_id == Spotlight::Engine.config.ga_web_property_id } end |
#user(scope = 'https://www.googleapis.com/auth/analytics.readonly') ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'app/models/spotlight/analytics/ga.rb', line 32 def user(scope = 'https://www.googleapis.com/auth/analytics.readonly') @user ||= begin Legato::User.new(oauth_token(scope)) rescue StandardError => e Rails.logger.info(e) nil end end |