Last modified: 2014-06-26 22:06:07 UTC
This is a reminder to check whether the click logging works properly for image page links, which navigate the browser away. We use a 0.5 sec timeout to make sure the log request has enough time to lead before it would be aborted by the browser aborts it while unloading the page; this might be too little or unnecessarily much. See Mattflaschen's comment at https://gerrit.wikimedia.org/r/#/c/92445/ for more details.
It's actually possible to make logging work on navigating away without a timeout by making a synchronous XHR call during the onbeforeunload. Browsers will abort an classic async one, but not a synchronous one. The drawback is that it freezes the page, but since the backend of event logging correctly aborts the request right away, it would be hardly felt. (I've already built something like that in production at dA). This change would imply modifying (or overloading) mw.eventLog to make it do a synchronous XHR when needed instead of using an image object. What do you think? Is the synchronous thing worth filing in Mingle?
I like this better than using timeouts that may not be enough. +1
Certainly a better solution as it does not take more time than necessary (I imagine on a fast connection way less than half sec is needed, so currently we are making the user wait for no reason). We can still set a timeout on the XHR object so this does not get too annoying for people with extremely slow connections.
I've just realized that we don't need onbeforeunload, since we capture a specific click. We just need a callback/deferred to tell us when the .log() call is done. Conveniently, ext.eventLogging already provides that. The technique I've described would be useful if we want to track people navigating away altogether (including entering a new URL in their browser). Worth keeping in mind, but not necessary for "site-link-click". https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/255