Jump to content

User activity / Idle time


mika

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 months later...

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.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...