In my client websites a bunch of URL with dynamic parts are going to be changed (replacing UUIDs with more user friendly slugs, e.g. mywebsite . org/product/018c9101-1f0b-7a51-9c19-191c7c5356b9/ to mywebsite . org/product/im-so-pretty-and-unique/)
I would like matomo to use the new URL format without losing my old data, and that tracking from the old and new URL be merged.
I believe this is a fairly common use case, but I did not found anything on the documentation except for setCustomUrl (but I think that my old data is not going to be updated with this)
You can migrate historical data directly in your DB, but it seems rather complicated. First, you might destroy your DB doing it, so test it on test system or have a roll back plan ready.
In Matomo, there are two key types of data:
Raw Data: Stored in tables such as log_visit, log_link_visit_action, and log_action. This is the granular data used to generate reports.
Archived Reports: Precomputed reports stored in tables like archive_numeric_* and archive_blob_*. These are created for performance optimization.
Usually, raw data is deleted after a certain amount of time (configurable in settings) once archiving is done.
Migrating raw data could be done using SQL. You’d need to address all relevant tables, like log_visit, log_link_visit_action, and log_action. I can’t give you a full list, sorry. Also, make sure that all relevant data fields in those relevant tables are migrated.
If you do that, you can invalidate existiing archives and have matomo re-archive it from changed raw data. Careful: you need full historical raw data to do that.
If raw data is gone, merging historical data becomes significantly harder because the archived data does not reference URLs in a way you can directly edit. Archived data is pre-aggregated and stored in archive_blob_* and archive_numeric_*, which makes direct editing complex and error-prone. I have never thought about this before…
So, if I’d be in your position, i’d do this:
set up a matomo test system
backup prod matomo DB
restore backup in test system
replace hostorical data using SQL scripts
test
If this works, i’d deploy on prod:
stop matomo tracking
backup matomo DB
replace URLs on website
run SQL scripts on matomo DB
test
re-enable matomo tracking
that’s just a rough approach to give you a hint. maybe it’s over-complicated and someone has a better idea…
to be honest, i’d probably just live without doing all that
This is a great question and definitely something that comes up often when websites go through URL changes. The good news is that there are ways to handle this in Matomo without losing your historical data. Let me break it down for you:
One straightforward approach is to use Custom Dimensions or Custom Variables in Matomo. By assigning a unique identifier (like the product ID) to each page, you can ensure both the old and new URLs are grouped under the same identifier. This won’t physically merge the old and new URLs in Matomo’s database, but it allows you to analyze the data together as if they were the same entity.
If you’re looking for a deeper solution to actually “merge” the old and new URLs in your data, you might consider using Matomo’s Log Importer. With this method, you could export the old tracking data, rewrite the URLs to match the new format, and then re-import it. Be cautious, though—this process can get pretty technical and might require database backups just in case something goes wrong.
Another simpler approach is using Segmentation within Matomo. You can create segments that group both old and new URLs based on something they have in common (like /product/). This way, even though the URLs themselves aren’t merged in the data, you can still view combined stats easily in your reports.
For future tracking, you could also set up 301 redirects from the old URLs to the new ones. This ensures users and search engines are directed to the updated URLs, and Matomo will still capture the traffic coming through those redirects. Over time, your reports will naturally shift toward the new URL format as the old ones phase out.
I hope one of these solutions fits your needs! Let me know if you need help figuring out which option is best for your setup or how to get started.
@RobertJoseph as I crawl through the documentation I find myself unable to locate meaningful ressources on Log Importer. All I can see with an import / export process is with mysqldump export (with URL replacement, it may works?) or Import Server logs which doesn’t look like what I want.
Can you point some link to me?