Tag: tracking Posts

Track Outbound Links On Your Website


I’ve been trying to track where exactly people go when they leave my website for a few pages recently, and wrote some code based on a few other examples on the Internet. Basically this bit of Javascript will force Google Analytics to log a special request so that you can see where the user went. It uses jQuery, so you have to make sure you have that included in your theme. Here’s some code that will let you track outbound links on your WordPress website. jQuery( ‘a’ ).on( ‘click’,function( e ) { var url = jQuery( this ).attr( ‘href’ ); var customName = jQuery( this ).attr( ‘data-link-name’ ); if ( !customName ) { customName = url; } if ( e.currentTarget.host != window.location.host ) { ga( ‘send’, ‘event’, ‘Outbound Link’, customName, document.title ); if (e.metaKey || e.ctrlKey) { var newtab = true; } if (!newtab) { e.preventDefault(); setTimeout(‘document.location = “‘ + […]