added unique visitors analytics
only update it every hour
v1.18.x
barisusakli 10 years ago
parent cb934acb5d
commit 5d79d2a75a

@ -45,7 +45,18 @@ middleware.updateLastOnlineTime = function(req, res, next) {
user.updateLastOnlineTime(req.user.uid);
}
db.sortedSetScore('ip:recent', req.ip, function(err, score) {
if (err) {
return;
}
var today = new Date();
today.setHours(today.getHours(), 0, 0, 0);
if (!score || score < today.getTime()) {
db.sortedSetIncrBy('analytics:uniquevisitors', 1, today.getTime());
db.sortedSetAdd('ip:recent', Date.now(), req.ip || 'Unknown');
}
});
next();
};

@ -188,7 +188,7 @@ SocketAdmin.analytics.get = function(socket, data, callback) {
if (data.graph === 'traffic') {
async.parallel({
uniqueVisitors: function(next) {
getHourlyStatsForSet('ip:recent', data.amount, next);
getHourlyStatsForSet('analytics:uniquevisitors', data.amount, next);
},
pageviews: function(next) {
getHourlyStatsForSet('analytics:pageviews', data.amount, next);

Loading…
Cancel
Save