How to monitor users' time spent on thingworx
I am trying to track how much time users spend on thingworx. It is kind of like how this PTC community portal tracks how many minutes each user spends here.
I have a couple of subscriptions that tracks when a user logs in and when a user logs out. It updates a property called trueLastConnection, when the following "SecurityMonitor" events occur:
- LoginSucceeded
- Logout
In the subscription called "UpdateTrueLastConnectionLogout", I have the following code:
var currentDate = new Date();
Users[eventData.user].TotalMinutesOnline = Users[eventData.user].TotalMinutesOnline + ((currentDate - Users[eventData.user].trueLastConnection)/60000);
Users[eventData.user].trueLastConnection = currentDate;
This subscription is triggered by the "SecurityMonitor" event called "Logout".
I expected it to update the user property called "TotalMinutesOnline"; however, I noticed that it only works if the user actually clicks on the logout button. If the user closes the tab or browser, it seems the "TotalMinutesOnline" property does not get updated. Is there a way to check how much time a user spends on thingworx?

