mirror of
https://github.com/discourse/discourse.git
synced 2024-12-17 03:13:46 +08:00
bd4e8422fe
This commit brings back some reports hidden or changed
by the commit in 14b436923c
if
the site setting `use_legacy_pageviews` is false.
* Unhide the old “Consolidated Pageviews” report and rename it
to “Legacy Consolidated Pageviews”
* Add a legacy_page_view_total_reqs report called “Legacy Pageviews”,
which calculates pageviews in the same way the old page_view_total_reqs
report did.
This will allow admins to better compare old and new pageview
stats which are based on browser detection if they have switched
over to _not_ use legacy pageviews.
43 lines
1.3 KiB
Ruby
43 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Reports::ConsolidatedPageViews
|
|
extend ActiveSupport::Concern
|
|
|
|
class_methods do
|
|
# NOTE: This report is superseded by "SiteTraffic". Eventually once
|
|
# use_legacy_pageviews is always false or no longer needed, and users
|
|
# no longer rely on the data in this old report in the transition period,
|
|
# we can delete this.
|
|
def report_consolidated_page_views(report)
|
|
filters = %w[page_view_logged_in page_view_anon page_view_crawler]
|
|
|
|
report.modes = [:stacked_chart]
|
|
|
|
requests =
|
|
filters.map do |filter|
|
|
color = report.colors[:turquoise]
|
|
color = report.colors[:lime] if filter == "page_view_anon"
|
|
color = report.colors[:purple] if filter == "page_view_crawler"
|
|
|
|
{
|
|
req: filter,
|
|
label: I18n.t("reports.consolidated_page_views.xaxis.#{filter}"),
|
|
color: color,
|
|
data: ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter]),
|
|
}
|
|
end
|
|
|
|
requests.each do |request|
|
|
request[:data] = request[:data]
|
|
.where("date >= ? AND date <= ?", report.start_date, report.end_date)
|
|
.order(date: :asc)
|
|
.group(:date)
|
|
.sum(:count)
|
|
.map { |date, count| { x: date, y: count } }
|
|
end
|
|
|
|
report.data = requests
|
|
end
|
|
end
|
|
end
|