将我的网站分析从 Matomo 迁移到 Umami
Migrating my web analytics from Matomo to Umami

原始链接: https://stanislas.blog/2025/12/migrating-matomo-to-umami-web-analytics/

## 从 Matomo 迁移到 Umami:10 年数据拯救 作者在使用 Matomo(前身为 Piwik)进行网站分析十年后,寻求更现代的解决方案,并在 2022 年过渡到 Umami。虽然 Umami 提供了更简洁的 UI 和更简单的托管(NextJS/PostgreSQL 与 Matomo 的 PHP/MySQL),但一个主要障碍是迁移 10 年的历史数据。 由于不存在直接导出/导入功能,作者开发了一个 Python 工具 `matomo-to-umami`(可在 GitHub 上找到),以直接将数据从 Matomo 的 MySQL 数据库迁移到 Umami 的 PostgreSQL 数据库。这涉及仔细映射数据模型并生成兼容的 SQL INSERT 语句。 迁移过程包括一次预览运行和使用本地 Docker 环境进行彻底测试,以确保数据准确性——验证诸如跳出率、浏览器和国家/地区等指标。成功迁移了 angristan.fr 和 stanislas.blog 这两个网站的数据后,作者终于可以停用他们的 Matomo 实例并简化他们的分析设置,同时保留了宝贵的历史数据。该工具被提供给面临类似迁移挑战的其他人作为资源。

一个 Hacker News 的讨论围绕着将网站分析从 Matomo 迁移到 Umami。发帖者成功迁移了数据并节省了资源。 评论者分享了其他轻量级的分析解决方案,例如 GoatCounter,因为它简单(仅记录页面浏览量)。有人提出了对 Matomo 过时用户界面和更新困难的担忧,并质疑仅有两个网站是否需要切换到 Umami(一个 NextJS/PostgreSQL 应用)。 讨论还涉及 Matomo 的插件系统(以及 Umami 中缺乏插件系统的情况)、功能集,以及 Umami 向云优先模式的转变,这让一些寻求自托管开源解决方案的用户感到失望。 还有一个关于菲利普斯螺丝刀的玩笑性辩论。 最终,帖子因分享迁移过程和工具而受到赞扬。
相关文章

原文

Quickly after starting French blog in 2014, I switched from Google Analytics to Piwik for my web analytics. It’s been since renamed Matomo in 2018. It’s been working pretty well for more than 10 years, and I’m thankful for the creator and maintainers.

Finding a modern alternative to Matomo #

In 2022 I started using Umami as well, with the intention of replacing Matomo. Matomo has barely evolved in terms of UI, and it feels pretty dated now. Umami, in comparison, has a much more modern and clean UI.

Matomo also has a lot of features, most of which I don’t use. It has a few gotchas like this weirdness around updating it in its Docker image. It terms of stack, Matomo is PHP + MySQL, Umami is a NextJS app with PostgreSQL. Not fundamentally different, but Umami is just simpler to host: automatic database migrations, no plugins, reduced feature set, etc.

Matomo dashboard showing visitor logs, real-time map, and various analytics widgets
Matomo dashboard. Very powerful and very busy

It’s been a few years now, and I’m happy with Umami! I’m feeling like it’s time to decommission my Matomo instance.

However Matomo holds my analytics data for angristan.fr and stanislas.blog for the past 10 years… I don’t want to lose that!

I tried searching for a way to export my data from Matomo and import it into Umami, but it doesn’t seem to exist. There is an open issue on this subject. It seems that their Cloud hosted version has an import feature, but it’s not open source. Fair!

I was able to create my own tool to do so, by studying the data models of both Matomo and Umami, and evaluating how to possibly map every field. It’s available as angristan/matomo-to-umami on GitHub.

It’s a Python program to migrate analytics data from Matomo’s database (MySQL/MariaDB) to Umami’s database (PostgreSQL). It extracts visitor sessions and pageview events from a Matomo database and generates SQL INSERT statements compatible with Umami’s schema.

It covers all the features I need! I double-checked that the mappings were correct for browsers, countries, etc. And things such as outlinks and downloads, or return visits to make sure the bounce rate is the same.

I decided not to use APIs to export/import sessions to bypass any limitations and have full control. It’s also much faster to do raw SQL.

Testing the migration #

To sanity check my data in Umami, I set up a local docker-compose environment in the repo which allows me to import the generated dump into a local umami instance to check if the numbers and values look good.

This was very useful and allowed me to catch bugs. I suggest that anyone following the migration step do a sanity check as well.

My migration #

I run both Matomo and Umami on my k8s node. Matomo is backed by a MariaDB instance and Umami by a PostgreSQL instance.

I have two sites to migrate:

Matomo IDUmami UUIDDomain
1a5d41854-bde7-4416-819f-3923ea2b2706angristan.fr
53824c584-bc9d-4a9b-aa35-9aa64f797c6fstanislas.blog

Port-forward MariaDB #

kubectl -n matomo port-forward svc/mariadb 3306:3306 &

Dry-run migration (preview) #

➜  matomo-to-umami git:(master) uv run migrate \
 --mysql-host localhost --mysql-port 3307 \
 --mysql-user root --mysql-password password --mysql-database matomo \
 --site-mapping "1:a5d41854-bde7-4416-819f-3923ea2b2706:angristan.fr" \
 --site-mapping "5:3824c584-bc9d-4a9b-aa35-9aa64f797c6f:stanislas.blog" \
 --start-date 2015-01-01 --end-date 2022-07-10 \
 --dry-run -v
[22:13:22] INFO     Configured 2 site mapping(s)
           INFO     Connecting to MySQL at localhost:3307
[22:13:23] INFO     Successfully connected to MySQL database

Dry Run Mode - No SQL will be generated

            Migration Summary
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ Metric           ┃ Value               ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ Total Sessions   │ 1,352,812           │
│ Total Events     │ 1,999,709           │
│ Date Range Start │ 2015-01-18 10:45:32 │
│ Date Range End   │ 2022-07-09 23:58:58 │
└──────────────────┴─────────────────────┘
                 Per-Site Breakdown
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Matomo ID ┃ Domain         ┃ Sessions ┃    Events ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━┩
│ 1         │ angristan.fr   │  861,301 │ 1,332,275 │
│ 5         │ stanislas.blog │  491,511 │   667,434 │
└───────────┴────────────────┴──────────┴───────────┘

Ready to migrate. Run without --dry-run to generate SQL.

Result: 1,352,812 sessions, 1,999,709 events to migrate

Generate migration SQL #

Terminal recording showing the matomo-to-umami migration tool generating SQL statements

Import to Umami #

kubectl -n umami exec -i umami-cnpg-1 -- env PGPASSWORD=<password> \
 psql -h localhost -U app -d app < migration.sql

Umami dashboard displaying pageviews and sessions over time with a clean, modern interface

Now, I’m free to say goodbye to Matomo, and save resources.

Feel free to use matomo-to-umami, I hope it will be useful to someone else.

Thank you Matomo and Umami for being open source ❤️

联系我们 contact @ memedata.com