Editor's note:
Thanks for visiting GA Tip of the Day. All of my newer posts are published on the E-Nor blog. Please visit and sign up for updates.
- Eric Fettman


Use onmousedown JavaScript Listener for Events if onclick Doesn’t Work

Real-Time Events reportview at full size

Whichever JavaScript listener you use, you can check your event in the Real-Time reports.

If you’re trying to generate a Google Analytics event based on a click and onclick isn’t working, try onmousedown instead.

Let’s say that you want to track a click on the following mailto: link as a Google Analytics event:

<a href="mailto:[email protected]?subject=Demo%20Request">mailto: link</a>.

If you use the JavaScript onclick handler, make sure to test the event in multiple browsers, because if the “mouseup” part of the click is not recognized, onclick never fires:

<a onclick="ga('send', 'event', 'link', 'mailto', this.href);" href="mailto:[email protected]?subject=Demo%20Request">mailto: link</a>.

If onclick is proving unreliable, use onmousedown instead:

<a onmousedown="ga('send', 'event', 'link', 'mailto', this.href);" href="mailto:[email protected]?subject=Demo%20Request">mailto: link</a>.

If you’re using jQuery, you can similarly use the .mousedown() listener instead of .click().

Whichever option you choose to capture your events, you can test your events in the Real-Time reports.

Please share this post:
Facebook Twitter Plusone Linkedin Email

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>