How do I fix an “Allowed memory size exhausted” error in Media Analytics?
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:
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
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
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
500 or an even lower value in your
Starting with version 4.2.0 of the plugin, you have the option of limiting the results that are used to generate the archived table. By default, the primary results will be limited to 10,000 rows, ranking them so that the resources with the most plays will be in those first 10,000 rows. Any remaining resources will be grouped together under the
Other row. When you expand a resource in the report, it shows secondary information specific to that resource. By default, those results are limited to 75,000 rows to be divided amongst the 10,000 resources. If you find that the secondary information seems to be incomplete, you can increase the secondary limit or decrease the primary limit. Decreasing the primary limit will also decrease the likelihood of running out of memory while MediaAnalytics reports are being archived. Setting the new configs in your
config/config.ini.php file would look something like the following:
[MediaAnalytics] archiving_ranking_query_row_limit_primary = 5000 archiving_ranking_query_row_limit_secondary = 70000
For cloud, please contact support and they should be able to adjust those configs for you.