fix(send): keep the root path when REMOVE_TRAILING_SLASH is enabled

The trailing-slash regex also matched the leading slash of the root URL, so with REMOVE_TRAILING_SLASH set every home page view was stored with an empty url_path: the home page vanished from the paths/entry/exit reports and could not be selected as a funnel step. Skip the match at the start of the path so "/" and "/#hash" are preserved while "/blog/" and "/blog/#hash" are still trimmed.

Closes #4152
This commit is contained in:
NoiceHax authored and Francis Cao committed 2026-08-17 11:21:07 -07:00
1 parent d6a3b8c6d3
commit 319a09cdb5
2 files changed
+35 -1

No files matched your search

+2 -1
View File
@@ -214,7 +214,8 @@ export async function POST(request: Request) {
const twclid = currentUrl.searchParams.get('twclid');
if (process.env.REMOVE_TRAILING_SLASH) {
urlPath = urlPath.replace(/\/(?=(#.*)?$)/, '');
// Never strip the root slash, otherwise the home page is saved with an empty path
urlPath = urlPath.replace(/(?!^)\/(?=(#.*)?$)/, '');
}
if (referrer) {