Google Analytics can be setup to record whenever a 404 error page is shown on your website. This can be useful to fix broken links or setup redirects to new content.

Create or open your custom 404 error page. If you’re running your website on Apache, just create a new page and name it something like 404errorpage.php. Then modify your htaccess file by adding the line in bold:

ErrorDocument 404 /404errorpage.php

Then modify the Google Analytics tracking code as shown in bold:

<script type=”text/javascript”>

var gaJsHost = ((”https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);

document.write(unescape(”%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));

</script>

<script type=”text/javascript”>

var pageTracker = _gat._getTracker(”UA-XXXXXX-XX”);

pageTracker._trackPageview(”/404errorpage.php?page=” + document.location.pathname + document.location.search + “&from=” + document.referrer);

</script>

The 404 error pages can then be viewed in the top pages report by searching for 404errorpage.php.