We have an affiliate websites and we are attempting to track the clicks to outbound affiliates sites. I inserted the below code into our html.
In header:
<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>
In the body on the link:
<a href="http://domain.com?aff_link=123456" onclick="trackOutboundLink('http://domain.com'); return false;"> The link </a>
This script was correctly tracking affiliate link clicks but managed to strip the affiliate code from the domain when the user clicked. In other words
http://domain.com?aff_link=123456
became
http://domain.com
As a result no commissions were tracked. Does anyone know possibly why this is happening and how to track the links with GA and keep the affiliate links in tact?
Thanks!