mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-11 18:13:04 +01:00
feat: closes #13578, increase uniquevisitors
on ap pageviews like normal pageviews
This commit is contained in:
@@ -102,8 +102,17 @@ Analytics.pageView = async function (payload) {
|
||||
local.pageViewsGuest += 1;
|
||||
}
|
||||
|
||||
if (payload.ip) {
|
||||
const score = await db.sortedSetScore('ip:recent', payload.ip);
|
||||
await incrementUniqueVisitors(payload.ip);
|
||||
};
|
||||
|
||||
Analytics.apPageView = async function ({ ip }) {
|
||||
local.apPageViews += 1;
|
||||
await incrementUniqueVisitors(ip);
|
||||
};
|
||||
|
||||
async function incrementUniqueVisitors(ip) {
|
||||
if (ip) {
|
||||
const score = await db.sortedSetScore('ip:recent', ip);
|
||||
let record = !score;
|
||||
if (score) {
|
||||
const today = new Date();
|
||||
@@ -113,14 +122,10 @@ Analytics.pageView = async function (payload) {
|
||||
|
||||
if (record) {
|
||||
local.uniquevisitors += 1;
|
||||
await db.sortedSetAdd('ip:recent', Date.now(), payload.ip);
|
||||
await db.sortedSetAdd('ip:recent', Date.now(), ip);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Analytics.apPageView = function () {
|
||||
local.apPageViews += 1;
|
||||
};
|
||||
}
|
||||
|
||||
Analytics.writeData = async function () {
|
||||
const today = new Date();
|
||||
|
||||
@@ -10,7 +10,7 @@ const middleware = module.exports;
|
||||
middleware.enabled = async (req, res, next) => next(!meta.config.activitypubEnabled ? 'route' : undefined);
|
||||
|
||||
middleware.pageview = async (req, res, next) => {
|
||||
analytics.apPageView();
|
||||
await analytics.apPageView({ ip: req.ip });
|
||||
next();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user