document.addEventListener('click', function(e) { var a = e.target.closest('a'); if (a && a.hostname && a.hostname !== window.location.hostname && (a.protocol === 'http:' || a.protocol === 'https:')) { gtag('event', 'outbound_click', { link_url: a.href, post_title: document.title }); } }); });