Please see my comments to the question. You should understand, not quite possible, unless you do authentication.
If the user is authenticated, it makes more sense.
Still, it would be much better to detect access to your site (log in, log out). Imagine the user loads another page not closing the page you are counting. Is the page in question left or not? You cannot detect activation of the pages, as this is not an event visible to the Web application.
and sending HTTP request to the site using Ajax: