How do I delete historical Matomo data? (data retention for old web analytics raw data logs and/or old processed reports)
Matomo (Piwik) tracks visitors activity, and then computes aggregated reports. The settings page lets you
- 1) Delete the Tracking Logs (RAW data) and / or….
- 2) Delete the old processed stats (archived reports)
Delete old RAW data (old tracking logs)
You can configure Matomo to automatically delete your older tracking logs from the database. Deleting old logs has many advantages: 1) it will free significant database space, 2) which will slightly increase performance, 3) for Privacy reasons, it is sometimes recommended to keep detailed logs only for 6 months or so, and remove older data.
To configure Log delete in Matomo, login as the Super User, click on Administration > Privacy > Anonymize Data > Delete old visitor logs. You can then configure to Delete logs older than N days, and execute the log purging every day, every week or every month. When ‘Delete old logs’ is enabled, only the raw logs of activity will be deleted from the database. Specifically, only the Mysql tables starting with matomo_log_*
are affected.
You can delete old logs data in various ways: by using the UI, a console command, or even SQL queries. Read this FAQ for more information: How do I delete old visitors statistics for a given website and/or date?
Important: When you enable automatic log deletion, you must ensure that all previous daily reports have been processed, so that no data is lost. See this FAQ for more information.
What is the impact of deleting historical RAW data?
If you have properly setup the auto archiving script (see important note), you will still access all historical reports (even when RAW data is deleted). But there are important points to be aware of:
-
Deleted data: All deleted data is lost forever.
-
The Visits Log will be empty across the periods without RAW data.
-
Transitions report: The Transitions report is processed in real time, using the logs. When deleting old log data, the report will still partially work but only display transitions for the days that still have log data.
-
Unique visitors metrics: The Unique visitors metrics for Weeks, Months, Years will be available only for those date ranges that still have log data. Unique visitors metric will still be processed for days.
-
If you were to create a new custom report, the data included could only go as far back as the amount of RAW data you have.
-
Roll-up reporting also relies on RAW data so for the period of missing data roll-up reporting will not be available.
-
If you were to invalidate data across a period with missing RAW data you do not need to be concerned about losing report data, as Matomo will detect the RAW data is missing and maintain the current archived data.
Delete old reports data
If your Mysql database space is limited, you can also Delete old reports in Matomo > Administration > Privacy. You can choose to keep daily, weekly, monthly and / or yearly data. We recommend keeping monthly and yearly data as an interesting dataset.
If you enable any of the 2 features to delete old data, the Database estimate size will refresh and give you an idea how much space you would save using the feature. If you cannot wait for the next automatic tasks schedule, you can also force the purge by clicking on ‘Purge Now’.