Class: ShopifyDashboardPlus::TrafficReport

Inherits:
Report
  • Object
show all
Defined in:
lib/shopify_dashboard_plus/report.rb

Constant Summary

Constants included from ApplicationHelpers

ApplicationHelpers::DESIRED_FIELDS

Instance Method Summary collapse

Methods inherited from Report

#initialize

Methods included from ApplicationHelpers

#close_connection, #connected?, #date_range_valid?, #date_today, #days, #display_as_currency, #get_average_revenue, #get_daily_revenues, #get_date_range, #get_detailed_revenue_metrics, #get_host, #get_list_of_orders, #get_total_revenue, #hash_to_graph_format, #open_connection, #order_parameters_paginate, #set_connection, #shop_name, #strip_protocol

Constructor Details

This class inherits a constructor from ShopifyDashboardPlus::Report

Instance Method Details

#number_of_referralsObject



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/shopify_dashboard_plus/report.rb', line 147

def number_of_referrals
  referring_sites, referring_pages = Hash.new(0), Hash.new(0)

  @orders.each do |order|
    if order.attributes['referring_site'].empty?
      referring_pages['None'] += 1
      referring_sites['None'] += 1
    else
      host = get_host(order.referring_site)
      page = strip_protocol(order.referring_site)
      referring_pages[page] += 1
      referring_sites[host] += 1
    end
  end
  {
    :referral_sites => (referring_sites.sort().to_h rescue {}),
    :referral_pages => (referring_pages.sort().to_h rescue {})
  }
end

#to_hObject



189
190
191
# File 'lib/shopify_dashboard_plus/report.rb', line 189

def to_h
  traffic_revenue.merge(number_of_referrals)
end

#traffic_revenueObject



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/shopify_dashboard_plus/report.rb', line 167

def traffic_revenue
  revenue_per_referral_page, revenue_per_referral_site = Hash.new(0.0), Hash.new(0.0)

  @orders.each do |order|
    order.line_items.each do |item|
      if order.attributes['referring_site'].empty?
        revenue_per_referral_page['None'] = revenue_per_referral_page['None'].plus(item.price)
        revenue_per_referral_site['None'] = revenue_per_referral_site['None'].plus(item.price)
      else
        host = get_host(order.referring_site)
        page = strip_protocol(order.referring_site)
        revenue_per_referral_site[host] = revenue_per_referral_site[host].plus(item.price)
        revenue_per_referral_page[page] = revenue_per_referral_page[page].plus(item.price)
      end
    end
  end
  {
    :revenue_per_referral_site => (revenue_per_referral_site.sort().to_h rescue {}),
    :revenue_per_referral_page => (revenue_per_referral_page.sort().to_h rescue {})
  }
end