mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 22:57:12 +01:00
Updated events page.
This commit is contained in:
parent
3a97bfe11c
commit
c6b8114945
13 changed files with 122 additions and 46 deletions
|
|
@ -26,6 +26,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
async function clickhouseQuery(websiteId: string, filters: QueryFilters, pageParams?: PageParams) {
|
||||
const { pagedQuery, parseFilters, getDateStringSQL } = clickhouse;
|
||||
const { params, dateQuery, filterQuery } = await parseFilters(websiteId, filters);
|
||||
const { query } = pageParams;
|
||||
|
||||
return pagedQuery(
|
||||
`
|
||||
|
|
@ -46,9 +47,10 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
where website_id = {websiteId:UUID}
|
||||
${dateQuery}
|
||||
${filterQuery}
|
||||
${query ? `and (positionCaseInsensitive(event_name, {query:String}) > 0)` : ''}
|
||||
order by created_at desc
|
||||
`,
|
||||
params,
|
||||
{ ...params, query },
|
||||
pageParams,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import clickhouse from 'lib/clickhouse';
|
||||
import { EVENT_TYPE } from 'lib/constants';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import prisma from 'lib/prisma';
|
||||
import { QueryFilters } from 'lib/types';
|
||||
|
|
@ -25,7 +24,6 @@ async function relationalQuery(
|
|||
const { getTimestampDiffSQL, parseFilters, rawQuery } = prisma;
|
||||
const { filterQuery, joinSession, params } = await parseFilters(websiteId, {
|
||||
...filters,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
});
|
||||
|
||||
return rawQuery(
|
||||
|
|
@ -35,12 +33,15 @@ async function relationalQuery(
|
|||
count(distinct t.session_id) as "visitors",
|
||||
count(distinct t.visit_id) as "visits",
|
||||
count(distinct t.country) as "countries",
|
||||
count(t.event_name) as "countries",
|
||||
sum(case when t.event_type = 2 then 1 else 0 end) as "events",
|
||||
sum(case when t.c = 1 then 1 else 0 end) as "bounces",
|
||||
sum(${getTimestampDiffSQL('t.min_time', 't.max_time')}) as "totaltime",
|
||||
from (
|
||||
select
|
||||
website_event.session_id,
|
||||
website_event.visit_id,
|
||||
website_event.event_type,
|
||||
session.country,
|
||||
count(*) as "c",
|
||||
min(website_event.created_at) as "min_time",
|
||||
|
|
@ -49,9 +50,8 @@ async function relationalQuery(
|
|||
${joinSession}
|
||||
where website_event.website_id = {{websiteId::uuid}}
|
||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||
and event_type = {{eventType}}
|
||||
${filterQuery}
|
||||
group by 1, 2, 3
|
||||
group by 1, 2, 3, 4
|
||||
) as t
|
||||
`,
|
||||
params,
|
||||
|
|
@ -67,7 +67,6 @@ async function clickhouseQuery(
|
|||
const { rawQuery, parseFilters } = clickhouse;
|
||||
const { filterQuery, params } = await parseFilters(websiteId, {
|
||||
...filters,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
});
|
||||
|
||||
let sql = '';
|
||||
|
|
@ -79,12 +78,14 @@ async function clickhouseQuery(
|
|||
uniq(t.session_id) as "visitors",
|
||||
uniq(t.visit_id) as "visits",
|
||||
uniq(t.country) as "countries",
|
||||
sum(if(t.c = 1, 1, 0)) as "bounces",
|
||||
sumIf(1, t.event_type = 2) as "events",
|
||||
sumIf(1, t.c = 1) as "bounces",
|
||||
sum(max_time-min_time) as "totaltime"
|
||||
from (
|
||||
select
|
||||
session_id,
|
||||
visit_id,
|
||||
event_type,
|
||||
country,
|
||||
count(*) c,
|
||||
min(created_at) min_time,
|
||||
|
|
@ -92,9 +93,8 @@ async function clickhouseQuery(
|
|||
from website_event
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and event_type = {eventType:UInt32}
|
||||
${filterQuery}
|
||||
group by session_id, visit_id, country
|
||||
group by session_id, visit_id, event_type, country
|
||||
) as t;
|
||||
`;
|
||||
} else {
|
||||
|
|
@ -104,12 +104,14 @@ async function clickhouseQuery(
|
|||
uniq(session_id) as "visitors",
|
||||
uniq(visit_id) as "visits",
|
||||
uniq(country) as "countries",
|
||||
sumIf(1, t.event_type = 2) as "events",
|
||||
sumIf(1, t.c = 1) as "bounces",
|
||||
sum(max_time-min_time) as "totaltime"
|
||||
from (
|
||||
select
|
||||
session_id,
|
||||
visit_id,
|
||||
event_type,
|
||||
country,
|
||||
sum(views) c,
|
||||
min(min_time) min_time,
|
||||
|
|
@ -117,9 +119,8 @@ async function clickhouseQuery(
|
|||
from umami.website_event_stats_hourly "website_event"
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and event_type = {eventType:UInt32}
|
||||
${filterQuery}
|
||||
group by session_id, visit_id, country
|
||||
group by session_id, visit_id, event_type, country
|
||||
) as t;
|
||||
`;
|
||||
}
|
||||
|
|
@ -133,6 +134,7 @@ async function clickhouseQuery(
|
|||
bounces: Number(a.bounces),
|
||||
totaltime: Number(a.totaltime),
|
||||
countries: Number(a.countries),
|
||||
events: Number(a.events),
|
||||
};
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -14,10 +14,12 @@ export async function getWebsiteSessions(
|
|||
|
||||
async function relationalQuery(websiteId: string, filters: QueryFilters, pageParams: PageParams) {
|
||||
const { pagedQuery } = prisma;
|
||||
const { query } = pageParams;
|
||||
|
||||
const where = {
|
||||
...filters,
|
||||
id: websiteId,
|
||||
...prisma.getSearchParameters(query, [{ eventName: 'contains' }, { urlPath: 'contains' }]),
|
||||
};
|
||||
|
||||
return pagedQuery('session', { where }, pageParams);
|
||||
|
|
@ -26,6 +28,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
async function clickhouseQuery(websiteId: string, filters: QueryFilters, pageParams?: PageParams) {
|
||||
const { pagedQuery, parseFilters } = clickhouse;
|
||||
const { params, dateQuery, filterQuery } = await parseFilters(websiteId, filters);
|
||||
const { query } = pageParams;
|
||||
|
||||
return pagedQuery(
|
||||
`
|
||||
|
|
@ -49,6 +52,7 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||
where website_id = {websiteId:UUID}
|
||||
${dateQuery}
|
||||
${filterQuery}
|
||||
${query ? `and (positionCaseInsensitive(event_name, {query:String}) > 0)` : ''}
|
||||
group by session_id, website_id, hostname, browser, os, device, screen, language, country, subdivision1, city
|
||||
order by lastAt desc
|
||||
`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue