Skip to content

Only track analytics on the production hostname - #46

Merged
dubsector merged 3 commits into
mainfrom
analytics-production-only
Aug 2, 2026
Merged

Only track analytics on the production hostname#46
dubsector merged 3 commits into
mainfrom
analytics-production-only

Conversation

@dubsector

Copy link
Copy Markdown
Owner

Follow-up to #45.

Worker secrets belong to the Worker, not to a single version, so branch previews deployed with wrangler versions upload inherit MATOMO_ORIGIN / MATOMO_SITE_ID and would log preview traffic as real dubsector.dev visits. The client now checks location.hostname before loading the tracker, so previews and local wrangler dev stay silent.

Testing

Ran wrangler dev locally with both vars set in .dev.vars:

  • as written (PRODUCTION_HOST = "dubsector.dev") on localhost: no _paq, no tracker script, zero requests to /mtm/* — while /api/analytics still returns {"siteId":"1"}, confirming the gate is what stops it and not a missing config
  • with PRODUCTION_HOST temporarily flipped to "localhost" and rebuilt: /mtm/mtm.js 200, pageview hit to /mtm/mtm.php accepted 204 by Matomo, then reverted

Secrets belong to the Worker rather than to a single version, so branch
previews deployed with wrangler versions upload inherit them and were
logging preview traffic as real dubsector.dev visits. Checking
location.hostname before loading the tracker keeps previews and local
wrangler dev out of the stats.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 2, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
terminal 249b960 Commit Preview URL

Branch Preview URL
Aug 02 2026, 03:37 AM

disableCookies traded returning-visitor accuracy for skipping a consent
banner; keep the cookies and the accurate visitor counts instead.
Cookies only bought returning-visitor identification, which is close to
meaningless on a single-page site with no accounts, and buying it meant
adding a consent banner. Cookieless plus anonymized IPs on a self-hosted
install keeps the exemption and skips the banner.
@dubsector
dubsector merged commit 596e514 into main Aug 2, 2026
5 checks passed
@dubsector
dubsector deleted the analytics-production-only branch August 2, 2026 03:38
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