Track 404 Error Pages Effectively with Google Analytics

404 Error Pages are created inorder to notify visitors that they have landed on a page which does not exist. This can happen when either the visitor have typed the wrong URL or the user have reached a broken link from an external or internal link. Like we use Google Analytics to track traffic for different pages of a website by pasting the Google Analytics code on every pages of a website, we can also track the number of visitors coming to the 404 error page.

But 404 error page views are always a concern for webmaster, since they are not aware of what the user actually typed or what they were looking for when they landed on the 404 error page. By getting all these information, a webmaster would be able to either create a new page for a particular topic that the user searched and landed on an error page or fix the broken link.

These information can be gathered to some extend by adding a small piece of code to the regular Google Analytics code. The basic steps for getting this is mentioned below.

1) Make sure that the 404 error page has Google Analytics installed.
2) Now modify the existing Google Analytics code in the 404 error page as given below.

<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”>
try{
var pageTracker = _gat._getTracker(“UA-xxxxx-x”);
pageTracker._trackPageview(“/404.html?page=” + document.location.pathname + document.location.search + “&from=” + document.referrer);
} catch(err) {}
</script>

By adding this code a virtual page view of “/404.html?page=[pagename.html?queryparameter]&from=[referrer]” is  send to your account, where [pagename.html?queryparameters] represents the missing page name and referrer is the URL of the page from where the user reached the 404 error page.

3) Now got to your Google Analytics dashboard and select the Top Content tab.

4) In the Top Content report look for /404.html page. Now you can see  more detailed report regarding your 404 error page traffic and there by improve your site quality.

This has worked for me and hope you can also benefit from this code.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *