Sha256: d72b3f2dda782d73ba02d716f607f78f540b413a55b1e1e1f87a95c327c4b72c

Contents?: true

Size: 1.58 KB

Versions: 28

Compression:

Stored size: 1.58 KB

Contents

module Workarea
  module Storefront
    class AnalyticsController < Storefront::ApplicationController
      skip_before_action :verify_authenticity_token
      before_action :ignore_bots

      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

      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

      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

      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

      private

      def ignore_bots
        if browser.bot?
          head(:forbidden)
          return false
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-storefront-3.5.27 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.26 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.25 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.23 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.22 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.21 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.20 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.19 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.18 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.17 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.16 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.15 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.14 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.13 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.12 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.11 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.10 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.9 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.8 app/controllers/workarea/storefront/analytics_controller.rb
workarea-storefront-3.5.7 app/controllers/workarea/storefront/analytics_controller.rb