mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-06 08:07:49 +02: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;
|
local.pageViewsGuest += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload.ip) {
|
await incrementUniqueVisitors(payload.ip);
|
||||||
const score = await db.sortedSetScore('ip:recent', 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;
|
let record = !score;
|
||||||
if (score) {
|
if (score) {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
@@ -113,14 +122,10 @@ Analytics.pageView = async function (payload) {
|
|||||||
|
|
||||||
if (record) {
|
if (record) {
|
||||||
local.uniquevisitors += 1;
|
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 () {
|
Analytics.writeData = async function () {
|
||||||
const today = new Date();
|
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.enabled = async (req, res, next) => next(!meta.config.activitypubEnabled ? 'route' : undefined);
|
||||||
|
|
||||||
middleware.pageview = async (req, res, next) => {
|
middleware.pageview = async (req, res, next) => {
|
||||||
analytics.apPageView();
|
await analytics.apPageView({ ip: req.ip });
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user