A platform for community discussion. Free, open, simple.
FEATURE: Revive legacy pageview reports (#29308)
Martin Brennanbd4e8422fe46
diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rbindex ea3c0a6cd5b..c22e2697739 100644--- a/app/controllers/admin/reports_controller.rb+++ b/app/controllers/admin/reports_controller.rb@@ -3,10 +3,9 @@class Admin::ReportsController < Admin::StaffControllerREPORTS_LIMIT = 50- HIDDEN_PAGEVIEW_REPORTS = ["site_traffic"]+ HIDDEN_PAGEVIEW_REPORTS = %w[site_traffic page_view_legacy_total_reqs]HIDDEN_LEGACY_PAGEVIEW_REPORTS = %w[- consolidated_page_viewsconsolidated_page_views_browser_detectionpage_view_anon_reqspage_view_logged_in_reqs@@ -21,6 +20,10 @@ class Admin::ReportsController < Admin::StaffController.select { |r| r =~ /\Apage_view_/ && r !~ /mobile/ }.map { |r| r + "_reqs" }+ if !SiteSetting.use_legacy_pageviews+ page_view_req_report_methods << "page_view_legacy_total_reqs"+ end+reports_methods =page_view_req_report_methods +Report.singleton_methods.grep(/\Areport_(?!about|storage_stats)/)@@ -38,13 +41,27 @@ class Admin::ReportsController < Admin::StaffControllernext reports_acc if HIDDEN_LEGACY_PAGEVIEW_REPORTS.include?(type)end- reports_acc << {+ report_data = {type: type,title: I18n.t("reports.#{type}.title"),description: description.presence ? description : nil,description_link: description_link.presence ? description_link : nil,}+ # HACK: We need to show a different label and description for this+ # old report while people are still relying on it, that lets us+ # point toward the new 'Site traffic' report as well. Not ideal,+ # but apart from duplicating the report there's not a nicer way to do this.+ if SiteSetting.use_legacy_pageviews+ if type == "consolidated_page_views" ||+ type === "consolidated_page_views_browser_detection"+ report_data[:title] = I18n.t("reports.#{type}.title_legacy")+ report_data[:description] = I18n.t("reports.#{type}.description_legacy")+ end+ end++ reports_acc << report_data+reports_accend.sort_by { |report| report[:title] }diff --git a/app/models/concerns/reports/consolidated_page_views.rb b/app/models/concerns/reports/consolidated_page_views.rbindex d73f764c93a..4d48f18415b 100644--- a/app/models/concerns/reports/consolidated_page_views.rb+++ b/app/models/concerns/reports/consolidated_page_views.rb@@ -4,8 +4,10 @@ module Reports::ConsolidatedPageViewsextend ActiveSupport::Concernclass_methods do- # NOTE: This report is deprecated, once use_legacy_pageviews is- # always false or no longer needed we can delete this.+ # 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]diff --git a/app/models/report.rb b/app/models/report.rbindex 03765b52b98..37770371bd3 100644--- a/app/models/report.rb+++ b/app/models/report.rb@@ -305,30 +305,14 @@ class Report# they can be removed.def self.req_report(report, filter = nil)data =+ # For this report we intentionally do not want to count mobile pageviews.if filter == :page_view_total- # For this report we intentionally do not want to count mobile pageviews.- if SiteSetting.use_legacy_pageviews- # We purposefully exclude "browser" pageviews. See- # `ConsolidatedPageViewsBrowserDetection` for browser pageviews.- ApplicationRequest.where(- req_type: [- ApplicationRequest.req_types[:page_view_crawler],- ApplicationRequest.req_types[:page_view_anon],- ApplicationRequest.req_types[:page_view_logged_in],- ].flatten,- )- else- # We purposefully exclude "crawler" pageviews here and by- # only doing browser pageviews we are excluding "other" pageviews- # too. This is to reflect what is shown in the "Site traffic" report- # by default.- ApplicationRequest.where(- req_type: [- ApplicationRequest.req_types[:page_view_anon_browser],- ApplicationRequest.req_types[:page_view_logged_in_browser],- ].flatten,- )- end+ SiteSetting.use_legacy_pageviews ? legacy_page_view_requests : page_view_requests+ # This is a separate report because if people have switched over+ # to _not_ use legacy pageviews, we want to show both a Pageviews+ # and Legacy Pageviews report.+ elsif filter == :page_view_legacy_total_reqs+ legacy_page_view_requestselseApplicationRequest.where(req_type: ApplicationRequest.req_types[filter])end@@ -351,6 +335,31 @@ class Report)end+ # We purposefully exclude "browser" pageviews. See+ # `ConsolidatedPageViewsBrowserDetection` for browser pageviews.+ def self.legacy_page_view_requests+ ApplicationRequest.where(+ req_type: [+ ApplicationRequest.req_types[:page_view_crawler],+ ApplicationRequest.req_types[:page_view_anon],+ ApplicationRequest.req_types[:page_view_logged_in],+ ].flatten,+ )+ end++ # We purposefully exclude "crawler" pageviews here and by+ # only doing browser pageviews we are excluding "other" pageviews+ # too. This is to reflect what is shown in the "Site traffic" report+ # by default.+ def self.page_view_requests+ ApplicationRequest.where(+ req_type: [+ ApplicationRequest.req_types[:page_view_anon_browser],+ ApplicationRequest.req_types[:page_view_logged_in_browser],+ ].flatten,+ )+ end+def self.report_about(report, subject_class, report_method = :count_per_day)basic_report_about report, subject_class, report_method, report.start_date, report.end_dateadd_counts report, subject_classdiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 561be644488..4d883b97abe 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1353,13 +1353,15 @@ en:yaxis: "Day"description: "Number of users who increased their Trust Level during this period."consolidated_page_views:- title: "Consolidated Pageviews"+ title: "Legacy Consolidated Pageviews"+ title_legacy: "Consolidated Pageviews"xaxis:page_view_crawler: "Crawlers"page_view_anon: "Anonymous users"page_view_logged_in: "Logged in users"yaxis: "Day"- description: "Pageviews for logged in users, anonymous users and crawlers."+ description: "Legacy report showing pageviews for logged in users, anonymous users and crawlers. This has been superseded by the 'Site traffic' report."+ description_legacy: "Pageviews for logged in users, anonymous users and crawlers."labels:post: Posteditor: Editor@@ -1374,13 +1376,15 @@ en:description: "API requests for regular API keys and user API keys."consolidated_page_views_browser_detection:title: "Consolidated Pageviews with Browser Detection (Experimental)"+ title_legacy: "Consolidated Pageviews with Browser Detection (Experimental)"xaxis:page_view_anon_browser: "Anonymous Browser"page_view_logged_in_browser: "Logged In Browser"page_view_crawler: "Known Crawler"page_view_other: "Other pageviews"yaxis: "Day"- description: "Pageviews for logged in users, anonymous users, known crawlers and other. This experimental report ensures logged-in/anon requests are coming from real browsers before counting them. Historical data for this report is unavailable, for historical data see the ‘Consolidated Pageviews' report."+ description: "Pageviews for logged in users, anonymous users, known crawlers and other. This experimental report ensures logged-in/anon requests are coming from real browsers before counting them. Historical data for this report is unavailable, for historical data see the 'Legacy Consolidated Pageviews' report."+ description_legacy: "Pageviews for logged in users, anonymous users, known crawlers and other. This experimental report ensures logged-in/anon requests are coming from real browsers before counting them. Historical data for this report is unavailable, for historical data see the ‘Consolidated Pageviews' report."site_traffic:title: "Site traffic"xaxis:@@ -1541,6 +1545,11 @@ en:xaxis: "Day"yaxis: "Total Pageviews"description: "Number of new pageviews from all visitors."+ page_view_legacy_total_reqs:+ title: "Legacy Pageviews"+ xaxis: "Day"+ yaxis: "Total Pageviews"+ description: "Legacy report showing the number of new pageviews from all visitors."page_view_logged_in_mobile_reqs:title: "Logged In Pageviews"xaxis: "Day"diff --git a/spec/requests/admin/reports_controller_spec.rb b/spec/requests/admin/reports_controller_spec.rbindex 0e2f53f38d5..3a6b1a57f16 100644--- a/spec/requests/admin/reports_controller_spec.rb+++ b/spec/requests/admin/reports_controller_spec.rb@@ -246,7 +246,7 @@ RSpec.describe Admin::ReportsController doexpect(response.status).to eq(200)expect(response.parsed_body["reports"].count).to eq(5)expect(response.parsed_body["reports"][0]["type"]).to eq("site_traffic")- expect(response.parsed_body["reports"][1]).to include("error" => "not_found", "data" => nil)+ expect(response.parsed_body["reports"][1]["type"]).to eq("consolidated_page_views")expect(response.parsed_body["reports"][2]).to include("error" => "not_found", "data" => nil)expect(response.parsed_body["reports"][3]).to include("error" => "not_found", "data" => nil)expect(response.parsed_body["reports"][4]).to include("error" => "not_found", "data" => nil)@@ -366,6 +366,11 @@ RSpec.describe Admin::ReportsController doexpect(response.parsed_body["errors"]).to include(I18n.t("not_found"))endend++ it "does not allow running the page_view_legacy_total_reqs report" do+ get "/admin/reports/page_view_legacy_total_reqs.json"+ expect(response.status).to eq(404)+ endendcontext "when use_legacy_pageviews is false" do@@ -381,6 +386,11 @@ RSpec.describe Admin::ReportsController doexpect(response.parsed_body["errors"]).to include(I18n.t("not_found"))endend++ it "does allow running the page_view_legacy_total_reqs report" do+ get "/admin/reports/page_view_legacy_total_reqs.json"+ expect(response.status).to eq(200)+ endendendend