Class: Workarea::Storefront::AnalyticsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/workarea/storefront/analytics_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_layout, #current_user_info, #health_check, #layout_content

Methods included from OrderLookup

#lookup_order, #lookup_order=

Methods included from CurrentCheckout

#clear_current_order, #completed_order, #completed_order=, #current_checkout, #current_order, #current_order=, #current_shipping, #current_shippings, #logout

Instance Method Details

#category_viewObject



15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/workarea/storefront/analytics_controller.rb', line 15

def category_view
  if params[:category_id].present?
    Metrics::CategoryByDay.inc(key: { category_id: params[:category_id] }, views: 1)
    Metrics::User.save_affinity(
      id: current_metrics_id,
      action: 'viewed',
      category_ids: params[:category_id]
    )
  end
end

#new_sessionObject



7
8
9
10
11
12
13
# File 'app/controllers/workarea/storefront/analytics_controller.rb', line 7

def new_session
  Metrics::SalesByDay.inc(sessions: 1)

  current_segments.each do |segment|
    Metrics::SegmentByDay.inc(key: { segment_id: segment.id }, sessions: 1)
  end
end

#product_viewObject



26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/workarea/storefront/analytics_controller.rb', line 26

def product_view
  if params[:product_id].present?
    Metrics::ProductByDay.inc(key: { product_id: params[:product_id] }, views: 1)
    Metrics::User.save_affinity(
      id: current_metrics_id,
      action: 'viewed',
      product_ids: params[:product_id]
    )
  end
end

#searchObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/workarea/storefront/analytics_controller.rb', line 37

def search
  query_string = QueryString.new(params[:q])

  if query_string.present? && !query_string.short?
    Metrics::SearchByDay.save_search(params[:q], params[:total_results])
    Metrics::User.save_affinity(
      id: current_metrics_id,
      action: 'viewed',
      search_ids: query_string.id
    )
  end
end