How to Detect 404 errors in Google Analytics and Google Webmaster Tools

If you just migrated your website, or you frequently change your URLs structure, you may suffer of broken external links that end like 404 errors for your visitors.

Even if you try keeping control by using an Excel or strict protocols, some links may escape from your attention. You should detect and repair these links for two reasons: 1) they create bad user experience, 2) they weaken your position in Google, since they once helped you to hold good positions, but now they're useless.

You have two complementary ways to detect these external links:

Detect 404 errors in Google Analytics

Introduce this PHP code before </body> in your 404 error page. Each time a visitor arrives to this page, an event will be recorded in Google Analytics with the broken URL. For this solution to work, the URL must be kept intact in the address bar of the visitor's browser:

<script type="text/javascript">
ga('send', 'event', 'Error', '<?=$_SERVER['REQUEST_URI'];?>')";

Detect 404 errors in Google Webmaster Tools

Under the tool "Crawl" > "Crawl errors" in Google Webmaster Tools, you can find broken links pointing to your site, that thus create 404 errors.

Contribute with a comment comment0 Comments
mode_editContribute with a comment