I have successfully integrated the universal GA for tracking outbound clicks, however I have also added a "speed bump" pop-up message that appears when a user clicks on an offsite link. The JavaScript code for this is as follows: (specific to bank client - speed bump required)
My question is, will this affect the GA outbound click tracking in any way? When a user clicks on an external link, they will see a modal box with a disclaimer and options to "Continue" or "Decline."
$(document).ready(function() {
$('.external').click(function() {
var link = $(this).attr('href');
$('<div>By accessing this link you will be leaving the site...</div>').dialog({
title: "Third-Party Site Disclaimer",
modal : true,
overlay: {
backgroundColor: '#fff',
opacity: 1
},
buttons: {
'Continue': function() {
$(this).dialog('close').remove();
window.open(link);
},
'Decline': function() {
$(this).dialog('close').remove();
return false;
}
}
});
return false;
});
});
The Google outbound click tracking code included in my setup:
<script>
/**
* Function that tracks a click on an outbound link in Analytics.
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
*/
var trackOutboundLink = function(url) {
ga('send', 'event', 'outbound', 'click', url, {
'transport': 'beacon',
'hitCallback': function(){document.location = url;}
});
}
</script>