17

I've been dealing with a bane-of-my-existence Javascript problem involving tracking when a user clicks on a link (in case you're curious, here it is: Why does using target="_blank" cause Javascript to fail?).

I've figured out that I can solve the problem by tracking an onMousedown event rather than an onClick event.

I'm curious about the downsides of this approach. The ones I can think of:

  1. If a user clicked down on a link and then moved the mouse off the link before releasing it, then the event would be recorded even though the user hadn't visited the link
  2. If a user used the tab key to move the browser focus to the link and then hit enter, the click would not be recorded

Neither of these are common, so I'm not terribly worried about them.

Are there any other downsides I'm missing?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jack7890
  • 1,311
  • 4
  • 19
  • 27

1 Answers1

18

One more: mousedown captures right / middle clicks too.

But for your two reasons, I would stick to onclick. I know quite a few people who use keyboard nav. Especially search-and-gotolink in FF.(/ to search followed by enter to go to the link).

But if these two are not a problem for you, I think right / middle clicks wouldn't be too.

I think the way to track all the users who follow the link is quite tricky -- the user could right click and click on new tab / new window...

fmatt
  • 464
  • 1
  • 5
  • 15
Raze
  • 2,175
  • 14
  • 30
  • I agree with your post, but it bothers me that Google's search page uses onmousedown rather than onclick to track clicks, which suggests they handle these issues or at least consider onmousedown best practice. Any thoughts? – Dunc Sep 21 '11 at 13:29
  • I don't exactly know how google tracks clicks, but these are some points I can think of regarding them using onmousedown: They are interested in the aggregate click %ages - a few less or more don't matter. Using either of onclick / onmousedown, there is no reliable way to know if the user has followed a link or not (using onclick can result in missing right-click + open in new tab, using mousedown can result in every right-click being registered as a link follow). However, right click could mean the user is somehow interested in the link. – Raze Sep 21 '11 at 17:08
  • 6
    Also, mousedown event gives more time to send data to Google before the link is followed (the small time difference after pressing the mouse button and before releasing it) -- enough for a request to be sent to Google's server. Not sure if onclick will leave enough time for this. The alternate option, which Yahoo does, is to first take you to their server, and then redirect you to your URL of interest. – Raze Sep 21 '11 at 17:12
  • 2
    Interesting point about onmousedown allowing more time to send data back to Google - I notice Bing also does this – Dunc Sep 21 '11 at 20:48
  • 4
    In short onclick event takes < 400mi/sec to fire and onmousedown takes 200mi/sec, Explained here http://www.cardinalpath.com/experiment-onclick-vs-onmousedown-event-tracking-in-google-analytics/ – user3127648 Feb 16 '17 at 15:46