9 November 2026 · 9 min read

404 tracking in GA4: finding broken links before visitors do

A customer clicks a link in an email you sent two years ago, lands on a page that no longer exists, and leaves. Nothing in your reports marks that visit as a failure. The session looks like any other short visit, and the dead link keeps collecting traffic until somebody complains.

GA4 can catch this. It does not do it out of the box, and the reason is structural rather than a setting somebody forgot to switch on. Understanding that reason tells you which of the available signals you actually need, and which ones will lie to you.

Why the status code never reaches your tag

When a visitor requests a missing page, the server answers with a 404 status and still returns a page. That page carries your GTM container and your GA4 tag, so a page_view is sent with the URL of the page that does not exist. The view is real. What is missing is any statement that the response failed.

JavaScript cannot read the HTTP status of the document it runs inside. There is no property on document that carries it. The tag knows the URL, the referrer and the title, and it has no way to learn whether the server answered 200 or 404. Google's enhanced measurement does not close the gap either. The automatic events it offers are page views, scrolls, outbound clicks, site search, video engagement, file downloads and form interactions. There is no error event in that list, and the page view it collects carries page_location and page_referrer only.

So the signal is already in your data, unlabelled. Every 404 sits in Reports, then Engagement, then Pages and screens, as a page path with a view count, next to the pages that work.

Four signals, four different questions

Before adding anything, decide which question you are answering. These four sources overlap without being interchangeable.

Naming the event in the error template

The most reliable approach is one small script in your 404 template, placed after the GTM container snippet so the dataLayer already exists.

<script>
  window.dataLayer = window.dataLayer || [];
  window.dataLayer.push({
    event: 'page_not_found',
    broken_path: window.location.pathname,
    broken_url: window.location.href,
    referring_page: document.referrer || '(direct)'
  });
</script>

Do not name the event 404. Event names must start with a letter, hyphens and spaces are not allowed, and a leading digit is rejected at collection. page_not_found also tells a reader what happened, which a bare number never will.

In GTM, create a Custom Event trigger on page_not_found, then a GA4 event tag that fires on it and passes the three parameters through. Register broken_path as an event-scoped custom dimension under Admin, then Custom definitions. Allow 24 to 48 hours before it appears in reports.

Three limits are worth knowing before you add more parameters. An event name and a parameter name are capped at 40 characters, a parameter value at 100, and one event carries at most 25 parameters. A standard property allows 50 event-scoped custom dimensions, a 360 property allows 125. Long URLs survive because page_location is a standard parameter with a 1,000 character allowance, which is one more reason to send the path on its own and let the standard fields carry the full address.

Keep this event out of your key events. It measures a defect, and counting it as a conversion inflates every funnel that includes it.

When you cannot edit the error page

Some platforms give you no template access. The fallback is a Page View trigger in GTM filtered on Page Path contains /404, or Page Title contains not found. Both filters fail in the same ways. A localised site says something else in the title, a custom error template uses a different path, and a working page whose slug happens to contain 404 will match. Treat the filter as a way to get visibility this week, and treat every false positive it produces as the reason to move to the template push.

Soft 404s are the ones that cost money

Google's Search Console documentation defines a soft 404 as a page that returns a user-friendly not found message without returning a 404 status code. The guidance that follows is to return a 404 for pages that are genuinely gone, and to put enough information on the page that it does not read as a soft 404.

These hide twice. A visitor gets a dead end that looks like a page. Your analytics records a healthy page view with normal engagement, so every dashboard built on page views says the site is fine. Search Console surfaces them in the Page indexing report under a soft 404 reason, which is often the first place anyone notices.

One command tells you which case you have:

curl -I https://example.com/old-page

The status line is the answer. If it says 200 while the body says the page cannot be found, the page is broken and every tool that reads status codes believes otherwise. Run it against the top URLs in your broken list rather than trusting the template to behave.

Fix the link, not only the URL

Google's guidance in the Page indexing report is narrower than most cleanup projects assume. Fix only the 404s you link to yourself or list in a sitemap, and where a page has moved, return a 3XX redirect to the new page.

That rule points at the part of the job most site owners skip. A 404 is usually a symptom. The cause is an internal link pointing at a URL that changed, a stale sitemap entry, a campaign link built on last year's slug, or a redirect chain that ends nowhere. The referrer on your new event gives you the page to open and fix.

Routing by case:

The home page redirect deserves its own line, because it is the standard shortcut and it makes things worse. It creates a soft 404 at scale, it tells search engines that dozens of unrelated URLs now share one destination, and it leaves the visitor on a page that does not answer what they asked for.

What the counts should look like

Volume by itself means little. A site with 40,000 pages will always return some 404s from old inbound links that nobody controls. What matters is where they come from.

A steady trickle from external referrers is housekeeping. A step change the day after a deploy is a release problem, and the list will name the slugs that broke. A single broken path with hundreds of hits and an internal referrer is a link on a high traffic page that has been dead for weeks.

Two views make the list actionable. Sort by event count to find what hurts now. Group by referring page to find what will keep hurting, because one bad link in a navigation menu generates 404s on every page view.

A routine that takes twenty minutes a week

  1. Confirm the event fires. Open a URL you know does not exist, check Preview mode for page_not_found, then check Realtime in GA4.
  2. Open the broken_path dimension for the last seven days, sorted by event count.
  3. Fix the top three. Read the referrer first, because the fix is usually on that page.
  4. Redirect the moved pages that still earn links. Leave the genuinely dead ones dead.
  5. Once a month, open Search Console, then Page indexing, then the 404 reason. It catches crawler 404s from the past month, including URLs no visitor has reported.
  6. After any deploy that changes URL structure, repeat step one before the traffic arrives.

What this does not catch

Consent changes the picture. If your setup blocks analytics tags until a visitor accepts, the 404 event is not sent for anyone who declines, so the count understates the problem. Server-side collection moves the measurement out of the browser and is the usual answer where that gap matters. Ad blockers and bot filtering remove another slice.

None of that makes the client-side event useless. It makes it a floor rather than a total. A path with 200 recorded 404 hits has more, and the ranking of paths barely moves.

One limit is worth stating to anyone who asks for the dashboard. This measures pages people reached, not pages that exist. A broken link on an orphan page with no traffic stays invisible here and turns up in a crawl instead, which is why the Search Console list stays in the routine rather than being replaced by it.

The bigger point is that a 404 costs more than a lost visit. It is a dead end delivered to somebody who was interested enough to click. Catching it in a weekly list turns an invisible leak into a twenty minute fix, and the event that makes it visible is about ten lines of code.

Not sure what your 404s are costing? Book a free tracking audit and we will check the error tracking, the redirects and the links that send people to dead pages.