mika Posted March 13, 2016 Posted March 13, 2016 Is it possible to monitor user activity simple way? Ie. when was the last time user used keyboard or clicked something. Currently our software monitors only who are logged in but it doesn't tell us if user is actually doing anything or if user is only idling. Is there some common event(s) sent to server when user is active and if there is, what is the correct way to handle those event(s)? I know I can code system that updates database every time user actually does something, but that is not really an option because it would be time consuming to cover whole software for user activity and there would be bound to be gaps. This is not crucial to us, but it would certainly be helpful. --Mika Quote
Sherzod Posted March 13, 2016 Posted March 13, 2016 Hi, Here is pure JavaScript way to track the idle time and when it reach certain limit do some action, you can modify accordingly and use: var IDLE_TIMEOUT = 60; //seconds var _idleSecondsCounter = 0; document.onclick = function() { _idleSecondsCounter = 0; }; document.onmousemove = function() { _idleSecondsCounter = 0; }; document.onkeypress = function() { _idleSecondsCounter = 0; }; window.setInterval(CheckIdleTime, 1000); function CheckIdleTime() { _idleSecondsCounter++; var oPanel = document.getElementById("SecondsUntilExpire"); if (oPanel) oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + ""; if (_idleSecondsCounter >= IDLE_TIMEOUT) { alert("Time expired!"); document.location.href = "logout.html"; } } Source: http://stackoverflow.com/questions/13246378/detecting-user-inactivity-over-a-browser-purely-through-javascript http://stackoverflow.com/questions/9564602/how-to-know-browser-idle-time/9564811#9564811 Best regards. Quote
mika Posted March 14, 2016 Author Posted March 14, 2016 This seems quite easy to integrate to our software Thank you! Quote
mmx110 Posted July 16, 2016 Posted July 16, 2016 Hi Delphi Developer! How I can Integrate this code with UniEvents? Thanks - Regards Quote
Sherzod Posted July 16, 2016 Posted July 16, 2016 Hi! For example: 1. MainForm.Script: var IDLE_TIMEOUT = 60; //seconds var _idleSecondsCounter = 0; document.onclick = function() { _idleSecondsCounter = 0; }; document.onmousemove = function() { _idleSecondsCounter = 0; }; document.onkeypress = function() { _idleSecondsCounter = 0; }; window.setInterval(CheckIdleTime, 1000); function CheckIdleTime() { _idleSecondsCounter++; var oPanel = document.getElementById("SecondsUntilExpire"); if (oPanel) oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + ""; if (_idleSecondsCounter >= IDLE_TIMEOUT) { //alert("Time expired!"); //document.location.href = "logout.html"; ajaxRequest(MainForm.form, '_idle_timeout', []); } } 2. MainForm->onAjaxEvent: procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = '_idle_timeout' then begin // your logic ShowMessage('idle_timeout'); end; end; Best regards. 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.