Class: Spree::ProductViewsReport
- Defined in:
- app/reports/spree/product_views_report.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- DEFAULT_SORTABLE_ATTRIBUTE =
:product_name- HEADERS =
{ product_name: :string, views: :integer, users: :integer, guest_sessions: :integer }
- SEARCH_ATTRIBUTES =
{ start_date: :product_view_from, end_date: :product_view_till, name: :name}
- SORTABLE_ATTRIBUTES =
[:product_name, :views, :users, :guest_sessions]
Constants inherited from Report
Instance Attribute Summary
Attributes inherited from Report
#current_page, #paginate, #records_per_page, #reporting_period, #search, #sortable_attribute, #sortable_type, #total_records
Instance Method Summary collapse
Methods inherited from Report
#active_record_sort, deeplink, #deeplink_properties, #generate, #get_results, #header_sorted?, #initialize, #name, #paginated?, #pagination_required?, #set_sortable_attributes, #time_scale_columns, #time_scale_columns_to_s, #time_scale_selects, #total_pages
Constructor Details
This class inherits a constructor from Spree::Report
Instance Method Details
#report_query ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/reports/spree/product_views_report.rb', line 16 def report_query viewed_events = Spree::Product .where(Spree::Product.arel_table[:name].matches(search_name)) .joins(:page_view_events) .where(spree_page_events: { created_at: reporting_period }) .group('product_name', 'product_slug', 'spree_page_events.actor_id', 'spree_page_events.session_id') .select( 'spree_products.name as product_name', 'spree_products.slug as product_slug', 'COUNT(*) as total_views_per_session', 'spree_page_events.session_id as session_id', 'spree_page_events.actor_id as actor_id' ) Spree::Report::QueryFragments .from_subquery(viewed_events) .group('product_name', 'product_slug') .project( 'product_name', 'product_slug', 'SUM(total_views_per_session) as views', 'COUNT(DISTINCT actor_id) as users', '(COUNT(DISTINCT session_id) - COUNT(actor_id)) as guest_sessions' ) end |