Track 404 Errors on your Website with Google Analytics

If you change the URL of an existing page on your website, or delete it completely, visitors will get a 404 or “File Not Found” error when they try to access that page. The other reason why you have end up having 404 pages on your site is not in your control. Say your page URL is and another site links to that page but with a wrong URL, visitors will get a 404 when they click that link.

It is important that you fix your 404 errors are they offer a bad visitor experience and your site may also lose Google juice. Google gives you points for every incoming link but the benefit is lost if that link is pointing to a non-existent 404 page.

Track the Missing 404 Pages on your Site

If you are using Google Analytics, which you most likely are, you can use the same service to easily keep a track of all the 404 missing pages on your website. Let me show you how:

Google Analytics for 404 Errors

You take your standard Analytics tracking code, the one that is already on your web pages, and add a few extra lines inside the script tag that will enable tracking for 404s. The modified code will generate a virtual pageview in your Analytics reports (see the above screenshot) that will not only provide you with the URL of the missing page on your website but also the URL of the referring site.


  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  /* Standard Analytics Code */
  ga('create', 'UA-XXXXX-YY', '');
  ga('send', 'pageview');

  /* Track 404 Errors */
  var url = "/404/?url=" + window.location.pathname + + "&from=" + document.referrer;
  ga('send', 'pageview', url);


Please note that this code should only be added to your 404 template and not every page.

To get a report of all the 404 pages on your site, go to your Google Analytics dashboard and choose Behaviour -> Site Content -> All Pages. Here select any date range and put /404 in the search box and you’ll know what’s missing from your site.

Also, since Google Analytics now offer near real time tracking, you’ll know about the 404 pages on your website as they happen.

Find 404 Pages in Webmaster Tools

If you are not using Google Analytics, or if you do not have to option to modify the code in your web pages, you can use Google Webmaster tools to find the 404 pages on your website. Once you have added and verified your site with the Google Webmaster panel, go to Dashboard –> Diagnostics –> Crawl Errors and select the “Not found” option.

404 - Google Report

Here you’ll see a list of all pages that returned a 404 status code to Google while it was trying to index your site. The tool may not catch every single missing page of your site but, as Matt Cutts remarked, “the vast majority of the backlinks you’d care about, at least as far as Google is concerned.”

Amit Agarwal

Amit Agarwal

Google Developer Expert, Google Cloud Champion

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.

Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory


Awards & Titles

Digital Inspiration has won several awards since it's launch in 2004.

Google Developer Expert

Google Developer Expert

Google awarded us the Google Developer Expert award recogizing our work in Google Workspace.

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards in 2017.

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional (MVP) title for 5 years in a row.

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator title recognizing our technical skill and expertise.

Email Newsletter

Sign up for our email newsletter to stay up to date.

We will never send any spam emails. Promise.