Why GA4 does not tell 404 pages apart
Unless your URL changes to /404, the address stays, along with its title, and that is what Google Analytics collects.
To identify them properly, you need to set up a 404 signal.
The principle: read the 404 status in the browser
The visitor's browser knows the response code of the page (404 for an error). With a variable in Google Tag Manager, a page_404 event is sent to GA4 each time it occurs.
Setting up 404 tracking in GTM
Step 1: Create the custom JavaScript variable
In GTM, go to Variables > User-Defined Variables > New, choose the Custom JavaScript type, name it JS - Page status code then paste the following script:
function() {
var page = performance.getEntriesByType('navigation')[0];
return page ? page.responseStatus : undefined;
}
This function reads the code of the open page: 200 for a normal page, 404 for a page not found.
Step 2: Create the trigger
In Triggers > New, choose the Page View type then limit it to the pages where the JS - Page status code variable equals 404.
Step 3: Send the event to GA4
Create a Google Analytics: GA4 Event tag named page_404 with this trigger. Every 404 page displayed then sends the event, with its address and the previous page.
Display the 404 pages in Google Analytics
Open the Explore menu, create a Free form exploration then add the following items in the Variables column:
- Dimensions: Page location (the requested address), Page referrer (the previous page)
- Metrics: Event count
Place Page location then Page referrer in rows and Event count in values. Filter on Event name with the condition exactly matches page_404, then sort in descending order: you get the most broken addresses, with the page the visitors came from.
How to handle the identified 404s
Once you have your list in front of you, the distinction is simple:
- If the source (Page referrer) is a page of your site: it is a broken link on your side. Go to your CMS and fix the link directly in the content.
- If the source is external or empty: the page no longer exists but still receives traffic. Set up an automatic redirect (301) to the closest equivalent page. If possible, notify the referring site.
Tools
- Google Tag Manager: Custom JavaScript variable, Page View trigger, event tag.
- Google Analytics 4: explorations, Page location and Page referrer dimensions.
Isolating 404 pages and their source in analytics is part of the tracking expertise.