This commit is contained in:
payacom
2026-09-13 21:32:36 +03:30
parent 90c5f94b57
commit c302aea177
49 changed files with 4063 additions and 920 deletions

View File

@@ -0,0 +1,66 @@
const mongoose = require('mongoose')
// رویدادهای خام رفتار کاربر (بازدید صفحه، کلیک، شروع/پایان نشست) — برای بخش
// «آنالیتیکس» پنل. هر رکورد سبک نگه داشته می‌شه چون حجم بالایی داره؛ تجمیع/گزارش‌گیری
// توی کنترلرهای panel/analytics انجام می‌شه، نه اینجا
const AnalyticsEventSchema = new mongoose.Schema(
{
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
default: null,
index: true
},
sessionId: {
type: String,
required: true,
index: true
},
type: {
type: String,
enum: ['session_start', 'page_view', 'click'],
required: true,
index: true
},
// page_view/click: مسیر صفحه‌ای که رویداد توش رخ داده
path: {
type: String,
default: null
},
// فقط page_view: چند میلی‌ثانیه کاربر روی این صفحه مونده (موقع رفتن به صفحه‌ی
// بعدی یا بستن تب محاسبه و ارسال می‌شه)
durationMs: {
type: Number,
default: null
},
// فقط click: شناسه‌ی قابل‌خوندنِ عنصر کلیک‌شده (data-analytics-id یا برچسب/متن آن)
label: {
type: String,
default: null
},
platform: {
type: String,
enum: ['web', 'android', 'ios'],
required: true,
index: true
},
device: {
type: String,
default: null
},
browser: {
type: String,
default: null
},
os: {
type: String,
default: null
}
},
{ timestamps: true }
)
AnalyticsEventSchema.index({ createdAt: -1 })
AnalyticsEventSchema.index({ type: 1, createdAt: -1 })
module.exports = mongoose.model('AnalyticsEvent', AnalyticsEventSchema)