mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 14:17:13 +01:00
Session details screen.
This commit is contained in:
parent
c3c3b46ef6
commit
f32bf0a2e0
21 changed files with 252 additions and 33 deletions
50
src/queries/analytics/sessions/getWebsiteSession.ts
Normal file
50
src/queries/analytics/sessions/getWebsiteSession.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, PRISMA, CLICKHOUSE } from 'lib/db';
|
||||
|
||||
export async function getWebsiteSession(...args: [websiteId: string, sessionId: string]) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, sessionId: string) {
|
||||
return prisma.client.session.findUnique({
|
||||
where: {
|
||||
id: sessionId,
|
||||
websiteId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function clickhouseQuery(websiteId: string, sessionId: string) {
|
||||
const { rawQuery } = clickhouse;
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select
|
||||
session_id as id,
|
||||
website_id as websiteId,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
subdivision1,
|
||||
city,
|
||||
min(created_at) as firstAt,
|
||||
max(created_at) as lastAt,
|
||||
uniq(visit_id) as "visits",
|
||||
sumIf(1, event_type = 1) as "views",
|
||||
sumIf(1, event_type = 2) as "events"
|
||||
from website_event
|
||||
where website_id = {websiteId:UUID}
|
||||
and session_id = {sessionId:UUID}
|
||||
group by session_id, website_id, hostname, browser, os, device, screen, language, country, subdivision1, city
|
||||
`,
|
||||
{ websiteId, sessionId },
|
||||
).then(result => result?.[0]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue