Add this script to your footer.php before the closing </body>
<script>
// Function that tracks a click on an outbound link in Analytics.
// @refer https://support.google.com/analytics/answer/7478520?hl=en
var trackOutboundLink = function(url) {
gtag('event', 'click', {
'event_category': 'outbound',
'event_label': url,
'transport_type': 'beacon'
});
}
function onclickCallback(e) { // @refer https://stackoverflow.com/a/8496919/8255629
var e = window.e || e;
if ( (e.target.tagName !== 'A') || (e.target.host == window.location.host) ) return;
trackOutboundLink(e.target); // GA event tracker
}
if (document.addEventListener)
document.addEventListener('click', onclickCallback, false);
else
document.attachEvent('onclick', onclickCallback);
</script>
Leave a Reply