Suggestion on how to track user online activity

Hi.

I need to keep track of the real online users, that means it’s not enough for me to know the last page visited, I need to know if the user is still online. This means I cannot just keep track of the last time the user opened a page, because if they close the browser I would never know.

From what I could find the way to go is to use websockets. I found Ratchet library which seems to do something in the way I need.

Is there another way to do that? Keeping track of real time user activity?

thanks