Perspective session connection closed unexpectedly

I have some clean-up that needs to occur when a session ends. If the user logs out this is a simple task. On tablets, sometimes the user just kills the application rather than logging out. Is there a way to trigger a Gateway script or session script to run when this occurs? When the operator does this, it generates a log in the event log, but I don't know how to run a script off of an specific error in the log.

There is a session event for this, but note that it runs after a timeout, since browsers generally do not affirmatively close sessions.

Yes, there are Session Events, including the Shutdown Event. Note that a user logging out does not shut down the session, so be wary of logic dependent on a user logging out.

Thanks that worked!