mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
implement visit duration
This commit is contained in:
parent
fc758745dc
commit
f9c7129a3e
@ -1,6 +1,7 @@
|
|||||||
import { useMessages } from 'components/hooks';
|
import { useMessages } from 'components/hooks';
|
||||||
import MetricCard from 'components/metrics/MetricCard';
|
import MetricCard from 'components/metrics/MetricCard';
|
||||||
import MetricsBar from 'components/metrics/MetricsBar';
|
import MetricsBar from 'components/metrics/MetricsBar';
|
||||||
|
import { formatShortTime } from 'lib/format';
|
||||||
|
|
||||||
export function SessionStats({ data }) {
|
export function SessionStats({ data }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
@ -10,6 +11,11 @@ export function SessionStats({ data }) {
|
|||||||
<MetricCard label={formatMessage(labels.visits)} value={data?.visits} />
|
<MetricCard label={formatMessage(labels.visits)} value={data?.visits} />
|
||||||
<MetricCard label={formatMessage(labels.views)} value={data?.views} />
|
<MetricCard label={formatMessage(labels.views)} value={data?.views} />
|
||||||
<MetricCard label={formatMessage(labels.events)} value={data?.events} />
|
<MetricCard label={formatMessage(labels.events)} value={data?.events} />
|
||||||
|
<MetricCard
|
||||||
|
label={formatMessage(labels.visitDuration)}
|
||||||
|
value={data?.totaltime / data?.visits}
|
||||||
|
formatValue={n => `${+n < 0 ? '-' : ''}${formatShortTime(Math.abs(~~n), ['m', 's'], ' ')}`}
|
||||||
|
/>
|
||||||
</MetricsBar>
|
</MetricsBar>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,8 @@ async function clickhouseQuery(websiteId: string, sessionId: string) {
|
|||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
`
|
`
|
||||||
select
|
select id,
|
||||||
session_id as id,
|
websiteId,
|
||||||
website_id as websiteId,
|
|
||||||
hostname,
|
hostname,
|
||||||
browser,
|
browser,
|
||||||
os,
|
os,
|
||||||
@ -37,13 +36,32 @@ async function clickhouseQuery(websiteId: string, sessionId: string) {
|
|||||||
city,
|
city,
|
||||||
min(min_time) as firstAt,
|
min(min_time) as firstAt,
|
||||||
max(max_time) as lastAt,
|
max(max_time) as lastAt,
|
||||||
uniq(visit_id) as visits,
|
uniq(visit_id) visits,
|
||||||
sumIf(views, event_type = 1) as views,
|
sum(views) as views,
|
||||||
length(groupArrayArray(event_name)) as events
|
sum(events) as events,
|
||||||
from website_event_stats_hourly
|
sum(max_time-min_time) as totaltime
|
||||||
where website_id = {websiteId:UUID}
|
from (select
|
||||||
and session_id = {sessionId:UUID}
|
session_id as id,
|
||||||
group by session_id, website_id, hostname, browser, os, device, screen, language, country, subdivision1, city;
|
visit_id,
|
||||||
|
website_id as websiteId,
|
||||||
|
hostname,
|
||||||
|
browser,
|
||||||
|
os,
|
||||||
|
device,
|
||||||
|
screen,
|
||||||
|
language,
|
||||||
|
country,
|
||||||
|
subdivision1,
|
||||||
|
city,
|
||||||
|
min(min_time) as min_time,
|
||||||
|
max(max_time) as max_time,
|
||||||
|
sum(views) as views,
|
||||||
|
length(groupArrayArray(event_name)) as events
|
||||||
|
from website_event_stats_hourly
|
||||||
|
where website_id = {websiteId:UUID}
|
||||||
|
and session_id = {sessionId:UUID}
|
||||||
|
group by session_id, visit_id, website_id, hostname, browser, os, device, screen, language, country, subdivision1, city) t
|
||||||
|
group by id, websiteId, hostname, browser, os, device, screen, language, country, subdivision1, city;
|
||||||
`,
|
`,
|
||||||
{ websiteId, sessionId },
|
{ websiteId, sessionId },
|
||||||
).then(result => result?.[0]);
|
).then(result => result?.[0]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user