Tel: +44 (0) 1224 582948

#3 How to capture all 404 pages and fix them within Craft CMS

The Problem

You want to avoid 404’s at all costs! When you move pages, sections and sites around, people can land on error / 404 pages, these must be avoided and prevented.

Why use Google Analytics?

It’s free, powerful, popular and works very well.

Let’s get started

In your 404 template:

{% extends “_layout” %}{% set fourohfour %}ga(‘send’, ‘pageview’, ‘/404/?url=‘ + document.location.pathname + ‘&ref=‘ + document.referrer);{% endset %}{% block content %}</br>Content of 404 in here…</br>{% endblock %}</br>

In your layout template at the foot

< script> (function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,’script’,’//','ga'); ga(‘create’, ‘UA-12345678’, ‘auto’); {% if fourohfour is defined %}{{ fourohfour }}{% else %}ga(‘send’, ‘pageview’);{% endif %} </script>

Take action

Go and sort these pages, edit templates, set up 301s or fix links within Craft CMS settings.

Google Analytics tip

Be default Google Analytics shows you data from yesterday and before. You can however view stats from almost immediately ago. Simply set the date in the top right to todays date.

Super ‘cool’ and creative 404 pages?

Absolute madness, even 404 galleries have cropped up! When people land on a 404 page they don’t want some witty and clever design and message. Frustrated… They want what they came to see!

There is a time and a place for emotional design but 404’s are NOT that place.

Whats on a good 404 page anyway?

For start don’t use the language ‘404’, generally people won’t have a clue what that means!

A clear error message, stating something has gone wrong


  • Link to the home page (Every page should)
  • Popular content - 5 links
  • Search facility
  • Contact option

Taken from…

I picked this tip from the fantastic EE Guidebook, which i highly recommend you buy if you use ExpressionEngine.