Module: Spree::AnalyticsHelper

Included in:
StoreController
Defined in:
app/helpers/spree/analytics_helper.rb

Instance Method Summary collapse

Instance Method Details

#analytics_event_handlersObject



3
4
5
6
7
# File 'app/helpers/spree/analytics_helper.rb', line 3

def analytics_event_handlers
  @analytics_event_handlers ||= Spree::Analytics.event_handlers.map do |handler|
    handler.new(user: try_spree_current_user, session: session, request: request)
  end
end

#track_event(event_name, record) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/spree/analytics_helper.rb', line 9

def track_event(event_name, record)
  return if current_theme_preview.present?
  return if unsupported_event?(event_name)

  analytics_event_handlers.each do |handler|
    handler.handle_event(event_name, record)
  end
rescue => e
  Rails.error.report(
    e,
    context: { event_name: event_name, record_id: record&.id, record_type: record&.class&.name },
    source: 'spree.storefront'
  )
end

#unsupported_event?(event_name) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/helpers/spree/analytics_helper.rb', line 24

def unsupported_event?(event_name)
  !Spree::Analytics.events.key?(event_name.to_sym)
end