Analytics JS AJAX调用

I am writing some js code to send user-page interaction data to analytics server. I am in this context:

  1. No Google analytics.
  2. No third party library.

And I need to achieve:

  1. shouldn't block user navigation. (or as invisible as possible)
  2. should ensure each request is sent to the server.
  3. should be universal, not servlet solution for one site.

Currently what I observed from making a normal AJAX request is when I navigate to another page, the request is canceled from browser side, which indicated data loss.

Any comment/answer is welcome.