The Google Tag Manager gives you the possibility to track every click on your website. When you would like to know which outbound link clicks gets most of your traffic it is useful to save every external link click as an event in Google Analytics.
We need the GTM built-in variable Click URL to check if our outbound link meets our conditions. We have to activate this first.
Create a new Trigger based on a Click. Don’t check Wait for Tags or Wait validation. Fire this trigger when the Click URL does not contain yourdomain.com.
Update: Due to the comment of Simo you can mark the next words as unwritten 😉
When an url is relative, for example,
href="../index/", then it’s an internal link. We would not like to track these. Absolute (outbound) urls are always starting with http://, // or https://. We are going to check this with a RegEx.
Use this regex to check if a link starts with
When you are creating Regular expressions on your own, you could test them with Regex101.com.
When our trigger is set, we could use it for firing our Google Analytics tag.
External clicks will now be recorded in Google Analytics