Site icon Travelpayouts Blog – Travel Partnership Platform

How to track outbound link clicks in Google Analytics

How to track outbound link clicks in Google Analytics

Why track outbound link clicks

Here is what you can learn after checking the number of clicks on outbound links:

To understand how many users go from your blog to third-party resources, set up events in Google Analytics.

There are two ways to set up events:

The second method is easier, as you’ll only need to add the code once. Then, you’ll be able to set up all the events through GTM without adjusting the code on the website.

How to set up tracking of outbound link clicks in Google Analytics

If, for some reason, you find it easier to track clicks directly through GA, here is how you can set up tracking. First, connect your blog to Google Analytics (if you haven’t already). 

1. Create a resource in GA. Find detailed instructions in Google’s guidelines.

2. Add the analytics.js tracking code to your blog pages. This code will look as follows:

<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};
ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->

UA-XXXXX-Y — your individual tracking code.

If you have already connected your blog to Google Analytics, make sure that you’ve set up this tracking code exactly, as the script that we’ll discuss below only works using this code.

Tracking outbound link clicks in Google Analytics

To see internal link clicks on your blog, you can simply set up a standard tracking code. In order to send data on internal link clicks to GA, add the following script to the <head> after the tracking code:

<script>
var trackOutboundLink = function(url) {
   ga('send', 'event', 'outbound', 'click', url, {
 	'transport': 'beacon',
 	'hitCallback': function(){document.location = url;}
   });
}
</script>

Add the “onclick” attribute to codes of those links on the page with an installed script for which you want to track clicks.

<a href="http://www.example.com" onclick="trackOutboundLink('example.com');
 return false;">Открыть example.com</a>

How to check that tracking works properly

How to set up tracking of outbound link clicks in Google Tag Manager

If you want to manage all the settings in Google Tag Manager, you can remove GA tracking codes from your blog after setting up GTM. Your statistics in GA won’t be removed, because, in fact, you have simply changed the way of adding Google Analytics to your website.

1. Set up Google Tag Manager on your blog:

If your blog operates on WordPress, open the header.php file. Add the first code to <head> immediately after the opening tag. Add the second code to <body> after the opening tag.

2. Activate built-in variables.

These variables are necessary for tracking link clicks.

3. Add the Google Analytics ID to GTM as a custom variable. You can use it for all tags.

4. Set up page tracking through GTM:

5. Create a trigger to track outbound links:

6. Create a tag for tracking outbound links:

7. Publish the container:

8. Make sure that everything works properly:

Do you track clicks on outbound links? Which method do you use and find best?

Exit mobile version