fix: strip self-referrals from tracking script
This commit is contained in:
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- **More accurate pageview counts.** Refreshing a page no longer inflates your pageview numbers. The tracking script now detects when the same page is loaded again within a few seconds and skips the duplicate, so metrics like total pageviews, pages per session, and visit duration reflect real navigation instead of reload habits.
|
- **More accurate pageview counts.** Refreshing a page no longer inflates your pageview numbers. The tracking script now detects when the same page is loaded again within a few seconds and skips the duplicate, so metrics like total pageviews, pages per session, and visit duration reflect real navigation instead of reload habits.
|
||||||
|
- **Self-referrals no longer pollute your traffic sources.** Internal navigation within your own site (e.g. clicking from your homepage to your about page) no longer shows your own domain as a referrer. Only external traffic sources appear in your Referrers panel now.
|
||||||
|
|
||||||
## [0.15.0-alpha] - 2026-03-13
|
## [0.15.0-alpha] - 2026-03-13
|
||||||
|
|
||||||
|
|||||||
@@ -270,7 +270,18 @@
|
|||||||
lcpObserved = false;
|
lcpObserved = false;
|
||||||
clsObserved = false;
|
clsObserved = false;
|
||||||
currentEventId = null;
|
currentEventId = null;
|
||||||
const referrer = document.referrer || '';
|
// * Strip self-referrals: don't send referrer if it matches the current site domain
|
||||||
|
var rawReferrer = document.referrer || '';
|
||||||
|
var referrer = '';
|
||||||
|
if (rawReferrer) {
|
||||||
|
try {
|
||||||
|
var refHost = new URL(rawReferrer).hostname.replace(/^www\./, '');
|
||||||
|
var siteHost = domain.replace(/^www\./, '');
|
||||||
|
if (refHost !== siteHost) referrer = rawReferrer;
|
||||||
|
} catch (e) {
|
||||||
|
referrer = rawReferrer;
|
||||||
|
}
|
||||||
|
}
|
||||||
const screen = {
|
const screen = {
|
||||||
width: window.innerWidth || screen.width,
|
width: window.innerWidth || screen.width,
|
||||||
height: window.innerHeight || screen.height,
|
height: window.innerHeight || screen.height,
|
||||||
|
|||||||
Reference in New Issue
Block a user