Skip to content

fix: count a visitor once per day, not once per page - #11

Open
scobb wants to merge 1 commit into
mainfrom
fix/unique-visitor-key
Open

scobb wants to merge 1 commit into
mainfrom
fix/unique-visitor-key

Conversation

@scobb

@scobb scobb commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Problem

The unique-visitor key was date|path|country|browser|screen_width, so one person browsing five pages in a day counted as five visitors. Headline "Unique Visitors" overcounted on any multi-page site, and the dashboard disagreed with the weekly digest (which already left out path).

Fix

  • New src/lib/visitorKey.ts defines the key once: date|country|browser|screen_width. It replaces seven inline copies across the dashboard, public dashboard, API, insights and goals.
  • Goal event converters used the same per-page key (date|path|country|referrer). With the smaller visitor denominator, an event fired on several pages could have pushed event-goal conversion rates past 100%, so the event key drops path too.
  • Public copy on / and /how-it-works no longer lists path, and the landing page no longer calls the tuple a "hash" (nothing is hashed).

Impact

Visitor counts will drop for every site, most on sites where people view several pages. Counts are computed when a page loads, so historical periods drop too: trends stay internally consistent, with no step change at deploy. Worth a changelog note or email to customers before this ships.

Not included: src/scheduled.ts (weekly digest), to avoid conflicting with the unmerged fix/weekly-digest-cron branch. The digest already leaves out path; it can switch to PAGEVIEW_VISITOR_KEY_SQL after both merge.

Testing

  • test/visitor-key.test.ts runs the real SQL against in-memory SQLite: multi-page visitor counts once, differing attributes count separately, the key rotates daily, an event goal on 3 pages converts once (100%, not 300%). With path temporarily put back in the key, 3 of the 5 tests fail.
  • npm test: 163 pass, 0 fail, 4 skipped (WordPress plugin, separate repo)
  • npm run typecheck: clean
  • Not yet run: npm run test:smoke, which the deploy checklist requires

🤖 Generated with Claude Code

The unique-visitor key was date|path|country|browser|screen_width, so one
person browsing five pages counted as five visitors. Drop path from the key
and define it once in src/lib/visitorKey.ts instead of seven inline copies
across dashboard, public, API, insights and goals.

Goal event converters had the same per-page key; with the smaller visitor
denominator that could push event-goal conversion rates past 100%, so the
event key drops path too.

Public copy on / and /how-it-works no longer lists path, and the landing
page no longer calls the tuple a hash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant