mirror of
https://github.com/umami-software/umami.git
synced 2026-02-05 21:27:20 +01:00
Session details screen.
This commit is contained in:
parent
c3c3b46ef6
commit
f32bf0a2e0
21 changed files with 252 additions and 33 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { getSessions, getEvents, getPageviewStats, getSessionStats } from 'queries/index';
|
||||
import { getWebsiteSessions, getEvents, getPageviewStats, getSessionStats } from 'queries/index';
|
||||
|
||||
const MAX_SIZE = 50;
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ export async function getRealtimeData(
|
|||
const filters = { startDate, endDate: new Date(), unit: 'minute', timezone };
|
||||
const [events, sessions, pageviews, sessionviews] = await Promise.all([
|
||||
getEvents(websiteId, { startDate, timezone }, { pageSize: 10000 }),
|
||||
getSessions(websiteId, { startDate, timezone }, { pageSize: 10000 }),
|
||||
getWebsiteSessions(websiteId, { startDate, timezone }, { pageSize: 10000 }),
|
||||
getPageviewStats(websiteId, filters),
|
||||
getSessionStats(websiteId, filters),
|
||||
]);
|
||||
|
|
|
|||
44
src/queries/analytics/sessions/getSessionActivity.ts
Normal file
44
src/queries/analytics/sessions/getSessionActivity.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, PRISMA, CLICKHOUSE } from 'lib/db';
|
||||
|
||||
export async function getSessionActivity(...args: [websiteId: string, sessionId: string]) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, sessionId: string) {
|
||||
return prisma.client.websiteEvent.findMany({
|
||||
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,
|
||||
created_at as createdAt,
|
||||
url_path as urlPath,
|
||||
url_query as urlQuery,
|
||||
referrer_domain as referrerDomain,
|
||||
event_id as eventId,
|
||||
event_type as eventType,
|
||||
event_name as eventName,
|
||||
visit_id as visitId
|
||||
from website_event
|
||||
where website_id = {websiteId:UUID}
|
||||
and session_id = {sessionId:UUID}
|
||||
order by created_at desc
|
||||
`,
|
||||
{ websiteId, sessionId },
|
||||
);
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ import prisma from 'lib/prisma';
|
|||
import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, PRISMA, CLICKHOUSE } from 'lib/db';
|
||||
|
||||
export async function getSession(...args: [websiteId: string, sessionId: string]) {
|
||||
export async function getWebsiteSession(...args: [websiteId: string, sessionId: string]) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
|
|
@ -13,6 +13,7 @@ async function relationalQuery(websiteId: string, sessionId: string) {
|
|||
return prisma.client.session.findUnique({
|
||||
where: {
|
||||
id: sessionId,
|
||||
websiteId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
@ -35,7 +36,10 @@ async function clickhouseQuery(websiteId: string, sessionId: string) {
|
|||
subdivision1,
|
||||
city,
|
||||
min(created_at) as firstAt,
|
||||
max(created_at) as lastAt
|
||||
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}
|
||||
|
|
@ -3,7 +3,7 @@ import clickhouse from 'lib/clickhouse';
|
|||
import { runQuery, PRISMA, CLICKHOUSE } from 'lib/db';
|
||||
import { PageParams, QueryFilters } from 'lib/types';
|
||||
|
||||
export async function getSessions(
|
||||
export async function getWebsiteSessions(
|
||||
...args: [websiteId: string, filters?: QueryFilters, pageParams?: PageParams]
|
||||
) {
|
||||
return runQuery({
|
||||
|
|
@ -19,9 +19,10 @@ export * from './analytics/reports/getUTM';
|
|||
export * from './analytics/pageviews/getPageviewMetrics';
|
||||
export * from './analytics/pageviews/getPageviewStats';
|
||||
export * from './analytics/sessions/createSession';
|
||||
export * from './analytics/sessions/getSession';
|
||||
export * from './analytics/sessions/getWebsiteSession';
|
||||
export * from './analytics/sessions/getSessionMetrics';
|
||||
export * from './analytics/sessions/getSessions';
|
||||
export * from './analytics/sessions/getWebsiteSessions';
|
||||
export * from './analytics/sessions/getSessionActivity';
|
||||
export * from './analytics/sessions/getSessionStats';
|
||||
export * from './analytics/sessions/saveSessionData';
|
||||
export * from './analytics/getActiveVisitors';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue