In some very rare cases you might see a memory error caused by Media Analytics if you are tracking hundreds of thousands of different media URLs per day. This can typically be the case if every media resource URL includes a random URL parameter such as key in the below example:

https://example.com/media.mp4?key=123
https://example.com/media.mp4?key=456

In this case you could avoid this memory issue by excluding the URL parameter that changes every time. In above example the URL parameter to exclude would be key. To exclude this parameter locate your local config file in $matomoDir/config/config.ini.php and tweak the media_analytics_exclude_query_parameters setting which by default only excludes the two URL parameters enablejsapi and player_id:

[MediaAnalytics]
media_analytics_exclude_query_parameters=enablejsapi,player_id,key

Simply append any randomly changing URL parameter to the media_analytics_exclude_query_parameters setting separated by a comma. This will not only fix the memory issue but also improve your reports since the number of views and plays will no longer be always 1 but can be accurately calculated based on the number of visits that viewed and played a particular media.

If you want to fix the issue retrospectively, you can execute the following SQL query in your database. Make sure to adjust the matomo_ database table prefix if needed, the idSite, and the URL parameter key

update matomo_log_media set resource = substring_index(resource, '?key', 1) where idsite = 1 and server_time > date_sub(NOW(), INTERVAL 1 week) and resource like '%?key%'

If above does not fix your issue

If you are still getting a memory error from Media Analytics you may want to limit the number of rows per subtable by changing the default value of 1000 to 500 or an even lower value in your config/config.ini.php:

[MediaAnalytics]
datatable_archiving_maximum_rows_subtable_media=500