discourse/lib/middleware
Osama Sayegh 27a843fa0f
FEATURE: beacon-based implementation for BPV (#38897)
This commit adds a new parallel page view counting system that uses `fetch` with `keepalive: true` to POST to a dedicated `/srv/pv` endpoint, gated behind the `use_beacon_for_browser_page_views` site setting.                                                                                                                                                                        

Unlike the existing deferred tracking (which piggybacks on AJAX headers), the beacon approach sends page view data directly as a JSON body. Both systems run simultaneously when the setting is enabled to allow comparing counts before fully migrating.

Key details:
                                                                                                                                                                                                                                      
* New middleware endpoint `POST /srv/pv` short-circuits with 204
* Dedicated `ApplicationRequest` counters (`*_beacon`) track beacon page views separately from the existing browser page view counters
* A separate `:beacon_browser_pageview` DiscourseEvent avoids double-firing with the existing `:browser_pageview` event
* On Ember route transitions, `routeDidChange` sends the beacon. For non-Ember pages (e.g. `/pub/*`), `pageview.js` handles it

Internal topic: t/179398.
2026-04-15 16:32:05 +03:00
..
anonymous_cache.rb DEV: Fix AnonymousCache for pitchfork in dev/test modes (#37852) 2026-02-17 09:12:02 +00:00
crawler_hooks.rb DEV: Check for setting prior to applying transformation on crawler view (#34478) 2025-08-22 14:17:45 +08:00
csp_script_nonce_injector.rb DEV: Memoize CSP nonce placeholder on response (#25724) 2024-02-16 12:15:55 +00:00
default_headers.rb DEV: ensure Rails application default headers are present in responses (#31619) 2025-03-05 13:19:09 +08:00
discourse_public_exceptions.rb SECURITY: Error responses missing Cache-Control header 2025-10-28 14:40:41 +08:00
enforce_hostname.rb DEV: Simplify CORS logic for public asset routes (#33106) 2025-06-09 08:58:27 +01:00
missing_avatars.rb DEV: Prefer \A and \z over ^ and $ in regexes (#19936) 2023-01-20 12:52:49 -06:00
omniauth_bypass_middleware.rb FIX: 'destination_url' cookie handling (#33072) 2025-08-06 10:09:01 +02:00
overload_protections.rb PERF: Reject anonymous requests with 503 upon aggressive queuing (#36519) 2025-12-18 10:23:42 +08:00
processing_request.rb PERF: Reject anonymous requests with 503 upon aggressive queuing (#36519) 2025-12-18 10:23:42 +08:00
request_tracker.rb FEATURE: beacon-based implementation for BPV (#38897) 2026-04-15 16:32:05 +03:00