mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-09 23:48:36 +01:00
add session to visits and events
This commit is contained in:
@@ -77,12 +77,15 @@ async function process_visit(data: Record<string, string>, sessionHash: string)
|
||||
browser: userAgentParsed.browser.name || 'NO_BROWSER',
|
||||
os: userAgentParsed.os.name || 'NO_OS',
|
||||
device: userAgentParsed.device.type,
|
||||
session: sessionHash,
|
||||
continent: geoLocation[0],
|
||||
country: geoLocation[1],
|
||||
});
|
||||
|
||||
await visit.save();
|
||||
|
||||
|
||||
|
||||
await ProjectCountModel.updateOne({ project_id: pid }, { $inc: { 'visits': 1 } }, { upsert: true });
|
||||
await ProjectLimitModel.updateOne({ project_id: pid }, { $inc: { 'visits': 1 } });
|
||||
|
||||
@@ -118,7 +121,7 @@ async function process_event(data: Record<string, string>, sessionHash: string)
|
||||
metadataObject = { error: 'Error parsing metadata' }
|
||||
}
|
||||
|
||||
const event = new EventModel({ project_id: pid, name, metadata: metadataObject });
|
||||
const event = new EventModel({ project_id: pid, name, metadata: metadataObject, session: sessionHash });
|
||||
await event.save();
|
||||
|
||||
await ProjectCountModel.updateOne({ project_id: pid }, { $inc: { 'events': 1 } }, { upsert: true });
|
||||
|
||||
@@ -4,6 +4,7 @@ export type TEvent = {
|
||||
project_id: Schema.Types.ObjectId,
|
||||
name: string,
|
||||
metadata: Record<string, string>,
|
||||
session: string,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
@@ -11,6 +12,7 @@ const EventSchema = new Schema<TEvent>({
|
||||
project_id: { type: Types.ObjectId, index: 1 },
|
||||
name: { type: String, required: true },
|
||||
metadata: Schema.Types.Mixed,
|
||||
session: { type: String },
|
||||
created_at: { type: Date, default: () => Date.now() },
|
||||
})
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ export type TVisit = {
|
||||
continent: string,
|
||||
country: string,
|
||||
|
||||
session: string,
|
||||
device: string,
|
||||
|
||||
website: string,
|
||||
@@ -26,6 +27,8 @@ const VisitSchema = new Schema<TVisit>({
|
||||
|
||||
continent: { type: String },
|
||||
country: { type: String },
|
||||
|
||||
session: { type: String },
|
||||
|
||||
device: { type: String },
|
||||
|
||||
|
||||
Reference in New Issue
Block a user