Sha256: 7969c03a1cfe137b4043dca94250ff5e40bcd05fd2e9246c07d0d20f287f8530

Contents?: true

Size: 1.51 KB

Versions: 13

Compression:

Stored size: 1.51 KB

Contents

module Workarea
  module Reports
    class SalesByTrafficReferrer
      include Report

      self.reporting_class = Metrics::TrafficReferrerByDay
      self.sort_fields = %w(
        units_sold
        orders
        merchandise
        discounts
        shipping
        tax
        revenue
        _id.medium
        _id.source
      )

      def aggregation
        [filter, project_used_fields, group_by_traffic_referrer]
      end

      def filter
        {
          '$match' => {
            'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
            'orders' => { '$gt' => 0 }
          }
        }
      end

      def project_used_fields
        {
          '$project' => {
            'medium' => 1,
            'source' => 1,
            'orders' => 1,
            'units_sold' => 1,
            'merchandise' => 1,
            'shipping' => 1,
            'discounts' => 1,
            'tax' => 1,
            'revenue' => 1
          }
        }
      end

      def group_by_traffic_referrer
        {
          '$group' => {
            '_id' => { 'medium' => '$medium', 'source' => '$source' },
            'orders' => { '$sum' => '$orders' },
            'units_sold' => { '$sum' => '$units_sold' },
            'merchandise' => { '$sum' => '$merchandise' },
            'shipping' => { '$sum' => '$shipping' },
            'discounts' => { '$sum' => '$discounts' },
            'tax' => { '$sum' => '$tax' },
            'revenue' => { '$sum' => '$revenue' }
          }
        }
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
workarea-core-3.4.22 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.5.0 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.21 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.5.0.beta.1 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.20 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.19 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.18 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.17 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.16 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.15 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.14 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.13 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.12 app/queries/workarea/reports/sales_by_traffic_referrer.rb