Track 404 Errors on your Website with Google Analytics

Published in: 404 - Google Analytics - WordPress

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.”

📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: 404 - Google Analytics - WordPress

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

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. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube