mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-06 01:15:42 +01:00
Updated events page.
This commit is contained in:
parent
3a97bfe11c
commit
c6b8114945
@ -5,7 +5,6 @@ import { ReactNode } from 'react';
|
|||||||
|
|
||||||
export default function EventsDataTable({
|
export default function EventsDataTable({
|
||||||
websiteId,
|
websiteId,
|
||||||
children,
|
|
||||||
}: {
|
}: {
|
||||||
websiteId?: string;
|
websiteId?: string;
|
||||||
teamId?: string;
|
teamId?: string;
|
||||||
@ -13,12 +12,8 @@ export default function EventsDataTable({
|
|||||||
}) {
|
}) {
|
||||||
const queryResult = useWebsiteEvents(websiteId);
|
const queryResult = useWebsiteEvents(websiteId);
|
||||||
|
|
||||||
if (queryResult?.result?.data?.length === 0) {
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataTable queryResult={queryResult} allowSearch={false}>
|
<DataTable queryResult={queryResult} allowSearch={true}>
|
||||||
{({ data }) => <EventsTable data={data} />}
|
{({ data }) => <EventsTable data={data} />}
|
||||||
</DataTable>
|
</DataTable>
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
import WebsiteDateFilter from 'components/input/WebsiteDateFilter';
|
||||||
|
import { Flexbox } from 'react-basics';
|
||||||
|
import MetricsBar from 'components/metrics/MetricsBar';
|
||||||
|
import MetricCard from 'components/metrics/MetricCard';
|
||||||
|
import { useMessages } from 'components/hooks';
|
||||||
|
import useWebsiteStats from 'components/hooks/queries/useWebsiteStats';
|
||||||
|
import { formatLongNumber } from 'lib/format';
|
||||||
|
|
||||||
|
export function EventsMetricsBar({ websiteId }: { websiteId: string }) {
|
||||||
|
const { formatMessage, labels } = useMessages();
|
||||||
|
const { data, isLoading, isFetched, error } = useWebsiteStats(websiteId);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flexbox direction="row" justifyContent="space-between" style={{ minHeight: 120 }}>
|
||||||
|
<MetricsBar isLoading={isLoading} isFetched={isFetched} error={error}>
|
||||||
|
<MetricCard
|
||||||
|
value={data?.visitors?.value}
|
||||||
|
label={formatMessage(labels.visitors)}
|
||||||
|
formatValue={formatLongNumber}
|
||||||
|
/>
|
||||||
|
<MetricCard
|
||||||
|
value={data?.visits?.value}
|
||||||
|
label={formatMessage(labels.visits)}
|
||||||
|
formatValue={formatLongNumber}
|
||||||
|
/>
|
||||||
|
<MetricCard
|
||||||
|
value={data?.pageviews?.value}
|
||||||
|
label={formatMessage(labels.views)}
|
||||||
|
formatValue={formatLongNumber}
|
||||||
|
/>
|
||||||
|
<MetricCard
|
||||||
|
value={data?.events?.value}
|
||||||
|
label={formatMessage(labels.events)}
|
||||||
|
formatValue={formatLongNumber}
|
||||||
|
/>
|
||||||
|
</MetricsBar>
|
||||||
|
<WebsiteDateFilter websiteId={websiteId} />
|
||||||
|
</Flexbox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EventsMetricsBar;
|
@ -1,12 +1,31 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import WebsiteHeader from '../WebsiteHeader';
|
import WebsiteHeader from '../WebsiteHeader';
|
||||||
import EventsDataTable from './EventsDataTable';
|
import EventsDataTable from './EventsDataTable';
|
||||||
|
import EventsMetricsBar from './EventsMetricsBar';
|
||||||
|
import EventsChart from 'components/metrics/EventsChart';
|
||||||
|
import { GridRow } from 'components/layout/Grid';
|
||||||
|
import MetricsTable from 'components/metrics/MetricsTable';
|
||||||
|
import { useMessages } from 'components/hooks';
|
||||||
|
|
||||||
export default function EventsPage({ websiteId }) {
|
export default function EventsPage({ websiteId }) {
|
||||||
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WebsiteHeader websiteId={websiteId} />
|
<WebsiteHeader websiteId={websiteId} />
|
||||||
<EventsDataTable websiteId={websiteId} />
|
<EventsMetricsBar websiteId={websiteId} />
|
||||||
|
<GridRow columns="two-one">
|
||||||
|
<EventsChart websiteId={websiteId} />
|
||||||
|
<MetricsTable
|
||||||
|
websiteId={websiteId}
|
||||||
|
type="event"
|
||||||
|
title={formatMessage(labels.events)}
|
||||||
|
metric={formatMessage(labels.actions)}
|
||||||
|
/>
|
||||||
|
</GridRow>
|
||||||
|
<GridRow columns="one">
|
||||||
|
<EventsDataTable websiteId={websiteId} />
|
||||||
|
</GridRow>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import WebsiteDateFilter from 'components/input/WebsiteDateFilter';
|
import WebsiteDateFilter from 'components/input/WebsiteDateFilter';
|
||||||
import { Flexbox, Loading } from 'react-basics';
|
import { Flexbox } from 'react-basics';
|
||||||
|
import MetricsBar from 'components/metrics/MetricsBar';
|
||||||
import MetricCard from 'components/metrics/MetricCard';
|
import MetricCard from 'components/metrics/MetricCard';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages } from 'components/hooks';
|
||||||
import useWebsiteStats from 'components/hooks/queries/useWebsiteStats';
|
import useWebsiteStats from 'components/hooks/queries/useWebsiteStats';
|
||||||
@ -7,33 +8,32 @@ import { formatLongNumber } from 'lib/format';
|
|||||||
|
|
||||||
export function SessionsMetricsBar({ websiteId }: { websiteId: string }) {
|
export function SessionsMetricsBar({ websiteId }: { websiteId: string }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { data, isLoading } = useWebsiteStats(websiteId);
|
const { data, isLoading, isFetched, error } = useWebsiteStats(websiteId);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flexbox direction="row" justifyContent="space-between" style={{ height: 120 }}>
|
<Flexbox direction="row" justifyContent="space-between" style={{ minHeight: 120 }}>
|
||||||
<Flexbox direction="row">
|
<MetricsBar isLoading={isLoading} isFetched={isFetched} error={error}>
|
||||||
{isLoading && <Loading icon="dots" />}
|
<MetricCard
|
||||||
{!isLoading && data && (
|
value={data?.visitors?.value}
|
||||||
<>
|
label={formatMessage(labels.visitors)}
|
||||||
<MetricCard
|
formatValue={formatLongNumber}
|
||||||
value={data.visitors.value}
|
/>
|
||||||
label={formatMessage(labels.visitors)}
|
<MetricCard
|
||||||
formatValue={formatLongNumber}
|
value={data?.visits?.value}
|
||||||
/>
|
label={formatMessage(labels.visits)}
|
||||||
<MetricCard
|
formatValue={formatLongNumber}
|
||||||
value={data.visits.value}
|
/>
|
||||||
label={formatMessage(labels.visits)}
|
<MetricCard
|
||||||
formatValue={formatLongNumber}
|
value={data?.pageviews?.value}
|
||||||
/>
|
label={formatMessage(labels.views)}
|
||||||
<MetricCard
|
formatValue={formatLongNumber}
|
||||||
value={data.pageviews.value}
|
/>
|
||||||
label={formatMessage(labels.views)}
|
<MetricCard
|
||||||
formatValue={formatLongNumber}
|
value={data?.countries?.value}
|
||||||
/>
|
label={formatMessage(labels.countries)}
|
||||||
<MetricCard value={data?.countries?.value} label={formatMessage(labels.countries)} />
|
formatValue={formatLongNumber}
|
||||||
</>
|
/>
|
||||||
)}
|
</MetricsBar>
|
||||||
</Flexbox>
|
|
||||||
<WebsiteDateFilter websiteId={websiteId} />
|
<WebsiteDateFilter websiteId={websiteId} />
|
||||||
</Flexbox>
|
</Flexbox>
|
||||||
);
|
);
|
||||||
|
@ -34,7 +34,7 @@ export function DataTable({
|
|||||||
const { page, pageSize, count, data } = result || {};
|
const { page, pageSize, count, data } = result || {};
|
||||||
const { query } = params || {};
|
const { query } = params || {};
|
||||||
const hasData = Boolean(!isLoading && data?.length);
|
const hasData = Boolean(!isLoading && data?.length);
|
||||||
const noResults = Boolean(!isLoading && query && !hasData);
|
const noResults = Boolean(query && !hasData);
|
||||||
const { router, renderUrl } = useNavigation();
|
const { router, renderUrl } = useNavigation();
|
||||||
|
|
||||||
const handleSearch = (query: string) => {
|
const handleSearch = (query: string) => {
|
||||||
|
@ -15,6 +15,7 @@ export function useWebsiteSessions(websiteId: string, params?: { [key: string]:
|
|||||||
...data,
|
...data,
|
||||||
...params,
|
...params,
|
||||||
...filters,
|
...filters,
|
||||||
|
pageSize: 20,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
3
src/components/input/DateFilter.module.css
Normal file
3
src/components/input/DateFilter.module.css
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.dropdown span {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
@ -5,6 +5,8 @@ import DatePickerForm from 'components/metrics/DatePickerForm';
|
|||||||
import { useLocale, useMessages } from 'components/hooks';
|
import { useLocale, useMessages } from 'components/hooks';
|
||||||
import Icons from 'components/icons';
|
import Icons from 'components/icons';
|
||||||
import { formatDate, parseDateValue } from 'lib/date';
|
import { formatDate, parseDateValue } from 'lib/date';
|
||||||
|
import styles from './DateFilter.module.css';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
export interface DateFilterProps {
|
export interface DateFilterProps {
|
||||||
value: string;
|
value: string;
|
||||||
@ -123,7 +125,7 @@ export function DateFilter({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Dropdown
|
<Dropdown
|
||||||
className={className}
|
className={classNames(className, styles.dropdown)}
|
||||||
items={options}
|
items={options}
|
||||||
renderValue={renderValue}
|
renderValue={renderValue}
|
||||||
value={value}
|
value={value}
|
||||||
|
@ -27,6 +27,10 @@
|
|||||||
padding-inline-end: 0;
|
padding-inline-end: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.col.one {
|
||||||
|
grid-column: span 6;
|
||||||
|
}
|
||||||
|
|
||||||
.col.two {
|
.col.two {
|
||||||
grid-column: span 3;
|
grid-column: span 3;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(auto-fit, minmax(140px, max-content));
|
grid-template-columns: repeat(auto-fit, minmax(140px, max-content));
|
||||||
gap: 20px;
|
gap: 20px;
|
||||||
|
width: 100%;
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 768px) {
|
@media screen and (max-width: 768px) {
|
||||||
|
@ -26,6 +26,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||||||
async function clickhouseQuery(websiteId: string, filters: QueryFilters, pageParams?: PageParams) {
|
async function clickhouseQuery(websiteId: string, filters: QueryFilters, pageParams?: PageParams) {
|
||||||
const { pagedQuery, parseFilters, getDateStringSQL } = clickhouse;
|
const { pagedQuery, parseFilters, getDateStringSQL } = clickhouse;
|
||||||
const { params, dateQuery, filterQuery } = await parseFilters(websiteId, filters);
|
const { params, dateQuery, filterQuery } = await parseFilters(websiteId, filters);
|
||||||
|
const { query } = pageParams;
|
||||||
|
|
||||||
return pagedQuery(
|
return pagedQuery(
|
||||||
`
|
`
|
||||||
@ -46,9 +47,10 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
${dateQuery}
|
${dateQuery}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
|
${query ? `and (positionCaseInsensitive(event_name, {query:String}) > 0)` : ''}
|
||||||
order by created_at desc
|
order by created_at desc
|
||||||
`,
|
`,
|
||||||
params,
|
{ ...params, query },
|
||||||
pageParams,
|
pageParams,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import clickhouse from 'lib/clickhouse';
|
import clickhouse from 'lib/clickhouse';
|
||||||
import { EVENT_TYPE } from 'lib/constants';
|
|
||||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||||
import prisma from 'lib/prisma';
|
import prisma from 'lib/prisma';
|
||||||
import { QueryFilters } from 'lib/types';
|
import { QueryFilters } from 'lib/types';
|
||||||
@ -25,7 +24,6 @@ async function relationalQuery(
|
|||||||
const { getTimestampDiffSQL, parseFilters, rawQuery } = prisma;
|
const { getTimestampDiffSQL, parseFilters, rawQuery } = prisma;
|
||||||
const { filterQuery, joinSession, params } = await parseFilters(websiteId, {
|
const { filterQuery, joinSession, params } = await parseFilters(websiteId, {
|
||||||
...filters,
|
...filters,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
@ -35,12 +33,15 @@ async function relationalQuery(
|
|||||||
count(distinct t.session_id) as "visitors",
|
count(distinct t.session_id) as "visitors",
|
||||||
count(distinct t.visit_id) as "visits",
|
count(distinct t.visit_id) as "visits",
|
||||||
count(distinct t.country) as "countries",
|
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(case when t.c = 1 then 1 else 0 end) as "bounces",
|
||||||
sum(${getTimestampDiffSQL('t.min_time', 't.max_time')}) as "totaltime",
|
sum(${getTimestampDiffSQL('t.min_time', 't.max_time')}) as "totaltime",
|
||||||
from (
|
from (
|
||||||
select
|
select
|
||||||
website_event.session_id,
|
website_event.session_id,
|
||||||
website_event.visit_id,
|
website_event.visit_id,
|
||||||
|
website_event.event_type,
|
||||||
session.country,
|
session.country,
|
||||||
count(*) as "c",
|
count(*) as "c",
|
||||||
min(website_event.created_at) as "min_time",
|
min(website_event.created_at) as "min_time",
|
||||||
@ -49,9 +50,8 @@ async function relationalQuery(
|
|||||||
${joinSession}
|
${joinSession}
|
||||||
where website_event.website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
and event_type = {{eventType}}
|
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1, 2, 3
|
group by 1, 2, 3, 4
|
||||||
) as t
|
) as t
|
||||||
`,
|
`,
|
||||||
params,
|
params,
|
||||||
@ -67,7 +67,6 @@ async function clickhouseQuery(
|
|||||||
const { rawQuery, parseFilters } = clickhouse;
|
const { rawQuery, parseFilters } = clickhouse;
|
||||||
const { filterQuery, params } = await parseFilters(websiteId, {
|
const { filterQuery, params } = await parseFilters(websiteId, {
|
||||||
...filters,
|
...filters,
|
||||||
eventType: EVENT_TYPE.pageView,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let sql = '';
|
let sql = '';
|
||||||
@ -79,12 +78,14 @@ async function clickhouseQuery(
|
|||||||
uniq(t.session_id) as "visitors",
|
uniq(t.session_id) as "visitors",
|
||||||
uniq(t.visit_id) as "visits",
|
uniq(t.visit_id) as "visits",
|
||||||
uniq(t.country) as "countries",
|
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"
|
sum(max_time-min_time) as "totaltime"
|
||||||
from (
|
from (
|
||||||
select
|
select
|
||||||
session_id,
|
session_id,
|
||||||
visit_id,
|
visit_id,
|
||||||
|
event_type,
|
||||||
country,
|
country,
|
||||||
count(*) c,
|
count(*) c,
|
||||||
min(created_at) min_time,
|
min(created_at) min_time,
|
||||||
@ -92,9 +93,8 @@ async function clickhouseQuery(
|
|||||||
from website_event
|
from website_event
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
and event_type = {eventType:UInt32}
|
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by session_id, visit_id, country
|
group by session_id, visit_id, event_type, country
|
||||||
) as t;
|
) as t;
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
@ -104,12 +104,14 @@ async function clickhouseQuery(
|
|||||||
uniq(session_id) as "visitors",
|
uniq(session_id) as "visitors",
|
||||||
uniq(visit_id) as "visits",
|
uniq(visit_id) as "visits",
|
||||||
uniq(country) as "countries",
|
uniq(country) as "countries",
|
||||||
|
sumIf(1, t.event_type = 2) as "events",
|
||||||
sumIf(1, t.c = 1) as "bounces",
|
sumIf(1, t.c = 1) as "bounces",
|
||||||
sum(max_time-min_time) as "totaltime"
|
sum(max_time-min_time) as "totaltime"
|
||||||
from (
|
from (
|
||||||
select
|
select
|
||||||
session_id,
|
session_id,
|
||||||
visit_id,
|
visit_id,
|
||||||
|
event_type,
|
||||||
country,
|
country,
|
||||||
sum(views) c,
|
sum(views) c,
|
||||||
min(min_time) min_time,
|
min(min_time) min_time,
|
||||||
@ -117,9 +119,8 @@ async function clickhouseQuery(
|
|||||||
from umami.website_event_stats_hourly "website_event"
|
from umami.website_event_stats_hourly "website_event"
|
||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
and event_type = {eventType:UInt32}
|
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by session_id, visit_id, country
|
group by session_id, visit_id, event_type, country
|
||||||
) as t;
|
) as t;
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -133,6 +134,7 @@ async function clickhouseQuery(
|
|||||||
bounces: Number(a.bounces),
|
bounces: Number(a.bounces),
|
||||||
totaltime: Number(a.totaltime),
|
totaltime: Number(a.totaltime),
|
||||||
countries: Number(a.countries),
|
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) {
|
async function relationalQuery(websiteId: string, filters: QueryFilters, pageParams: PageParams) {
|
||||||
const { pagedQuery } = prisma;
|
const { pagedQuery } = prisma;
|
||||||
|
const { query } = pageParams;
|
||||||
|
|
||||||
const where = {
|
const where = {
|
||||||
...filters,
|
...filters,
|
||||||
id: websiteId,
|
id: websiteId,
|
||||||
|
...prisma.getSearchParameters(query, [{ eventName: 'contains' }, { urlPath: 'contains' }]),
|
||||||
};
|
};
|
||||||
|
|
||||||
return pagedQuery('session', { where }, pageParams);
|
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) {
|
async function clickhouseQuery(websiteId: string, filters: QueryFilters, pageParams?: PageParams) {
|
||||||
const { pagedQuery, parseFilters } = clickhouse;
|
const { pagedQuery, parseFilters } = clickhouse;
|
||||||
const { params, dateQuery, filterQuery } = await parseFilters(websiteId, filters);
|
const { params, dateQuery, filterQuery } = await parseFilters(websiteId, filters);
|
||||||
|
const { query } = pageParams;
|
||||||
|
|
||||||
return pagedQuery(
|
return pagedQuery(
|
||||||
`
|
`
|
||||||
@ -49,6 +52,7 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters, pagePar
|
|||||||
where website_id = {websiteId:UUID}
|
where website_id = {websiteId:UUID}
|
||||||
${dateQuery}
|
${dateQuery}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
|
${query ? `and (positionCaseInsensitive(event_name, {query:String}) > 0)` : ''}
|
||||||
group by session_id, website_id, hostname, browser, os, device, screen, language, country, subdivision1, city
|
group by session_id, website_id, hostname, browser, os, device, screen, language, country, subdivision1, city
|
||||||
order by lastAt desc
|
order by lastAt desc
|
||||||
`,
|
`,
|
||||||
|
Loading…
Reference in New Issue
Block a user