Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Add top entry URLs to Site Traffic (#42669)

Alan Guo Xiang Tan2859ead8ce79
diff --git a/app/jobs/scheduled/maintain_browser_pageview_rollups.rb b/app/jobs/scheduled/maintain_browser_pageview_rollups.rb
index 14d604d38a4..ab616a6ad94 100644
--- a/app/jobs/scheduled/maintain_browser_pageview_rollups.rb
+++ b/app/jobs/scheduled/maintain_browser_pageview_rollups.rb
@@ -12,8 +12,10 @@ module Jobs
aggregate_pageviews
aggregate_engagement
aggregate_crawlers
- backfill_referrers
- backfill_urls
+ entry_url_rollups_initialized = BrowserPageviewEntryUrlDailyRollup.exists?
+ backfill_referrers(recompute_entry_urls: entry_url_rollups_initialized)
+ backfill_urls(recompute_entry_urls: entry_url_rollups_initialized)
+ aggregate_entry_urls if referrer_backfill_complete? && url_backfill_complete?
backfill_browsers
end
@@ -56,6 +58,24 @@ module Jobs
)
end
+ def aggregate_entry_urls
+ start_date, end_date = entry_url_aggregation_window
+
+ BrowserPageviewEntryUrlDailyRollup.aggregate(start_date:, end_date:) if start_date
+ end
+
+ def entry_url_aggregation_window
+ end_date = Time.zone.today
+ start_date =
+ if BrowserPageviewEntryUrlDailyRollup.none?
+ earliest_event_date
+ else
+ 1.day.ago.to_date
+ end
+
+ [start_date, end_date]
+ end
+
def engagement_aggregation_window
end_date = Time.zone.today
start_date =
@@ -83,19 +103,22 @@ module Jobs
&.to_date
end
- def backfill_referrers
+ def backfill_referrers(recompute_entry_urls:)
rows = next_batch
return if rows.empty?
ids = rows.map(&:id)
store_normalized_referrers(rows)
- BrowserPageviewReferrerDailyRollup.recompute(recomputable_dates(ids))
+ referrer_dates = recomputable_dates(ids)
+ entry_url_dates = entry_url_recomputable_dates(ids, backfill: :referrer)
+ BrowserPageviewReferrerDailyRollup.recompute(referrer_dates)
+ BrowserPageviewEntryUrlDailyRollup.recompute(entry_url_dates) if recompute_entry_urls
stamp_version(ids)
end
- def next_batch
- params = { version: BrowserPageviewEventUrlNormalizer::REFERRER_VERSION, limit: batch_size }
+ def next_batch(limit: batch_size)
+ params = { version: BrowserPageviewEventUrlNormalizer::REFERRER_VERSION, limit: }
retention_clause = ""
if SiteSetting.clean_up_browser_pageview_events
@@ -186,31 +209,90 @@ module Jobs
SQL
end
- def backfill_urls
+ def referrer_backfill_complete?
+ next_batch(limit: 1).empty?
+ end
+
+ def backfill_urls(recompute_entry_urls:)
rows = url_batch
return if rows.empty?
ids = rows.map(&:id)
normalized = rows.map { |row| BrowserPageviewEventUrlNormalizer.normalize_site_path(row.url) }
- DB.exec(
- <<~SQL,
+ DB.exec(<<~SQL, ids: ids, normalized: normalized)
UPDATE browser_pageview_events AS e
- SET
- normalized_url = data.normalized_url,
- normalized_url_version = :version
+ SET normalized_url = data.normalized_url
FROM unnest(
ARRAY[:ids]::bigint[],
ARRAY[:normalized]::text[]
) AS data(id, normalized_url)
WHERE e.id = data.id
SQL
- ids: ids,
- normalized: normalized,
- version: BrowserPageviewEventUrlNormalizer::SITE_PATH_VERSION,
+ if recompute_entry_urls
+ BrowserPageviewEntryUrlDailyRollup.recompute(
+ entry_url_recomputable_dates(ids, backfill: :url),
+ )
+ end
+ stamp_url_version(ids)
+ end
+
+ def url_backfill_complete?
+ url_batch(limit: 1).empty?
+ end
+
+ def entry_url_recomputable_dates(ids, backfill:)
+ url_batch_condition = backfill == :url ? "AND events.id NOT IN (:ids)" : ""
+ referrer_batch_condition = backfill == :referrer ? "AND events.id NOT IN (:ids)" : ""
+
+ DB.query_single(
+ <<~SQL,
+ WITH touched_dates AS (
+ SELECT DISTINCT created_at::date AS date
+ FROM browser_pageview_events
+ WHERE id IN (:ids)
+ )
+ SELECT touched_dates.date
+ FROM touched_dates
+ WHERE NOT EXISTS (
+ SELECT 1
+ FROM browser_pageview_events events
+ WHERE events.created_at >= touched_dates.date
+ AND events.created_at < touched_dates.date + 1
+ AND #{BrowserPageviewEvent.rollup_source_condition(table: "events")}
+ AND (
+ (
+ (
+ events.normalized_url_version IS NULL
+ OR events.normalized_url_version < :url_version
+ )
+ #{url_batch_condition}
+ )
+ OR (
+ events.referrer IS NOT NULL
+ AND (
+ events.normalized_referrer_version IS NULL
+ OR events.normalized_referrer_version < :referrer_version
+ )
+ #{referrer_batch_condition}
+ )
+ )
+ )
+ SQL
+ ids:,
+ url_version: BrowserPageviewEventUrlNormalizer::SITE_PATH_VERSION,
+ referrer_version: BrowserPageviewEventUrlNormalizer::REFERRER_VERSION,
)
end
+ def stamp_url_version(ids)
+ DB.exec(<<~SQL, version: BrowserPageviewEventUrlNormalizer::SITE_PATH_VERSION, ids: ids)
+ UPDATE browser_pageview_events
+ SET normalized_url_version = :version
+ WHERE id IN (:ids)
+ SQL
+ end
+
def backfill_browsers
rows = browser_batch
return if rows.empty?
@@ -247,7 +329,7 @@ module Jobs
SQL
end
- def url_batch
+ def url_batch(limit: batch_size)
DB.query(
<<~SQL,
SELECT id, url
@@ -263,7 +345,7 @@ module Jobs
SQL
retention_cutoff: BrowserPageviewEvent.retention_cutoff,
version: BrowserPageviewEventUrlNormalizer::SITE_PATH_VERSION,
- limit: batch_size,
+ limit:,
)
end
diff --git a/app/models/browser_pageview_entry_url_daily_rollup.rb b/app/models/browser_pageview_entry_url_daily_rollup.rb
new file mode 100644
index 00000000000..0f36bcb5ee0
--- /dev/null
+++ b/app/models/browser_pageview_entry_url_daily_rollup.rb
@@ -0,0 +1,113 @@
+# frozen_string_literal: true
+
+class BrowserPageviewEntryUrlDailyRollup < ActiveRecord::Base
+ def self.aggregate(start_date:, end_date:)
+ start_date = [start_date.to_date, BrowserPageviewEvent.retention_cutoff.to_date].max
+ start_date = rebuildable_start_date(start_date)
+ end_date = end_date.to_date
+ return if start_date > end_date
+
+ exclusive_end_date = end_date + 1
+ source_condition =
+ BrowserPageviewEvent.rollup_source_condition(
+ table: "events",
+ start_date:,
+ end_date: exclusive_end_date,
+ )
+ transaction do
+ DB.exec(<<~SQL, start_date:, end_date: exclusive_end_date)
+ DELETE FROM browser_pageview_entry_url_daily_rollups rollup
+ WHERE rollup.date >= :start_date
+ AND rollup.date < :end_date
+ AND EXISTS (
+ SELECT 1
+ FROM browser_pageview_events events
+ WHERE events.created_at >= rollup.date
+ AND events.created_at < rollup.date + 1
+ AND #{source_condition}
+ )
+ SQL
+
+ DB.exec(<<~SQL, start_date:, end_date: exclusive_end_date, site_hostnames:)
+ INSERT INTO browser_pageview_entry_url_daily_rollups (
+ date,
+ entry_url,
+ count,
+ logged_in_count,
+ likely_crawler_count,
+ likely_crawler_logged_in_count
+ )
+ SELECT
+ events.created_at::date,
+ events.normalized_url,
+ COUNT(*),
+ COUNT(*) FILTER (WHERE events.user_id IS NOT NULL),
+ COUNT(*) FILTER (
+ WHERE COALESCE(#{CrawlerScorer.likely_crawler_condition(table: "events")}, false)
+ ),
+ COUNT(*) FILTER (
+ WHERE events.user_id IS NOT NULL
+ AND COALESCE(#{CrawlerScorer.likely_crawler_condition(table: "events")}, false)
+ )
+ FROM browser_pageview_events events
+ WHERE events.created_at >= :start_date
+ AND events.created_at < :end_date
+ AND #{source_condition}
+ AND events.normalized_url IS NOT NULL
+ AND (
+ NULLIF(events.referrer, '') IS NULL
+ OR (
+ events.normalized_referrer IS NOT NULL
+ AND split_part(split_part(events.normalized_referrer, '/', 1), '?', 1)
+ NOT IN (:site_hostnames)
+ )
+ )
+ GROUP BY events.created_at::date, events.normalized_url
+ SQL
+ end
+ end
+
+ def self.recompute(dates)
+ Array(dates).map(&:to_date).uniq.each { |date| aggregate(start_date: date, end_date: date) }
+ end
+
+ def self.rebuildable_start_date(start_date)
+ earliest_source_date =
+ BrowserPageviewEvent
+ .where("created_at >= ?", BrowserPageviewEvent.retention_cutoff)
+ .where(BrowserPageviewEvent.rollup_source_condition)
+ .minimum(:created_at)
+ &.to_date
+ return start_date if earliest_source_date.nil? || start_date > earliest_source_date
+
+ has_older_rollups = where("date < ?", earliest_source_date).exists?
+ has_older_rollups ? earliest_source_date + 1 : start_date
+ end
+ private_class_method :rebuildable_start_date
+
+ def self.site_hostnames
+ hostnames =
+ RailsMultisite::ConnectionManagement.current_db_hostnames + [Discourse.current_hostname]
+ hostnames
+ .filter_map { |hostname| BrowserPageviewEventUrlNormalizer.normalize_host(hostname) }
+ .uniq
+ end
+ private_class_method :site_hostnames
+end
+
+# == Schema Information
+#
+# Table name: browser_pageview_entry_url_daily_rollups
+#
+# id :bigint not null, primary key
+# count :bigint not null
+# date :date not null
+# entry_url :string(2000) not null
+# likely_crawler_count :bigint default(0), not null
+# likely_crawler_logged_in_count :bigint default(0), not null
+# logged_in_count :bigint not null
+#
+# Indexes
+#
+# idx_bpeu_daily_rollups_date_url_unique (date,entry_url) UNIQUE
+#
diff --git a/app/models/concerns/reports/top_entry_urls.rb b/app/models/concerns/reports/top_entry_urls.rb
new file mode 100644
index 00000000000..11f7dcb116c
--- /dev/null
+++ b/app/models/concerns/reports/top_entry_urls.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+module Reports::TopEntryUrls
+ extend ActiveSupport::Concern
+
+ MAX_ROWS = 200
+
+ class_methods do
+ def report_top_entry_urls(report)
+ report.modes = [Report::MODES[:table]]
+ report.labels = [
+ {
+ properties: %i[entry_url entry_url],
+ type: :link,
+ title: I18n.t("reports.top_entry_urls.labels.entry_url"),
+ },
+ { property: :count, type: :number, title: I18n.t("reports.top_entry_urls.labels.count") },
+ ]
+
+ count_sql = BrowserPageviewEvent.rollup_count_sql
+
+ report.data =
+ DB
+ .query(
+ <<~SQL,
+ WITH ranked AS (
+ SELECT
+ entry_url,
+ SUM(#{count_sql}) AS count,
+ SUM(SUM(#{count_sql})) OVER () AS total
+ FROM browser_pageview_entry_url_daily_rollups
+ WHERE date >= :start_date
+ AND date <= :end_date
+ GROUP BY entry_url
+ HAVING SUM(#{count_sql}) > 0
+ )
+ SELECT
+ entry_url,
+ count,
+ CASE
+ WHEN total = 0 THEN 0
+ ELSE ROUND((count::numeric / total) * 100)::integer
+ END AS percent
+ FROM ranked
+ ORDER BY count DESC, entry_url ASC
+ LIMIT :limit
+ SQL
+ start_date: report.start_date.to_date,
+ end_date: report.end_date.to_date,
+ limit: MAX_ROWS,
+ )
+ .map { |row| { entry_url: row.entry_url, count: row.count, percent: row.percent } }
+ end
+ end
+end
diff --git a/app/models/report.rb b/app/models/report.rb
index 4f70e5ded66..858781fe2fe 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -28,7 +28,7 @@ class Report
storage_stats: :storage_stats,
}
- HIDDEN_PAGEVIEW_REPORTS = %w[site_traffic page_view_legacy_total_reqs]
+ HIDDEN_PAGEVIEW_REPORTS = %w[site_traffic page_view_legacy_total_reqs top_entry_urls]
HIDDEN_LEGACY_PAGEVIEW_REPORTS = %w[
consolidated_page_views_browser_detection
@@ -40,12 +40,14 @@ class Report
admin_logins
top_uploads
topic_view_stats
+ top_entry_urls
top_referrers_by_browser_pageviews
top_countries_by_browser_pageviews
]
IP_ADDRESS_REPORTS = %w[suspicious_logins]
BROWSER_PAGEVIEW_REPORTS = %w[
top_countries_by_browser_pageviews
+ top_entry_urls
top_referrers_by_browser_pageviews
]
@@ -122,6 +124,7 @@ class Report
include Reports::SystemPrivateMessages
include Reports::TimeToFirstResponse
include Reports::TopCountriesByBrowserPageviews
+ include Reports::TopEntryUrls
include Reports::TopIgnoredUsers
include Reports::TopReferredTopics
include Reports::TopReferrers
diff --git a/app/services/admin_dashboard_site_traffic.rb b/app/services/admin_dashboard_site_traffic.rb
index cb5bb654e87..7ccdf82128e 100644
--- a/app/services/admin_dashboard_site_traffic.rb
+++ b/app/services/admin_dashboard_site_traffic.rb
@@ -46,6 +46,9 @@ class AdminDashboardSiteTraffic
top_referrers = fetch_card("top_referrers_by_browser_pageviews")
response[:top_referrers] = top_referrers if top_referrers
+
+ top_entry_urls = fetch_card("top_entry_urls")
+ response[:top_entry_urls] = top_entry_urls if top_entry_urls
end
response
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 772af7d26af..7825e34ef06 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -7694,6 +7694,10 @@ en:
title: "Top referrers"
empty: "No referrer data for this period."
error: "Couldn't load top referrers. Try refreshing the page."
+ top_entry_urls:
+ title: "Top entry URLs"
+ empty: "No entry URL data for this period."
+ error: "Couldn't load top entry URLs. Try refreshing the page."
series:
logged_in: "Logged in"
anonymous: "Anonymous"
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 7b7203f97c0..b35b5365ef6 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1663,6 +1663,12 @@ en:
labels:
country_code: "Country code"
count: "Visits"
+ top_entry_urls:
+ title: "Top entry URLs"
+ description: "Pages that received the most direct or externally referred browser visits in the selected period."
+ labels:
+ entry_url: "Entry URL"
+ count: "Visits"
top_referrers_by_browser_pageviews:
title: "Top referrers"
description: "External sites referring the most browser pageviews to your forum in the selected period."
diff --git a/db/migrate/20260818081537_create_browser_pageview_entry_url_rollups.rb b/db/migrate/20260818081537_create_browser_pageview_entry_url_rollups.rb
new file mode 100644
index 00000000000..ecffe75670c
--- /dev/null
+++ b/db/migrate/20260818081537_create_browser_pageview_entry_url_rollups.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class CreateBrowserPageviewEntryUrlRollups < ActiveRecord::Migration[8.0]
+ def change
+ create_table :browser_pageview_entry_url_daily_rollups do |t|
+ t.date :date, null: false
+ t.string :entry_url, limit: 2000, null: false
+ t.bigint :count, null: false
+ t.bigint :logged_in_count, null: false
+ t.bigint :likely_crawler_count, default: 0, null: false
+ t.bigint :likely_crawler_logged_in_count, default: 0, null: false
+ end
+
+ add_index :browser_pageview_entry_url_daily_rollups,
+ %i[date entry_url],
+ unique: true,
+ name: "idx_bpeu_daily_rollups_date_url_unique"
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index d35200eda7e..ce8fda7a3e6 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -2013,6 +2013,40 @@ CREATE SEQUENCE public.browser_pageview_crawler_daily_rollups_id_seq
ALTER SEQUENCE public.browser_pageview_crawler_daily_rollups_id_seq OWNED BY public.browser_pageview_crawler_daily_rollups.id;
+--
+-- Name: browser_pageview_entry_url_daily_rollups; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE public.browser_pageview_entry_url_daily_rollups (
+ id bigint NOT NULL,
+ date date NOT NULL,
+ entry_url character varying(2000) NOT NULL,
+ count bigint NOT NULL,
+ logged_in_count bigint NOT NULL,
+ likely_crawler_count bigint DEFAULT 0 NOT NULL,
+ likely_crawler_logged_in_count bigint DEFAULT 0 NOT NULL
+);
+
+
+--
+-- Name: browser_pageview_entry_url_daily_rollups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE public.browser_pageview_entry_url_daily_rollups_id_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+
+--
+-- Name: browser_pageview_entry_url_daily_rollups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE public.browser_pageview_entry_url_daily_rollups_id_seq OWNED BY public.browser_pageview_entry_url_daily_rollups.id;
+
+
--
-- Name: browser_pageview_event_scores; Type: TABLE; Schema: public; Owner: -
--
@@ -12818,6 +12852,13 @@ ALTER TABLE ONLY public.browser_pageview_country_daily_rollups ALTER COLUMN id S
ALTER TABLE ONLY public.browser_pageview_crawler_daily_rollups ALTER COLUMN id SET DEFAULT nextval('public.browser_pageview_crawler_daily_rollups_id_seq'::regclass);
+--
+-- Name: browser_pageview_entry_url_daily_rollups id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.browser_pageview_entry_url_daily_rollups ALTER COLUMN id SET DEFAULT nextval('public.browser_pageview_entry_url_daily_rollups_id_seq'::regclass);
+
+
--
-- Name: browser_pageview_event_scores id; Type: DEFAULT; Schema: public; Owner: -
--
@@ -15119,6 +15160,14 @@ ALTER TABLE ONLY public.browser_pageview_crawler_daily_rollups
ADD CONSTRAINT browser_pageview_crawler_daily_rollups_pkey PRIMARY KEY (id);
+--
+-- Name: browser_pageview_entry_url_daily_rollups browser_pageview_entry_url_daily_rollups_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.browser_pageview_entry_url_daily_rollups
+ ADD CONSTRAINT browser_pageview_entry_url_daily_rollups_pkey PRIMARY KEY (id);
+
+
--
-- Name: browser_pageview_event_scores browser_pageview_event_scores_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@@ -17693,6 +17742,13 @@ CREATE INDEX idx_bpe_normalized_url_version ON public.browser_pageview_events US
CREATE INDEX idx_bpe_session_created_at ON public.browser_pageview_events USING btree (session_id, created_at);
+--
+-- Name: idx_bpeu_daily_rollups_date_url_unique; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE UNIQUE INDEX idx_bpeu_daily_rollups_date_url_unique ON public.browser_pageview_entry_url_daily_rollups USING btree (date, entry_url);
+
+
--
-- Name: idx_bprd_rollups_date_referrer_unique; Type: INDEX; Schema: public; Owner: -
--
@@ -23225,6 +23281,7 @@ ALTER TABLE ONLY public.ad_plugin_house_ads_groups
SET search_path TO "$user", public;
INSERT INTO "schema_migrations" (version) VALUES
+('20260818081537'),
('20260818045317'),
('20260818045314'),
('20260818045311'),
diff --git a/frontend/discourse/admin/components/dashboard/traffic.gjs b/frontend/discourse/admin/components/dashboard/traffic.gjs
index d0c384e86cb..749c9a57579 100644
--- a/frontend/discourse/admin/components/dashboard/traffic.gjs
+++ b/frontend/discourse/admin/components/dashboard/traffic.gjs
@@ -7,6 +7,7 @@ import DashboardSection from "discourse/admin/components/dashboard/section";
import { countryFlag, countryName } from "discourse/admin/lib/format-country";
import DTooltip from "discourse/float-kit/components/d-tooltip";
import { formatMinutesSeconds } from "discourse/lib/formatter";
+import getURL from "discourse/lib/get-url";
import { or } from "discourse/truth-helpers";
import dIcon from "discourse/ui-kit/helpers/d-icon";
import I18n, { i18n } from "discourse-i18n";
@@ -434,7 +435,13 @@ export default class DashboardTraffic extends Component {
{{#unless @fetchError}}
{{#if @traffic}}
- {{#if (or @traffic.top_countries @traffic.top_referrers)}}
+ {{#if
+ (or
+ @traffic.top_countries
+ @traffic.top_referrers
+ @traffic.top_entry_urls
+ )
+ }}
<div class="db-section__row">
<div class="db-section__row-block">
<h3 class="db-section__row-block-title">
@@ -492,6 +499,63 @@ export default class DashboardTraffic extends Component {
{{/if}}
</div>
+ {{#if @traffic.top_entry_urls}}
+ <div class="db-section__row-block">
+ <h3 class="db-section__row-block-title">
+ <LinkTo
+ @route="adminReports.show"
+ @model="top_entry_urls"
+ @query={{hash
+ start_date=this.reportQuery.start_date
+ end_date=this.reportQuery.end_date
+ }}
+ >
+ {{i18n
+ "admin.dashboard.site_traffic.top_entry_urls.title"
+ }}
+ <span class="db-link-arrow" aria-hidden="true">
+ {{dIcon "arrow-right"}}
+ </span>
+ </LinkTo>
+ </h3>
+
+ {{#if @traffic.top_entry_urls.error}}
+ <p class="db-traffic__list-error" role="status">
+ {{i18n
+ "admin.dashboard.site_traffic.top_entry_urls.error"
+ }}
+ </p>
+ {{else if @traffic.top_entry_urls.rows.length}}
+ <ul class="db-traffic__list">
+ {{#each @traffic.top_entry_urls.rows as |row|}}
+ <li class="db-traffic__list-row">
+ <a
+ class="db-traffic__link"
+ href={{getURL row.entry_url}}
+ >
+ {{row.entry_url}}
+ </a>
+ <span class="db-traffic__metric">
+ <span class="db-traffic__percent">
+ {{row.percent}}%
+ </span>
+ <span class="db-traffic__count">
+ ({{this.formatHeadlineCount row.count}})
+ </span>
+ </span>
+ </li>
+ {{/each}}
+ </ul>
+ {{else}}
+ <p class="db-traffic__list-empty">
+ {{i18n
+ "admin.dashboard.site_traffic.top_entry_urls.empty"
+ }}
+ </p>
+ {{/if}}
+ </div>
+ {{/if}}
+
<div class="db-section__row-block">
<h3 class="db-section__row-block-title">
<LinkTo
@@ -558,6 +622,14 @@ export default class DashboardTraffic extends Component {
</h3>
<div class="db-traffic__list-shell"></div>
</div>
+ {{#if this.currentUser.admin}}
+ <div class="db-section__row-block">
+ <h3 class="db-section__row-block-title">
+ {{i18n "admin.dashboard.site_traffic.top_entry_urls.title"}}
+ </h3>
+ <div class="db-traffic__list-shell"></div>
+ </div>
+ {{/if}}
<div class="db-section__row-block">
<h3 class="db-section__row-block-title">
{{i18n "admin.dashboard.site_traffic.top_countries.title"}}
diff --git a/frontend/discourse/tests/integration/components/dashboard/traffic-test.gjs b/frontend/discourse/tests/integration/components/dashboard/traffic-test.gjs
new file mode 100644
index 00000000000..a208b2ca569
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/dashboard/traffic-test.gjs
@@ -0,0 +1,92 @@
+import { render } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import DashboardTraffic from "discourse/admin/components/dashboard/traffic";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+
+const startDate = new Date("2026-05-01");
+const endDate = new Date("2026-05-14");
+const entryUrlCard = ".db-section__row-block:nth-child(2)";
+
+function trafficWithEntryUrls(topEntryUrls) {
+ return {
+ kpis: { browser_pageviews: { value: 0 } },
+ pageview_series: [],
+ top_entry_urls: topEntryUrls,
+ };
+}
+
+module("Integration | Component | Dashboard | Traffic", function (hooks) {
+ setupRenderingTest(hooks, { stubRouter: true });
+
+ test("renders the entry URL loading placeholder for admins", async function (assert) {
+ this.currentUser.admin = true;
+
+ await render(
+ <template>
+ <DashboardTraffic
+ @traffic={{null}}
+ @startDate={{startDate}}
+ @endDate={{endDate}}
+ />
+ </template>
+ );
+
+ assert
+ .dom(".db-traffic__list-shell")
+ .exists({ count: 3 }, "shows all three loading placeholders");
+ assert
+ .dom(`${entryUrlCard} .db-section__row-block-title`)
+ .hasText("Top entry URLs", "places it beside Top referrers");
+ });
+
+ test("renders the entry URL report error", async function (assert) {
+ const traffic = trafficWithEntryUrls({
+ rows: [],
+ error: "exception",
+ });
+
+ await render(
+ <template>
+ <DashboardTraffic
+ @traffic={{traffic}}
+ @startDate={{startDate}}
+ @endDate={{endDate}}
+ />
+ </template>
+ );
+
+ assert
+ .dom(`${entryUrlCard} .db-traffic__list-error`)
+ .hasText(
+ "Couldn't load top entry URLs. Try refreshing the page.",
+ "shows a retryable error in the entry URL card"
+ );
+ });
+
+ test("renders the entry URL empty state", async function (assert) {
+ const traffic = trafficWithEntryUrls({
+ rows: [],
+ error: null,
+ });
+
+ await render(
+ <template>
+ <DashboardTraffic
+ @traffic={{traffic}}
+ @startDate={{startDate}}
+ @endDate={{endDate}}
+ />
+ </template>
+ );
+
+ assert
+ .dom(`${entryUrlCard} .db-traffic__list-empty`)
+ .hasText(
+ "No entry URL data for this period.",
+ "shows when no eligible entries exist"
+ );
+ assert
+ .dom("[data-identifier='site-traffic-top-entry-urls-tooltip']")
+ .doesNotExist("omits the entry URL tooltip");
+ });
+});
diff --git a/lib/dashboard_rollup_rebuilder.rb b/lib/dashboard_rollup_rebuilder.rb
index 1221568871b..101ba245b75 100644
--- a/lib/dashboard_rollup_rebuilder.rb
+++ b/lib/dashboard_rollup_rebuilder.rb
@@ -8,6 +8,7 @@
class DashboardRollupRebuilder
NAMES = %w[
browser_pageview_country
+ browser_pageview_entry_url
browser_pageview_referrer
browser_pageview_session_engagement
browser_pageview_crawler
@@ -44,6 +45,10 @@ class DashboardRollupRebuilder
aggregate_browser_pageviews(BrowserPageviewCountryDailyRollup)
end
+ def rebuild_browser_pageview_entry_url
+ aggregate_browser_pageviews(BrowserPageviewEntryUrlDailyRollup)
+ end
+
def rebuild_browser_pageview_referrer
aggregate_browser_pageviews(BrowserPageviewReferrerDailyRollup)
end
diff --git a/spec/fabricators/browser_pageview_entry_url_daily_rollup_fabricator.rb b/spec/fabricators/browser_pageview_entry_url_daily_rollup_fabricator.rb
new file mode 100644
index 00000000000..d7bfe238fdb
--- /dev/null
+++ b/spec/fabricators/browser_pageview_entry_url_daily_rollup_fabricator.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+Fabricator(:browser_pageview_entry_url_daily_rollup) do
+ date { Time.zone.today }
+ entry_url "/latest"
+ count 1
+ logged_in_count 0
+ likely_crawler_count 0
+ likely_crawler_logged_in_count 0
+end
diff --git a/spec/jobs/maintain_browser_pageview_rollups_spec.rb b/spec/jobs/maintain_browser_pageview_rollups_spec.rb
index 5806f29d303..7406ed27897 100644
--- a/spec/jobs/maintain_browser_pageview_rollups_spec.rb
+++ b/spec/jobs/maintain_browser_pageview_rollups_spec.rb
@@ -521,8 +521,100 @@ RSpec.describe Jobs::MaintainBrowserPageviewRollups do
end
end
- context "when backfilling URLs" do
- it "normalizes retained stale rows and stamps the current version" do
+ context "when aggregating entry URLs" do
+ it "keeps entry URL counts stable across repeated runs" do
+ freeze_time(Time.zone.local(2026, 5, 14, 12, 0, 0))
+ Fabricate(:browser_pageview_event, url: "/search?q=private", created_at: "2026-05-12")
+
+ job.execute({})
+
+ expect(BrowserPageviewEntryUrlDailyRollup.pluck(:entry_url, :count)).to eq([["/search", 1]])
+
+ job.execute({})
+
+ expect(BrowserPageviewEntryUrlDailyRollup.pluck(:entry_url, :count)).to eq([["/search", 1]])
+ end
+
+ it "does not publish partial counts while retained URLs are being normalized" do
+ freeze_time(Time.zone.local(2026, 5, 14, 12, 0, 0))
+ SiteSetting.browser_pageview_referrer_backfill_batch_size = 1
+ 2.times do |index|
+ event =
+ Fabricate(
+ :browser_pageview_event,
+ session_id: "stale-url-session-#{index}",
+ url: "/latest",
+ created_at: "2026-05-12",
+ )
+ event.update_columns(normalized_url: nil, normalized_url_version: nil)
+ end
+
+ job.execute({})
+
+ expect(BrowserPageviewEntryUrlDailyRollup.all).to be_empty
+
+ job.execute({})
+
+ expect(BrowserPageviewEntryUrlDailyRollup.sum(:count)).to eq(2)
+ end
+
+ it "includes every retained date in the first report" do
+ freeze_time(Time.zone.local(2026, 5, 14, 12, 0, 0))
+ Fabricate(:browser_pageview_event, url: "/latest", created_at: "2026-05-10")
+ stale = Fabricate(:browser_pageview_event, url: "/top", created_at: "2026-05-12")
+ stale.update_columns(normalized_url: nil, normalized_url_version: nil)
+
+ job.execute({})
+
+ expect(
+ BrowserPageviewEntryUrlDailyRollup.pluck(:date, :entry_url, :count),
+ ).to contain_exactly(
+ [Date.new(2026, 5, 10), "/latest", 1],
+ [Date.new(2026, 5, 12), "/top", 1],
+ )
+ end
+
+ it "updates recent counts without changing older counts" do
+ freeze_time(Time.zone.local(2026, 5, 14, 12, 0, 0))
+ Fabricate(:browser_pageview_event, url: "/latest", created_at: "2026-05-10")
+ job.execute({})
+
+ Fabricate(:browser_pageview_event, url: "/top", created_at: "2026-05-10")
+ Fabricate(:browser_pageview_event, url: "/faq", created_at: "2026-05-14")
+
+ freeze_time(Time.zone.local(2026, 5, 15, 0, 10, 0))
+ job.execute({})
+
+ expect(
+ BrowserPageviewEntryUrlDailyRollup.pluck(:date, :entry_url, :count),
+ ).to contain_exactly(
+ [Date.new(2026, 5, 10), "/latest", 1],
+ [Date.new(2026, 5, 14), "/faq", 1],
+ )
+ end
+
+ it "does not publish partial counts while retained referrers are being normalized" do
+ freeze_time(Time.zone.local(2026, 5, 14, 12, 0, 0))
+ SiteSetting.browser_pageview_referrer_backfill_batch_size = 1
+ 2.times do
+ Fabricate(
+ :browser_pageview_event_with_unnormalized_referrer,
+ url: "/latest",
+ referrer: "https://google.com/search",
+ created_at: "2026-05-12",
+ )
+ end
+
+ job.execute({})
+
+ expect(BrowserPageviewEntryUrlDailyRollup.all).to be_empty
+
+ job.execute({})
+
+ expect(BrowserPageviewEntryUrlDailyRollup.sum(:count)).to eq(2)
+ end
+
+ it "normalizes retained URLs before reporting them" do
event =
Fabricate(
:browser_pageview_event,
@@ -539,7 +631,7 @@ RSpec.describe Jobs::MaintainBrowserPageviewRollups do
)
end
- it "resumes bounded batches without revisiting current rows" do
+ it "finishes URL normalization across bounded maintenance runs" do
SiteSetting.browser_pageview_referrer_backfill_batch_size = 1
first = Fabricate(:browser_pageview_event, url: "/first")
second = Fabricate(:browser_pageview_event, url: "/second")
@@ -558,9 +650,13 @@ RSpec.describe Jobs::MaintainBrowserPageviewRollups do
expect(BrowserPageviewEvent.where(normalized_url_version: nil)).to be_empty
end
- it "re-normalizes rows stamped with an older version" do
+ it "updates historical counts when URL normalization changes" do
+ freeze_time(Time.zone.local(2026, 5, 14, 12, 0, 0))
raw = "https://forum.example/latest/?sort=recent#section"
- event = Fabricate(:browser_pageview_event, url: raw)
+ changed_raw = "https://forum.example/top/"
+ event = Fabricate(:browser_pageview_event, url: raw, created_at: "2026-05-10")
+ job.execute({})
+ event.update_column(:url, changed_raw)
stub_const(
BrowserPageviewEventUrlNormalizer,
@@ -571,15 +667,66 @@ RSpec.describe Jobs::MaintainBrowserPageviewRollups do
event.reload
expect(event.normalized_url).to eq(
- BrowserPageviewEventUrlNormalizer.normalize_site_path(raw),
+ BrowserPageviewEventUrlNormalizer.normalize_site_path(changed_raw),
)
expect(event.normalized_url_version).to eq(
BrowserPageviewEventUrlNormalizer::SITE_PATH_VERSION,
)
+ expect(
+ BrowserPageviewEntryUrlDailyRollup.pluck(:date, :entry_url, :count),
+ ).to contain_exactly([Date.new(2026, 5, 10), "/top", 1])
end
end
- it "does not backfill rows outside the retained window" do
+ it "removes a historical entry after interrupted referrer normalization resumes" do
+ freeze_time(Time.zone.local(2026, 5, 14, 12, 0, 0))
+ event =
+ Fabricate(
+ :browser_pageview_event,
+ url: "/latest",
+ referrer: nil,
+ created_at: "2026-05-10",
+ )
+ job.execute({})
+ event.update_columns(
+ referrer: "https://test.localhost/top",
+ normalized_referrer: nil,
+ normalized_referrer_version: nil,
+ )
+
+ BrowserPageviewEntryUrlDailyRollup.stubs(:recompute).raises("entry rollup boom")
+ expect { job.execute({}) }.to raise_error("entry rollup boom")
+ expect(event.reload.normalized_referrer_version).to be_nil
+
+ BrowserPageviewEntryUrlDailyRollup.unstub(:recompute)
+ job.execute({})
+
+ expect(event.reload.normalized_referrer_version).to eq(
+ BrowserPageviewEventUrlNormalizer::REFERRER_VERSION,
+ )
+ expect(BrowserPageviewEntryUrlDailyRollup.where(date: "2026-05-10")).to be_empty
+ end
+
+ it "replaces a historical entry after interrupted URL normalization resumes" do
+ freeze_time(Time.zone.local(2026, 5, 14, 12, 0, 0))
+ event = Fabricate(:browser_pageview_event, url: "/latest", created_at: "2026-05-10")
+ job.execute({})
+ event.update_columns(url: "/top", normalized_url: nil, normalized_url_version: nil)
+
+ BrowserPageviewEntryUrlDailyRollup.stubs(:recompute).raises("entry rollup boom")
+ expect { job.execute({}) }.to raise_error("entry rollup boom")
+ expect(event.reload.normalized_url_version).to be_nil
+
+ BrowserPageviewEntryUrlDailyRollup.unstub(:recompute)
+ job.execute({})
+
+ expect(event.reload.normalized_url_version).to eq(
+ BrowserPageviewEventUrlNormalizer::SITE_PATH_VERSION,
+ )
+ expect(BrowserPageviewEntryUrlDailyRollup.pluck(:entry_url, :count)).to eq([["/top", 1]])
+ end
+
+ it "leaves expired URLs unchanged" do
event = Fabricate(:browser_pageview_event, url: "/expired", created_at: 4.months.ago)
event.update_columns(normalized_url: nil, normalized_url_version: nil)
diff --git a/spec/models/browser_pageview_entry_url_daily_rollup_spec.rb b/spec/models/browser_pageview_entry_url_daily_rollup_spec.rb
new file mode 100644
index 00000000000..6349faca0ac
--- /dev/null
+++ b/spec/models/browser_pageview_entry_url_daily_rollup_spec.rb
@@ -0,0 +1,140 @@
+# frozen_string_literal: true
+
+RSpec.describe BrowserPageviewEntryUrlDailyRollup do
+ before do
+ freeze_time(Time.zone.local(2026, 5, 14, 12, 0, 0))
+ RailsMultisite::ConnectionManagement.stubs(:current_db_hostnames).returns(
+ %w[test.localhost alias.test.localhost],
+ )
+ Discourse.stubs(:current_hostname).returns("test.localhost")
+ end
+
+ describe ".aggregate" do
+ it "counts direct and external-referrer pageviews but excludes configured site hosts" do
+ topic = Fabricate(:topic)
+ Fabricate(
+ :browser_pageview_event,
+ topic_id: topic.id,
+ url: "https://test.localhost/t/topic/#{topic.id}?utm_source=email#post_1",
+ referrer: "https://www.google.com/search?q=discourse",
+ normalized_referrer: "google.com/search?q=discourse",
+ normalized_referrer_version: BrowserPageviewEventUrlNormalizer::REFERRER_VERSION,
+ created_at: "2026-05-12 10:00:00",
+ )
+ Fabricate(
+ :browser_pageview_event,
+ url: "https://test.localhost/top",
+ referrer: nil,
+ created_at: "2026-05-12 10:01:00",
+ )
+ Fabricate(
+ :browser_pageview_event,
+ url: "https://test.localhost/latest",
+ referrer: "https://test.localhost/t/topic/1",
+ normalized_referrer: "test.localhost/t/topic/1",
+ normalized_referrer_version: BrowserPageviewEventUrlNormalizer::REFERRER_VERSION,
+ created_at: "2026-05-12 10:05:00",
+ )
+ Fabricate(
+ :browser_pageview_event,
+ url: "https://test.localhost/new",
+ referrer: "https://alias.test.localhost/latest",
+ normalized_referrer: "alias.test.localhost/latest",
+ normalized_referrer_version: BrowserPageviewEventUrlNormalizer::REFERRER_VERSION,
+ created_at: "2026-05-12 10:06:00",
+ )
+
+ described_class.aggregate(start_date: "2026-05-12".to_date, end_date: "2026-05-12".to_date)
+
+ expect(described_class.pluck(:entry_url, :count)).to contain_exactly(
+ ["/t/topic/#{topic.id}", 1],
+ ["/top", 1],
+ )
+ end
+
+ it "keeps subfolder paths distinct from root paths" do
+ Discourse.stubs(:base_path).returns("/forum")
+ topic = Fabricate(:topic)
+ Fabricate(:browser_pageview_event, url: "/forum", created_at: "2026-05-12")
+ Fabricate(
+ :browser_pageview_event,
+ topic_id: topic.id,
+ url: "/forum/t/topic/#{topic.id}",
+ created_at: "2026-05-12",
+ )
+ Fabricate(:browser_pageview_event, url: "/forum/latest", created_at: "2026-05-12")
+ Fabricate(:browser_pageview_event, url: "/latest", created_at: "2026-05-12")
+
+ described_class.aggregate(start_date: "2026-05-12".to_date, end_date: "2026-05-12".to_date)
+
+ expect(described_class.order(:entry_url).pluck(:entry_url)).to eq(
+ ["/forum", "/forum/latest", "/forum/t/topic/#{topic.id}", "/latest"],
+ )
+ end
+
+ it "separates logged-in and likely crawler pageviews" do
+ SiteSetting.improved_crawler_detection = true
+ Fabricate(
+ :browser_pageview_event,
+ user_id: Fabricate(:user).id,
+ score: CrawlerScorer::BOT_SCORE_THRESHOLD + 1,
+ url: "/latest",
+ created_at: "2026-05-12",
+ )
+
+ described_class.aggregate(start_date: "2026-05-12".to_date, end_date: "2026-05-12".to_date)
+
+ expect(
+ described_class.pick(
+ :count,
+ :logged_in_count,
+ :likely_crawler_count,
+ :likely_crawler_logged_in_count,
+ ),
+ ).to eq([1, 1, 1, 1])
+ end
+
+ it "preserves the oldest rollup when only a later retained event remains" do
+ SiteSetting.clean_up_browser_pageview_events = true
+ freeze_time(Time.zone.local(2026, 2, 15, 12, 0, 0))
+ Fabricate(
+ :browser_pageview_event,
+ url: "https://test.localhost/top",
+ created_at: "2026-02-13 23:59:00",
+ )
+ Fabricate(
+ :browser_pageview_event,
+ url: "https://test.localhost/latest",
+ referrer: "https://test.localhost/top",
+ normalized_referrer: "test.localhost/top",
+ normalized_referrer_version: BrowserPageviewEventUrlNormalizer::REFERRER_VERSION,
+ created_at: "2026-02-14 00:01:00",
+ )
+ described_class.aggregate(start_date: "2026-02-13".to_date, end_date: "2026-02-14".to_date)
+
+ freeze_time(Time.zone.local(2026, 5, 14, 12, 0, 0))
+ Jobs::CleanUpBrowserPageviewEvents.new.execute({})
+ described_class.aggregate(start_date: "2026-02-13".to_date, end_date: "2026-02-14".to_date)
+
+ expect(BrowserPageviewEvent.pluck(:created_at).map(&:to_date)).to eq(["2026-02-14".to_date])
+ expect(described_class.pluck(:date, :entry_url)).to eq([["2026-02-13".to_date, "/top"]])
+ end
+ end
+
+ describe ".recompute" do
+ it "removes a historical entry when its referrer becomes internal" do
+ date = "2026-05-12".to_date
+ event = Fabricate(:browser_pageview_event, url: "/latest", created_at: date)
+ described_class.aggregate(start_date: date, end_date: date)
+ event.update_columns(
+ referrer: "https://test.localhost/top",
+ normalized_referrer: "test.localhost/top",
+ normalized_referrer_version: BrowserPageviewEventUrlNormalizer::REFERRER_VERSION,
+ )
+
+ described_class.recompute([date, date])
+
+ expect(described_class.all).to be_empty
+ end
+ end
+end
diff --git a/spec/models/reports/top_entry_urls_spec.rb b/spec/models/reports/top_entry_urls_spec.rb
new file mode 100644
index 00000000000..8adef178265
--- /dev/null
+++ b/spec/models/reports/top_entry_urls_spec.rb
@@ -0,0 +1,88 @@
+# frozen_string_literal: true
+
+RSpec.describe Reports::TopEntryUrls do
+ let(:start_date) { "2026-05-01".to_date }
+ let(:end_date) { "2026-05-07".to_date }
+
+ it "makes entry URLs navigable" do
+ expect(Report.find("top_entry_urls", start_date:, end_date:).labels.first).to include(
+ type: :link,
+ properties: %i[entry_url entry_url],
+ )
+ end
+
+ it "ranks entry URLs and calculates percentages from all qualifying pageviews" do
+ Fabricate(
+ :browser_pageview_entry_url_daily_rollup,
+ date: start_date,
+ entry_url: "/t/topic/1",
+ count: 5,
+ )
+ Fabricate(
+ :browser_pageview_entry_url_daily_rollup,
+ date: start_date,
+ entry_url: "/categories",
+ count: 3,
+ )
+ Fabricate(
+ :browser_pageview_entry_url_daily_rollup,
+ date: start_date,
+ entry_url: "/faq",
+ count: 2,
+ )
+
+ expect(Report.find("top_entry_urls", start_date:, end_date:).data).to eq(
+ [
+ { entry_url: "/t/topic/1", count: 5, percent: 50 },
+ { entry_url: "/categories", count: 3, percent: 30 },
+ { entry_url: "/faq", count: 2, percent: 20 },
+ ],
+ )
+ end
+
+ it "excludes anonymous and likely crawler pageviews when both filters apply" do
+ Fabricate(
+ :browser_pageview_entry_url_daily_rollup,
+ date: start_date,
+ entry_url: "/latest",
+ count: 5,
+ logged_in_count: 3,
+ likely_crawler_count: 2,
+ likely_crawler_logged_in_count: 1,
+ )
+
+ SiteSetting.login_required = true
+ SiteSetting.improved_crawler_detection = true
+
+ expect(Report.find("top_entry_urls", start_date:, end_date:).data).to eq(
+ [{ entry_url: "/latest", count: 2, percent: 100 }],
+ )
+ end
+
+ it "keeps percentages based on all rows when the display is limited" do
+ stub_const(described_class, "MAX_ROWS", 2) do
+ Fabricate(
+ :browser_pageview_entry_url_daily_rollup,
+ date: start_date,
+ entry_url: "/a",
+ count: 5,
+ )
+ Fabricate(
+ :browser_pageview_entry_url_daily_rollup,
+ date: start_date,
+ entry_url: "/b",
+ count: 3,
+ )
+ Fabricate(
+ :browser_pageview_entry_url_daily_rollup,
+ date: start_date,
+ entry_url: "/c",
+ count: 2,
+ )
+
+ expect(Report.find("top_entry_urls", start_date:, end_date:).data).to eq(
+ [{ entry_url: "/a", count: 5, percent: 50 }, { entry_url: "/b", count: 3, percent: 30 }],
+ )
+ end
+ end
+end
diff --git a/spec/requests/admin/dashboard_controller_spec.rb b/spec/requests/admin/dashboard_controller_spec.rb
index 7a3054d07ff..eb72f1c6952 100644
--- a/spec/requests/admin/dashboard_controller_spec.rb
+++ b/spec/requests/admin/dashboard_controller_spec.rb
@@ -273,6 +273,7 @@ RSpec.describe Admin::DashboardController do
country_code = "US"
normalized_referrer = "sensitive-referrer.example"
+ entry_url = "/sensitive-entry"
event_date = Time.zone.local(2026, 5, 2, 12)
UpcomingChangeEvent.create!(
upcoming_change_name: "dashboard_improvements",
@@ -296,6 +297,12 @@ RSpec.describe Admin::DashboardController do
}
BrowserPageviewCountryDailyRollup.aggregate(**rollup_range)
BrowserPageviewReferrerDailyRollup.aggregate(**rollup_range)
+ Fabricate(
+ :browser_pageview_entry_url_daily_rollup,
+ date: event_date.to_date,
+ entry_url:,
+ count: 2,
+ )
get "/admin/dashboard.json", params: { start_date: "2026-05-01", end_date: "2026-05-03" }
@@ -308,6 +315,7 @@ RSpec.describe Admin::DashboardController do
expect(admin_traffic_data.dig("top_referrers", "rows", 0, "normalized_referrer")).to eq(
normalized_referrer,
)
+ expect(admin_traffic_data.dig("top_entry_urls", "rows", 0, "entry_url")).to eq(entry_url)
sign_in(moderator)
@@ -318,7 +326,9 @@ RSpec.describe Admin::DashboardController do
response.parsed_body["sections"].find { |section| section["id"] == "traffic" }["data"]
expect(moderator_traffic_data).not_to have_key("top_countries")
expect(moderator_traffic_data).not_to have_key("top_referrers")
+ expect(moderator_traffic_data).not_to have_key("top_entry_urls")
expect(response.body).not_to include(normalized_referrer)
+ expect(response.body).not_to include(entry_url)
end
end
diff --git a/spec/services/admin_dashboard_site_traffic_spec.rb b/spec/services/admin_dashboard_site_traffic_spec.rb
index dc5f1eecfb4..af0a46f0140 100644
--- a/spec/services/admin_dashboard_site_traffic_spec.rb
+++ b/spec/services/admin_dashboard_site_traffic_spec.rb
@@ -623,21 +623,23 @@ RSpec.describe AdminDashboardSiteTraffic do
)
end
- context "for top countries and top referrers" do
+ context "for top countries, top referrers, and top entry URLs" do
before { SiteSetting.persist_browser_pageview_events = true }
def aggregate_rollups
range = { start_date: 1.year.ago.to_date, end_date: Date.current }
BrowserPageviewCountryDailyRollup.aggregate(**range)
BrowserPageviewReferrerDailyRollup.aggregate(**range)
+ BrowserPageviewEntryUrlDailyRollup.aggregate(**range)
end
- it "omits top_countries and top_referrers when persist_browser_pageview_events is disabled" do
+ it "omits browser pageview cards when persist_browser_pageview_events is disabled" do
SiteSetting.persist_browser_pageview_events = false
result = build_traffic(start_date: nil, end_date: nil)
expect(result).not_to have_key(:top_countries)
expect(result).not_to have_key(:top_referrers)
+ expect(result).not_to have_key(:top_entry_urls)
end
it "omits top_countries and top_referrers when legacy pageviews are enabled" do
@@ -647,44 +649,60 @@ RSpec.describe AdminDashboardSiteTraffic do
expect(result.keys).to contain_exactly(:kpis, :pageview_series)
end
- it "returns top_countries and top_referrers with rows and no error when matching events exist" do
- 6.times do
- Fabricate(:browser_pageview_event, country_code: "US", normalized_referrer: "google.com")
- end
- aggregate_rollups
-
- result = build_traffic(start_date: nil, end_date: nil)
-
- expect(result[:top_countries][:rows].first[:country_code]).to eq("US")
- expect(result[:top_countries][:error]).to be_nil
-
- expect(result[:top_referrers][:rows].first[:normalized_referrer]).to eq("google.com")
- expect(result[:top_referrers][:error]).to be_nil
- end
-
- it "caps each card at the top 5 rows on both the fresh and cached paths" do
+ it "returns the same top five card rows from fresh and cached results" do
%w[US GB DE FR JP CA].each do |code|
Fabricate(
:browser_pageview_event,
+ url: "/#{code.downcase}",
country_code: code,
normalized_referrer: "#{code.downcase}.example.com",
)
end
+ Fabricate(
+ :browser_pageview_event,
+ url: "/outside-range",
+ country_code: "AU",
+ normalized_referrer: "outside-range.example.com",
+ created_at: "2026-03-01",
+ )
aggregate_rollups
+ expected_cards = {
+ top_countries: {
+ rows: %w[CA DE FR GB JP].map { |code| { country_code: code, count: 1, percent: 17 } },
+ error: nil,
+ },
+ top_referrers: {
+ rows:
+ %w[ca de fr gb jp].map do |code|
+ { normalized_referrer: "#{code}.example.com", count: 1, percent: 17 }
+ end,
+ error: nil,
+ },
+ top_entry_urls: {
+ rows:
+ %w[ca de fr gb jp].map { |code| { entry_url: "/#{code}", count: 1, percent: 17 } },
+ error: nil,
+ },
+ }
+
fresh = build_traffic(start_date: nil, end_date: nil)
- expect(fresh[:top_countries][:rows].size).to eq(5)
- expect(fresh[:top_referrers][:rows].size).to eq(5)
+ expect(fresh.slice(*expected_cards.keys)).to eq(expected_cards)
+
+ BrowserPageviewCountryDailyRollup.delete_all
+ BrowserPageviewReferrerDailyRollup.delete_all
+ BrowserPageviewEntryUrlDailyRollup.delete_all
+ BrowserPageviewEvent.delete_all
cached = build_traffic(start_date: nil, end_date: nil)
- expect(cached[:top_countries][:rows].size).to eq(5)
- expect(cached[:top_referrers][:rows].size).to eq(5)
+ expect(cached.slice(*expected_cards.keys)).to eq(expected_cards)
end
it "returns empty rows when no events match the date range" do
result = build_traffic(start_date: nil, end_date: nil)
expect(result[:top_countries]).to eq(rows: [], error: nil)
expect(result[:top_referrers]).to eq(rows: [], error: nil)
+ expect(result[:top_entry_urls]).to eq(rows: [], error: nil)
end
it "returns an exception error payload when the underlying report cannot be built" do
@@ -693,24 +711,7 @@ RSpec.describe AdminDashboardSiteTraffic do
result = build_traffic(start_date: nil, end_date: nil)
expect(result[:top_countries]).to eq(rows: [], error: "exception")
expect(result[:top_referrers]).to eq(rows: [], error: "exception")
- end
-
- it "serves the cached payload on subsequent calls within the cache window" do
- 4.times do
- Fabricate(:browser_pageview_event, country_code: "US", normalized_referrer: "google.com")
- end
- aggregate_rollups
-
- first = build_traffic(start_date: nil, end_date: nil)
- expect(first[:top_countries][:rows].first[:country_code]).to eq("US")
-
- BrowserPageviewCountryDailyRollup.delete_all
- BrowserPageviewReferrerDailyRollup.delete_all
- BrowserPageviewEvent.delete_all
-
- second = build_traffic(start_date: nil, end_date: nil)
- expect(second[:top_countries][:rows].first[:country_code]).to eq("US")
- expect(second[:top_countries][:rows].first.keys).to all(be_a(Symbol))
+ expect(result[:top_entry_urls]).to eq(rows: [], error: "exception")
end
it "invalidates the cached payload when login_required is toggled" do
diff --git a/spec/system/admin_dashboard_redesign/site_traffic_section_spec.rb b/spec/system/admin_dashboard_redesign/site_traffic_section_spec.rb
index 6f0d0d3f8bd..02d638da63f 100644
--- a/spec/system/admin_dashboard_redesign/site_traffic_section_spec.rb
+++ b/spec/system/admin_dashboard_redesign/site_traffic_section_spec.rb
@@ -177,7 +177,7 @@ describe "Admin Dashboard Redesign | Site Traffic section" do
)
end
- context "with top countries and top referrers cards" do
+ context "with top countries, top referrers, and top entry URLs cards" do
let(:browser_pageview_source) { BrowserPageviewEvent::SOURCE_BEACON }
before do
@@ -199,6 +199,7 @@ describe "Admin Dashboard Redesign | Site Traffic section" do
expect(traffic).to have_no_top_countries_card
expect(traffic).to have_no_top_referrers_card
+ expect(traffic).to have_no_top_entry_urls_card
expect(traffic).to have_no_metric("Direct traffic")
end
@@ -273,15 +274,48 @@ describe "Admin Dashboard Redesign | Site Traffic section" do
)
end
- it "shows an empty state in both cards but keeps the headers as drill-down links when no events qualify",
+ it "lets admins identify the URLs that started the most browser entries in the selected period",
time: Time.zone.local(2026, 5, 14, 12, 0, 0) do
- dashboard.visit
+ {
+ "/t/viral-topic/1" => 5,
+ "/associate/secret-token" => 4,
+ "/categories" => 3,
+ "/email/unsubscribe/secret-key" => 2,
+ "/faq" => 1,
+ }.each do |entry_url, count|
+ Fabricate(:browser_pageview_entry_url_daily_rollup, date: "2026-05-12", entry_url:, count:)
+ end
+
+ dashboard.visit_with_query(range: "custom", start_date: "2026-05-12", end_date: "2026-05-12")
+ traffic = dashboard.site_traffic
+
+ expect(traffic).to have_top_entry_url_rows(
+ [
+ { path: "/t/viral-topic/1", percent: 33, count: 5 },
+ { path: "/associate/secret-token", percent: 27, count: 4 },
+ { path: "/categories", percent: 20, count: 3 },
+ { path: "/email/unsubscribe/secret-key", percent: 13, count: 2 },
+ { path: "/faq", percent: 7, count: 1 },
+ ],
+ )
+
+ traffic.click_top_entry_urls_drilldown
+ expect(page).to have_current_path(
+ "/admin/reports/top_entry_urls?end_date=2026-05-12&start_date=2026-05-12",
+ )
+ end
+
+ it "shows empty states but keeps the report headers as drill-down links when no events qualify",
+ time: Time.zone.local(2026, 5, 14, 12, 0, 0) do
+ dashboard.visit_with_query(range: "custom", start_date: "2026-05-02", end_date: "2026-05-14")
traffic = dashboard.site_traffic
expect(traffic).to have_top_countries_empty_state
expect(traffic).to have_top_referrers_empty_state
+ expect(traffic).to have_top_entry_urls_empty_state
expect(traffic).to have_top_referrers_drilldown
expect(traffic).to have_top_countries_drilldown
+ expect(traffic).to have_top_entry_urls_drilldown
expect(traffic).to have_no_metric("Direct traffic")
end
diff --git a/spec/system/page_objects/components/admin_dashboard_site_traffic.rb b/spec/system/page_objects/components/admin_dashboard_site_traffic.rb
index e8f398710c4..bbe24bb5ca0 100644
--- a/spec/system/page_objects/components/admin_dashboard_site_traffic.rb
+++ b/spec/system/page_objects/components/admin_dashboard_site_traffic.rb
@@ -87,6 +87,10 @@ module PageObjects
has_no_top_card?("Top referrers")
end
+ def has_no_top_entry_urls_card?
+ has_no_top_card?("Top entry URLs")
+ end
+
def has_top_country_rows?(rows)
within_top_card("Top countries") do
next false unless has_css?(".db-traffic__list-row", count: rows.size)
@@ -113,6 +117,19 @@ module PageObjects
end
end
+ def has_top_entry_url_rows?(rows)
+ within_top_card("Top entry URLs") do
+ next false unless has_css?(".db-traffic__list-row", count: rows.size)
+
+ rows.each_with_index.all? do |row, index|
+ nth = ".db-traffic__list-row:nth-child(#{index + 1})"
+ has_css?("#{nth} a.db-traffic__link[href='#{row[:path]}']", text: row[:path]) &&
+ has_css?("#{nth} .db-traffic__percent", exact_text: "#{row[:percent]}%") &&
+ has_css?("#{nth} .db-traffic__count", exact_text: "(#{row[:count]})")
+ end
+ end
+ end
+
def has_top_countries_empty_state?
has_empty_state_in?("Top countries", "No country data for this period.")
end
@@ -121,6 +138,10 @@ module PageObjects
has_empty_state_in?("Top referrers", "No referrer data for this period.")
end
+ def has_top_entry_urls_empty_state?
+ has_empty_state_in?("Top entry URLs", "No entry URL data for this period.")
+ end
+
def click_top_referrers_drilldown
within_top_card("Top referrers") { find("h3.db-section__row-block-title a").click }
end
@@ -129,6 +150,10 @@ module PageObjects
within_top_card("Top countries") { find("h3.db-section__row-block-title a").click }
end
+ def click_top_entry_urls_drilldown
+ within_top_card("Top entry URLs") { find("h3.db-section__row-block-title a").click }
+ end
+
def has_top_referrers_drilldown?
within_top_card("Top referrers") { has_css?("h3.db-section__row-block-title a") }
end
@@ -137,6 +162,10 @@ module PageObjects
within_top_card("Top countries") { has_css?("h3.db-section__row-block-title a") }
end
+ def has_top_entry_urls_drilldown?
+ within_top_card("Top entry URLs") { has_css?("h3.db-section__row-block-title a") }
+ end
+
def has_bounce_rate?(value)
has_kpi_value?("bounce_rate", value)
end