PDA

View Full Version : User Online Duration etc... but then something unexpected



sitNsmile
05-03-2014, 06:25 PM
Okay,

So i've built a JS that communicates to the server (php).

a User enters the website, it adds a 24 hour cookie and a session cookie (both of which have a random number generated "key". If they have already been on the site, such as a session cookie or the 24 hour, the same key will be used.

Every 10 seconds they are on the page, it Pings a "new Image()" url, that sends the "key" to the server. the server then logs that key with their IP address, that way the combos could be endless and multiple users on the same IP can be entered, but keeping one log for one computer (to be accurate on how many real users are online)

I count their mouse movements. document.onmousemove (and if they do not move the mouse on the page for more than 2 minutes, they are now idle and I no longer send the Ping), the database removes users that have been idle/inactive for 3 minutes. (gives some buffer and forgiveness time). anyways all that seems to work great.

But I started logging the Time they entered and the last time they sent a ping to the server. The numbers are outstanding. I have decided to also delete users that have "entered" over 30 minutes ago, cause the average user doesnt stay on the site that long and there is a HUGE amount of users on the site too long to be real. That is what IDLE was for. if they dont move the mouse, they are idle, however, 2,000+ users online, 150 of them have been on the site longer than 20 minutes and moving the mouse (cause they are not idle), if I didnt remove the 30minute+ these guys would be on here for hours, and that would mess up the avg duration time.

I am lost for words. I'm trying to build a very accurate online counter (instant) , but how could someone be on the site that long, what's causing them to continue to send a ping to the server. Makes no sense.

sitNsmile
05-03-2014, 08:36 PM
Here is the JS I am running with.




var onses=decodeURIComponent(_srread('__SE3'));
var oncook=decodeURIComponent(_srread('__ON3'));
if(onses==''){var key=Math.floor((Math.random()*99999999)+1).toString();var bk=key;}else{var bk=onses;}

sr_pinge(1);
var idleTime = 0;
var idleInterval = setInterval(sr_idletime,1000);

function addEvent(evnt, elem, func) {
if (elem.addEventListener) {
elem.addEventListener(evnt,func,false);
}
else if (elem.attachEvent) {
elem.attachEvent("on"+evnt, func);
}
else {
elem[evnt] = func;
}
}

addEvent('mousemove',document,sr_movements);
function sr_movements(){idleTime=0;}
function sr_idletime() {
idleTime = idleTime + 1;
if (idleTime > 60) {
if (this.ping) {
clearInterval(this.ping);
this.ping=false;
}
}
else {
if (this.ping) {

}
else {
sr_ping();
}
}
}

function sr_ping(){this.ping=setInterval(function(){sr_pinge(0);},15000);}
function sr_pinge(pv) {
returned = 0;
if (pv==1) {
if (oncook=='') {
var ontime = new Date(),onexpire=ontime.setTime(ontime.getTime()+86400000);
_srset('__ON3',encodeURIComponent(bk),ontime);
_srset('__SE3',encodeURIComponent(bk));
}
else {
if (onses=='') {
returned = 1;
_srset('__SE3',encodeURIComponent(bk));
}
}
}
var im = new Image();
var img = 'http://'+domain+'/o/?v='+v+'&pv='+pv+'&r='+returned+'&k='+encodeURIComponent(bk);
img += '&a='+options.account_id+'&dn='+en(docdomain)+'&dt='+new Date().getTime();
im.src = img;
}