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:
Martin Brennan
2024-09-10 09:51:49 +10:00
committed by GitHub
parent aacd354de5
commit 14b436923c
16 changed files with 477 additions and 107 deletions

View File

@@ -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