I\'m trying to set up event tracking so that I can track when someone goes to my \'about\' page and clicks on a link to my LinkedIn profile. Below is the link that I want tracke
First you need to add The JavaScript tracking snippet.
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto'); //you should definitely change your tracking ID
ga('send', 'pageview');
then we write our event function
function handleOutboundLinkClicks(category, action, label) {
ga('send', 'event', {
eventCategory: category,
eventAction: action,
eventLabel: label
});
}
Finally we call our function at the place we want
CLICK ME