Tracking 404 pages is particularly important because no one wants to land on one (unless it’s entertaining), and it can potentially hurt your search rankings. Note that I highly recommend you make sure Google Webmaster Tools is implemented to detect any 404 errors that Google might be picking up. I also like to use Link Sleuth (PC) or Integrity (Mac) whenever launching or managing a new website to check for broken links that could be leading to a 404.

I’ve read a lot of different ways to track 404 pages with Google Tag Manager, but before we dive in, let’s first define the requirements for the insights we want to gain.

  • Understand the previous page users were on before they landed on the 404 page
  • Gain a general understanding of how the 404 page is performing in regards to engagement. Ex: time on page, exit rate, bounce rate

These requirements will greatly impact our implementation approach. The less insights we care to gain, the simpler the implementation.

I recommend the following method just because it can’t accidentally break if someone changes your 404 page title. Like some of my other posts, I’m going to be using WordPress in my example.

1. Add the data layer variable to the 404 template

In the 404.php template (use your 404 template if you’re not using WordPress), we’ll want to add a snippet of code that will push an event to the data layer on page load. This will allow us to set up a trigger in GTM that’ll fire a tag that we’ll set up in the third step.

<script> dataLayer.push({'event': '404_page'}); </script>

2. Add a custom event trigger

Create a new custom event trigger and make the event name 404_page. This means the trigger will fire whenever the 404_page event is pushed to the data layer from step 1.

Screen Shot 2015-10-25 at 7.45.57 PM

3. Create an HTTP Referrer variable

In order to understand the previous page users were on before they landed on the 404 page, we’ll create an HTTP Referrer variable that’ll get passed into the event tag in the next step. This will check off our first business requirement.

Screen Shot 2015-10-25 at 9.39.46 PM

4. Create a custom metric and custom dimension

In Google Analytics, create a custom 404 page view metric that will allow us to understand how many 404 page views we’re getting. This will also allow us to cut our data across the engagement metrics defined in our second business requirement to understand how our 404 page is performing.

Since WordPress doesn’t have an identifier in the URL that tells us it’s a 404 page, we need to create the custom 404 page view metric. For example, when using some other content management systems, you’ll sometimes find something like ‘404.aspx?=’ or something similar in the URL. If that was the case, then we could just segment all pages that contain that string. In this case, adding the custom metric will allow us to create a custom report with 404 page views and other metrics and dimensions like bounce, exit rate, page, etc.

Screen Shot 2015-11-01 at 1.35.01 PM

Create a custom dimension that will serve as our HTTP referrer. This way, in our pages report, we’ll be able to see where the users came from, as defined in our first requirement.

Screen Shot 2015-10-26 at 10.33.13 PM

5. Add an event tag

The event tag will not only push an event, but also set a custom metric so we can segment all 404 pages to better understand the 404 page behavior as defined in our requirements.

Note: We could create a pageview tag instead of an event, but then that would require us to make an exception in the global pageview tag. I also don’t mind using the event tag as it give us another way to cut through the data in our OOTB reports.

We’ll set the event label to the HTTP referrer variable that we set in step 3.

Set Non-interaction hit to true. This is very important because if users land on our site on a 404 page and leave without viewing another page, then they’ll need to count as a bounce. Setting this to false would result in the user exiting and not bouncing.

Screen Shot 2015-10-25 at 10.21.41 PM

Add the custom dimension and make sure the index corresponds with the the custom dimension created in Google Analytics. Set the Dimension Value to the referring URL variable we created in step 3.

Screen Shot 2015-10-25 at 10.30.34 PM

Set the custom metric value to 1 and make sure the index corresponds with the custom metric created in Google Analytics. This will essentially count the number of times a 404 page is viewed and increment by 1. It’ll also allow us to create a custom report telling us 404 page views and the engagement metrics we defined in our second requirement for a specified time period.

Screen Shot 2015-10-25 at 10.28.27 PM

Finally, set the trigger to the 404 page and save the tag.

Screen Shot 2015-10-25 at 10.34.53 PM

6. Create a custom report

In order to get our metrics and top off our requirements, we’ll want to create a custom report that shows all of our 404 page views and engagement metrics. Below is a screenshot from my test profile of the report configuration and output. Screen Shot 2015-11-13 at 1.28.33 PM

Screen Shot 2015-11-13 at 1.29.47 PM Screen Shot 2015-11-13 at 1.30.23 PM


In Conclusion…

As I mentioned in the beginning, there are tons of ways to track 404 pages, but it’s all about what insights you’re trying to gain and establishing requirements at the very beginning. I could have also just fired the tag based on a string in the page title instead of pushing the event in the data layer, but what if someone changed the page title in WordPress and forgot to update the trigger in GTM? Then I would start losing data. 404 pages can be one of your most important templates for large websites with high traffic volume. Use these insights to make sure your users don’t think they’re hitting a dead end.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.