Running a test of an app on my network want to log user activity

I want to track the users in my app which is hosted on a network.
how can I do this? I have found a way to log when the link is clicked by the users but I want to track when they close it as well and how long has the page been active.