mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 14:35:47 +01:00
show monthly page views
This commit is contained in:
@@ -105,6 +105,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.version-check {
|
.version-check {
|
||||||
@@ -123,6 +125,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.monthly-pageviews {
|
||||||
|
width:50%;
|
||||||
|
}
|
||||||
|
|
||||||
.motd textarea {
|
.motd textarea {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -331,6 +331,11 @@ define('admin/general/dashboard', ['semver'], function(semver) {
|
|||||||
|
|
||||||
graphs.traffic.scale.xLabels = getHoursArray();
|
graphs.traffic.scale.xLabels = getHoursArray();
|
||||||
graphs.traffic.update();
|
graphs.traffic.update();
|
||||||
|
|
||||||
|
$('#pageViewsThisMonth').html(data.monthlyPageViews.thisMonth);
|
||||||
|
$('#pageViewsLastMonth').html(data.monthlyPageViews.lastMonth);
|
||||||
|
utils.addCommasToNumbers($('#pageViewsThisMonth'));
|
||||||
|
utils.addCommasToNumbers($('#pageViewsLastMonth'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ var cronJob = require('cron').CronJob,
|
|||||||
|
|
||||||
if (pageViews > 0) {
|
if (pageViews > 0) {
|
||||||
db.sortedSetIncrBy('analytics:pageviews', pageViews, today.getTime());
|
db.sortedSetIncrBy('analytics:pageviews', pageViews, today.getTime());
|
||||||
|
var month = new Date();
|
||||||
|
month.setMonth(month.getMonth(), 1);
|
||||||
|
month.setHours(0, 0, 0, 0);
|
||||||
|
db.sortedSetIncrBy('analytics:pageviews:month', pageViews, month.getTime());
|
||||||
pageViews = 0;
|
pageViews = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -199,6 +199,9 @@ SocketAdmin.analytics.get = function(socket, data, callback) {
|
|||||||
},
|
},
|
||||||
pageviews: function(next) {
|
pageviews: function(next) {
|
||||||
getHourlyStatsForSet('analytics:pageviews', data.amount, next);
|
getHourlyStatsForSet('analytics:pageviews', data.amount, next);
|
||||||
|
},
|
||||||
|
monthlyPageViews: function(next) {
|
||||||
|
getMonthlyPageViews(next);
|
||||||
}
|
}
|
||||||
}, callback);
|
}, callback);
|
||||||
}
|
}
|
||||||
@@ -227,20 +230,15 @@ function getHourlyStatsForSet(set, hours, callback) {
|
|||||||
hour.setHours(hour.getHours() - 1, 0, 0, 0);
|
hour.setHours(hour.getHours() - 1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.each(hoursArr, function(term, next) {
|
db.sortedSetScores(set, hoursArr, function(err, counts) {
|
||||||
if (set.indexOf('analytics') !== -1) {
|
if (err) {
|
||||||
db.sortedSetScore(set, term, function(err, count) {
|
return callback(err);
|
||||||
terms[term] = count || 0;
|
|
||||||
next(err);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
db.sortedSetCount(set, term, Date.now(), function(err, count) {
|
|
||||||
terms[term] = count || 0;
|
|
||||||
next(err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, function(err) {
|
hoursArr.forEach(function(term, index) {
|
||||||
|
terms[term] = counts[index] || 0;
|
||||||
|
});
|
||||||
|
|
||||||
var termsArr = [];
|
var termsArr = [];
|
||||||
|
|
||||||
hoursArr.reverse();
|
hoursArr.reverse();
|
||||||
@@ -248,7 +246,25 @@ function getHourlyStatsForSet(set, hours, callback) {
|
|||||||
termsArr.push(terms[hour]);
|
termsArr.push(terms[hour]);
|
||||||
});
|
});
|
||||||
|
|
||||||
callback(err, termsArr);
|
callback(null, termsArr);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMonthlyPageViews(callback) {
|
||||||
|
var thisMonth = new Date();
|
||||||
|
var lastMonth = new Date();
|
||||||
|
thisMonth.setMonth(thisMonth.getMonth(), 1);
|
||||||
|
thisMonth.setHours(0, 0, 0, 0);
|
||||||
|
lastMonth.setMonth(thisMonth.getMonth() - 1, 1);
|
||||||
|
lastMonth.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
var values = [thisMonth.getTime(), lastMonth.getTime()];
|
||||||
|
|
||||||
|
db.sortedSetScores('analytics:pageviews:month', values, function(err, scores) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
callback(null, {thisMonth: scores[0] || 0, lastMonth: scores[1] || 0});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +275,6 @@ SocketAdmin.getMoreEvents = function(socket, next, callback) {
|
|||||||
events.getLog(next, 5000, callback);
|
events.getLog(next, 5000, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
SocketAdmin.dismissFlag = function(socket, pid, callback) {
|
SocketAdmin.dismissFlag = function(socket, pid, callback) {
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
return callback('[[error:invalid-data]]');
|
return callback('[[error:invalid-data]]');
|
||||||
|
|||||||
@@ -10,6 +10,15 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<canvas id="analytics-traffic" width="100%" height="400"></canvas>
|
<canvas id="analytics-traffic" width="100%" height="400"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="text-center pull-left monthly-pageviews">
|
||||||
|
<div><strong id="pageViewsLastMonth"></strong></div>
|
||||||
|
<div>Page views Last Month</div>
|
||||||
|
</div>
|
||||||
|
<div class="text-center pull-left monthly-pageviews">
|
||||||
|
<div><strong id="pageViewsThisMonth"></strong></div>
|
||||||
|
<div>Page views This Month</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user