Data & monitoring

Finding 404 errors with Google Analytics 4

How to set up GA4 so you can see which URLs lead nowhere and which link brought visitors there.

GA4 · ExplorationPage title contains “404”Page pathPage referrerViews/old-table/garden-furniture312/sale-2024/newsletter87/contact.html/imprint23
Michael WeberFirst published: August 18, 2018Last updated: November 4, 202611 min read
In short
  • GA4 only shows 404 errors if your 404 page is served at the requested URL with status 404 and loads the GA4 tag.
  • The easiest way is to filter by the page title of your 404 page. If it has no unique title, you send a custom page_not_found event.
  • The “Page referrer” dimension separates broken internal links from broken links on other websites.
  • GA4 only sees what visitors open. Search Console shows what Googlebot finds, and a crawl finds every broken link.

A 404 error costs you visitors who had already arrived. They came via a link, a search or a bookmark and land on a page that does not exist. Google Analytics 4 has no ready-made report for this. With a few settings you can still see which URLs lead nowhere, how often it happens and which link brought visitors there.

This guide applies to GA4. Standard Universal Analytics properties have not processed any data since 1 July 2023. Older guides with “Custom Reports” or “Views” therefore no longer help. In GA4 the tool for this is called “Explore”.

How to find, assess and fix 404 errors in general is covered in the guide Finding and fixing 404 errors.

What the 404 page needs for GA4

You do not need a custom report for the analysis in GA4. The data sits in the standard page_view event or in a custom event, and an exploration filters out the 404 pages. Before that, the error page has to meet four conditions. They also matter for SEO.

  1. The error page appears at the requested URL and does not redirect to /404/.
  2. The server sends status 404. A status 200 leads to soft 404 errors in Search Console. You can check the status with curl -I or the HTTP Status Code Checker.
  3. The GA4 tag is also included on the error page. Many systems use a separate template without tracking code for the error page.
  4. The page title contains a unique word, such as “404” or “Page not found”.

If your website redirects unknown URLs to /404/ or /error/, GA4 only shows that one address. Which URL the visitor actually requested is lost.

Method 1 via the page title

This is the simplest way, and it needs no extra code. GA4 stores the page title with every page view. If all error pages carry the same word in the title, you filter by it in the exploration. For a quick look, the standard “Pages and screens” report with the “Page title” dimension is enough. Which URLs and links are behind it only shows up in an exploration of your own, see Exploration for internal 404 errors.

Method 2 with a custom event

If the error page has no unique title or you cannot change it, the error page sends a custom event called page_not_found. You can do this with Google Tag Manager or directly with gtag.js. Event names must start with a letter, so a name like 404_error does not work.

With Google Tag Manager

In Tag Manager you first need a trigger that only fires on the error page. There are two common ways.

  • Via the data layer. Your CMS writes a value such as pageType: '404' to the dataLayer on the error page before the Tag Manager code loads. You create a variable of the type “Data Layer Variable” named pageType. The trigger of the type “Page View” fires on “Some Page Views” when pageType equals 404.
  • Via an element on the page. You create a variable of the type “DOM Element” that reads, for example, the text of the H1 via a CSS selector. The trigger of the type “DOM Ready” fires when the variable contains “Page not found”. Only at that point can the HTML be read completely.

Then create the event tag under “Tags” with “New” and connect it to this trigger. The built-in variables Page URL, Referrer and Page Path are usually already active in new containers. If they are missing, enable them under “Variables” in the built-in variables with “Configure”.

SettingValue
Tag typeGoogle Analytics: GA4 Event
Measurement IDYour GA4 measurement ID, for example G-XXXXXXXXXX
Event namepage_not_found
Event parameter page_location{{Page URL}}
Event parameter page_referrer{{Referrer}}
Event parameter requested_path{{Page Path}}
TriggerYour 404 trigger from the previous step

Older guides mention a “Configuration Tag” field in the event tag. In the current Tag Manager help, this is where you enter the measurement ID directly.

Method 2 without Tag Manager

If your website uses gtag.js without Tag Manager, add the following code to the error page template. It belongs below the Google tag snippet. Google does not process events placed above it. The three detection variants are combined with “or”. Keep the one that fits your error page and adjust the class, text or value.

// Add to the error page template, below the Google tag snippet. // The three variants are combined with "or". Keep the one that fits. function isErrorPage() { // Variant 1: an element or class that only exists on the 404 page if (document.querySelector('.error-404') || document.body.classList.contains('page-404')) { return true; } // Variant 2: a text that only appears on the 404 page if (document.body.innerText.indexOf('Page not found') !== -1) { return true; } // Variant 3: a value your CMS writes to the dataLayer return Array.isArray(window.dataLayer) && window.dataLayer.some(function (entry) { return entry && entry.pageType === '404'; }); } function reportErrorPage() { if (!isErrorPage()) { return; } gtag('event', 'page_not_found', { page_location: window.location.href, page_referrer: document.referrer, requested_path: window.location.pathname }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', reportErrorPage); } else { reportErrorPage(); }

The code waits until the page has loaded and only sends the event on the error page. requested_path contains the path without domain and without parameters. This makes it easy to group the same error across several domains.

Registering a custom dimension

GA4 already knows page_location and page_referrer as the dimensions “Page location” and “Page referrer”. You only see your own requested_path parameter in reports once you register it. For this you need the Editor or Administrator role in the property.

  1. Open “Admin” at the bottom left in GA4.
  2. Under “Data display”, choose “Custom definitions”.
  3. In the “Custom dimensions” tab, click “Create custom dimension”.
  4. Enter a dimension name such as “Requested path”. Choose “Event” as the scope and enter requested_path as the event parameter.
  5. Save the dimension. Scope and event parameter cannot be changed afterwards.

According to Google’s help, you can use the new dimension in reports 24 to 48 hours after creating it. Older data stays empty for it.

How long does GA4 keep your data?

Explorations only access data within the configured retention period. In standard properties that is 2 or 14 months. If the property is set to 2 months, you will not see older 404 errors in the following explorations. You find the setting in Admin under “Data retention”. A longer retention period does not bring back data that has already been deleted.

Exploration for internal 404 errors

This exploration shows broken links on your own website. They are entirely in your hands and should be fixed first.

  1. Click “Explore” on the left and create a new blank exploration. The “Free form” technique is preselected.
  2. In the “Variables” panel, click the plus next to “Dimensions”. For method 1, import “Page path and screen class”, “Page referrer” and “Page title”. For method 2, import “Event name”, “Page location” and “Page referrer”.
  3. Next to “Metrics”, import “Views” for method 1 and “Event count” for method 2.
  4. Drag the dimensions into “Rows” and the metric into “Values”. For method 2, leave the event name out, it is only needed for filtering.
  5. Under “Filters”, add two conditions. For method 1 the page title contains “404”, for method 2 the event name exactly matches page_not_found. As the second condition, the page referrer contains your domain, for example example.com.

Filters are case-sensitive, and all filters must apply at the same time. If the title says “Page not found”, write the filter value exactly like that.

Internal 404sMethod 1 · page titleMethod 2 · custom event
TechniqueFree formFree form
RowsPage path and screen class, Page referrer, Page titlePage location, Page referrer
ValuesViewsEvent count
Filter 1Page title contains “404”Event name exactly matches “page_not_found”
Filter 2Page referrer contains “example.com”Page referrer contains “example.com”

Exploration for external 404 errors

This exploration shows 404 errors that come from links on other websites. You cannot change the link itself. You can still catch the visitors with a redirect.

  1. Duplicate the exploration for internal 404 errors or create a new one as described above.
  2. Also import the dimension “Session source / medium” and drag it into “Rows”. It shows whether the visit came from search, from social networks or from a referring website.
  3. Change the condition of the page referrer filter to “does not contain”.

This list also includes visits without a referrer, for example from bookmarks, apps or typed-in addresses. For these, the page referrer field is empty.

External 404sMethod 1 · page titleMethod 2 · custom event
TechniqueFree formFree form
RowsPage path and screen class, Page referrer, Page title, Session source / mediumPage location, Page referrer, Session source / medium
ValuesViewsEvent count
Filter 1Page title contains “404”Event name exactly matches “page_not_found”
Filter 2Page referrer does not contain “example.com”Page referrer does not contain “example.com”

How to read the results

  • Page path and screen class or Page location shows the URL that responded with 404.
  • Page referrer shows the page the link is on.
  • Views or Event count shows how often visitors ran into the error. Start at the top.

The page referrer often shows only a domain without a path. That is down to the browser. Unless the linking website specifies otherwise, browsers only pass on the origin, meaning protocol and domain, for links to another domain. For search engines you therefore almost always see just the domain name. The rows with a full URL help you most, because there you know where the link is.

GA4 only sees what visitors open. 404 errors that only Googlebot finds are in Search Console, see Crawl errors in Search Console.

GA4 dimensions at a glance

What you are looking forGA4 dimensionMethod
The URL with 404Page path and screen class1
The full URL with 404Page location2
Where the visitor came fromPage referrerboth
Page title for filteringPage title1
Event for filteringEvent name2
Requested pathRequested path, custom2
Traffic sourceSession source / mediumboth
Domain, if one property measures several websitesHostnameboth

Fixing 404 errors from GA4

Broken internal links

  • Fix the link at the source. The “Page referrer” column tells you which page the link is on. Change it there to the right URL.
  • Add a redirect as well. A 301 redirect from the wrong to the right URL helps everyone who has already saved the old link.
  • Do not rely on redirects for good. Internal links to redirects cost crawl time and loading time. Always fix the link itself too.

Broken external links

  • Redirect with a 301. Redirect the broken URL to the page with matching content. Visitors arrive, and the link keeps working. How to set up and test redirects properly is covered in the guide Testing redirects.
  • Ask about important links. If the link comes from a page with many visitors, a short email to the site owner is worth it.
  • Also check Search Console. GA4 only knows errors that visitors ran into. What Googlebot finds is in Search Console, see Crawl errors in Search Console.

What GA4 does not see about 404 errors

  • Real visits only. GA4 only counts views by people who allow tracking. Broken links nobody has followed yet and errors only Googlebot sees are missing.
  • Consent. Visitors who do not consent to tracking appear either not at all or only as modeled data, depending on the consent mode. The figures are therefore more of a lower bound.
  • Bots and spam. Some views come from bots trying out URLs, such as /wp-login.php. You can ignore those rows.
  • Outgoing links. GA4 cannot check whether links from your website to other websites lead nowhere. That requires fetching the link target and reading the status code, which is what a crawler does.

A regular crawl of the whole website gives you a complete overview of all internal and outgoing links. How to assess the results from GA4, Search Console and the crawl together is covered in the guide Finding and fixing 404 errors.

Frequently asked questions

Why does GA4 not show any 404 errors?

Usually the GA4 tag is missing on the 404 page, or the error page has no unique title. Also check that the error page appears at the requested URL and does not redirect to a catch-all page. In explorations, the data retention setting also limits the time range.

Why do I see different 404 errors in Search Console than in GA4?

Search Console shows URLs that Googlebot fetched. GA4 shows URLs that visitors opened. The two lists only partly overlap, so it is worth looking at both.

How do I find out which links on my 404 page get clicked?

Create a trigger in Tag Manager for clicks on links within the 404 page and send them to GA4 as an event. This shows you which suggestions on the error page help.

Can I find broken outgoing links with GA4 or Tag Manager?

No. That would require fetching the link target and checking the status code. A crawler that also checks outgoing links does this, for example as a regularly scheduled crawl.

Some URLs from the report work after all. Why?

Some URLs only return a 404 temporarily, for example during a deployment or because of a cache error. Check the URL with curl -I. If the error keeps coming back, look at the server logs.

What do I do with 404 errors after a website migration?

Set up 301 redirects from the old URLs to the matching new ones. This is still worth doing when the migration was a while ago. More on this in the website migration checklist.

searchVIU crawls your whole website every week and checks your most important pages continuously throughout the day with Page Watch. searchVIU reports new 404 errors on important pages by email, Slack, Teams or webhook, with suggestions for the redirect target.

Request a demo

Sources

Retrieved on November 4, 2026. If something is out of date or missing, let us know.

  1. Google Analytics Help, Explorations: https://support.google.com/analytics/answer/7579450?hl=en · retrieved November 2, 2026
  2. Google Analytics Help, Segments and filters in explorations: https://support.google.com/analytics/answer/9328518?hl=en · retrieved November 2, 2026
  3. Google Analytics Help, Event-scoped custom dimensions: https://support.google.com/analytics/answer/14239696?hl=en · retrieved November 2, 2026
  4. Google Analytics Help, Dimensions and metrics: https://support.google.com/analytics/answer/9143382?hl=en · retrieved November 2, 2026
  5. Google Analytics Help, Event naming rules: https://support.google.com/analytics/answer/13316687?hl=en · retrieved November 2, 2026
  6. Tag Manager Help, Set up GA4 events: https://support.google.com/tagmanager/answer/13034206?hl=en · retrieved November 2, 2026
  7. Tag Manager Help, Built-in variables: https://support.google.com/tagmanager/answer/7182738?hl=en · retrieved November 2, 2026
  8. Tag Manager Help, User-defined variables for web: https://support.google.com/tagmanager/answer/7683362?hl=en · retrieved November 2, 2026
  9. Tag Manager Help, Page view trigger: https://support.google.com/tagmanager/answer/7679319?hl=en · retrieved November 2, 2026
  10. Google Tag Platform, gtag.js reference: https://developers.google.com/tag-platform/gtagjs/reference · retrieved November 2, 2026
  11. MDN, Referrer-Policy: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Referrer-Policy · updated September 4, 2026, retrieved November 2, 2026
  12. Google Analytics Help, Data retention: https://support.google.com/analytics/answer/7667196?hl=en · retrieved November 4, 2026
  13. Google Analytics Help, Universal Analytics is going away: https://support.google.com/analytics/answer/11583528?hl=en · retrieved November 4, 2026