I am trying to set up Event Tracking through Google Analytics. Getting it to work on text links is easy but I can't seem to get it to work on images. I follow Google's example of how to add the code should be, but it results in an image link that can't be clicked (I click the banner and nothing happens, but I can right click the banner and open in new window and it works).
See below for my code on the link:
<a href="http://keystonetech.com" target="_blank"
onclick="trackOutboundLink('http://keystonetech.com');return false;"><img
src="/wp-content/uploads/2017/09/keystone-direct-drive-led-t5.jpg" alt=""
width="617" height="128" /></a>
And then below is the Google Analytics scripts - 1st one is the standard Universal Analytics GA Script and the bottom one is for tracking the links (again, per the Google link above).
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-437557-
32"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'UA-437557-32');
</script>
<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>
Any thoughts on where the issue lies would be much appreciated! Thanks much for reading.