Skip to content

Commit 8baa5f9

Browse files
raifdmuellerclaude
andcommitted
fix(analytics): attribute referrer to the entry page only
document.referrer is fixed for the whole SPA session, so every in-app pageview we send (#562/#565) re-credited the entry referrer — e.g. a single visitor arriving from heise and browsing 20 anchors made heise's referrer list show all 20 paths. Report the referrer only on the initial load (handled by count.js); client-side route changes now send an empty referrer via a callback. External referrers are credited to the landing page only, matching the intuitive "where did this visit come from" meaning. Verified with GoatCounter's get_data: with document.referrer = heise, the landing keeps r="https://www.heise.de" while an SPA anchor view yields r="". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 36433af commit 8baa5f9

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

website/src/utils/router.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,18 @@ function trackPageview() {
155155
}
156156
const gc = typeof window !== 'undefined' ? window.goatcounter : null
157157
if (gc && typeof gc.count === 'function') {
158-
gc.count({ path: window.location.pathname, title: document.title })
158+
gc.count({
159+
path: window.location.pathname,
160+
title: document.title,
161+
// Report the referrer only on the initial load (handled by count.js).
162+
// document.referrer is fixed for the whole SPA session, so without this
163+
// every in-app view would be re-credited to the entry referrer (e.g.
164+
// heise), inflating that referrer's page list. A callback returning ''
165+
// drops the referrer for client-side navigations.
166+
referrer: function () {
167+
return ''
168+
},
169+
})
159170
}
160171
}
161172

0 commit comments

Comments
 (0)