Click Tracking [Google Analytics]

Event Tracking

<script>
/**
* Function that tracks a click on a link in Google 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 trackLink = function(url) {
   ga('send', 'event', 'link', 'click', url, {
     'transport': 'beacon',
     'hitCallback': function(){document.location = url;}
   });
}
</script>

On Page Implementation

<a href="http://www.example.com" onclick="trackLink('http://www.example.com'); return false;">Visit example.com</a>

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*