search

How to Find Where Your 404 Errors Come From in Google Analytics

Google Analytics will happily show you a pile of 404 hits, but it answers the wrong question. It tells you which URL failed, not how anyone reached a broken address. That second question is the one that matters, because it decides whether you fix a link, add a redirect, or ignore it.

The answer is the referrer: the page a visitor was on right before the 404. It is almost always an internal link, an external site, or direct traffic, and each points to a different fix. Capture the referrer and every error turns into a clear instruction.

Here is how to surface it in GA4, confirm it in Search Console, and log it automatically in WordPress.

For the full list of what triggers these errors in the first place, see what causes 404 errors in WordPress.

Track 404 Referrers in GA4

GA4 only sees a 404 if your error page loads the analytics tag and sends an event. Fire a dedicated event from your 404 template that carries the broken URL and the referrer.

// Run this on your 404 template, after gtag has loaded
gtag('event', 'page_not_found', {
  broken_url: location.pathname + location.search,   // the broken URL that was requested
  referrer: document.referrer || '(direct/none)'     // where the visitor came from
});

Before that data can show up in reports, register each parameter as an event-scoped custom dimension. In GA4, open Admin, then Custom definitions, then Custom dimensions, and click Create custom dimensions once for each row below.

Dimension nameScopeEvent parameter
Broken URLEventbroken_url
404 ReferrerEventreferrer

The Event parameter must match your code exactly, including case. If it is not in the dropdown yet, type it in by hand, since GA4 only lists parameters it has already received. Custom dimensions are not retroactive and can take 24 to 48 hours to appear in reports, but they show instantly in DebugView and Realtime, which is the fastest way to confirm the event is firing.

With the dimensions in place, build a Free Form exploration, set the event name to page_not_found, and add broken_url and referrer as dimensions. You get a table that pairs every broken URL with the page that led to it. It is the same custom parameter pattern from my guide to events in Google Analytics.

If your 404 page does not include your GA4 tag, those errors never reach Analytics. Confirm the tag loads before you trust the numbers.

Read the Referrer to Find the Cause

Once the referrer is visible, it points to one of those three causes, and each has a clear fix.

ReferrerWhat it meansWhat to do
A page on your own domainA broken internal linkEdit the source page and correct the link
An external domainAn outdated or wrong inbound linkAdd a 301 redirect to the right URL
(direct) or emptyTyped URL, old bookmark, or stripped referrerRedirect if it is a former URL, otherwise ignore

The Document.referrer property returns the URI of the page that linked to this page. (MDN Web Docs)

For an external link worth keeping, a permanent 301 redirect passes its value to the correct page instead of wasting it.

A blank referrer is not always direct traffic. Browsers, privacy settings, and apps can strip it, so treat empty values as unknown, not zero.

Confirm Crawler Errors in Search Console

Search Console catches the 404s that Google hits, which are the ones that hurt SEO. Open the Pages report, expand the Not found (404) group, and select a URL. The full workflow is in my complete Google Search Console guide.

Run URL Inspection and check the Referring page, which shows where Google found the broken link. If it is your page, fix the link. If it belongs to another site, a redirect keeps the value of that inbound link.

Log 404s Automatically in WordPress

On WordPress you can skip the manual setup. A logging plugin records the requested URL, the referrer, and the user agent for every 404, and lets you add a redirect on the spot.

The Redirection plugin is the common choice. Its log groups repeated misses, so you see which broken URLs get real traffic and which are just bots probing for files that never existed.

FAQs

Common questions about tracing the source of 404 errors.

Why does Google Analytics show 404s but not where they came from?
GA4 records the requested URL of the 404 event, not the previous page, unless you send the referrer as an event parameter. Capture document.referrer in a custom event so the source shows up next to each broken URL.
How do I know if a 404 comes from an internal or external link?
Look at the referrer. A referrer on your own domain is a broken internal link to fix at the source. A referrer from another domain is an external link that usually needs a 301 redirect to the correct page.
What does a (direct) or empty referrer on a 404 mean?
It usually means a typed URL, an old bookmark, or a browser or app that stripped the referrer. Redirect it if the address is a former URL on your site, otherwise it is often safe to ignore.
Should I redirect every 404 to the homepage?
No. Redirect a broken URL to the closest relevant page. Mass redirects to the homepage are treated by Google as soft 404s and confuse visitors. Let truly dead, irrelevant URLs return a clean 404.
Do I need a plugin to track 404 referrers in WordPress?
No. You can send a custom GA4 event from your 404 template, but a plugin like Redirection logs the referrer automatically and lets you add a redirect without writing code.

Summary

A 404 names the URL that failed; the referrer names the cause. Capture document.referrer in a GA4 event, confirm crawler errors in Search Console, or let a WordPress plugin log both. Once you see where each visitor came from, every 404 becomes a simple call: fix the link, add a redirect, or leave it alone.

Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo