Why & How to Track External/ Outbound Clicks from a Website & Label it through GTM

There could be a lot of circumstances when you want to know and label the external or outbound clicks which are happening on your website and going to some other websites. This action taken on your website could be because you wanted a user to click the link or a user simply clicked an external link and left the website. Following are some of the scenarios in where you would want to track the name of the websites to where a user left.

Sample scenarios to track outbound clicks

Tracking sponsored clicks

Let’s say you have posted a guest or a sponsored blog on your website or blog and you want to know the traffic originating from your website to the sponsored website. We can also use UTM parameter for the same. However, that would reflect the data in the analytics of the destination, not the source. Since we are the source, in this case, we want to track the clicks to the destination.

Affiliate links

Let’s say you are using affiliate links such as Amazon affiliates or apple affiliates. In that case, for the purpose of A/B testing to know which affiliate anchor links or ad formats are performing better, you can use Google Tag Manager to track outbound links.

Branding or some other purposes

I like to drive traffic to the Goodreads reviews of my first novel from my travel blog on desktop devices. In that case, I like to track how many clicked on the links and landed on the Goodreads to read the reviews. So, here is

How to Track Outbound Clicks from a Website & Label it through GTM

I am assuming that you have already installed Google Tag Manager & Google Analytics through GTM. So let’s continue and let’s start with a variable.

The logic behind creating this variable is that. This variable will store the value of the hostname of the link that will get clicked. So, in that case, we are going to track the “clicks where hostname is not your-website.com”. If the hostname of the link which was clicked contains your website name that means that is just another link of your website. But if the hostname is anything other than your website name that means that link is an external link. So, let us start

 1. Create a variable to store hostname of the link clicks:

Go to Variables -> Click new under user defined variables

1. Create a new user defined variable

 2. Choose new variable type as Auto Event variable

Give a recognizable name to your variable such as hostName. Click on the variable configuration and select auto event variable as the variable type.

Auto-Event Variables are used to access the target element of an auto-event action (e.g. Click, Error, Form Submit). For example:

  • When you click an image, you can access the image’s URL or target link.
  • When you submit a form, you can access the form’s ID, etc.

2. Configure the new variable in GTM for HostName

3. Configure the variable as follows

Choose variable type as Element URL and component type as Host Name.

3. Host Name variable configured

Now that the variable has been set. Let’s set the trigger for this variable.

4. Set up the trigger

Click Triggers -> New -> Name the trigger and choose a trigger type to begin the trigger setup.

4. Create trigger for hostname for external link tracking

5. Configure the trigger

Select the trigger type as Click – Just Links. This trigger type is used for link tracking. And check to wait for tags. By default, it will be 2000 ms. Just leave it like that. You can also check the check validation box.

Next, there are two options. First one is asking about enabling this tag. In this case, I have set up as every page. You can also use regex for the same.  Because we want to track the link clicks on all the pages of the website.

The second one is the firing condition. In that case, we want to fire the trigger on all the links which host-name is not your website name.

So we have selected the variable name which we made in the earlier steps along with does not contain condition in where we mentioned our website URL. Once done, save it.

5. External Link Clicks Trigger

 6. Create the tag

Create a new tag and name that as per your convention. Choose the tag type as universal analytics. I am also assuming that you already have Universal Analytics installed through GTM.

Select Event as track type because we are going to track those events. In the category and actions, give a name of your choice which you can recognize easily in GA.  In the Label, give that variable name within two opening & closing curly brackets like this {{}}. As you might have already understood that in the event label, we will be capturing the hostname of the external link which we had set up through the variable.

Then select the Google Analytics ID to which I am assuming that you have already done that. Once done save and publish.

6. External Link Click Tags

 7.  Track in GA

Go to GA. Click on Top events under behavior. You can see the categories. Look for the category that you gave in the tag. Browse through it to the event label. You will see the name of the external websites being captured in the event label as below.

7. External link clicks captured as events in Google Analytics

Let us know in the comments below if you face any issue while setting up the tags or triggers.

Have a Question? Get in Touch!

Leave a Reply

Your email address will not be published. Required fields are marked *