Add self-hosted Matomo analytics via first-party Worker proxy - #45
Merged
Conversation
Loads the tracker from /mtm/mtm.js and sends hits to /mtm/mtm.php, both proxied by the Worker to the Matomo install, so the browser only talks to dubsector.dev and the Matomo hostname stays out of the page source. The visitor IP is forwarded as X-Forwarded-For. Tracking is cookieless and honours DNT. Beyond the pageview, each command a visitor types by hand is sent as a terminal/command event; scripted intro commands are not tracked. With MATOMO_ORIGIN or MATOMO_SITE_ID unset, /api/analytics returns 204 and the client skips the tracker.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
terminal | 1bed75c | Commit Preview URL Branch Preview URL |
Aug 02 2026, 03:24 AM |
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.
Adds Matomo tracking for dubsector.dev, proxied through the Worker so the browser only ever talks to
dubsector.dev./mtm/mtm.js$MATOMO_ORIGIN/matomo.js/mtm/mtm.php$MATOMO_ORIGIN/matomo.phpKeeps the tracker off third-party blocklists and keeps the Matomo hostname out of the page source. The real visitor IP is forwarded as
X-Forwarded-For.disableCookies), honours Do Not Track.terminal/commandevent for each command a visitor types by hand (name = command line, truncated to 100 chars). Commands run by the scripted intro are not tracked.MATOMO_ORIGINorMATOMO_SITE_IDunset,/api/analyticsreturns 204 and the client never loads the tracker, so local builds stay silent.Before this does anything in production
Matomo also needs
proxy_client_headers[] = HTTP_X_FORWARDED_FORunder[General]inconfig.ini.php, otherwise every visit is geolocated to a Cloudflare egress IP.Testing
Ran
wrangler devlocally against the real Matomo install:/api/analytics204, no_paq, no tracker script, terminal renders normally/api/analytics200,/mtm/mtm.js200 (68 KB), pageview ande_c=terminal&e_a=commandevent hits both accepted 204 by Matomo