fix: screen size shadowing, popstate double pageview, custom event self-referrals

This commit is contained in:
Usman Baig
2026-03-13 01:09:45 +01:00
parent 765f8ec63e
commit a57ed871f1
2 changed files with 18 additions and 5 deletions

View File

@@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- **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.
- **Screen size fallback now works correctly.** A variable naming issue prevented the fallback screen dimensions from being read when the primary value wasn't available. Screen size data is now reliably captured on all browsers.
- **Browser back/forward no longer double-counts pageviews.** Pressing the back or forward button could occasionally register two pageviews instead of one. The tracking script now correctly deduplicates these navigations.
## [0.15.0-alpha] - 2026-03-13

View File

@@ -282,16 +282,16 @@
referrer = rawReferrer;
}
}
const screen = {
width: window.innerWidth || screen.width,
height: window.innerHeight || screen.height,
const screenSize = {
width: window.innerWidth || window.screen.width,
height: window.innerHeight || window.screen.height,
};
const payload = {
domain: domain,
path: path,
referrer: referrer,
screen: screen,
screen: screenSize,
session_id: getSessionId(),
};
@@ -354,6 +354,9 @@
// * Track popstate (browser back/forward)
window.addEventListener('popstate', function() {
var url = location.href;
if (url === lastUrl) return;
lastUrl = url;
trackPageview();
setTimeout(check404, 100);
if (trackScroll) scrollFired = {};
@@ -373,7 +376,15 @@
return;
}
var path = window.location.pathname + window.location.search;
var referrer = document.referrer || '';
var rawRef = document.referrer || '';
var referrer = '';
if (rawRef) {
try {
var rh = new URL(rawRef).hostname.replace(/^www\./, '');
var sh = domain.replace(/^www\./, '');
if (rh !== sh) referrer = rawRef;
} catch (e) { referrer = rawRef; }
}
var screenSize = { width: window.innerWidth || 0, height: window.innerHeight || 0 };
var payload = {
domain: domain,