Tracking 404’s/file not found errors in Google Analytics

Frequently we come across sites that don’t have Google Analytics tracking code installed on 404 error pages. This simple guide will show you how valuable the information is that can be obtained simply by implementing a piece of custom tracking code, and how to interpret it.

1. Check that there’s no tracking code on the 404 page

If there is, we can just modify the code to pass some extra data through to Analytics. We’ll look at the code later on. We can track visits to the 404 page using the standard Google Analytics ga.js tracking code, however it can be modified to present the missing page name within Analytics, i.e. the page that the visitor expected to see, as well as the referring page – where the visitor came from.
This is useful in a number of situations which will ultimately improve the quality of a site while allowing for error checking, especially in the following scenarios:

2. Add the Google Analytics tracking code to a custom 404 error page

In this case we’re using the latest version of the Google Analytics tracking code, ga.js. xxxx-x should be replaced with the appropriate Analytics account ID.

3. Modify the tracking code on the 404 page as follows 

(the unconventional code is in bold italics)

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? " <a href="https://ssl/">https://ssl</a> ." : "<a href="http://www/">http://www</a>.")
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-xxxxx-x");
pageTracker._trackPageview("/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer);

This code sends a virtual page view of "/404.html?page=[pagename.html?queryparameter]&from=[referrer]" to your account, where [pagename.html?queryparameters] is the missing page name, and referrer is the page URL from where the user reached the 404 page.

4. Look for /404.html in the Top Content report to display 404 pages and associated page and the referring information 

Drill down through Analytics to segment the data into paid and non-paid visits to identify sources of 404’s

5. Then decide on an appropriate course of action  

Considering the following for each significant instance of the 404