Hi there,
I am trying to determine how long users are on my webpage for.
My plan to do this was to record the time when the page is first loaded, and then again when they leave the page.
Recording the initial time the page is loaded is not difficult, but I am having difficulty in getting the time users are leaving. I have been trying to use the onunload() or onbeforeunload() (not sure what the difference is, maybe someone could explain?) methods in javascript to do this, but I need to call PHP code in these functions in order to put the times in a database, which I don't believe is possible (since PHP is server-side and Javascript client-side).
So to solve this, I thought maybe I could use AJAX. My problem is that I have no idea what AJAX function to call and/or how to use it to update the database using the onunload() function.
If anyone has any suggestions/explanations of how i could get the time that a user leaves my page (without requiring an extra pop-up to a new page), that would be awesome!
Thanks!