Track Broken Links on Your Website with Google Analytics and Webmaster Tools

Broken links are bad. Sometimes it’s possible to engage users while they visit 404 error page and use it to your advantage. But other times, it hurts your user experience. Also Google doesn’t like 404 pages and your site may lose it’s SEO value. Google adds some SEO value to every incoming URL to your site provided they do not end up in 404 error pages.

Many times you change the URL of old pages and it may lead to 404: Not found error page if you do not have a backup system such as 301 redirects in place. Also, there are other ways as well where users may reach a page with 404 error. Say, your website has a page at ‘www.mywebsite.com/my-page’ and somebody from some other website links to your page incorrectly, say ‘www.mywebsite.com/mine-page’, then it is most likely that users will encounter a 404 error page.

404 Error Page

404 Error Page

Detect 404 Error Pages Using Google Analytics

Google analytics offers a way for website admins to track pages. So if we add a tracking page code to 404 error page template, we can view the pages which users were unable to browse due to ‘404: not found’ error. Make sure you add this only to your 404-page template else you will not get the correct data. Also, you can refer a website’s URL so that it would be easy to know if these pages are linked from your website itself (take a note and correct them on high priority) or somebody else has linked them.

If you are using Google universal analytics then you would be having some code similar to the below one.

<!-- Google Analytics -->
<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->

Now right before the closing ‘</script>’ tag we add our tracking code (only to 404 templates).

/* Track 404 Error Page *//*create URL with current pages url and referrer*/
 var url = "/404/?url=" + window.location.pathname + window.location.search + "&from=" + document.referrer;
ga('send', {
 hitType: 'pageview',
 page: url
});

Thus, you final code should be similar to below code.

<!-- Google Analytics -->
<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');

/* Track 404 Error Page *//*create URL with current pages url and referrer*/
 var url = "/404/?url=" + window.location.pathname + window.location.search + "&from=" + document.referrer;
ga('send', {
 hitType: 'pageview',
 page: url
});

</script> 
<!-- End Google Analytics -->

Once the code is put in the right place, we are set to switch to Google analytics and view the collected data. As Google analytics can provide real-time analysis, we see these pages (with referrer) as they happen (and of course, later when we need it).

To view a list of all 404 pages in Google Analytics, go to your Google Analytics dashboard and select, ‘Behaviour -> Site Content -> All Pages’. Now put ‘/404’ in the search box and select a date range of your interest. This should present you with the missing pages on your website along with the referrers.

Track 404 Error Pages using Google Webmaster Tools

While the above method is good but Google Webmaster tools offer a similar solution without you having to do anything. This is especially useful when you are not using Google analytics tool and still want to track 404 error pages. After you verify the ownership of the website, in your Google Webmaster Tools dashboard, go to, ‘Crawl -> Crawl Errors’. Select ‘Not Found’. 

Google Webmaster Crawl Error Not Found Pages Example

Google Webmaster Crawl Error – Not Found Pages Example

You will see the list of all 404 pages which Google feels are important for you to take care off. Also, if you click on any result link, it gives you Error Details and information about the referrer or Linked from value. You can also try and click on Fetch as Google to know how Google views you page.

Deepak Pal
Follow Me:

Deepak Pal

Owner at Lofoya.com
Deepak is a web enthusiast who loves to write on technology related topics. He runs two educational platforms, Lofoya and GyanPal dedicated to the promotion of FREE EDUCATION.
Deepak Pal
Follow Me:

2 comments

Leave a Reply

Your email address will not be published.