feat: 访问埋点统计——VisitLog模型+/api GET埋点中间件(小程序/H5/直接访问来源识别)+访问统计接口+看板PV/UV/来源分布卡+日志页访问埋点Tab
This commit is contained in:
@@ -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)
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user