Class: Spotlight::Analytics::Ga

Inherits:
Object
  • Object
show all
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

Instance Method Details

#enabled?Boolean

Returns:

  • (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, options)
  model.context(exhibit).results(site, Spotlight::Engine.config.ga_analytics_options.merge(options)).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, options)
  options[:sort] ||= '-pageviews'
  query = model.context(exhibit).results(site, Spotlight::Engine.config.ga_page_analytics_options.merge(options))
  query.dimensions << :page_path
  query.dimensions << :page_title

  query.to_a
end

#siteObject



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