• GTM Courses
  • Blog
  • Services
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
  • About
    • About
    • Contact
  • GTM Courses
  • Blog
  • Services
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
  • About
    • About
    • Contact

April 9, 2017

How To Track 404 Errors With Google Analytics and Google Tag Manager

Let’s admit it – 404 errors suck. From both visitor’s and website owner’s perspective. As a website owner, you don’t want your visitors to appear in a dead end. It hurts your brand, your conversions, and in some cases your search engine optimization efforts. But that shouldn’t be a problem anymore, because in this blog post I’ll show you how to track 404 errors with Google Analytics + Google Tag Manager, and act accordingly (of course!).

 

The Premise

404 is an error message displayed by a browser indicating that an Internet address cannot be found.

Why is it bad? Mainly, it might hurt your conversions. Imagine that a person is looking for particular information and you have that topic covered on your website. But when he/she clicks the link – no luck.

In most cases that might result in a bounce or even worse – the visitor might jump over to your competitor’s website and (possibly) make a purchase there.

 

Just For Giggles

In fact, did not plan to post this example at all, but it’s too hilarious.

Anyway, I was looking for some blog post/guide to back my arguments about why 404 errors are important to monitor and why they might hurt your business. So I did a quick search and stumbled upon siteimprove.com blog post “What Broken Links Cost Your Business” in Google search.

Google search - 404 hurt conversions

Guess what? After I clicked the link, I got 404 error. Oh, the irony! What do broken links cost your business? I don’t know… a bounce, I guess.

siteimprove 404

A simple 301 redirect could have solved this issue.

 

 

What Should You Do?

There are two steps that need to be addressed:

  1. You need to monitor 404 errors (that’s my main focus in this blog post).
  2. You need to fix those broken links by redirecting people to a new destination URL (I’ll cover some general tactics and tools without diving deeper into details).

 

How Can You Track 404 Errors?

I’d like to point out several options:

  1. Track 404 errors with Google Search Console (GSC) offers a report of site errors (including 404s) that were spotted by Google’s crawlers. Joe Robinson at Moz has posted an in-depth guide how you can monitor and fix errors with GSC, I recommend reading it.
    However, there are some limitations: those errors are logged by the Googlebot crawler (not necessarily viewed by users), so you can’t see how it affects users’ overall sessions, and you can’t include it in your analytics reporting.
  2. Track 404 errors with Google Analytics behavior reports. Another option which also does not require any additional development is checking GA All Pages report. I’ll explain it in the further chapter of this blog post.
  3. Track 404 errors with Google Analytics events via Google Tag manager. Main focus of this blog post is dedicated to this option. Continue reading.

 

Track 404 Errors With Google Analytics – Without Additional Development

Is there a 404 page on your website? You can easily check that by adding some non-sense in the URL. For example, https://www.example.com/post/nonsense.

If you see a “Page not found” message, that’s a good start. Here’s mine:

Page not found

Next, check the title of that 404 page. Mine is Page not found – Analytics Mania.

Page not found tooltip

So all we need to do is to apply a custom filter to Behavior > Site Content > All Pages report in Google Analytics where we will see how many people (and how many times) have seen 404 error.

Open your Google Analytics account and head over to Behavior > Site Content > All Pages.

All pages report in Google Analytics

Now’ you’ll need to create an advanced filter which displays traffic only to those pages of which title contains “Page not found”.

  1. Add Page Title as a secondary dimension.
  2. Then click Advanced link next to the search field.
  3. Then choose rule Page title contains Page not found. Remember, your 404 error page might contain another title. I used “Page not found” as an example, because that’s a title of error page on my blog.

Custom filter in Google Analytics - Page not found

That’s it! Now you have a report of how many people ended up in 404 page, how many bounced of them, etc.

 

 

TRACK 404 ERRORS WITH GOOGLE ANALYTICS and GTM

Another way to approach this issue is to fire a Google Analytics event when a visitor encounters a 404 error. The most recommended way to fire “404” event is to utilize Google Tag Manager.

First, we’ll need to check whether a page view is actually a 404 error. Then we’ll trigger a Universal Analytics event and send the corresponding data to Google Analytics.

 

New Variable And Trigger

As I have previously mentioned, one of the easiest ways to distinguish a 404 page from a regular page in your analytics reports is page title.

I actually still cannot believe that this variable (Page title) isn’t among default variables in GTM. That’s why we need to create a user-defined variable in Google Tag Manager Page Title.

In order to do so, log in to your Google Tag Manager account, go to Variables and create a new one with the following settings:

  • Title – Javascript – Page Title
  • Type – Javascript
  • Global variable name – document.title

Javascript variable in Google Tag Manager

This variable will return a value of page title that a visitor is currently on.

After that, we should to create a trigger which fires when Page title contains “Page not found”. In your case the title might be different, so use what’s best suited for your website.

In your Google Tag Manager account, go to Triggers and create a trigger with the following settings:

Page not found trigger in Google Tag Manager

Important – this trigger is case sensitive. So if your 404 page title is Page Not Found, then Page not found trigger will not work because Not Found ≠ not found.

Or you can simply use this trigger condition instead:

Page not found regex condition in Google Tag Manager

 

Let’s send 404 Errors as Events to Google Analytics

In Google Tag Manager, go to Tags and create new tag:

  • Title – GA Event – 404 Error
  • Type – Universal Analytics
  • Enter Tracking ID (if you still don’t do it, I highly recommend adding Google Analytics Tracking ID as a constant variable. This will save you a lot of time and hassle in the long run).
  • Track Type – Event
  • Event Category – 404 error
  • Event Action – {{Page URL}}. Every time this even is fired, Google Tag Manager will dynamically fill in Page URL (full web address) as event action. This way you’ll see which URLs get the most 404 error hits.
    You can also use {{Page Path}} instead of {{Page URL}}, if you wish. If your web project spans across multiple domains and all data is visible in one Google Analytics account, then you should definitely stick with {{Page URL}} as event action.
  • No-interaction hit – true
  • Link previously created trigger Pageview – 404 Error to this Universal Analytics tag.

Hit Save, enable Preview & Debug mode and test whether the tag fires ONLY when it’s supposed to. If Preview and debug mode does not work for you, take a look at 10 ways to fix P&D mode in Google Tag Manager. If your newly created tag does not fire when it should, read this blog post – most common Google Tag Manager mistakes.

Leverage Google Analytics real-time reports: enter a gibberish URL that really does not exist on your website and open GA real-time Events report. If a 404 event appears there within seconds – you’re good to go!

Real time 404 event report

 

OK, Now What?

Once you’ve started tracking 404 errors with Google Analytics (or without), you can now earn more about how visitors interact with the website. Also, find out which pages are actually dead ends.

Usually 404 errors are “born” when page URLs change, e.g. you edited a web address in order to add relevant keywords for SEO. If that page was already indexed by Google, new visitors from search results will be redirected to the old address of a non-existing page.

So whenever you change the URL, ALWAYS create a 301 redirect (a.k.a. moved permanently) from old URL to a new one. If you’re using WordPress Plugin Redirection, you can easily do that right from your WP admin panel.

Also, this WP plugin automatically tracks 404 errors which you can turn into 301 redirects right away.

redirection wp plugin

Why 301 redirect is so important? Because Google honors this setting: it understands that resource X is not available anymore under the old URL and is now moved to another web address. This way the accumulated reputation is transferred from the old address to the new one.

 

Conclusion

In this blog post I have described two ways how you can track 404 errors with Google Analytics. The first option does not require any development – you can achieve the result just by using advanced search. The second one is to utilize Google Tag Manager and send 404 errors as events to Google Analytics.

These are not the only options available. I also briefly mentioned Google Search Console’s error reports (but those apply to Googlebot’s 404 errors rather than actual visitors).

Another options that was skipped in this blog post – asking a developer to fire a dataLayer event whenever a 404 error occurs (and then transfer that data with GTM to GA). But I ignored this option on purpose (this time), because I wanted to focus on possibilities that can be achieved without coding.

If you know more ways how to track 404 errors with Google Analytics (because there definitely are some), let me know in the comments!

 

 

Julius Fedorovicius
In Google Analytics Tips Google Tag Manager Tips
31 COMMENTS
Anonymous
  • Apr 15 2017
  • Reply

Hello,

In the above article perhaps by mistake you have written-
ALWAYS create a 302 redirect (a.k.a. moved permanently)

I am sorry, it should be 301 which means Permanent, and 302 means Temporary redirect.

Am I right?

    Julius Fedorovicius
    • Apr 16 2017
    • Reply

    Yes, you are right. This was totally my mistake. I meant 301 redirect. Thanks for pointing that out!

    This error is now fixed.

monah
  • Aug 25 2017
  • Reply

Hi
Thanks for this - I already set it up.
Is it possible to track also the referrer Domain?

And how?

Thanks a lot <3

    Julius Fedorovicius
    • Oct 1 2017
    • Reply

    Hey, sorry for the late reply. GTM offers a default variable called Referrer. You can add it to your Universal Analytics event tag.

Ricardo Godinho
  • Oct 3 2017
  • Reply

Hi,
Thank you,
It worked on a clean website
On full of analytics website or other wordpress theme, trigger didn't fire.

    Julius Fedorovicius
    • Oct 3 2017
    • Reply

    Hey, Could you give me more information about it? What's the website you're trying to track 404 errors on?

Wassim
  • Nov 21 2017
  • Reply

Thanks for the article but what about creating an entire filtered view just for 404 pages? That way you can see:
1) All 404 pages
2) Users who went on 404 pages
3) Countries who went on 404 pages
4) Devices on 404 pages
5) Sources on 404 pages
6) Bounce rates on 404 pages
7) Time on 404 pages
8) Browsers on 404 pages
and all the metrics just like tracking an entire website

Would you apply this method?

Thanks

    Julius Fed
    • Nov 22 2017
    • Reply

    Hey Wassim,

    I wouldn't do that. I'd create a Custom Google Analytics Segment, instead. It's much more flexible and empowers you to work with historical data. You can filter both users and sessions.

    Cheers

Wassim
  • Nov 23 2017
  • Reply

Hi Julius,

Thanks for the answer. I do have question though about your answer; How is a custom segment more flexible if an entire View can show you the same thing and also allow you to work with historic data? I am trying to make a decision on this before I go ahead.

Thank you

    Julius Fed
    • Nov 25 2017
    • Reply

    The entire view is limited only to certain pages. What happens if you make a mistake in configuration? The data will be missing or will be incorrect. Meanwhile, the segment allows you to filter/work with data which is already collected and you can slice it whatever you want. With segments, you can see how people who get a 404 convert, act on other pages, etc.

Dino Christou
  • Jun 7 2018
  • Reply

Hi Julius,

This is a great little article thank you.
I would like to know how to configure this slightly so that it works on link clicks instead of page views. By this I mean a user can be on your site and guess a page, get it wrong and get a 404. This is a user error and not page/content error. I think grabbing actual link 404 errors would work better based on link clicks.

Is this possible?

Many thanks
Dino

    Julius Fed
    • Jun 8 2018
    • Reply

    Hey, could you explain that in other words? I don't quite follow your logic.

      Dino Christou
      • Jun 8 2018
      • Reply

      Sorry my message wasn't very clear reading it back.

      A large percentage of our 404s are customers that tend to try 2nd guess a URL which results in a 404. I'm not bothered about these 404s as they are caused by user error/guessing.

      What I would like to do is only capture 404 errors when a user has clink on a link on our site and that click then resulted in a 404. This indicates that either the link is not correct or the resulting page is an actual 404.

      Does that make sense?

      Many thanks
      Dino

        Julius Fed
        • Jun 10 2018
        • Reply

        There's no need to do anything additional in the GTM. In Google Analytics, there is a dimension called Full Referrer.

        If a visitor landed on a 404 page by navigating from other page, "Full Referrer" will contain some value (the URL of the previous page)

        If a visitor enters an address manually in the address bar, Full Referrer will be equal to (not set).

Kacper
  • Sep 14 2018
  • Reply

Hey, should we use that event hit as Non-Interaction so we won't affect bounce rate and other stats?

    Julius Fedorovicius
    • Sep 14 2018
    • Reply

    Good catch. Yes, you should. I'll update the post as well.

James | Web Hosting Pakistan
  • Jan 10 2019
  • Reply

Thanks for explaining GA records - do you have any specific article that talks about 404 and other errors code handling via htaccess and in GA?

Laura Wheaton-Werle
  • Feb 14 2019
  • Reply

Hmm. Not sure what's happening. I set it up exactly as indicated, but the tag isn't firing. The tag fails at "_event equals gtm.js." Any idea what's going on? Has Google changed something since this article was published?

    Julius Fedorovicius
    • Feb 14 2019
    • Reply

    Hey,
    gtm.js means a simple "Page View" event in the preview and debug mode. Do you see the Page View event in the preview mode at all?

    If yes, share with me the link to your preview and debug mode and I'll take a look (of course, tell me which tag are you testing and on which page should I do that).

      Laura Wheaton-Werle
      • Feb 14 2019
      • Reply

      Well, dang! Today it's working. Go figure. Thanks!

Mike
  • Jul 22 2019
  • Reply

Can you also track 404 errors from outbound links to external sites?

    Julius Fedorovicius
    • Jul 22 2019
    • Reply

    Not with GTM (because you cannot place your GTM code there).

Sophie
  • Oct 13 2019
  • Reply

There are two types of 404 visitors: people who used broken linkes, and people who got to the mistaken pages on our site, and were redirected to 404 page. How can we find the referrer - for fixing the problem?

Niaz Ali
  • Nov 13 2019
  • Reply

Thanks and really informative article about the 404 errors of the website. I have an issue with website blog, google is crawling the blog URLs with duplication of /blog/blog in it. Which by default creating 404 Error for the blog posts URLs.The Actual URL of the Blog Post is with a single /blog in the URLs.

How i can tackle this issue to avoid the 404 errors problem within my Blog Posts URLs in the browser.

mehrdad
  • Jan 26 2020
  • Reply

great artcle.
one issue i have is that my page title is the same as other pages.
so can i see this via a http status or something?

mohammad
  • Sep 8 2020
  • Reply

Hi Julius,

A question is getting on my nerve.

As we know when the user sees page 404, it reports to us, so what is the difference between the two reports?
Why track 404 error with GTM "is more recommended" than GA?

    Julius Fedorovicius
    • Sep 8 2020
    • Reply

    What if the page title does not imply that there is 404 error?

      mohammad
      • Sep 8 2020
      • Reply

      So it doesnt track in GTM.
      The article said that Page title is considered as Variable. So if not so "page title does not imply that" GTM does not report that too. unless we set this tag with anothor variable.
      is it correct?

        Julius Fedorovicius
        • Sep 8 2020
        • Reply

        None of those options is superior. They are alternatives. If you want to see 404 errors as events, you will have to use GTM. If you are fine with pageview default data, then don't implement additional tracking via GTM.

        If the page title does not imply, you could ask a developer to push the 404 error data to the Data Layer and use that together with GTM.

        Many ways to tackle the situation.

          mohammad
          • Sep 8 2020

          yeah, its true. tnx for time.

Dinesh
  • Mar 4 2021
  • Reply

Hello Julius,

How to create a custom report in Google Analytics 4 to track 404 pages. It was easy to not found pages in Universal Analytics. Can you please help me?

Thanks

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *

 

Hi, I'm Julius Fedorovicius and I'm here to help you learn Google Tag Manager and Google Analytics. Join thousands of other digital marketers and digital analysts in this exciting journey. Read more
Essential resources


Popular articles
  • 🔥 GTM Form Tracking: 7 Effective Methods
  • 🔥 dataLayer.push: The Guide
  • 🔥 GTM vs Google Analytics
  • 🔥 99 Things You Can Do with GTM
  • 🔥 Common GTM Mistakes
  • 🔥 Data Layer: Ultimate Guide
  • 🔥 60+ Custom JavaScripts for GTM
Analytics Mania
  • Google Tag Manager Courses
  • Google Tag Manager Recipes
  • Google Tag Manager Resources
  • Google Tag Manager Community
  • Login to courses
Follow Analytics Mania
  • Subscribe to newsletter
  • RSS feed
Recent Posts
  • “Pages per Session” Conversion in Google Analytics 4
  • Scroll tracking with Google Analytics 4 and Google Tag Manager
  • How to Exclude Internal Traffic in Google Analytics 4
Analytics Mania - Google Tag Manager and Google Analytics Blog | Privacy Policy
Manage Cookie Settings