
August 1, 2022
How to Track and View 404 Errors with Google Analytics 4
If someone on your website lands on a page that does not exist, that someone gets a 404 error. 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 4.
If one method (explained in this article) does not work, I will show you a workaround that also includes Google Tag Manager.
Table of contents
+ Show table of contents +
Video tutorial
If you prefer video content, here’s a tutorial from my Youtube channel.
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.
For the giggles
In fact, did not plan to post this example at all, but it’s too hilarious.
Anyway, in 2017, I was looking for some blog post/guide to back up 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 the siteimprove.com blog post “What Broken Links Cost Your Business” in Google search.
Guess what? After I clicked the link, I got a 404 error. Oh, the irony! What do broken links cost your business? I don’t know… a bounce, I guess.
A simple 301 redirect could have solved this issue.
What Should You Do?
There are two steps that need to be addressed:
- You need to monitor 404 errors (that’s my main focus in this blog post).
- 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?
In this blog post, I will cover two options:
- Track 404 errors with Google Analytics 4 engagement reports. An option that does not require additional development. I’ll explain it in the further chapter of this blog post.
- Track 404 errors with Google Analytics 4 events via Google Tag manager. You will also learn this option here.
Track 404 Errors With Google Analytics 4 Engagement Reports
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 (or some other warning on a screen), that’s a good start. Next, check the title of that 404 page. Mine is Page not found – Analytics Mania.
If your 404 page’s title lets you distinguish that this is not just some regular page (but it says something about the page being not found), then this method will work for you. Continue reading.
If the title of your “Page not found” page is too generic (or maybe it’s just the same as your homepage), then the method I will show to you will not work. Jump to another chapter of this blog post where I explain a workaround with Google Tag Manager.
Anyway, let’s go back to the main topic of this chapter. Log in to your Google Analytics 4 property and go to Reports > Engagement > Pages.
Then make sure that the main dimension (selected in the report) contains “Page title”.
In the search field (above the table), enter the title (or a part of it) of the 404 page. In my case, the full title was “Page not found – Analytics Mania”, so it was enough to enter just “Page not found”. Then hit “ENTER” on your keyboard.
Ideally, you should see one row in the report. That is your “Page not found” page where people land once they visit some broken link.
In that table, you will also see metrics such as Views (the number of times the page was loaded), Sessions, etc. But this is not helpful yet. We don’t know what where the URLs of those 404 errors.
To see that, click the plus icon in the report (to add the secondary dimension).
Then select Page path dimension (it is available in the Page/screen section). The final report will look like this.
To see the full Page Path (which is a part of the URL), hover your mouse on it (in the report).
And that’s it! Now you know how to view the Page not found errors in Google Analytics 4 without any custom coding or configuration in Google Tag Manager.
However, on some websites, page titles of 404 errors are not descriptive, and this method does not work. That’s where we could use Google Tag Manager.
Track 404 errors with Google Analytics 4 and Google Tag Manager
Another way to approach this issue is to fire a Google Analytics 4 event when a visitor encounters a 404 error. In this chapter, we will have to cooperate a bit with developers. There are more advanced options where you could scrape the site (I show some examples in this course), but working with a developer is the most robust option.
Data Layer
When a visitor gets a 404 error, ask a developer to push that event to the Data Layer. We will later use that in your Google Tag Manager’s setup.
A sample code could look like this:
window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event' : 'page not found' });
When a developer implements this code, open Google Tag Manager’s preview mode by clicking the Preview button in the GTM interface, then enter the URL of any 404 page, and click connect.
When the preview mode fully loads, keep looking for the “page not found” event on the left side of the preview mode.
If you see the event, that’s good. If you don’t, then the developer did something wrong. He/she should double-check his/her code.
A trigger
Once the “page not found” event is in the data layer, it’s time to create a custom event trigger in Google Tag Manager. Basically, we will tell GTM to send an event to GA4 if there is a “page not found” in the data layer.
Go to Triggers > New > Custom Event and create a trigger with the following configuration:
Save it.
Create a Google Analytics 4 event tag
In this tutorial, I presume that you already have at least very basic understanding of how to install Google Analytics 4 on a website. If not, then read this tutorial.
At this point, you should already have a Google Analytics 4 configuration tag in your Google Tag Manager container. We will use it soon in the GA4 event tag.
In Google Tag Manager, go to Tags > New > GA4 event.
Then select your existing GA4 configuration tag (1) and enter a name for this event (that clearly describes it), for example, 404_error (2), page_not_found, or something else. Don’t send “error” though, because this name is reserved by GA4.
In the Triggering section of the tag, click anywhere and then select the Custom event trigger you previously created.
We did not add any additional parameters/settings in this tag because the GA4 event automatically tracks the Page URL where the error occurred, and that’s pretty much all we need.
Let’s test
Once you have created the custom event trigger and a GA4 event tag, click the Preview button in the top right corner of the GTM interface.
Enter the URL of the 404 page and click connect. Then check if the page not found event appeared on the left side of the GTM preview mode. Click it and check if the GA4 event tag fired.
If the tag fired, go to Google Analytics 4 > Configure > DebugView and check if you see the event there.
If the DebugView is not working, check this article.
If everything works fine, publish your changes in Google Tag Manager by clicking the Submit button in the top right corner.
Build a report
If you just implemented and published 404 error tracking in Google Analytics 4, you will have to wait for up to 48 hours to see the data.
Once that time has passed, go to Google Analytics 4 > Explorations > Blank.
Then click a Plus in the “Dimensions” section and select the following dimensions:
- Event name
- Page Path and screen name
In the Metrics section, add the Event Count metric.
Then double-click those two dimensions and one metric (to add them to the report).
Finally, in the Filters section, add the following filter: event name exactly matches 404_error. If the name of your event is different, then enter that one.
Once you have added dimensions, a metric, and a filter, a report will look like this (obviously, the values will be different).
OK, Now What?
Once you’ve started tracking 404 errors with Google Analytics (or without), you can now learn more about how visitors interact with the website. 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 would 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 the 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.
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.
Want to see what was the URL of the previous page that led the visitor to the current 404 page? Watch this tutorial (there is a section where I teach how to work with a referrer).
Track 404 errors with Google Analytics 4: Final words
In this blog post, I described two ways how you can track 404 errors with Google Analytics 4. The first option does not require any development – you can achieve the result just by using standard reports. The second one is to utilize Google Tag Manager and send 404 errors as events to Google Analytics 4.
41 COMMENTS
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?
Yes, you are right. This was totally my mistake. I meant 301 redirect. Thanks for pointing that out!
This error is now fixed.
Hi
Thanks for this - I already set it up.
Is it possible to track also the referrer Domain?
And how?
Thanks a lot <3
Hey, sorry for the late reply. GTM offers a default variable called Referrer. You can add it to your Universal Analytics event tag.
Hi,
Thank you,
It worked on a clean website
On full of analytics website or other wordpress theme, trigger didn't fire.
Hey, Could you give me more information about it? What's the website you're trying to track 404 errors on?
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
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
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
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.
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
Hey, could you explain that in other words? I don't quite follow your logic.
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
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).
Hey, should we use that event hit as Non-Interaction so we won't affect bounce rate and other stats?
Good catch. Yes, you should. I'll update the post as well.
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?
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?
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).
Well, dang! Today it's working. Go figure. Thanks!
Can you also track 404 errors from outbound links to external sites?
Not with GTM (because you cannot place your GTM code there).
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?
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.
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?
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?
What if the page title does not imply that there is 404 error?
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?
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.
yeah, its true. tnx for time.
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
Hi Julius,
Thanks for this helpful tutorial. Do you have any instructions about how to do it on GA4?
No, but just send the event to GA4 (with any event name) when the error is tracked on a page. Event tracking tutorial: https://www.analyticsmania.com/post/how-to-track-events-with-google-analytics-4-and-google-tag-manager/
Tkx!
Can you say how you would adapt this approach for an SPA built by Gatsby? Missing paths don't generate a fetch to the back end.
Ask a developer to push the 404 error to the data layer and then take that data from there.
Hi Julius, I'm facing the same issue, but when I filter the page title by Page not found, there is no data for this view. Is there any solution for this type of situation? Thanks.
Very usefull, thank you very much ;_
New question here... I have followed these instructions however it isfiring on all pages, not just the page not found ones.
I have a suspect page that is turning up a significant amount of page not found errors and it is not my page. I just need to find out where it is referring from.
Then you need to make your trigger more precise so that it would fire only on the 404 page
What about getting alerts / notifications if 404s?
In UA I solved this by creating a segment for those visiting 404 pages, then setting a daily alert. The insight feature in GA4 doesn't seem to allow me that. Any other ideas?