I want to trigger multiple inline OnClick events on a single click.
The first (window.open) triggers a Facebook share dialog box. This fires properly.
The second {ga(...) }
should trigger an event goal in Google (Universal) Analytics. However, this second OnClick event does not work properly and the goal is not being recorded in GA.
<a
class="facebook-share"
href="#"
onclick="
window.open('https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href),
'facebook-share-dialog',
'width=626,height=436');
return false;
ga('send', 'event', 'social share', 'facebook share', 'top button' );
">
Share on Facebook
</a>
Any idea how to fix such that the FB share dialog still fires, and the click is also tracked in GA?
You have
return false
between calls, so handler exits before the second call. Place it after the call toga()
function.