Tracking 404 error pages using Google Analytics

by Dipali on December 24, 2008 · 3 comments

in Google Analytics

Google Analytics can be setup to record whenever a 404 error page is shown on your website. This can be useful to fix broken links or setup redirects to new content.

Create or open your custom 404 error page. If you’re running your website on Apache, just create a new page and name it something like 404errorpage.php. Then modify your htaccess file by adding the line in bold:

ErrorDocument 404 /404errorpage.php

Then modify the Google Analytics tracking code as shown in bold:

<script type=”text/javascript”>

var gaJsHost = ((”https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);

document.write(unescape(”%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));

</script>

<script type=”text/javascript”>

var pageTracker = _gat._getTracker(”UA-XXXXXX-XX”);

pageTracker._trackPageview(”/404errorpage.php?page=” + document.location.pathname + document.location.search + “&from=” + document.referrer);

</script>

The 404 error pages can then be viewed in the top pages report by searching for 404errorpage.php.

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Related posts:

  1. Tracking Subdomains with Google Analytics
  2. Tracking Flash pages and events using Google Analytics
  3. Tracking outgoing links, downloads and RSS feed subscriptions with Google Analytics
  4. Google Analytics Seminares
  5. How to create google analytics custom reports ?

{ 3 comments… read them below or add one }

1 Rajeev Edmonds December 31, 2008 at 2:52 pm

Very effective technique to track 404 impressions. Combined with dead links report of Google Webmaster tools, its a plum.

Does it work with subdomains as well? I mean just a single set up works fine across all sub-domains?

[Reply]

2 dipalithakkar January 1, 2009 at 5:50 am

Hello Rajeev,

Thanks for your insights on my blog. well interesting question..

You can configure single custom 404 Error page for all domain and sub domains. but i would like to recommended you to configure single Custom 404 Error page for your each sub domain and put analytics code on that created page via this way you can track 404 errors for each of your sub domains.

[Reply]

3 clotilde January 8, 2009 at 2:01 pm

Hello Dipali, and thank you for sharing this useful tip.
Can you clarify how and where you can then view the collected info on Google Analytics?
I am able to find my custom 404 page in Content > Top Content > Find Page, but then when I look at the report for that file, I can’t figure out how to view the broken links and referrer info it should have tracked.
Many thanks for any pointers you can provide,
Clotilde.

[Reply]

Leave a Comment

Previous post:

Next post:

Get Adobe Flash playerPlugin by wpburn.com wordpress themes