I was just reading how to check users leave a page earlier on when suddenly I thought of performing AJAX when user leaves the page to send analytical data back to the server.
Is performing AJAX on the onunload
event a good or bad practice/implementation?
Performing AJAX calls on unload does not work very well in all situations. Usually, the web browser closes the panel almost immediately and the AJAX call may be lost.
If you want to send analytical data, I suggest to send them in advance of closing the page. For example, send it after 5sec, then 10sec, 20sec, etc. Use unique identifier to find the latest information. The interval is up to you based on how precise measuring you need and not to annoy the user for additional bandwidth :-)