fix(analytics): attribute referrer to the entry page only#566
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughDie ChangesGoatCounter Referrer-Handling in Client-Navigation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
JensGrote
left a comment
There was a problem hiding this comment.
LGTM ✅
Clean fix. GoatCounter's referrer callback API is the right approach for SPA sessions — the comment explains the problem (heise inflating 20 paths) well.
One thought for the future: if you ever want "full journey" attribution (mentioned in the PR description), you could send something like referrer: () => window.location.origin + previousPath to track internal navigation chains without external referrer bleeding. But entry-only is the sane default for now.
document.referrer is fixed for the whole SPA session, so every in-app pageview we send (LLM-Coding#562/LLM-Coding#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>
7758c65 to
8baa5f9
Compare
Why
Follow-up to #562/#565. Now that in-app navigation is counted, the referrer breakdown over-attributed external sources:
document.referrerstays fixed for the whole SPA session, so a single visitor arriving from heise and clicking through ~20 anchors made heise's referrer list show all 20 paths (mostly count 1) — even though heise only links 3-4 pages.What
Send the referrer only on the initial load (handled by
count.js). Client-side route changes now pass areferrercallback returning'', so in-app anchor/page views carry no referrer. External referrers are credited to the landing page only — matching the intuitive "where did this visit come from" meaning.(We may revisit "full journey" attribution later — it's a nice engagement signal — but entry-only is the expected default.)
Verification (preview, GoatCounter
get_data, fakeddocument.referrer = heise)r = "https://www.heise.de"(entry credited to heise)r = ""(no referrer)Router tests pass; lint + prettier clean.
🤖 Generated with Claude Code
Summary by CodeRabbit