Blog

Home > Analytics FAQs > How to Track 404 Errors with Google Tag Manager

How to Track 404 Errors with Google Tag Manager

If you have a website containing 100s of pages, chances are you will have pages which have been deleted or not existing. Somehow these pages are still appearing and people visit these pages from referral sites.

This results in a decrease in your organic rankings and hence provides a way to your competitors to rank. In this article, I will teach you how to track 404 errors with Google Tag Manager and view the reports in Google Analytics.

Step1: Check the error message

The very first step you will have to do is to check what message displays when a nonexisting page is loaded. On some websites, the title displays as ‘404 not found’  and some websites display simply the website name and message in the body.

You can test this by simply typing in the URL, www.yourwebsite.com/test. This will display not found page on your website.

404 not found in the title is easy to track so I will explain the second method. There is no 404 not found message displayed in the body nor the title. What will you do?

In this case, you will have to right click and open page source. Press ctrl+f and type not found, this will display the id or CSS selector.

 404 not found message

Copy this ID and go to your GTM account.

Step2: Create a User-Defined Variable

Open your Google Tag Manager account and navigate to variables section.

Create a new user-defined variable.

Select the variable type as DOM element

Select selection method as CSS Selector

Enter element selector as body

Enter id in the attribute name field

Enter a name of the variable and hit save

 not found variable

Step3: Create a new Trigger

Navigate to triggers section and create a new trigger

Select the trigger type as DOM ready

Select the trigger to fire on some DOM ready events

Select the not found variable equals not-found
Enter the trigger name as not found

 not found trigger

Hit save

Step4: Create a New Tag

Now, we have to send this data to Google Analytics. To do this, we will create a new Google analytics event tag.

Enter the tag name as GA Event PageNotFound
Set event name and event parameters as shown

Add the trigger we created in step 3.

Preview and publish the once you make sure it’s firing correctly.

Conclusion

The biggest benefit of tracking 404 pages is you can resolve the issues whenever it arises. This tracks even faster than search console and lets you find the issues instantly. If you have anything to ask related to this topic, please let us know directly on Twitter.

Share:

Data that Moves Your Business

Connect with Marketlytics

Join 120,000+ Marketers

Stay ahead with expert insights on marketing analysis, data-driven strategies, and industry trends.

Omair

Revenue Growth Analyst
Data Unification Specialist, previously at a leading Ecommerce Giant

Case Studies

Discover our latest success stories
and see how innovative strategies
drive measurable results.

Get a Free Attribution Dashboard

Gain clear insights into what’s
driving conversions and optimize
your marketing spend with ease.

Are you Ready to Fast Track your Marketing Attribution Decisions and Maximize your ROI?

Businesses that leverage automated marketing
attribution see a 20-30% improvement in ad
spend efficiency.