Reimplement Plausible analytics - #704
Open
mrdarrengriffin wants to merge 6 commits into
Open
Conversation
The tracker was inlined into main.html with a bare init, which meant the `privacy` plugin downloaded it at build time and served a frozen self-hosted copy, and every referrer reached Plausible untouched. Visitors arriving from their own Home Assistant or ESPHome instance send that private URL as the referrer, so those had to be filtered before Plausible ever recorded them. - Move the tracker into a `partials/plausible.html` partial, included from the `extrahead` block, and read the script and dashboard URLs from `extra` in mkdocs.yml. - Exclude the Plausible host from the `privacy` plugin so the tracker is loaded from the Plausible instance and stays current. - Add a `source/hooks/plausible.py` hook that fetches the Open Home Foundation referrer allow list once per build, caches it under `.cache` alongside the translations, and exposes it to the templates. Fetch failures fall back to the cached copy and never fail the build. - Initialize the tracker with a `transformRequest` that replaces any referrer outside the allow list with a single `unlisted.invalid` bucket, so we can see how much is filtered without learning anything about individual visitors. - Guard the 404 event on `window.plausible` and point the footer dashboard link at the configured URL. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UkMvZDbHQRYGY1u1P53uFd
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reimplements Plausible analytics integration for the MkDocs site to prevent private referrer URLs (e.g., from Home Assistant / ESPHome) from being recorded by Plausible, by fetching an allow list at build time and filtering referrers client-side before events are sent.
Changes:
- Moved Plausible initialization into a dedicated
partials/plausible.htmlpartial and included it frommain.html. - Added an MkDocs hook to fetch/cache an Open Home Foundation referrer allow list and expose it via
config.extrafor templating. - Updated MkDocs config to keep Plausible assets remote (privacy plugin exclude) and parameterized tracker/dashboard URLs via
extra.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| source/overrides/partials/plausible.html | Adds Plausible init with transformRequest referrer filtering using a build-fetched allow list. |
| source/overrides/partials/footer.html | Points the public dashboard link at a configurable config.extra.plausible.dashboard URL. |
| source/overrides/main.html | Includes the new Plausible partial from the extrahead block. |
| source/overrides/404.html | Guards the 404 Plausible event call on window.plausible availability. |
| source/hooks/plausible.py | Adds build-time allow list fetch + cache logic and injects it into config.extra.plausible.allowed_referrers. |
| source/assets/stylesheets/extra.css | Removes an extraneous blank line (no functional change). |
| mkdocs.yml | Configures privacy plugin asset exclusions, registers the new hook, and adds Plausible script/dashboard URLs under extra. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Merging main into this branch silently dropped the script src bump from hacs#702, because that commit edited the tracker line in main.html while this branch had replaced that whole file with an include. Move the new ID into the `extra` value the partial reads. Also declare `requests` explicitly. source/macros.py has always imported it and both pinned plugins depend on it, so builds were never actually broken, but the hook makes a second first-party use of a package the project never asked for. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UkMvZDbHQRYGY1u1P53uFd
ludeeus
requested changes
Aug 14, 2026
Co-authored-by: Joakim Sørensen <joasoe@proton.me>
Co-authored-by: Joakim Sørensen <joasoe@proton.me>
- Return early when the referrer cannot be parsed, instead of falling through to a loop that cannot match an empty host. - Lowercase the host. The URL parser only folds the host of special schemes, so an `android-app://com.Google.Android/` referrer kept its case and could miss an allow list entry. - Leave Plausible out of the build entirely when the allow list is unavailable. Reporting every visit as unlisted was data without value; failing the build would turn any transient network blip into a red deploy. - Use the current requests release. - Apply the lazy logging style to the remaining log calls for consistency. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UkMvZDbHQRYGY1u1P53uFd
mrdarrengriffin
marked this pull request as ready for review
August 17, 2026 14:18
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.
The tracker was inlined into main.html with a bare init, which meant the
privacyplugin downloaded it at build time and served a frozen self-hosted copy, and every referrer reached Plausible untouched. Visitors arriving from their own Home Assistant or ESPHome instance send that private URL as the referrer, so those had to be filtered before Plausible ever recorded them.partials/plausible.htmlpartial, included from theextraheadblock, and read the script and dashboard URLs fromextrain mkdocs.yml.privacyplugin so the tracker is loaded from the Plausible instance and stays current.source/hooks/plausible.pyhook that fetches the Open Home Foundation referrer allow list once per build, caches it under.cachealongside the translations, and exposes it to the templates. Fetch failures fall back to the cached copy and never fail the build.transformRequestthat replaces any referrer outside the allow list with a singleunlisted.invalidbucket, so we can see how much is filtered without learning anything about individual visitors.window.plausibleand point the footer dashboard link at the configured URL.Claude-Session: https://claude.ai/code/session_01UkMvZDbHQRYGY1u1P53uFd