Module: GaTrackable

Defined in:
lib/ga_trackable.rb,
lib/ga_trackable/engine.rb,
lib/ga_trackable/version.rb,
lib/ga_trackable/configuration.rb,
app/models/ga_trackable/page_views_counter.rb,
app/models/ga_trackable/video_plays_counter.rb

Defined Under Namespace

Modules: Trackable Classes: BaseFetcher, Configuration, Engine, PageViewsCounter, PageViewsFetcher, VideoPlaysCounter, VideoPlaysFetcher

Constant Summary collapse

InvalidConfigurationError =
Class.new(StandardError)
VERSION =
'0.0.2'

Class Method Summary collapse

Class Method Details

.analyticsObject



50
51
52
# File 'lib/ga_trackable.rb', line 50

def analytics
  @analytics ||= client.discovered_api('analytics', 'v3')
end

.clientObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ga_trackable.rb', line 37

def client
  @client ||= begin
                client = Google::APIClient.new(
                  application_name: config.app_name,
                  application_version: config.app_version
                )
                key = Google::APIClient::PKCS12.load_key(config.secret_path, config.secret_key)
                 = Google::APIClient::JWTAsserter.new(config.issuer_email, config.scope, key)
                client.authorization = .authorize
                client
              end
end

.configObject



33
34
35
# File 'lib/ga_trackable.rb', line 33

def config
  @config || raise(InvalidConfigurationError, 'GaTrackable is not configured!')
end

.resetObject



29
30
31
# File 'lib/ga_trackable.rb', line 29

def reset
  @config = nil
end

.setup(&blk) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/ga_trackable.rb', line 18

def setup(&blk)
  @config ||= GaTrackable::Configuration.new(&blk)

  if @config.invalid?
    msg = "GaTrackable configuration ERROR:\n"
    raise InvalidConfigurationError, msg + @config.errors.full_messages.join("\n")
  end

  @config
end