Log Analytics lets you import any web server log file. In this FAQ we will focus on one particular type of logs that you may find useful to import in Matomo: the Matomo (Piwik) tracking API logs.
What are Matomo (Piwik) Tracking API logs?
piwik.php Tracking API endpoint. If you use one of the Tracking API clients to measure your mobile apps or games or desktop apps, they will also send requests to
piwik.php. Your webserver handling those requests will create access log files containing the tracking data that Matomo will collect in your database.
Uses of replaying logs
Replaying logs is very useful for example when your database server breaks down and Matomo (Piwik) could not write the data for a few hours. Luckily you can use your web server logs matching
/piwik.php and replay them into Matomo. Replaying logs means that the Log Analytics tool will go through each line of the log and import them in your Matomo for the correct datetime in the past. Replaying logs is also useful if you want to setup High availability Matomo.
How to replay Tracking API logs?
Firstly you would prepare a log file containing only the requests that should imported. Typically you would import only a given period of time.
To replay the tracking API logs you then call the log analytics importer with
--replay-tracking parameter such as:
./misc/log-analytics/import_logs.py --url=piwik.example.net --replay-tracking /var/log/apache2/access.log
After replaying the logs it is recommended to reprocess the data with the
core:archive console command.