Skip to content

fix(analytics): attribute referrer to the entry page only#566

Merged
rdmueller merged 1 commit into
LLM-Coding:mainfrom
raifdmueller:fix/spa-referrer-entry-only
Jun 2, 2026
Merged

fix(analytics): attribute referrer to the entry page only#566
rdmueller merged 1 commit into
LLM-Coding:mainfrom
raifdmueller:fix/spa-referrer-entry-only

Conversation

@raifdmueller
Copy link
Copy Markdown
Contributor

@raifdmueller raifdmueller commented Jun 2, 2026

Why

Follow-up to #562/#565. Now that in-app navigation is counted, the referrer breakdown over-attributed external sources: document.referrer stays 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 a referrer callback 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, faked document.referrer = heise)

  • Landing vars → r = "https://www.heise.de" (entry credited to heise)
  • SPA anchor view vars → r = "" (no referrer)

Router tests pass; lint + prettier clean.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Verfeinerte Seitenaufruf-Erfassung: Bei internen (Client-)Navigationen werden keine vorherigen Seiten mehr als Referrer weitergegeben, wodurch Analytics-Daten präziser sind. Der initiale Seitenaufruf wird weiterhin automatisch erfasst.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 355284e8-4000-4bdd-9823-d891155b77b4

📥 Commits

Reviewing files that changed from the base of the PR and between 7758c65 and 8baa5f9.

📒 Files selected for processing (1)
  • website/src/utils/router.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/src/utils/router.js

Walkthrough

Die trackPageview()-Funktion in website/src/utils/router.js ruft bei Client-Navigationen gc.count() nun mit einem referrer-Callback auf, das konsequent einen leeren String zurückgibt, sodass Referrer nicht zwischen In-App-Views weitergereicht werden.

Changes

GoatCounter Referrer-Handling in Client-Navigation

Layer / File(s) Summary
trackPageview Referrer-Callback
website/src/utils/router.js
Die trackPageview()-Funktion ruft gc.count() mit einem referrer-Callback auf, das für Client-seitige Routen-Navigationen einen leeren String liefert; Kommentare dokumentieren die Änderung.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • LLM-Coding/Semantic-Anchors#562: Beide PRs modifizieren website/src/utils/router.js's SPA-Tracking (trackPageview / gc.count) — eines fügt SPA/Anchor-Counting hinzu, das andere ändert den referrer-Callback.

Suggested reviewers

  • JensGrote
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Der Titel beschreibt präzise die Hauptänderung: Referrer werden nur der Einstiegsseite zugeordnet, nicht zu nachfolgenden In-App-Navigationen.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Collaborator

@JensGrote JensGrote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@raifdmueller raifdmueller force-pushed the fix/spa-referrer-entry-only branch from 7758c65 to 8baa5f9 Compare June 2, 2026 12:05
@rdmueller rdmueller merged commit d14336d into LLM-Coding:main Jun 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants