How do I delete old visitors statistics for a given website and/or date?
Sometimes, you may need to delete some or all Visits log data for a given date, and/or a given website. For example if you have imported log files incorrectly in Matomo (Piwik) you may want to delete the invalid data that was imported.
Delete visits using the UI
As part of the GDPR Privacy features in Matomo, you can easily delete visits. Learn more in the FAQ How do I delete rows of a report and specific visits to clean-up some of the reporting data? and in the guide: GDPR Guide “Right to erasure”.
Delete visits using a console command
A console command lets you delete all visits log data (including Visits, Actions, Goal conversions, Ecommerce activity).
To use this console command, login to your server (using SSH) and go in the Matomo directory. Execute the following command to display the help:
./console help core:delete-logs-data
The following options are available:
--dateslets you delete log data with a date within this date range. Eg, 2012-01-01,2013-01-01
--idsitelets you delete log data belonging to the site with this ID. Comma separated list of website id. Eg, 1, 2, 3, etc. By default log data from all sites is purged.
--limitlets you pick the number of rows to delete at a time. The larger the number, the more time is spent deleting logs, and the less progress will be printed to the screen. (default: 1000)
For example to delete all log data for month of January 2015 on website ID 42, execute:
./console core:delete-logs-data --dates=2015-01-01,2015-02-01 --idsite=42
- all the visits log data for the given date range and website ID will be permanently deleted.
- When a date range is entered (comma separated), the time will be set to the beginning of the day (midnight UTC) so for example using
--dates=2015-01-01,2015-01-02will delete all the data only for the 1st of January 2015 (in UTC timezone).
core:delete-logs-datacommand uses UTC when deleting log data, so you will need to adjust the command depending on the time zone that your website uses. To delete the data for a specific day for a website that is UTC +4 for example, you will use the following
--datesparameter to delete data for the specific day of 1 January 2015 (in UTC+4 in this example):
--dates="2014-12-31 20:00:00,2015-01-01 20:00:00"
- this console command does not delete your archived report data but only delete the raw visits log data.
Delete visits using SQL query
Run the following SQL query to delete visits matching a certain criteria, for example here we delete all visits where the screen resolution wasn’t tracked properly in the date range 2019 May 1st-May 16th:
DELETE log_visit, log_link_visit_action, log_conversion, log_conversion_item FROM log_visit LEFT JOIN log_link_visit_action ON log_visit.idvisit = log_link_visit_action.idvisit LEFT JOIN log_action ON log_action.idaction = log_link_visit_action.idaction_url LEFT JOIN log_conversion ON log_visit.idvisit = log_conversion.idvisit LEFT JOIN matomo_log_conversion_item ON log_visit.idvisit = log_conversion_item.idvisit WHERE config_resolution = 'unknown' AND visit_last_action_time >= '2019-05-01' AND visit_last_action_time <= '2019-05-16';
or delete all data for a given website:
DELETE log_visit, log_link_visit_action, log_conversion, log_conversion_item FROM log_visit LEFT JOIN log_link_visit_action ON log_visit.idvisit = log_link_visit_action.idvisit LEFT JOIN log_action ON log_action.idaction = log_link_visit_action.idaction_url LEFT JOIN log_conversion ON log_visit.idvisit = log_conversion.idvisit LEFT JOIN log_conversion_item ON log_visit.idvisit = log_conversion_item.idvisit WHERE log_visit.idsite = X;
Delete actions (pageviews, events…) using a SQL query
Run the following SQL query to delete all actions, in this example all Events, where the “Event action” matches a certain string (in this example
DELETE llva.* FROM matomo_log_link_visit_action llva JOIN matomo_log_action as la WHERE llva.idaction_event_action = la.idaction AND la.name LIKE '%my-event-action-to-delete%';
Or for example, if you tracked in the past some custom events with some bogus data (say an event value that is too large), then you can delete the bogus event actions by running the following SQL queries:
# First, check the data that will be deleted SELECT * FROM matomo_log_link_visit_action WHERE custom_float >= 99999999 # Then delete the data DELETE * FROM matomo_log_link_visit_action WHERE custom_float >= 99999999
Or for example to delete any site searches tracked before a certain date (
type = 8 is for site searches, see DB schema reference and
TYPE_SITE_SEARCH for other action types):
DELETE matomo_log_action FROM matomo_log_link_visit_action LEFT JOIN matomo_log_action ON idaction_name=idaction WHERE type=8 AND server_time < "2020-06-01";
If you want to configure Matomo to automatically purge your old data (whether visits log data, or statistics reports data), see this FAQ How do I delete historical Matomo data? (purge old logs and/or old processed reports)
If you want to delete old reports, read this FAQ: How do I delete all statistics for a given website, or for all websites?