We\'re creating a click tracking app, that builds heatmaps. I\'m writing a script which users are suppose to insert into their pages for tracking to work.
It works
I would take a look at the navigator sendBeacon API mentioned in this stack overflow answer or directly linked to here.
From the description on the site
navigator.sendBeacon(url, data) - This method addresses the needs of analytics and diagnostics code that typically attempts to send data to a web server prior to the unloading of the document.