I've an anchor link which has an onclick event attached to it. Basically a Facebook share popup opens on clicking it.
<a target="_blank"
href="https://www.facebook.com/sharer/sharer.php?u=MYLINK"
onclick="javascript:window.open(this.href,'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"
>Share on Facebook</a>
Now I want to track it with Google Analytics Universal Tracking Event Tracking.
So I added a class named track to the each anchor that I want to track. My intention is to run the following javascript code
$('.track').click(function (e) {
ga('send', 'event', 'button', 'click', 'nav-buttons');
});
where click and nav-buttons values will be dynamically inserted through HTML5 data variables. (which will be attached to the anchor)
<a target="_blank" class="track"
href="https://www.facebook.com/sharer/sharer.php?u=MYLINK"
data-event="click"
data-label="nav-buttons"
onclick="javascript:window.open(this.href,'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"
>Share on Facebook</a>
How to integrate the whole thing? Will two onclick event work? Or only one will work? What is the best way to implement this. Please guide.