When websites are regularly updated, it’s common for outdated or incorrect links to remain in circulation either from external sources or within your own site. Matomo can track which URLs result in 404 errors and identify the referrer pages that lead visitors to those broken links.

You can capture 404 pages using either the Matomo JavaScript tracking code or Matomo Tag Manager. Both methods record a page view when a 404 page is displayed, allowing you to identify the missing URL, the referring page, and how often visitors encounter these errors.

  1. 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.
  2. Add the Matomo tracking code in the custom 404 page and include the following in the JavaScript tracking code before _paq.push(['trackPageView']); :

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

In Matomo, view the new entry for the 404 pages in Behaviour > Pages Titles. It will also list the full URL of the 404 pages, as well as all referrers leading to this page.

To get advanced reporting about your 404 error pages, On-Premise users may want to consider the Custom Reports premium feature (free for Matomo Cloud users). This lets you create a new custom report for 404 error pages for quicker analysis and more insights.

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