Repository navigation
Zero analytics by default: an env-gated Umami Cloud script in a client-only Next.js app #4754
geMH
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Disclosure up front: I built the site linked at the end of this post. No affiliation with
Umami — just a user. Everything below is from code I actually shipped.
I run a small privacy-first tool site: every tool is client-side, no uploads, no accounts,
deployed as a Next.js 15 App Router app on Cloudflare Workers through OpenNext. Picking
analytics was awkward, because I can't say "your files never leave your device" and then ship
a full tracking stack. Umami Cloud is what I ended up with, and the part worth sharing isn't
the choice — it's how the site stays analytics-free by default.
The component that injects the tracker reads three env vars:
NEXT_PUBLIC_ANALYTICS_ID— if unset, the component returns null. No script tag, no request,nothing in the served HTML.
NEXT_PUBLIC_ANALYTICS_TYPE— "umami" (default) or "plausible".NEXT_PUBLIC_ANALYTICS_SRC— an override, so moving from Umami Cloud to a self-hostedinstance is an env change, not a code change.
That first one mattered more than I expected. The repository builds and runs cleanly before you
have an analytics account at all, and a fork that doesn't want telemetry can drop the env var and
get a genuinely clean page. For a site whose whole pitch is "nothing leaves your tab", that's a
nicer default than a commented-out script tag.
The Umami branch is a plain
<script defer src=... data-website-id=...>rendered in the rootlayout's
<head>— notnext/script. The tracker is a pure side channel; it has no Reactlifecycle to coordinate with, and every tool works identically if it's blocked. I did verify the
tag is present in the HTML that OpenNext/Workers actually serves, which was the one thing I
wasn't certain about before deploying.
Two honest constraints:
NEXT_PUBLIC_*values are inlined at build time, so changing the website id or pointing ata self-hosted src means a rebuild. Fine for a static-first site, less fine if you expect to
reconfigure at runtime.
policy says explicitly that blocking analytics doesn't change how any tool behaves, and with no
custom events that's easy to keep true.
One thing I'd genuinely like a maintainer's read on: on an App Router site with client-side
navigation, I'm relying on the tracker's own History API handling to record route changes — there
is no
pathnamelistener in my code. Is that sufficient for the current Umami tracker, or arethere App Router cases where a page view gets missed? I'd rather ask than add a hook I don't need.
The site is at https://offbasetools.com/ — the analytics note is in its privacy policy.
All reactions