Class: EventTracker

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
app/services/event_tracker.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEventTracker

Returns a new instance of EventTracker.


8
9
10
11
12
13
14
# File 'app/services/event_tracker.rb', line 8

def initialize
  @ga_id = Snippet.find_by(key: 'google_analytics_id').try(:body)
  return if Rails.env.test?

  @staccato = Staccato.tracker(@ga_id)
  @slack_notifier = Slack::Notifier.new ENV['SLACK_WEBHOOK_URL']
end

Instance Attribute Details

#slack_notifierObject (readonly)

Returns the value of attribute slack_notifier


6
7
8
# File 'app/services/event_tracker.rb', line 6

def slack_notifier
  @slack_notifier
end

Class Method Details

.method_missing(name, *args) ⇒ Object


36
37
38
# File 'app/services/event_tracker.rb', line 36

def self.method_missing(name, *args)
  instance.send(name, *args)
end

Instance Method Details

#notify(category, action, label = nil, value = nil) ⇒ Object


24
25
26
27
28
29
# File 'app/services/event_tracker.rb', line 24

def notify(category, action, label = nil, value = nil)
  return if Rails.env.test?
  slack_notifier.ping "#{category.to_s.titleize} #{action} #{label} #{value}"
rescue Exception => ex
  ExceptionNotifier.notify_exception ex
end

#track(category, action, label = nil, value = nil) ⇒ Object


16
17
18
19
20
21
22
# File 'app/services/event_tracker.rb', line 16

def track(category, action, label = nil, value = nil)
  return if Rails.env.test?
  Rails.logger.warn 'EventTracker.track is depricated'
  event(category: category, action: action, label: label, value: value, non_interactive: true)
rescue Exception => ex
  ExceptionNotifier.notify_exception ex
end

#track_and_notify(category, action, label = nil, value = nil) ⇒ Object


31
32
33
34
# File 'app/services/event_tracker.rb', line 31

def track_and_notify(category, action, label = nil, value = nil)
  track(category, action, label, value)
  notify(category, action, label, value)
end