@miscwrenches/astro-proxied-matomo (1.0.3)

Published 2026-02-11 06:29:13 -06:00 by tim in web/astro-packages

Installation

@miscwrenches:registry=
npm install @miscwrenches/astro-proxied-matomo@1.0.3
"@miscwrenches/astro-proxied-matomo": "1.0.3"

About this package

Adding the integration

Install with your package manager of choice, eg npm install @miscwrenches/astro-proxied-matomo.

In your main Astro config /astro.config.mjs, add the integration:

import { defineConfig } from 'astro/config';
import matomo from '@miscwrenches/matomo';
// ...
export default defineConfig({
  // ...
  integrations: [
    matomo({
      // Only load in production
      enabled: import.meta.env.PROD,
      // Match the site ID from Matomo
      siteId: 2,
      viewTransition: true,
    }),
  ],
});

Required reverse proxy setup steps

I've changed what is usually matomo.js and matomo.php to m.js and m.php, as ad ablockers look specifically for matomo. This Caddy example shows how you just have to route the m.js and m.php routes to Matomo in your caddy Caddyfile. In this case my matomo is served by frankenphp on port 8480.

mysite.tld {
    @matomo path /m.js /m.php
    handle @matomo {
        uri replace /m. /matomo. 1
        reverse_proxy http://localhost:8888 {
            # Change the host field in the header to your matomo site
            header_up Host matomo.mysite.tld
        }
    }
  
    # If you're serving other content from mysite.tld you'll need to continue with a file server, another reverse proxy, etc. This is just an example.
    root * /var/www/mysite.tld
    file_server
}

For completeness, these are my caddyfiles for the Matomo instance.

/etc/caddy/Caddyfile

matomo.mysite.tld {
    @exclude path /config/* /tmp/* /lang/en.json
    respond @exclude "Access Denied." 403
    reverse_proxy localhost:8888
}

/etc/frankenphp/Caddyfile

{
    frankenphp
    http_port 8888
    admin off # Don't conflict with caddy.
    persist_config off # Will conflict if run with same user as caddy.
}

matomo.mysite.tld:8888 {
    bind 127.0.0.1 [::1]
    root * /var/www/matomo.mysite.tld
    encode zstd br gzip
    php_server
}

Thanks to Felix Scholze for astro-matomo. It pointed me in the right direction regarding using an integration.

Dependencies

Development dependencies

ID Version
astro ^5.16.0

Peer dependencies

ID Version
astro ^4.0.0 || ^5.0.0

Keywords

astro integration matomo
Details
npm
2026-02-11 06:29:13 -06:00
7
Tim Payne
MIT
latest
2.5 KiB
Assets (1)
Versions (2) View all
1.0.3 2026-02-11
1.0.2 2026-01-20