Tracking 404 Errors in Google Analytics
404 errors (also known as Page Not Found errors) occur when an incorrect URL is used to access a page on a site. This could be due to the user mistyping a URL, or due to a link pointing to an incorrect URL or a page being deleted, but links to it remain.
Tracking these 404 errors can be useful as not only will you learn if there are any incorrect URLs on your site, but you can also get external incorrect URL links tracked and then get these links changed to correct URLs. This will help with SEO as it will mean PageRank is being passed to the correct page, instead of being lost on a non-existant page.
To track 404 errors in Google Analytics, you will first have to set up a custom 404 error page. Then simply place the code below into the 404 page (in replace of the standard Google Analytics code) and make sure to add the correct UA ID code.
<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-xxxxx-x“);
pageTracker._trackPageview(”/404.html?page=” + document.location.pathname + document.location.search + “&from=” + document.referrer);
</script>
This code sends a virtual pageview 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.
Look for /404.html in your Top Content report in Google Analytics to see where the 404 errors occured.





