Module: MinimumViableProduct::AnalyticsConcern

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/minimum_viable_product/analytics_concern.rb

Constant Summary collapse

'invisible'

Instance Method Summary collapse

Instance Method Details

#analytics_identify_eventsObject



53
54
55
56
# File 'app/controllers/concerns/minimum_viable_product/analytics_concern.rb', line 53

def analytics_identify_events
  flash['__analytics_identify_events'] ||= []
  flash['__analytics_identify_events']
end

#analytics_track_eventsObject



58
59
60
61
# File 'app/controllers/concerns/minimum_viable_product/analytics_concern.rb', line 58

def analytics_track_events
  flash['__analytics_track_events'] ||= []
  flash['__analytics_track_events']
end

#identify!(id, properties = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/concerns/minimum_viable_product/analytics_concern.rb', line 14

def identify!(id, properties={})
  return if session[INVISIBLE_SESSION_COOKIE].to_b == true

  events = flash['__analytics_identify_events'] ||= []
  events << {
    'id': id,
    'properties': properties
  }
  flash['__analytics_identify_events'] = events
end

#slack!(message, properties = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/concerns/minimum_viable_product/analytics_concern.rb', line 40

def slack!(message, properties=nil)
  if ENV['SLACK_WEBHOOK_URL']
    _msg = [message]
    _msg << properties.inspect if properties

    begin
      slack_notifier.ping _msg.join(' ')
    rescue
      slack_notifier.ping "Tried to use slack messaging but failure happened"
    end
  end
end

#track!(event, properties = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/concerns/minimum_viable_product/analytics_concern.rb', line 25

def track!(event, properties={})
  return if session[INVISIBLE_SESSION_COOKIE].to_b == true

  events = flash['__analytics_track_events'] ||= []
  events << {
    'name': event,
    'properties': properties.reverse_merge({
      iteration: MVP::Iteration.version,
      user: current_user.try(:name),
      url: request.fullpath
    })
  }
  flash['__analytics_track_events'] = events
end