Skip to content

Count views of external pages through a one-pixel beacon (/seen.gif) - #145

Merged
mspinola merged 1 commit into
mainfrom
claude/dbmf-view-beacon
Oct 15, 2026
Merged

mspinola merged 1 commit into
mainfrom
claude/dbmf-view-beacon

Conversation

@mspinola

Copy link
Copy Markdown
Owner

Why

dbmf.bluemagicai.com is a static GitHub Pages site with no server, so its views could never reach the visitor log the way this app's own pages do through record_visit. This adds a beacon endpoint so they land in the same visitor_logs table and the same /admin charts.

What

  • routing.py: BEACON_PATH = '/seen.gif' (admitted by the unknown-path guard via EXTRA_PATHS), the EXTERNAL_PAGES allowlist (dbmf -> /dbmf), the 1x1 GIF bytes, and a no-store cache policy for the pixel.
  • visitors.py: clean_referrer, which keeps a client-reported referrer only when it looks like a web address, capped at 512 chars.
  • app_cot.py: the external_page_beacon route. One load writes the same pair of rows one of the app's own document loads writes: a landing carrying the external page's referrer and a pageview the admin page counts. The pixel request itself is excluded from record_visit. _enqueue_visit grows an optional explicit referrer, defaulting to the old behaviour.
  • server-side/README.md: a section on the mechanism and how to admit another external page.

Tests

New coverage for the allowlist, the cache header, the two-row shape through the test client, a direct visit (referrer None), unlisted keys, and the GIF decoding. Full suite 919 passed, ruff check src tests clean.

Also verified live on a second instance against a scratch DB: the pixel answered 200 image/gif with Cache-Control: no-store, one load wrote exactly the landing and pageview rows under /dbmf with geography resolved, and an unlisted p wrote nothing.

Rollout

Deploy with server-side/restart.sh BEFORE the page-side change (mspinola/dbmf-tracker, the publish-step PR) goes live, or the page requests a 404 until then. Harmless, but uncounted.

🤖 Generated with Claude Code

The DBMF dashboard at dbmf.bluemagicai.com is a static GitHub Pages site:
no server, no hook, no access log, so nothing on its side can run
record_visit. It now loads GET /seen.gif?p=dbmf&r=<document.referrer>
once per document load, and the app writes the same two rows one of its
own page loads writes: a 'landing' carrying the referrer and a 'pageview'
the admin page counts, under path /dbmf. Everything after the enqueue is
shared (forwarded address, daily visitor hash, geo cache, datacenter
flag), so a reader of both sites is one visitor id across them.

`p` is matched against routing.EXTERNAL_PAGES rather than passed through,
and `r` is kept only when it looks like a web address (visitors.
clean_referrer), because both are query values anyone can write. The
pixel request itself is excluded from record_visit so there is no third
row, and the response is a real 1x1 GIF with Cache-Control: no-store.

Verified live on a scratch instance: one load wrote exactly the landing
and pageview rows with geography resolved; an unlisted `p` wrote nothing.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@mspinola
mspinola merged commit f60fc60 into main Oct 15, 2026
3 checks passed
@mspinola
mspinola deleted the claude/dbmf-view-beacon branch October 15, 2026 21:50
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