Consolidating Your 404s in Google Analytics

by Chadwick Wood
November 23rd, 2006

Here's a bit of Javascript you can use on your website's 404 page so that when you look at your stats in Google Analytics, all the missing pages that your visitors tried to visit are grouped into one place. This technique can be useful as it gives you a single place to look in your stats for any bad URLs that people visit often, perhaps as the result of a mistyped link, or a deleted page. For this example, let's say your website is at www.mysite.com, and your website's Analytics account number is UA-555555-5. In place of the usual code snippet for Google Analytics, you would put the following on your 404 page, in its place:



The idea is to record every visit to a missing page as the address of the missing page, but prepended with a folder name. Once you do this, in Google Analytics you can view "Content Drilldown" (Content Optimization -> Content Performance -> Content Drilldown) and you'll see a folder with the name "notfound". Inside that folder will be all of the missing pages that your visitors looked for.

For more information on 404 pages and how to make them very nice, there's a great article at A List Apart.