Skip to content

feat(analytics): add Plausible alongside GA4 - #168

Merged
Gowiem merged 1 commit into
mainfrom
feature/plausible-analytics
Aug 21, 2026
Merged

feat(analytics): add Plausible alongside GA4#168
Gowiem merged 1 commit into
mainfrom
feature/plausible-analytics

Conversation

@Gowiem

@Gowiem Gowiem commented Aug 21, 2026

Copy link
Copy Markdown
Member

what

  • Adds Plausible Analytics to the site, running in parallel with the existing GA4/GTM setup. Nothing about GA4 changes.
  • New layouts/partials/plausible.html, called from head.html just above the gtag block.
  • Two netlify.toml rewrites under /mpx/ that proxy the Plausible tracker and event endpoint through our own domain.
  • Enables outbound link, file download, and form submission tracking. Scroll depth and time-on-page need no configuration.

why

We use GA4 but effectively never log into it, and it has never been usable for a non-power-user. Plausible is the replacement candidate. This PR runs both side by side so we can compare before deciding whether to retire GA4.

Three deliberate choices, each worth a look during review:

1. Plausible is not consent-gated, on purpose.

GA4 and GTM load as type="text/plain" with data-category="analytics", so CookieConsent blocks them until a visitor accepts. Plausible is cookieless and stores no personal data, so it does not require consent and loads unconditionally.

This is the main reason to adopt it: every visitor who ignores or declines the banner is currently invisible to GA4. Expect the two tools to report very different totals. Plausible will be meaningfully higher, and that gap is traffic GA4 has never shown us. Compare trends and rankings, not absolute numbers.

2. Proxied first-party, and not installed via GTM.

The /mpx/ rewrites serve the tracker from our own domain so ad blockers do not strip it. Plausible's dashboard suggests a GTM install instead; that was rejected on two counts. Our GTM container is itself consent-gated, so Plausible would inherit the gate and lose benefit 1. And googletagmanager.com is widely ad-blocked, so the tracker would be blocked whenever GTM is, which the proxy cannot fix because the blocked resource would be the container rather than the tracker.

Note the rewrites must stay above the catch-all /* to /404.html rule, which would otherwise swallow those paths.

3. Production only.

Guarded on HUGO_ENV, which Netlify sets in the production and split1 contexts but not in deploy previews. Without the guard, preview traffic would be attributed to the live site, since Plausible counts against the configured site rather than the actual hostname.

verification

Built locally with hugo --minify (matching the Netlify build command) in both contexts:

  • HUGO_ENV=production: Plausible renders with all four init options, GA4 untouched
  • HUGO_ENV unset: Plausible absent entirely, GA4 untouched
  • Rendered tag is a plain <script async> with no type="text/plain" and no data-category, confirming it sits outside the consent gate

trunk check passes clean on all three files.

Local build used cached Hugo v0.146.4 rather than the pinned v0.162.1, because aqua install currently fails to fetch that version (hugo_extended_0.162.1_darwin-universal.tar.gz is not published under that name). The template features used are old and stable, but the Netlify build is the real check.

after merge

Worth confirming on the deployed site, especially the negative cases:

  • /mpx/js/script.js returns 200 and /mpx/api/event returns 202
  • With an ad blocker enabled, the event request still returns 202
  • Decline the cookie banner, reload: GA4 stays silent, Plausible fires
  • Open a deploy preview: no Plausible requests at all

If Netlify Asset Optimization rewrites the script URL, either disable Bundle JS / Minify JS or switch the src to an absolute URL.

references

🤖 Generated with Claude Code

@Gowiem
Gowiem requested a review from a team as a code owner August 21, 2026 05:36
@netlify

netlify Bot commented Aug 21, 2026

Copy link
Copy Markdown

Deploy Preview for masterpoint ready!

Name Link
🔨 Latest commit b192a78
🔍 Latest deploy log https://app.netlify.com/projects/masterpoint/deploys/6a87e50ef72a06000986becc
😎 Deploy Preview https://deploy-preview-168--masterpoint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 37
Accessibility: 89
Best Practices: 92
SEO: 79
PWA: 70
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 72768625-bf42-4e5e-bd66-ca4c68f8e042


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.

Adds Plausible Analytics to run in parallel with the existing GA4/GTM
setup, ahead of a possible GA4 retirement.

Three deliberate choices worth noting:

- Not consent-gated. GA4 and GTM load as type="text/plain" with
  data-category="analytics", so CookieConsent blocks them until a visitor
  accepts. Plausible is cookieless and stores no personal data, so it
  loads unconditionally. This is the point: it sees the traffic GA4
  never has. Expect the two tools to report very different totals.

- Proxied first-party via netlify.toml rewrites under /mpx/, so ad
  blockers don't strip the tracker. The rewrites sit above the catch-all
  404, which would otherwise swallow them. Installing via GTM was
  rejected: GTM is both consent-gated here and widely ad-blocked, which
  would forfeit both accuracy gains.

- Production only, guarded on HUGO_ENV, which Netlify sets in the
  production and split1 contexts but not in deploy previews. Without the
  guard, preview traffic would be attributed to the live site.

Scroll depth and time-on-page need no configuration. Outbound links,
file downloads, and form submissions are enabled in plausible.init().

plausible.html is added to .prettierignore for the reason that file
already documents: prettier mangles Hugo's {{ }} actions. It collapsed
the Go template comment and rewrote the init snippet into a form CI's
prettier then disagreed with.

Verified with hugo --minify in both contexts: rendered in production,
absent with HUGO_ENV unset.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Gowiem
Gowiem force-pushed the feature/plausible-analytics branch from 791a0f5 to b192a78 Compare August 21, 2026 05:41
@Gowiem

Gowiem commented Aug 21, 2026

Copy link
Copy Markdown
Member Author

Verified against the deploy preview, which is the real Hugo 0.162.1 + Netlify build rather than a local approximation.

The HUGO_ENV guard works. The preview serves no Plausible tag at all, while GA4 is still present and untouched:

deploy-preview-168 homepage:  mpx/js/script.js  -> 0 matches  (correct)
deploy-preview-168 homepage:  G-C2CKKGCDB6      -> 1 match    (GA4 unchanged)

The proxy works. Even on the preview, where the tag is deliberately not rendered, both rewrite rules resolve and serve Plausible's real infrastructure rather than our 404 page:

GET  /mpx/js/script.js  -> 200, 6027 bytes, application/javascript
POST /mpx/api/event     -> 202

The script body starts !function(){var e,t,n,i,o={};function a(e,t,n){window.fetch&&fetch(... which is Plausible's tracker, so the rewrite is not being swallowed by the catch-all 404 below it.

Also fixed since the first push: layouts/partials/plausible.html is now in .prettierignore, for exactly the reason that file already documents. Prettier collapsed the Go template comment and rewrote the init snippet into a form CI's prettier then rejected, which is what failed Trunk Check on the first attempt. All checks green now.

One caveat on the local side, unrelated to this PR but worth flagging: aqua install currently cannot fetch the pinned Hugo v0.162.1 (hugo_extended_0.162.1_darwin-universal.tar.gz is not published under that name), and the repo CLAUDE.md still says v0.145.0 is required while Netlify pins 0.162.1. Local builds here used a cached v0.146.4. Worth untangling separately.

@Gowiem
Gowiem merged commit 58c5700 into main Aug 21, 2026
8 checks passed
@Gowiem
Gowiem deleted the feature/plausible-analytics branch August 21, 2026 16:10
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.

2 participants