mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +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',
|
browser: userAgentParsed.browser.name || 'NO_BROWSER',
|
||||||
os: userAgentParsed.os.name || 'NO_OS',
|
os: userAgentParsed.os.name || 'NO_OS',
|
||||||
device: userAgentParsed.device.type,
|
device: userAgentParsed.device.type,
|
||||||
|
session: sessionHash,
|
||||||
continent: geoLocation[0],
|
continent: geoLocation[0],
|
||||||
country: geoLocation[1],
|
country: geoLocation[1],
|
||||||
});
|
});
|
||||||
|
|
||||||
await visit.save();
|
await visit.save();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
await ProjectCountModel.updateOne({ project_id: pid }, { $inc: { 'visits': 1 } }, { upsert: true });
|
await ProjectCountModel.updateOne({ project_id: pid }, { $inc: { 'visits': 1 } }, { upsert: true });
|
||||||
await ProjectLimitModel.updateOne({ project_id: pid }, { $inc: { 'visits': 1 } });
|
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' }
|
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 event.save();
|
||||||
|
|
||||||
await ProjectCountModel.updateOne({ project_id: pid }, { $inc: { 'events': 1 } }, { upsert: true });
|
await ProjectCountModel.updateOne({ project_id: pid }, { $inc: { 'events': 1 } }, { upsert: true });
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export type TEvent = {
|
|||||||
project_id: Schema.Types.ObjectId,
|
project_id: Schema.Types.ObjectId,
|
||||||
name: string,
|
name: string,
|
||||||
metadata: Record<string, string>,
|
metadata: Record<string, string>,
|
||||||
|
session: string,
|
||||||
created_at: Date
|
created_at: Date
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ const EventSchema = new Schema<TEvent>({
|
|||||||
project_id: { type: Types.ObjectId, index: 1 },
|
project_id: { type: Types.ObjectId, index: 1 },
|
||||||
name: { type: String, required: true },
|
name: { type: String, required: true },
|
||||||
metadata: Schema.Types.Mixed,
|
metadata: Schema.Types.Mixed,
|
||||||
|
session: { type: String },
|
||||||
created_at: { type: Date, default: () => Date.now() },
|
created_at: { type: Date, default: () => Date.now() },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export type TVisit = {
|
|||||||
continent: string,
|
continent: string,
|
||||||
country: string,
|
country: string,
|
||||||
|
|
||||||
|
session: string,
|
||||||
device: string,
|
device: string,
|
||||||
|
|
||||||
website: string,
|
website: string,
|
||||||
@@ -27,6 +28,8 @@ const VisitSchema = new Schema<TVisit>({
|
|||||||
continent: { type: String },
|
continent: { type: String },
|
||||||
country: { type: String },
|
country: { type: String },
|
||||||
|
|
||||||
|
session: { type: String },
|
||||||
|
|
||||||
device: { type: String },
|
device: { type: String },
|
||||||
|
|
||||||
website: { type: String, required: true },
|
website: { type: String, required: true },
|
||||||
|
|||||||
Reference in New Issue
Block a user