mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:38:17 +08:00
FEATURE: Switch to new methods of pageview measurement and reporting (#28729)
### UI changes
All of the UI changes described are gated behind the `use_legacy_pageviews`
site setting.
This commit changes the admin dashboard pageviews report to
use the "Consolidated Pageviews with Browser Detection" report
introduced in 2f2da72747
with
the following changes:
* The report name is changed to "Site traffic"
* The pageview count on the dashboard is counting only using the new method
* The old "Consolidated Pageviews" report is renamed as "Consolidated Legacy Pageviews"
* By default "known crawlers" and "other" sources of pageviews are hidden on the report
When `use_legacy_pageviews` is `true`, we do not show or allow running
the "Site traffic" report for admins. When `use_legacy_pageviews` is `false`,
we do not show or allow running the following legacy reports:
* consolidated_page_views
* consolidated_page_views_browser_detection
* page_view_anon_reqs
* page_view_logged_in_reqs
### Historical data changes
Also part of this change is that, since we introduced our new "Consolidated
Pageviews with Browser Detection" report, some admins are confused at either:
* The lack of data before a certain date , which didn’t exist before
we started collecting it
* Comparing this and the current "Consolidated Pageviews" report data,
which rolls up "Other Pageviews" into "Anonymous Browser" and so it
appears inaccurate
All pageview data in the new report before the date where the _first_
anon or logged in browser pageview was recorded is now hidden.
This commit is contained in:
parent
aacd354de5
commit
14b436923c
|
@ -8,10 +8,14 @@ export default class AdminReportStackedChart extends Component {
|
|||
get chartConfig() {
|
||||
const { model } = this.args;
|
||||
|
||||
const options = this.args.options || {};
|
||||
options.hiddenLabels ??= [];
|
||||
|
||||
const chartData = makeArray(model.chartData || model.data).map((cd) => ({
|
||||
label: cd.label,
|
||||
color: cd.color,
|
||||
data: Report.collapse(model, cd.data),
|
||||
req: cd.req,
|
||||
}));
|
||||
|
||||
const data = {
|
||||
|
@ -21,6 +25,7 @@ export default class AdminReportStackedChart extends Component {
|
|||
stack: "pageviews-stack",
|
||||
data: cd.data,
|
||||
backgroundColor: cd.color,
|
||||
hidden: options.hiddenLabels.includes(cd.req),
|
||||
})),
|
||||
};
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<ul class="breadcrumb">
|
||||
{{#if this.showAllReportsLink}}
|
||||
<li class="item all-reports">
|
||||
<LinkTo @route="admin.dashboardReports" class="report-url">
|
||||
<LinkTo @route="adminReports.index" class="report-url">
|
||||
{{i18n "admin.dashboard.all_reports"}}
|
||||
</LinkTo>
|
||||
</li>
|
||||
|
|
|
@ -391,6 +391,8 @@ export default class AdminReport extends Component {
|
|||
Report.groupingForDatapoints(report.chartData.length),
|
||||
})
|
||||
);
|
||||
} else if (mode === "stacked-chart") {
|
||||
return this.get("reportOptions.stackedChart") || {};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ export default class AdminDashboardGeneralController extends AdminDashboardTabCo
|
|||
get isCommunityHealthVisible() {
|
||||
return [
|
||||
"consolidated_page_views",
|
||||
"site_traffic",
|
||||
"signups",
|
||||
"topics",
|
||||
"posts",
|
||||
|
@ -101,6 +102,13 @@ export default class AdminDashboardGeneralController extends AdminDashboardTabCo
|
|||
};
|
||||
}
|
||||
|
||||
@discourseComputed
|
||||
siteTrafficOptions() {
|
||||
return {
|
||||
stackedChart: { hiddenLabels: ["page_view_other", "page_view_crawler"] },
|
||||
};
|
||||
}
|
||||
|
||||
@discourseComputed
|
||||
topReferredTopicsFilters() {
|
||||
return {
|
||||
|
|
|
@ -22,11 +22,20 @@
|
|||
|
||||
<div class="section-body">
|
||||
<div class="charts">
|
||||
<AdminReport
|
||||
@dataSourceName="consolidated_page_views"
|
||||
@forcedModes="stacked-chart"
|
||||
@filters={{this.filters}}
|
||||
/>
|
||||
{{#if this.siteSettings.use_legacy_pageviews}}
|
||||
<AdminReport
|
||||
@dataSourceName="consolidated_page_views"
|
||||
@forcedModes="stacked-chart"
|
||||
@filters={{this.filters}}
|
||||
/>
|
||||
{{else}}
|
||||
<AdminReport
|
||||
@dataSourceName="site_traffic"
|
||||
@forcedModes="stacked-chart"
|
||||
@reportOptions={{this.siteTrafficOptions}}
|
||||
@filters={{this.filters}}
|
||||
/>
|
||||
{{/if}}
|
||||
|
||||
<AdminReport
|
||||
@dataSourceName="signups"
|
||||
|
|
|
@ -145,7 +145,8 @@
|
|||
.admin-report {
|
||||
grid-column: span 4;
|
||||
|
||||
&.consolidated-page-views {
|
||||
&.consolidated-page-views,
|
||||
&.site-traffic {
|
||||
grid-column: span 12;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,31 +3,53 @@
|
|||
class Admin::ReportsController < Admin::StaffController
|
||||
REPORTS_LIMIT = 50
|
||||
|
||||
HIDDEN_PAGEVIEW_REPORTS = ["site_traffic"]
|
||||
|
||||
HIDDEN_LEGACY_PAGEVIEW_REPORTS = %w[
|
||||
consolidated_page_views
|
||||
consolidated_page_views_browser_detection
|
||||
page_view_anon_reqs
|
||||
page_view_logged_in_reqs
|
||||
]
|
||||
|
||||
def index
|
||||
reports_methods =
|
||||
page_view_req_report_methods =
|
||||
["page_view_total_reqs"] +
|
||||
ApplicationRequest
|
||||
.req_types
|
||||
.keys
|
||||
.select { |r| r =~ /\Apage_view_/ && r !~ /mobile/ }
|
||||
.map { |r| r + "_reqs" } +
|
||||
.map { |r| r + "_reqs" }
|
||||
|
||||
reports_methods =
|
||||
page_view_req_report_methods +
|
||||
Report.singleton_methods.grep(/\Areport_(?!about|storage_stats)/)
|
||||
|
||||
reports =
|
||||
reports_methods.map do |name|
|
||||
type = name.to_s.gsub("report_", "")
|
||||
description = I18n.t("reports.#{type}.description", default: "")
|
||||
description_link = I18n.t("reports.#{type}.description_link", default: "")
|
||||
reports_methods
|
||||
.reduce([]) do |reports_acc, name|
|
||||
type = name.to_s.gsub("report_", "")
|
||||
description = I18n.t("reports.#{type}.description", default: "")
|
||||
description_link = I18n.t("reports.#{type}.description_link", default: "")
|
||||
|
||||
{
|
||||
type: type,
|
||||
title: I18n.t("reports.#{type}.title"),
|
||||
description: description.presence ? description : nil,
|
||||
description_link: description_link.presence ? description_link : nil,
|
||||
}
|
||||
end
|
||||
if SiteSetting.use_legacy_pageviews
|
||||
next reports_acc if HIDDEN_PAGEVIEW_REPORTS.include?(type)
|
||||
else
|
||||
next reports_acc if HIDDEN_LEGACY_PAGEVIEW_REPORTS.include?(type)
|
||||
end
|
||||
|
||||
render_json_dump(reports: reports.sort_by { |report| report[:title] })
|
||||
reports_acc << {
|
||||
type: type,
|
||||
title: I18n.t("reports.#{type}.title"),
|
||||
description: description.presence ? description : nil,
|
||||
description_link: description_link.presence ? description_link : nil,
|
||||
}
|
||||
|
||||
reports_acc
|
||||
end
|
||||
.sort_by { |report| report[:title] }
|
||||
|
||||
render_json_dump(reports: reports)
|
||||
end
|
||||
|
||||
def bulk
|
||||
|
@ -40,6 +62,18 @@ class Admin::ReportsController < Admin::StaffController
|
|||
report = nil
|
||||
report = Report.find_cached(report_type, args) if (report_params[:cache])
|
||||
|
||||
if SiteSetting.use_legacy_pageviews
|
||||
if HIDDEN_PAGEVIEW_REPORTS.include?(report_type)
|
||||
report = Report._get(report_type, args)
|
||||
report.error = :not_found
|
||||
end
|
||||
else
|
||||
if HIDDEN_LEGACY_PAGEVIEW_REPORTS.include?(report_type)
|
||||
report = Report._get(report_type, args)
|
||||
report.error = :not_found
|
||||
end
|
||||
end
|
||||
|
||||
if report
|
||||
reports << report
|
||||
else
|
||||
|
@ -65,6 +99,12 @@ class Admin::ReportsController < Admin::StaffController
|
|||
|
||||
raise Discourse::NotFound unless report_type =~ /\A[a-z0-9\_]+\z/
|
||||
|
||||
if SiteSetting.use_legacy_pageviews
|
||||
raise Discourse::NotFound if HIDDEN_PAGEVIEW_REPORTS.include?(report_type)
|
||||
else
|
||||
raise Discourse::NotFound if HIDDEN_LEGACY_PAGEVIEW_REPORTS.include?(report_type)
|
||||
end
|
||||
|
||||
args = parse_params(params)
|
||||
|
||||
report = nil
|
||||
|
|
|
@ -4,6 +4,8 @@ module Reports::ConsolidatedPageViews
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
# NOTE: This report is deprecated, once use_legacy_pageviews is
|
||||
# always false or no longer needed we can delete this.
|
||||
def report_consolidated_page_views(report)
|
||||
filters = %w[page_view_logged_in page_view_anon page_view_crawler]
|
||||
|
||||
|
|
|
@ -4,72 +4,12 @@ module Reports::ConsolidatedPageViewsBrowserDetection
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
# NOTE: This report is deprecated, once use_legacy_pageviews is
|
||||
# always false or no longer needed we can delete this.
|
||||
#
|
||||
# The new version of this report is site_traffic.
|
||||
def report_consolidated_page_views_browser_detection(report)
|
||||
report.modes = [:stacked_chart]
|
||||
|
||||
data =
|
||||
DB.query(
|
||||
<<~SQL,
|
||||
SELECT
|
||||
date,
|
||||
SUM(CASE WHEN req_type = :page_view_logged_in_browser THEN count ELSE 0 END) AS page_view_logged_in_browser,
|
||||
SUM(CASE WHEN req_type = :page_view_anon_browser THEN count ELSE 0 END) AS page_view_anon_browser,
|
||||
SUM(CASE WHEN req_type = :page_view_crawler THEN count ELSE 0 END) AS page_view_crawler,
|
||||
SUM(
|
||||
CASE WHEN req_type = :page_view_anon THEN count
|
||||
WHEN req_type = :page_view_logged_in THEN count
|
||||
WHEN req_type = :page_view_anon_browser THEN -count
|
||||
WHEN req_type = :page_view_logged_in_browser THEN -count
|
||||
ELSE 0
|
||||
END
|
||||
) AS page_view_other
|
||||
FROM application_requests
|
||||
WHERE date >= :start_date AND date <= :end_date
|
||||
GROUP BY date
|
||||
ORDER BY date ASC
|
||||
SQL
|
||||
start_date: report.start_date,
|
||||
end_date: report.end_date,
|
||||
page_view_anon: ApplicationRequest.req_types[:page_view_anon],
|
||||
page_view_crawler: ApplicationRequest.req_types[:page_view_crawler],
|
||||
page_view_logged_in: ApplicationRequest.req_types[:page_view_logged_in],
|
||||
page_view_anon_browser: ApplicationRequest.req_types[:page_view_anon_browser],
|
||||
page_view_logged_in_browser: ApplicationRequest.req_types[:page_view_logged_in_browser],
|
||||
)
|
||||
|
||||
report.data = [
|
||||
{
|
||||
req: "page_view_logged_in_browser",
|
||||
label:
|
||||
I18n.t(
|
||||
"reports.consolidated_page_views_browser_detection.xaxis.page_view_logged_in_browser",
|
||||
),
|
||||
color: report.colors[:turquoise],
|
||||
data: data.map { |row| { x: row.date, y: row.page_view_logged_in_browser } },
|
||||
},
|
||||
{
|
||||
req: "page_view_anon_browser",
|
||||
label:
|
||||
I18n.t(
|
||||
"reports.consolidated_page_views_browser_detection.xaxis.page_view_anon_browser",
|
||||
),
|
||||
color: report.colors[:lime],
|
||||
data: data.map { |row| { x: row.date, y: row.page_view_anon_browser } },
|
||||
},
|
||||
{
|
||||
req: "page_view_crawler",
|
||||
label:
|
||||
I18n.t("reports.consolidated_page_views_browser_detection.xaxis.page_view_crawler"),
|
||||
color: report.colors[:purple],
|
||||
data: data.map { |row| { x: row.date, y: row.page_view_crawler } },
|
||||
},
|
||||
{
|
||||
req: "page_view_other",
|
||||
label: I18n.t("reports.consolidated_page_views_browser_detection.xaxis.page_view_other"),
|
||||
color: report.colors[:magenta],
|
||||
data: data.map { |row| { x: row.date, y: row.page_view_other } },
|
||||
},
|
||||
]
|
||||
Report.report_site_traffic(report)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
80
app/models/concerns/reports/site_traffic.rb
Normal file
80
app/models/concerns/reports/site_traffic.rb
Normal file
|
@ -0,0 +1,80 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Reports::SiteTraffic
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def report_site_traffic(report)
|
||||
report.modes = [:stacked_chart]
|
||||
|
||||
first_browser_pageview_date =
|
||||
DB.query_single(
|
||||
<<~SQL,
|
||||
SELECT date FROM application_requests
|
||||
WHERE req_type = :page_view_logged_in_browser OR req_type = :page_view_anon_browser ORDER BY date LIMIT 1
|
||||
SQL
|
||||
page_view_logged_in_browser: ApplicationRequest.req_types[:page_view_logged_in_browser],
|
||||
page_view_anon_browser: ApplicationRequest.req_types[:page_view_anon_browser],
|
||||
).first
|
||||
|
||||
data =
|
||||
DB.query(
|
||||
<<~SQL,
|
||||
SELECT
|
||||
date,
|
||||
SUM(CASE WHEN req_type = :page_view_logged_in_browser THEN count ELSE 0 END) AS page_view_logged_in_browser,
|
||||
SUM(CASE WHEN req_type = :page_view_anon_browser THEN count ELSE 0 END) AS page_view_anon_browser,
|
||||
SUM(CASE WHEN req_type = :page_view_crawler THEN count ELSE 0 END) AS page_view_crawler,
|
||||
SUM(
|
||||
CASE WHEN req_type = :page_view_anon THEN count
|
||||
WHEN req_type = :page_view_logged_in THEN count
|
||||
WHEN req_type = :page_view_anon_browser THEN -count
|
||||
WHEN req_type = :page_view_logged_in_browser THEN -count
|
||||
ELSE 0
|
||||
END
|
||||
) AS page_view_other
|
||||
FROM application_requests
|
||||
WHERE date >= :start_date AND date <= :end_date AND date >= :first_browser_pageview_date
|
||||
|
||||
GROUP BY date
|
||||
ORDER BY date ASC
|
||||
SQL
|
||||
start_date: report.start_date,
|
||||
end_date: report.end_date,
|
||||
page_view_anon: ApplicationRequest.req_types[:page_view_anon],
|
||||
page_view_crawler: ApplicationRequest.req_types[:page_view_crawler],
|
||||
page_view_logged_in: ApplicationRequest.req_types[:page_view_logged_in],
|
||||
page_view_anon_browser: ApplicationRequest.req_types[:page_view_anon_browser],
|
||||
page_view_logged_in_browser: ApplicationRequest.req_types[:page_view_logged_in_browser],
|
||||
first_browser_pageview_date: first_browser_pageview_date,
|
||||
)
|
||||
|
||||
report.data = [
|
||||
{
|
||||
req: "page_view_logged_in_browser",
|
||||
label: I18n.t("reports.site_traffic.xaxis.page_view_logged_in_browser"),
|
||||
color: report.colors[:turquoise],
|
||||
data: data.map { |row| { x: row.date, y: row.page_view_logged_in_browser } },
|
||||
},
|
||||
{
|
||||
req: "page_view_anon_browser",
|
||||
label: I18n.t("reports.site_traffic.xaxis.page_view_anon_browser"),
|
||||
color: report.colors[:lime],
|
||||
data: data.map { |row| { x: row.date, y: row.page_view_anon_browser } },
|
||||
},
|
||||
{
|
||||
req: "page_view_crawler",
|
||||
label: I18n.t("reports.site_traffic.xaxis.page_view_crawler"),
|
||||
color: report.colors[:purple],
|
||||
data: data.map { |row| { x: row.date, y: row.page_view_crawler } },
|
||||
},
|
||||
{
|
||||
req: "page_view_other",
|
||||
label: I18n.t("reports.site_traffic.xaxis.page_view_other"),
|
||||
color: report.colors[:magenta],
|
||||
data: data.map { |row| { x: row.date, y: row.page_view_other } },
|
||||
},
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -20,6 +20,7 @@ class Report
|
|||
include Reports::ConsolidatedApiRequests
|
||||
include Reports::ConsolidatedPageViews
|
||||
include Reports::ConsolidatedPageViewsBrowserDetection
|
||||
include Reports::SiteTraffic
|
||||
include Reports::DailyEngagedUsers
|
||||
include Reports::DauByMau
|
||||
include Reports::Emails
|
||||
|
@ -294,19 +295,35 @@ class Report
|
|||
report
|
||||
end
|
||||
|
||||
# NOTE: Once use_legacy_pageviews is always false or no longer needed
|
||||
# we will no longer support the page_view_anon and page_view_logged_in reports,
|
||||
# they can be removed.
|
||||
def self.req_report(report, filter = nil)
|
||||
data =
|
||||
if filter == :page_view_total
|
||||
# For this report we intentionally do not want to count mobile pageviews
|
||||
# or "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,
|
||||
)
|
||||
# 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
|
||||
else
|
||||
ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter])
|
||||
end
|
||||
|
|
|
@ -1371,7 +1371,17 @@ en:
|
|||
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."
|
||||
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."
|
||||
site_traffic:
|
||||
title: "Site traffic"
|
||||
xaxis:
|
||||
page_view_anon_browser: "Pageviews (anonymous)"
|
||||
page_view_logged_in_browser: "Pageviews (logged in)"
|
||||
page_view_crawler: "Known crawlers"
|
||||
page_view_other: "Other traffic"
|
||||
yaxis: "Day"
|
||||
description: "Pageviews for logged in users, anonymous users, known crawlers and other traffic."
|
||||
description_link: "https://meta.discourse.org/t/understanding-pageviews-and-the-site-traffic-report/324062"
|
||||
dau_by_mau:
|
||||
title: "DAU/MAU"
|
||||
xaxis: "Day"
|
||||
|
|
|
@ -429,6 +429,7 @@ basic:
|
|||
use_legacy_pageviews:
|
||||
default: false
|
||||
hidden: true
|
||||
client: true
|
||||
login:
|
||||
invite_only:
|
||||
refresh: true
|
||||
|
|
|
@ -339,18 +339,40 @@ RSpec.describe Report do
|
|||
CachedCounting.disable
|
||||
end
|
||||
|
||||
it "works and does not count browser or mobile pageviews" do
|
||||
3.times { ApplicationRequest.increment!(:page_view_crawler) }
|
||||
8.times { ApplicationRequest.increment!(:page_view_logged_in) }
|
||||
6.times { ApplicationRequest.increment!(:page_view_logged_in_browser) }
|
||||
2.times { ApplicationRequest.increment!(:page_view_logged_in_mobile) }
|
||||
2.times { ApplicationRequest.increment!(:page_view_anon) }
|
||||
1.times { ApplicationRequest.increment!(:page_view_anon_browser) }
|
||||
4.times { ApplicationRequest.increment!(:page_view_anon_mobile) }
|
||||
context "when use_legacy_pageviews is true" do
|
||||
before { SiteSetting.use_legacy_pageviews = true }
|
||||
|
||||
CachedCounting.flush
|
||||
it "works and does not count browser or mobile pageviews" do
|
||||
3.times { ApplicationRequest.increment!(:page_view_crawler) }
|
||||
8.times { ApplicationRequest.increment!(:page_view_logged_in) }
|
||||
6.times { ApplicationRequest.increment!(:page_view_logged_in_browser) }
|
||||
2.times { ApplicationRequest.increment!(:page_view_logged_in_mobile) }
|
||||
2.times { ApplicationRequest.increment!(:page_view_anon) }
|
||||
1.times { ApplicationRequest.increment!(:page_view_anon_browser) }
|
||||
4.times { ApplicationRequest.increment!(:page_view_anon_mobile) }
|
||||
|
||||
expect(report.data.sum { |r| r[:y] }).to eq(13)
|
||||
CachedCounting.flush
|
||||
|
||||
expect(report.data.sum { |r| r[:y] }).to eq(13)
|
||||
end
|
||||
end
|
||||
|
||||
context "when use_legacy_pageviews is false" do
|
||||
before { SiteSetting.use_legacy_pageviews = false }
|
||||
|
||||
it "works and does not count mobile pageviews, and only counts browser pageviews" do
|
||||
3.times { ApplicationRequest.increment!(:page_view_crawler) }
|
||||
8.times { ApplicationRequest.increment!(:page_view_logged_in) }
|
||||
6.times { ApplicationRequest.increment!(:page_view_logged_in_browser) }
|
||||
2.times { ApplicationRequest.increment!(:page_view_logged_in_mobile) }
|
||||
2.times { ApplicationRequest.increment!(:page_view_anon) }
|
||||
1.times { ApplicationRequest.increment!(:page_view_anon_browser) }
|
||||
4.times { ApplicationRequest.increment!(:page_view_anon_mobile) }
|
||||
|
||||
CachedCounting.flush
|
||||
|
||||
expect(report.data.sum { |r| r[:y] }).to eq(7)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1348,6 +1370,7 @@ RSpec.describe Report do
|
|||
CachedCounting.reset
|
||||
CachedCounting.enable
|
||||
ApplicationRequest.enable
|
||||
SiteSetting.use_legacy_pageviews = true
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -1392,6 +1415,51 @@ RSpec.describe Report do
|
|||
|
||||
expect(total_consolidated).to eq(total_page_views)
|
||||
end
|
||||
|
||||
it "does not include any data before the first recorded browser page view (anon or logged in)" do
|
||||
freeze_time DateTime.parse("2024-02-10")
|
||||
|
||||
3.times { ApplicationRequest.increment!(:page_view_logged_in) }
|
||||
2.times { ApplicationRequest.increment!(:page_view_anon) }
|
||||
|
||||
CachedCounting.flush
|
||||
|
||||
freeze_time DateTime.parse("2024-03-10")
|
||||
|
||||
3.times { ApplicationRequest.increment!(:page_view_logged_in) }
|
||||
2.times { ApplicationRequest.increment!(:page_view_anon) }
|
||||
|
||||
CachedCounting.flush
|
||||
|
||||
freeze_time DateTime.parse("2024-04-10")
|
||||
|
||||
3.times { ApplicationRequest.increment!(:page_view_crawler) }
|
||||
8.times { ApplicationRequest.increment!(:page_view_logged_in) }
|
||||
6.times { ApplicationRequest.increment!(:page_view_logged_in_browser) }
|
||||
2.times { ApplicationRequest.increment!(:page_view_anon) }
|
||||
1.times { ApplicationRequest.increment!(:page_view_anon_browser) }
|
||||
|
||||
CachedCounting.flush
|
||||
|
||||
report_in_range =
|
||||
Report.find(
|
||||
"consolidated_page_views_browser_detection",
|
||||
start_date: DateTime.parse("2024-02-10").beginning_of_day,
|
||||
end_date: DateTime.parse("2024-04-11").beginning_of_day,
|
||||
)
|
||||
|
||||
page_view_crawler_report = report_in_range.data.find { |r| r[:req] == "page_view_crawler" }
|
||||
page_view_logged_in_browser_report =
|
||||
report_in_range.data.find { |r| r[:req] == "page_view_logged_in_browser" }
|
||||
page_view_anon_browser_report =
|
||||
report_in_range.data.find { |r| r[:req] == "page_view_anon_browser" }
|
||||
page_view_other_report = report_in_range.data.find { |r| r[:req] == "page_view_other" }
|
||||
|
||||
expect(page_view_crawler_report[:data].sum { |d| d[:y] }).to eql(3)
|
||||
expect(page_view_logged_in_browser_report[:data].sum { |d| d[:y] }).to eql(6)
|
||||
expect(page_view_anon_browser_report[:data].sum { |d| d[:y] }).to eql(1)
|
||||
expect(page_view_other_report[:data].sum { |d| d[:y] }).to eql(3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -5,6 +5,52 @@ RSpec.describe Admin::ReportsController do
|
|||
fab!(:moderator)
|
||||
fab!(:user)
|
||||
|
||||
describe "#index" do
|
||||
before { sign_in(admin) }
|
||||
|
||||
it "excludes page view mobile reports" do
|
||||
get "/admin/reports.json"
|
||||
expect(response.parsed_body["reports"].map { |r| r[:type] }).not_to include(
|
||||
"page_view_anon_browser_mobile_reqs",
|
||||
"page_view_logged_in_browser_mobile_reqs",
|
||||
"page_view_anon_mobile_reqs",
|
||||
"page_view_logged_in_mobile_reqs",
|
||||
)
|
||||
end
|
||||
|
||||
it "excludes about and storage stats reports" do
|
||||
get "/admin/reports.json"
|
||||
expect(response.parsed_body["reports"].map { |r| r[:type] }).not_to include(
|
||||
"report_about",
|
||||
"report_storage_stats",
|
||||
)
|
||||
end
|
||||
|
||||
context "when use_legacy_pageviews is true" do
|
||||
before { SiteSetting.use_legacy_pageviews = true }
|
||||
|
||||
it "excludes the site_traffic report and includes legacy pageview reports" do
|
||||
get "/admin/reports.json"
|
||||
expect(response.parsed_body["reports"].map { |r| r[:type] }).not_to include("site_traffic")
|
||||
expect(response.parsed_body["reports"].map { |r| r[:type] }).to include(
|
||||
*Admin::ReportsController::HIDDEN_LEGACY_PAGEVIEW_REPORTS,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "when use_legacy_pageviews is false" do
|
||||
before { SiteSetting.use_legacy_pageviews = false }
|
||||
|
||||
it "includes the site_traffic report and excludes legacy pageview reports" do
|
||||
get "/admin/reports.json"
|
||||
expect(response.parsed_body["reports"].map { |r| r[:type] }).to include("site_traffic")
|
||||
expect(response.parsed_body["reports"].map { |r| r[:type] }).not_to include(
|
||||
*Admin::ReportsController::HIDDEN_LEGACY_PAGEVIEW_REPORTS,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#bulk" do
|
||||
context "when logged in as an admin" do
|
||||
before { sign_in(admin) }
|
||||
|
@ -128,6 +174,84 @@ RSpec.describe Admin::ReportsController do
|
|||
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
|
||||
end
|
||||
end
|
||||
|
||||
context "when use_legacy_pageviews is true" do
|
||||
before do
|
||||
SiteSetting.use_legacy_pageviews = true
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
it "marks the site_traffic report as not_found and does not run it" do
|
||||
get "/admin/reports/bulk.json",
|
||||
params: {
|
||||
reports: {
|
||||
site_traffic: {
|
||||
limit: 10,
|
||||
},
|
||||
consolidated_page_views: {
|
||||
limit: 10,
|
||||
},
|
||||
consolidated_page_views_browser_detection: {
|
||||
limit: 10,
|
||||
},
|
||||
page_view_anon_reqs: {
|
||||
limit: 10,
|
||||
},
|
||||
page_view_logged_in_reqs: {
|
||||
limit: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["reports"].count).to eq(5)
|
||||
expect(response.parsed_body["reports"][0]).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]["type"]).to eq(
|
||||
"consolidated_page_views_browser_detection",
|
||||
)
|
||||
expect(response.parsed_body["reports"][3]["type"]).to eq("page_view_anon_reqs")
|
||||
expect(response.parsed_body["reports"][4]["type"]).to eq("page_view_logged_in_reqs")
|
||||
end
|
||||
end
|
||||
|
||||
context "when use_legacy_pageviews is false" do
|
||||
before do
|
||||
SiteSetting.use_legacy_pageviews = false
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
it "marks the legacy pageview reports as not_found and does not run them" do
|
||||
get "/admin/reports/bulk.json",
|
||||
params: {
|
||||
reports: {
|
||||
site_traffic: {
|
||||
limit: 10,
|
||||
},
|
||||
consolidated_page_views: {
|
||||
limit: 10,
|
||||
},
|
||||
consolidated_page_views_browser_detection: {
|
||||
limit: 10,
|
||||
},
|
||||
page_view_anon_reqs: {
|
||||
limit: 10,
|
||||
},
|
||||
page_view_logged_in_reqs: {
|
||||
limit: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(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"][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)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#show" do
|
||||
|
@ -228,5 +352,35 @@ RSpec.describe Admin::ReportsController do
|
|||
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
|
||||
end
|
||||
end
|
||||
|
||||
context "when use_legacy_pageviews is true" do
|
||||
before do
|
||||
SiteSetting.use_legacy_pageviews = true
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
it "does not allow running site_traffic report" do
|
||||
Admin::ReportsController::HIDDEN_PAGEVIEW_REPORTS.each do |report_type|
|
||||
get "/admin/reports/#{report_type}.json"
|
||||
expect(response.status).to eq(404)
|
||||
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when use_legacy_pageviews is false" do
|
||||
before do
|
||||
SiteSetting.use_legacy_pageviews = false
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
it "does not allow running legacy pageview reports" do
|
||||
Admin::ReportsController::HIDDEN_LEGACY_PAGEVIEW_REPORTS.each do |report_type|
|
||||
get "/admin/reports/#{report_type}.json"
|
||||
expect(response.status).to eq(404)
|
||||
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
33
spec/system/admin_dashboard_community_health_spec.rb
Normal file
33
spec/system/admin_dashboard_community_health_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe "Admin Dashboard Community Health", type: :system do
|
||||
fab!(:current_user) { Fabricate(:admin) }
|
||||
|
||||
before { sign_in(current_user) }
|
||||
|
||||
describe "Pageview Report" do
|
||||
context "when use_legacy_pageviews is true" do
|
||||
before { SiteSetting.use_legacy_pageviews = true }
|
||||
|
||||
it "shows the 'Consolidated Pageviews' report" do
|
||||
visit("/admin")
|
||||
expect(page).to have_css(
|
||||
".admin-report.consolidated-page-views",
|
||||
text: I18n.t("reports.consolidated_page_views.title"),
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "when use_legacy_pageviews is false" do
|
||||
before { SiteSetting.use_legacy_pageviews = false }
|
||||
|
||||
it "shows the 'Site Traffic' report" do
|
||||
visit("/admin")
|
||||
expect(page).to have_css(
|
||||
".admin-report.site-traffic",
|
||||
text: I18n.t("reports.site_traffic.title"),
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user