You don't want your website visitors coming across your 404 page. It hurts your brand, your conversions, and in some cases your search engine optimization efforts. In order to best treat 404 issues, it's best to find out 2 things:
- What URLs are attempting to be accessed?
- From where are those URLs being linked to?
This way you can either 301 redirect a page that is incorrectly being linked to from an outside website or fix a broken link on your own website.
How to do it:
It's super simple. In the header template of your 404 page, find this line in your Google Analytics Tracking Code:
Then change it as follows:
_gaq.push(['_trackPageview','/404error/?url=' + document.location.pathname + document.location.search + '&ref=' + document.referrer]);
What's happening here is we're creating a virtual pageview that starts with /404error/ (you can name it what you wish) and then appending 2 made-up parameters to help us spot the source of the problem:
- "url=" will catch the URL which a visitor attempted to access.
- "ref=" will catch the referring page.
Here's what it will look like in your reports (when you do a search for "404error"):
Just today, it helped me quickly identify 2 websites that were linking to pages that don't exist on our website. One is the NYTM.org "Made in NYC" page, which is incorrectly linking to our careers page. The others are a couple of blog posts purposefully linking to a 404'ing URL as they are mentioning our Pacman 404 page. Being the rankings-hungry SEO that I am, what I'll do is make that specific URL give a 200 status rather than a 404, turning it into a page that will benefit our search engine optimization efforts.
Obviously there are other ways of tracking 404 errors: Webmaster Tools, your log files, various site crawling tools, etc. but Google Analytics will reveal problems to you quickly and give you a sense of priority about what 404 issues you should be tackling immediately.