A Python script that migrates analytics data from Matomo to Umami by generating SQL statements for direct database import.
- Complete Data Migration: Transfers sessions, page views, and visitor information
- Flexible Date Ranges: Migrate specific time periods or default to last 2 years
- Data Preservation: Maintains visitor sessions, browser info, location data, and referrer information
- Python 3.7+
- Access to your Matomo instance
- PostgreSQL database (Umami backend)
Install required packages:
pip install -r requirements.txtYou need to generate an API authentication token from your Matomo dashboard.
- Log in to your Matomo dashboard
- Go to Personal Settings → Security → Auth Tokens
- Give it a descriptive name
- Untick the "Only allow secure requests" checkbox and click Create New Token
- Copy the generated token (you'll need this for the script)
- In your Matomo dashboard, go to Administration → Websites → Manage
- Note the ID number next to your website (usually 1 for the first site)
- Log in to your Umami dashboard
- Go to Settings → Websites
- Click on Edit to view details
- Copy the Website ID (UUID format)
python matomo2umami.py https://your-matomo-url.com SITE_ID MATOMO_TOKEN UMAMI_WEBSITE_UUIDpython matomo2umami.py https://your-matomo-url.com SITE_ID MATOMO_TOKEN UMAMI_WEBSITE_UUID --start-date 2023-01-01 --end-date 2023-12-31python matomo2umami.py https://your-matomo-url.com SITE_ID MATOMO_TOKEN UMAMI_WEBSITE_UUID -o my_migration.sqlpython matomo2umami.py https://analytics.example.com 1 1234567890abcdef 550e8400-e29b-41d4-a716-446655440000 --start-date 2024-01-01 --end-date 2024-03-31 -o march_2024_migration.sql --batch-size 5000 --days-per-request 10| Argument | Required | Description | Example |
|---|---|---|---|
matomo_url |
✅ | Your Matomo installation URL | https://analytics.example.com |
site_id |
✅ | Matomo site ID (usually 1) | 1 |
token_auth |
✅ | Matomo API authentication token | 1234567890abcdef |
website_id |
✅ | Umami website UUID | 550e8400-e29b-41d4-a716-446655440000 |
-o, --output |
❌ | Output SQL file path | migration.sql (default) |
--start-date |
❌ | Start date (YYYY-MM-DD) | 2023-01-01 |
--end-date |
❌ | End date (YYYY-MM-DD) | 2023-12-31 |
--batch-size |
❌ | The batch size to use for the sql import statements | 1000 (default) |
--days-per-request |
❌ | How many days should be fetched with each Matomo request | 1 (default) |
The script generates a PostgreSQL-compatible SQL file containing:
- File Header: Migration metadata and settings
- Session Records: Visitor sessions with device/location info
- Event Records: Page view events with URL and referrer data
After generating the SQL file, import it into your Umami PostgreSQL database:
# Using psql command line
psql -h localhost -U umami_user -d umami_db -f migration.sql
# Or using PostgreSQL client of your choice- Install docker compose
- Install psql
- Run
python preview.py
This will create a local instance of Umami using docker and import the generated migration into it for verification.
