Tracking error pages from WordPressPlugins & Hacks
Tracking error pages is something that page tag solutions cannot track out of the box – including Google Analytics. In Chapter 9 of the book I describe how to track all your error pages using Google Analytics. Essentially, you modify the server error template to include the GATC, then use an advanced filter to rewrite the URL string.
However, if you are a WordPress user, there is a simpler method than tinkering with your web server…
WordPress includes a template file called "404 template" (404.php). This is the file used to display an error message if a page is not found. By default it does not contain very much:
<?php get_header(); ?> <div id="content"> <h2>Error 404 - Not Found</h2> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
Modifying it to this (assuming you are using ga.js in your pages):
allows you to to view the URLs of missing pages in the Google Analytics Content > Top Content report (see screenshot).
As a tip, use the inline filter as shown to bubble up these pages – otherwise they could be buried deep in your reports. Once you have identified the missing URLs, click through on the pages and then select "Navigation Summary". This tells you which links within your website point to these missing pages – that is, have broken links.
_udl.search are Google Analytics variables captured by the GATC, so it is important that the GATC is loaded first.
Tip: if you are still using the legacy urchin.js page tag (why?), subsitute the string
pageTracker._trackPageview in the above functions.
Obviously there is more than one way to skin a cat. Please let me know if you have used a different hack to acheive this by leaving a comment.