mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 14:47:14 +01:00
Added session data display.
This commit is contained in:
parent
f32bf0a2e0
commit
b3e6e52473
23 changed files with 239 additions and 34 deletions
|
|
@ -4,7 +4,7 @@ import clickhouse from 'lib/clickhouse';
|
|||
import kafka from 'lib/kafka';
|
||||
import prisma from 'lib/prisma';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import { saveEventData } from 'queries/analytics/eventData/saveEventData';
|
||||
import { saveEventData } from './saveEventData';
|
||||
|
||||
export async function saveEvent(args: {
|
||||
websiteId: string;
|
||||
|
|
|
|||
41
src/queries/analytics/sessions/getSessionData.ts
Normal file
41
src/queries/analytics/sessions/getSessionData.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, PRISMA, CLICKHOUSE } from 'lib/db';
|
||||
|
||||
export async function getSessionData(...args: [websiteId: string, sessionId: string]) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, sessionId: string) {
|
||||
return prisma.client.sessionData.findMany({
|
||||
where: {
|
||||
id: sessionId,
|
||||
websiteId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function clickhouseQuery(websiteId: string, sessionId: string) {
|
||||
const { rawQuery } = clickhouse;
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select
|
||||
website_id as websiteId,
|
||||
session_id as sessionId,
|
||||
data_key as dataKey,
|
||||
data_type as dataType,
|
||||
string_value as stringValue,
|
||||
number_value as numberValue,
|
||||
date_value as dateValue,
|
||||
created_at as createdAt
|
||||
from session_data
|
||||
where website_id = {websiteId:UUID}
|
||||
and session_id = {sessionId:UUID}
|
||||
`,
|
||||
{ websiteId, sessionId },
|
||||
);
|
||||
}
|
||||
|
|
@ -37,9 +37,9 @@ async function clickhouseQuery(websiteId: string, sessionId: string) {
|
|||
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"
|
||||
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}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
subdivision1,
|
||||
city,
|
||||
min(created_at) as firstAt,
|
||||
max(created_at) as lastAt
|
||||
max(created_at) as lastAt,
|
||||
uniq(visit_id) as visits
|
||||
from website_event
|
||||
where website_id = {websiteId:UUID}
|
||||
${dateQuery}
|
||||
|
|
@ -52,5 +53,8 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
`,
|
||||
params,
|
||||
pageParams,
|
||||
);
|
||||
).then((result: any) => ({
|
||||
...result,
|
||||
visits: Number(result.visits),
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ export * from 'queries/prisma/team';
|
|||
export * from 'queries/prisma/teamUser';
|
||||
export * from 'queries/prisma/user';
|
||||
export * from 'queries/prisma/website';
|
||||
export * from './analytics/events/getEventDataEvents';
|
||||
export * from './analytics/events/getEventDataFields';
|
||||
export * from './analytics/events/getEventDataStats';
|
||||
export * from './analytics/events/getEventDataUsage';
|
||||
export * from './analytics/events/getEventMetrics';
|
||||
export * from './analytics/events/getEventUsage';
|
||||
export * from './analytics/events/getEvents';
|
||||
export * from './analytics/eventData/getEventDataEvents';
|
||||
export * from './analytics/eventData/getEventDataFields';
|
||||
export * from './analytics/eventData/getEventDataStats';
|
||||
export * from './analytics/eventData/getEventDataUsage';
|
||||
export * from './analytics/events/getEventUsage';
|
||||
export * from './analytics/events/saveEvent';
|
||||
export * from './analytics/reports/getFunnel';
|
||||
export * from './analytics/reports/getJourney';
|
||||
|
|
@ -20,6 +20,7 @@ export * from './analytics/pageviews/getPageviewMetrics';
|
|||
export * from './analytics/pageviews/getPageviewStats';
|
||||
export * from './analytics/sessions/createSession';
|
||||
export * from './analytics/sessions/getWebsiteSession';
|
||||
export * from './analytics/sessions/getSessionData';
|
||||
export * from './analytics/sessions/getSessionMetrics';
|
||||
export * from './analytics/sessions/getWebsiteSessions';
|
||||
export * from './analytics/sessions/getSessionActivity';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue