How To Find 404 Errors and Broken Links in Google Analytics

How to Track 404 Errors in Google Analytics

This article was updated on 9/27/12.

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 + + '&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"):

Tracking 404 errors in your Google Analytics

Just today, it helped me quickly identify 2 websites that were linking to pages that don't exist on our website. One is the "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.

Search Engine Optimization Whitepaper

Share this post

Comments on this post

  1. For some reason, I’m not capturing the Referring page. Any help would be apprecaited.


  2. Alhan Keser said:

    Hi S Eakins, please send the URL of your 404 page and I’ll see if I can help.

  3. Pingback: Website redesign Google Analytics segítségével

  4. Pingback: The Nerdiest Way to Get a Company’s Attention | Mr Ryan Connors Blog

  5. Great tip, thanks! Question though: does this affect any other pageview tracking or simply make this provision for tracking 404s? Nothing else is negatively affected by applying this tweak, correct?


  6. Pingback: Make the Best of It: Optimizing Your 404 Page - Testomato Blog

  7. 404 in GA? Nice tip thx!

Comment on this post


Ready to discuss your project? Work With Us
Blue Fountain Media is recognized as a
Top Digital Agency by
Ranked #1 Interactive
Agency by top interactive agencies example
Ranked Top 10 Digital
Agency by awwwards logo
Ranked Top 10 Agency
Worldwide by IMA logo
Our Locations
New York Headquarters
New York Headquarters
102 Madison Avenue - Second Floor
New York, NY 10016
Chicago Office
Chicago Office
222 Merchandise Mart Plaza, Suite 1212
Chicago, IL 60654
Seattle Office
Seattle Office
14980 NE 31st Way, Suite 120
Redmond, WA 98052