mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-05 17:05:46 +01:00
fix websiteSession screens
This commit is contained in:
parent
917916c224
commit
7bc5635b9d
@ -17,22 +17,22 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||
return rawQuery(
|
||||
`
|
||||
select
|
||||
website_event.session_id as sessionId,
|
||||
website_event.event_name as eventName,
|
||||
website_event.created_at as createdAt,
|
||||
website_event.session_id as "sessionId",
|
||||
website_event.event_name as "eventName",
|
||||
website_event.created_at as "createdAt",
|
||||
session.browser,
|
||||
session.os,
|
||||
session.device,
|
||||
session.country,
|
||||
session.url_path as urlPath,
|
||||
session.referrer_domain as referrerDomain
|
||||
website_event.url_path as "urlPath",
|
||||
website_event.referrer_domain as "referrerDomain"
|
||||
from website_event
|
||||
inner join session
|
||||
on session.session_id = website_event.session_id
|
||||
where website_id = {{websiteId::uuid}}
|
||||
where website_event.website_id = {{websiteId::uuid}}
|
||||
${filterQuery}
|
||||
${dateQuery}
|
||||
order by created_at asc
|
||||
order by website_event.created_at asc
|
||||
limit 100
|
||||
`,
|
||||
params,
|
||||
|
@ -67,8 +67,8 @@ export async function getRealtimeData(websiteId: string, criteria: { startDate:
|
||||
visitors: sessions,
|
||||
},
|
||||
totals: {
|
||||
views: pageviews.reduce((sum: number, { y }: { y: number }) => sum + y, 0),
|
||||
visitors: sessions.reduce((sum: number, { y }: { y: number }) => sum + y, 0),
|
||||
views: pageviews.reduce((sum: number, { y }: { y: number }) => Number(sum) + Number(y), 0),
|
||||
visitors: sessions.reduce((sum: number, { y }: { y: number }) => Number(sum) + Number(y), 0),
|
||||
events: activity.filter(e => e.eventName).length,
|
||||
countries: Object.keys(countries).length,
|
||||
},
|
||||
|
@ -19,7 +19,7 @@ async function relationalQuery(
|
||||
) {
|
||||
return prisma.client.websiteEvent.findMany({
|
||||
where: {
|
||||
id: sessionId,
|
||||
sessionId,
|
||||
websiteId,
|
||||
createdAt: { gte: startDate, lte: endDate },
|
||||
},
|
||||
|
@ -10,12 +10,26 @@ export async function getSessionData(...args: [websiteId: string, sessionId: str
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, sessionId: string) {
|
||||
return prisma.client.sessionData.findMany({
|
||||
where: {
|
||||
id: sessionId,
|
||||
websiteId,
|
||||
},
|
||||
});
|
||||
const { rawQuery } = prisma;
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select
|
||||
website_id as "websiteId",
|
||||
session_id as "sessionId",
|
||||
data_key as "dataKey",
|
||||
data_type as "dataType",
|
||||
replace(string_value, '.0000', '') 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}}
|
||||
order by data_key asc
|
||||
`,
|
||||
{ websiteId, sessionId },
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(websiteId: string, sessionId: string) {
|
||||
@ -28,7 +42,7 @@ async function clickhouseQuery(websiteId: string, sessionId: string) {
|
||||
session_id as sessionId,
|
||||
data_key as dataKey,
|
||||
data_type as dataType,
|
||||
string_value as stringValue,
|
||||
replace(string_value, '.0000', '') as stringValue,
|
||||
number_value as numberValue,
|
||||
date_value as dateValue,
|
||||
created_at as createdAt
|
||||
|
@ -10,12 +10,53 @@ export async function getWebsiteSession(...args: [websiteId: string, sessionId:
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, sessionId: string) {
|
||||
return prisma.client.session.findUnique({
|
||||
where: {
|
||||
id: sessionId,
|
||||
websiteId,
|
||||
},
|
||||
});
|
||||
const { rawQuery, getTimestampDiffSQL } = prisma;
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select id,
|
||||
website_id as "websiteId",
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
subdivision1,
|
||||
city,
|
||||
min(min_time) as "firstAt",
|
||||
max(max_time) as "lastAt",
|
||||
count(distinct visit_id) as visits,
|
||||
sum(views) as views,
|
||||
sum(events) as events,
|
||||
sum(${getTimestampDiffSQL('min_time', 'max_time')}) as "totaltime"
|
||||
from (select
|
||||
session.session_id as id,
|
||||
website_event.visit_id,
|
||||
session.website_id,
|
||||
session.hostname,
|
||||
session.browser,
|
||||
session.os,
|
||||
session.device,
|
||||
session.screen,
|
||||
session.language,
|
||||
session.country,
|
||||
session.subdivision1,
|
||||
session.city,
|
||||
min(website_event.created_at) as min_time,
|
||||
max(website_event.created_at) as max_time,
|
||||
sum(case when website_event.event_type = 1 then 1 else 0 end) as views,
|
||||
sum(case when website_event.event_type = 1 then 1 else 0 end) as events
|
||||
from session
|
||||
join website_event on website_event.session_id = session.session_id
|
||||
where session.website_id = {{websiteId::uuid}}
|
||||
and session.session_id = {{sessionId::uuid}}
|
||||
group by session.session_id, visit_id, session.website_id, session.hostname, session.browser, session.os, session.device, session.screen, session.language, session.country, session.subdivision1, session.city) t
|
||||
group by id, website_id, hostname, browser, os, device, screen, language, country, subdivision1, city;
|
||||
`,
|
||||
{ websiteId, sessionId },
|
||||
).then(result => result?.[0]);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(websiteId: string, sessionId: string) {
|
||||
|
Loading…
Reference in New Issue
Block a user