It all began with a server migration and improving the way 404s were rendered. While poking around the Web, I happened across a promising Google Analytics tip on tracking these evasive creatures. So I captured the code, pasted it in, and a day later looked at the results.
Nada. I then looked at the code more closely and realized it was the old format, which one usually puts in the footer. No problem. But a day later still nothing.
More scrambling…. and somewhere along the way, buried in a forum as I recall, I found some code that looked right. Jackpot. Now when I check our Google Analytics Top Content and enter /404.html in the page filter at the bottom I get a lovely tidy list of 404s, including their source.
To save others who might be on the same quest, here’s the code to use in your 404 html pages. Just replace “UA-xxxxxxx-x” with your account number. Then get out your virtual feather duster and start cleaning out those cobwebs.
var _gaq = _gaq || ;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script'); s.parentNode.insertBefore(ga, s);