Broken backlinks are very frustrating for your users. If someone clicks on a link to your website, they want the content they were expecting. A broken link will immediately make them go back to where they came from and try another link. Most users will not attempt to find what they were looking for (like if it has moved) but will just navigate away. This can take away valuable traffic that was coming to your website.
Just to be clear, we are talking about backlinks here (also called inbound links) which are are links from other website to your website. Unlike broken internal links, which you can find using crawls, you cannot identify all the broken inbound links (unless you decide to become Google and crawl the entire internet). This is where Google Tag Manager (GTM) and Google Analytics come to the rescue, and we can use GTM to find such broken backlinks.
As a bonus, this trick will also work for broken internal links. But, you should still periodically run a crawl to find them).
As the title indicates, you should be using Google Tag Manager, and a web analytics tool setup inside GTM. This post assumes you are using Google Analytics, but it can be any other similar analytics tool you are using.
You should also have GTM running on your error pages, and not be redirecting them anywhere.
If you are not using Google Tag Manager, I highly recommend it! You can read what my basic Google Tag Manager setup looks like.
Steps to Find Broken Backlinks
The way we will do this is by setting up a custom event trigger inside GTM. Whenever a user lands on a broken page, we want to fire a Google Analytics event which records where they came from (the HTTP referrer).
Since we only want our event to record something when the user lands on an error page, we need a way to identify that the page is a 404 error page. The easiest way will be to match the page title to see if it is an error page. If it is, we fire a Google Analytics event.
1. Create custom variable to identify page title
GTM does not have a default varialble for page title, so we will have to create one.
Now this new variable will return the page title.
2. Create a trigger for your 404 error page
Now that we have a variable that returns the page title, we can use it to setup a trigger for our error page. The trigger will fire on page view when the page title matches your error page title.
Next, we need to set it to fire on “Some Page Views” where the “Page Title” equals your exact <title> text from the error page.
We use equals, because we want to only match the 404 error pages. We need to be careful not to accidently match any other pages. You can use containing, begins with, or ends with or the other options like RegEx, but only if your error page title is not fixed (for whatever reason), and be careful.
3. Create Google Analytics event tag
Next step is to fire a Google Analytics event. This event will store the fact that the user faced a broken page, and where they came from.
Go to Tags > New. Set the name as something like “GA Event – 404 Page” (or any naming convention you follow). We’ll select the trigger type to be “Google Analytics: Universal Analytics” and change the Track Type to be “Event”.
It’s up to you how to define your category and action names (following any other convention you have). I will use the following:
Notice how I am not saving the actual destination URL (on our website) anywhere in the event. We don’t need that as Google Analytics should already stores the page where any event was triggered, and we can find that by adding “Page” as a secondary dimension in the Events report.
Set the Google Analytics settings to be the varibale which you use for your Google Analytics ID. Set the Tag firing priority to “1”, this will make sure that this tag is only fired after the main Google Analytics tag (which has a default priority of 0). Lastly, set the Non-Interaction Hit to “True”, so Google Analytics does not think this event means the user interacted with the page (which can skew bounce rates)
Under Triggering, this is where we add the filtering trigger we created above. This will mean that our new event tag fires only when the page title is our 404 page’s title.
That’s it! You can now find broken backlinks.
All you need to do now is submit your workspace and you’re done. This event will now trigger whenever a user lands on a 404 error page. Keep in mind that we haven’t filtered for it to be only external; so this will fire for both inbound and internal links that lead to a 404 page.
If you wish to restrict it to only to inbound links, you can add another condition to the trigger we made, where the Referrer “does not start with” your own URL (or you can use “does not contain” or “does not match RegEx” according to your needs).
You can also achieve this by creating a separate trigger where the referrer is your own domain and adding that as an exception into your event tag; so that it only fires when the referrer is not your own site.
Lastly, I want to point out that this will not always work. Some sites don’t like sending referrer information, and that can be hidden by adding
rel="noreferrer" to the link anchor tags. Some sites can also hide the exact page by redirecting the user through a different path (Google does something like this, so Google’s referrer only contains their domain and not the full URL with the query string). This may also not work if you have any redirects in place on your site before the user sees the 404 error (like HTTP to HTTPS); unless you specifically configure such redirects to pass on the referrer information.
Nevertheless, it should work in most cases, and this will give you a good idea of any broken backlinks out there in the wild. You can then either contact the referring websites to correct the link, or redirect those URLs to the right page on your website.