Pages regularly appear and disappear on websites, other websites might link to wrong URLs on your website, etc. You can track with Matomo (Piwik) which URLs are leading to a 404, and which referrer pages link to 404 on your website.

  • Setup a custom 404 page: you can easily do this if you use a CMS (for example, in wordpress, all 404 pages are loading a custom 404 template). If you don’t use a Content Management System, you can usually specify a 404 custom page in your webserver configuration file.
  • Add the Matomo tracking code in this custom 404 page. In the Javascript tracking code, add the following:

    _paq.push(['setDocumentTitle',  '404/URL = ' +  encodeURIComponent(document.location.pathname+document.location.search) + ' /From = ' + encodeURIComponent(document.referrer)]);
    

before the line

_paq.push(['trackPageView']);
  • In your Matomo report, in Behavior > Pages Titles, you will now have a new entry for the 404 pages. It will also list the full URL of the 404 pages, as well as all referrers leading to this page. Enjoy!

To get advanced reporting about your 404 error pages, you may want to consider the Custom Reports premium feature which lets you create a new report for 404 error pages. It lets you analyze the 404 reports faster and gives you more insights.

Previous FAQ: How do I track pages across Multilingual sites or sites in Multiple Languages in Matomo?