Avoid saving same-domain referrers and resolve path-only referrers correctly

This commit is contained in:
Mike Cao committed 2026-08-03 23:03:52 -07:00
1 parent c5d34d10ad
commit 8efd5d7279
4 files changed
+131 -6

No files matched your search

+7 -2
View File
@@ -274,6 +274,11 @@ type MetricEntry = PerformanceEntry & {
}
};
// Strip the origin from same-origin referrers so the referrer domain
// is never saved when it matches the current hostname
const stripOrigin = (url: string): string =>
url === origin || url?.startsWith(origin + '/') ? url.slice(origin.length) : url;
const getPayload = () => ({
website,
screen,
@@ -281,7 +286,7 @@ type MetricEntry = PerformanceEntry & {
title: document.title,
hostname,
url: currentUrl,
referrer: currentRef,
referrer: stripOrigin(currentRef),
tag,
id: identity ? identity : undefined,
});
@@ -631,7 +636,7 @@ type MetricEntry = PerformanceEntry & {
}
let currentUrl = normalize(href);
let currentRef = normalize(referrer.startsWith(origin) ? '' : referrer);
let currentRef = normalize(referrer);
let initialized = false;
let disabled = false;