# astro-matomo

> Matomo integration for Astro

Latest version **1.12.0** (published 2026-07-06) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install astro-matomo
pnpm add astro-matomo
yarn add astro-matomo
bun add astro-matomo
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.12.0 |
| Published | 2026-07-06 |
| First published | 2023-02-25 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 22 |
| Author | Felix Scholze |
| Maintainers | felix_berlin |
| Keywords | astro, astro.js, withastro, astro-integration, matomo, analytics, tracking |

## Links

- npm: https://www.npmjs.com/package/astro-matomo
- Repository: https://github.com/felix-berlin/astro-matomo
- Issues: https://github.com/felix-berlin/astro-matomo/issues
- Funding: https://paypal.me/FelixScholze
- npm.io page: https://npm.io/package/astro-matomo

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.12.0 (latest) — 2026-07-06
- 1.11.1 — 2026-07-06
- 1.11.0 — 2026-07-06
- 1.10.0 — 2026-03-11
- 1.9.0 — 2025-06-09
- 1.8.2 — 2025-06-09
- 1.8.1 — 2025-04-07
- 1.8.0 — 2025-02-02
- 1.7.0 — 2024-12-04
- 1.6.0 — 2024-05-16
- 1.5.0 — 2024-05-05
- 1.4.2 — 2024-01-28
- 1.4.1 — 2023-12-06
- 1.4.0 — 2023-08-30
- 1.3.1 — 2023-08-22
- … 5 more at https://npm.io/package/astro-matomo/versions

## README

# Astro Matomo

![npm](https://img.shields.io/npm/dm/astro-matomo?logo=npm&style=flat-square)
![npm](https://img.shields.io/npm/v/astro-matomo?logo=npm&style=flat-square)
![GitHub package.json version](https://img.shields.io/github/package-json/v/felix-berlin/astro-matomo?label=github&logo=github&style=flat-square)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/felix-berlin/astro-matomo/release.yml?label=release&logo=github&style=flat-square)

## Installation

```bash
pnpm add astro-matomo

npm install astro-matomo

yarn add astro-matomo
```

## Options

| Options            | Type                                    | Description                                                                                                                                                                                         |
| ------------------ | --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `enabled`          | `boolean`                               | Controls if the matomo script should be loaded                                                                                                                                                      |
| `host`             | `string`                                | Url to your matomo installation                                                                                                                                                                     |
| `siteId`           | `number`                                | Matomo site id.                                                                                                                                                                                     |
| `heartBeatTimer?`  | `number`                                | If set the heart beat timer will be enabled                                                                                                                                                         |
| `disableCookies?`  | `boolean`                               | If set cookies will be disabled                                                                                                                                                                     |
| `preInitCommands?` | `Array<[string, ...unknown[]]>`         | Matomo `_paq` commands pushed before default tracking commands. Use for calls like `requireCookieConsent`.                                                                                          |
| `preconnect?`      | `boolean`                               | Will create a preconnect link pointing to the matomo host                                                                                                                                           |
| `setCookieDomain?` | `string`                                | Share the tracking cookie across multiple domains                                                                                                                                                   |
| `trackerUrl?`      | `string`                                | Defaults to matomo.php                                                                                                                                                                              |
| `srcUrl?`          | `string`                                | Defaults to matomo.js                                                                                                                                                                               |
| `customSrcUrl?`    | `string`                                | Optional. A full URL to the Matomo tracking script. If set, it overrides `srcUrl`.                                                                                                                  |
| `debug?`           | `boolean`                               | Activate debug mode                                                                                                                                                                                 |
| `partytown?`       | `boolean`                               | Adds [Partytown](https://partytown.builder.io/) support. Matomo added as: `<script type="text/partytown">...</script>`                                                                              |
| `crossOrigin?`     | `string`                                | Set `crossorigin` attribute                                                                                                                                                                         |
| `viewTransition?`  | `boolean or { contentElement?: string, deleteCustomDimensions?: number[] }` | If true Matomo works in "SPA Mode" and will track every page visit after `astro:page-load`. When you pass a selector to `contentElement` Matomo is able to track new media files, forms and content. Custom dimension ids listed in `deleteCustomDimensions` are deleted on every navigation (useful for page-scoped dimensions that should not leak into the next page view) |

## Example usage

```js
// astro.config.mjs

import { defineConfig } from 'astro/config';
import matomo from 'astro-matomo';

// https://astro.build/config
export default defineConfig({
  site: "https://example.lol",
  integrations: [
    matomo({
      enabled: import.meta.env.PROD, // Only load in production
      host: "https://analytics.example.lol/",
      setCookieDomain: "*.example.lol",
      trackerUrl: "js/", // defaults to matomo.php
      srcUrl: "js/", // defaults to matomo.js
      siteId: 666,
      heartBeatTimer: 5,
      disableCookies: true,
      preInitCommands: [["requireCookieConsent"]],
      debug: false,
      viewTransition: {
        contentElement: "main",
        // Optional: delete page-scoped custom dimensions on every navigation
        deleteCustomDimensions: [2, 3]
      }
    }),
  ]
});

```

## Development

Go to demo directory:

```bash
cd demo
```

Go to the demo project and install the dev package:

```bash
pnpm install

npm install
```

Start the dev server:

```bash
pnpm run dev

npm run dev
```

---
_Source: https://npm.io/package/astro-matomo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
