Repository navigation
Count views of external pages through a one-pixel beacon (/seen.gif) - #145
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
dbmf.bluemagicai.comis 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 throughrecord_visit. This adds a beacon endpoint so they land in the samevisitor_logstable and the same/admincharts.What
routing.py:BEACON_PATH = '/seen.gif'(admitted by the unknown-path guard viaEXTRA_PATHS), theEXTERNAL_PAGESallowlist (dbmf->/dbmf), the 1x1 GIF bytes, and ano-storecache 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: theexternal_page_beaconroute. One load writes the same pair of rows one of the app's own document loads writes: alandingcarrying the external page's referrer and apageviewthe admin page counts. The pixel request itself is excluded fromrecord_visit._enqueue_visitgrows an optional explicitreferrer, 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 testsclean.Also verified live on a second instance against a scratch DB: the pixel answered 200
image/gifwithCache-Control: no-store, one load wrote exactly the landing and pageview rows under/dbmfwith geography resolved, and an unlistedpwrote nothing.Rollout
Deploy with
server-side/restart.shBEFORE 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