feat: 访问埋点统计——VisitLog模型+/api GET埋点中间件(小程序/H5/直接访问来源识别)+访问统计接口+看板PV/UV/来源分布卡+日志页访问埋点Tab

This commit is contained in:
Hermes Agent
2026-09-15 21:29:30 +08:00
parent 62fb40e415
commit f91d8f5418
6 changed files with 137 additions and 3 deletions
+28
View File
@@ -0,0 +1,28 @@
const mongoose = require('mongoose')
const { Schema } = mongoose
/**
* 访问埋点模型
* 记录所有 /api 页面级请求(小程序 + H5 + 未知来源),供管理后台访问统计使用。
* 与 LoginLog(登录行为)分离:匿名 H5 访问没有用户也能记录。
*/
const VisitLogSchema = new Schema({
path: { type: String, default: '' },
// 来源:小程序 / H5 / 直接访问
source: { type: String, default: '直接访问', index: true },
ip: { type: String, default: '', index: true },
userId: { type: Schema.Types.ObjectId, ref: 'User', default: null },
os: { type: String, default: '' },
browser: { type: String, default: '' },
device: { type: String, default: '' },
createdAt: { type: Date, default: Date.now, index: true }
})
VisitLogSchema.index({ createdAt: -1 })
module.exports = mongoose.model('VisitLog', VisitLogSchema)
+3 -1
View File
@@ -12,6 +12,7 @@ const Feedback = require('./Feedback')
const Trend = require('./Trend')
const VerificationCode = require('./VerificationCode')
const CoinLedger = require('./CoinLedger')
const VisitLog = require('./VisitLog')
module.exports = {
User,
@@ -27,5 +28,6 @@ module.exports = {
Feedback,
Trend,
VerificationCode,
CoinLedger
CoinLedger,
VisitLog
}