mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # src/app/(main)/websites/[websiteId]/ExpandedViewModal.tsx # src/app/(main)/websites/[websiteId]/WebsiteExpandedView.tsx
This commit is contained in:
commit
036748cdeb
15 changed files with 98 additions and 57 deletions
|
|
@ -19,7 +19,7 @@ export async function GET(
|
|||
return unauthorized();
|
||||
}
|
||||
|
||||
const data = await getEventData(eventId);
|
||||
const data = await getEventData(websiteId, eventId);
|
||||
|
||||
return json(data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { getQueryFilters, parseRequest } from '@/lib/request';
|
|||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getEventDataEvents } from '@/queries/sql/events/getEventDataEvents';
|
||||
import { filterParams } from '@/lib/schema';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
|
|
@ -12,6 +13,7 @@ export async function GET(
|
|||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
event: z.string().optional(),
|
||||
...filterParams,
|
||||
});
|
||||
const { auth, query, error } = await parseRequest(request, schema);
|
||||
|
||||
|
|
@ -25,12 +27,10 @@ export async function GET(
|
|||
return unauthorized();
|
||||
}
|
||||
|
||||
const { event } = query;
|
||||
const filters = await getQueryFilters(query, websiteId);
|
||||
|
||||
const data = await getEventDataEvents(websiteId, {
|
||||
...filters,
|
||||
event,
|
||||
});
|
||||
|
||||
return json(data);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { getQueryFilters, parseRequest } from '@/lib/request';
|
|||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getEventDataFields } from '@/queries/sql';
|
||||
import { filterParams } from '@/lib/schema';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
|
|
@ -11,6 +12,7 @@ export async function GET(
|
|||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
const { auth, query, error } = await parseRequest(request, schema);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import { z } from 'zod';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { filterParams } from '@/lib/schema';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getEventDataProperties } from '@/queries/sql';
|
||||
import { dateRangeParams, filterParams } from '@/lib/schema';
|
||||
import { z } from 'zod';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
propertyName: z.string().optional(),
|
||||
...dateRangeParams,
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
|
|
@ -27,10 +27,9 @@ export async function GET(
|
|||
return unauthorized();
|
||||
}
|
||||
|
||||
const { propertyName } = query;
|
||||
const filters = await getQueryFilters(query, websiteId);
|
||||
|
||||
const data = await getEventDataProperties(websiteId, { ...filters, propertyName });
|
||||
const data = await getEventDataProperties(websiteId, filters);
|
||||
|
||||
return json(data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { getQueryFilters, parseRequest } from '@/lib/request';
|
|||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getEventDataStats } from '@/queries/sql';
|
||||
import { filterParams } from '@/lib/schema';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
|
|
@ -11,7 +12,7 @@ export async function GET(
|
|||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
propertyName: z.string().optional(),
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
const { auth, query, error } = await parseRequest(request, schema);
|
||||
|
|
|
|||
|
|
@ -3,16 +3,17 @@ import { getQueryFilters, parseRequest } from '@/lib/request';
|
|||
import { unauthorized, json } from '@/lib/response';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getEventDataValues } from '@/queries/sql';
|
||||
import { dateRangeParams, filterParams } from '@/lib/schema';
|
||||
import { filterParams } from '@/lib/schema';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
eventName: z.string().optional(),
|
||||
propertyName: z.string().optional(),
|
||||
...dateRangeParams,
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
event: z.string(),
|
||||
propertyName: z.string(),
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
|
|
@ -28,12 +29,11 @@ export async function GET(
|
|||
return unauthorized();
|
||||
}
|
||||
|
||||
const { eventName, propertyName } = query;
|
||||
const { propertyName } = query;
|
||||
const filters = await getQueryFilters(query, websiteId);
|
||||
|
||||
const data = await getEventDataValues(websiteId, {
|
||||
...filters,
|
||||
eventName,
|
||||
propertyName,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
import { z } from 'zod';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { unauthorized, json } from '@/lib/response';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { filterParams, pagingParams, searchParams } from '@/lib/schema';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { dateRangeParams, pagingParams, filterParams, searchParams } from '@/lib/schema';
|
||||
import { getWebsiteEvents } from '@/queries/sql';
|
||||
import { z } from 'zod';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
...dateRangeParams,
|
||||
startAt: z.coerce.number().optional(),
|
||||
endAt: z.coerce.number().optional(),
|
||||
...filterParams,
|
||||
...pagingParams,
|
||||
...searchParams,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { useFilterParameters } from '../useFilterParameters';
|
|||
|
||||
export function useEventDataValuesQuery(
|
||||
websiteId: string,
|
||||
eventName: string,
|
||||
event: string,
|
||||
propertyName: string,
|
||||
options?: ReactQueryOptions,
|
||||
) {
|
||||
|
|
@ -16,7 +16,7 @@ export function useEventDataValuesQuery(
|
|||
return useQuery<any>({
|
||||
queryKey: [
|
||||
'websites:event-data:values',
|
||||
{ websiteId, eventName, propertyName, startAt, endAt, unit, timezone, ...filters },
|
||||
{ websiteId, event, propertyName, startAt, endAt, unit, timezone, ...filters },
|
||||
],
|
||||
queryFn: () =>
|
||||
get(`/websites/${websiteId}/event-data/values`, {
|
||||
|
|
@ -25,7 +25,7 @@ export function useEventDataValuesQuery(
|
|||
unit,
|
||||
timezone,
|
||||
...filters,
|
||||
eventName,
|
||||
event,
|
||||
propertyName,
|
||||
}),
|
||||
enabled: !!(websiteId && propertyName),
|
||||
|
|
|
|||
|
|
@ -15,14 +15,20 @@ export function useWebsiteEventsQuery(
|
|||
options?: ReactQueryOptions,
|
||||
) {
|
||||
const { get } = useApi();
|
||||
const date = useDateParameters();
|
||||
const { startAt, endAt, unit, timezone } = useDateParameters();
|
||||
const filters = useFilterParameters();
|
||||
|
||||
return usePagedQuery({
|
||||
queryKey: ['websites:events', { websiteId, ...date, ...filters, ...params }],
|
||||
queryKey: [
|
||||
'websites:events',
|
||||
{ websiteId, startAt, endAt, unit, timezone, ...filters, ...params },
|
||||
],
|
||||
queryFn: pageParams =>
|
||||
get(`/websites/${websiteId}/events`, {
|
||||
...date,
|
||||
startAt,
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
...filters,
|
||||
...pageParams,
|
||||
eventType: EVENT_TYPES[params.view],
|
||||
|
|
|
|||
|
|
@ -5,12 +5,13 @@ import { ReactQueryOptions } from '@/lib/types';
|
|||
|
||||
export function useWebsiteEventsSeriesQuery(websiteId: string, options?: ReactQueryOptions) {
|
||||
const { get, useQuery } = useApi();
|
||||
const date = useDateParameters();
|
||||
const { startAt, endAt, unit, timezone } = useDateParameters();
|
||||
const filters = useFilterParameters();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['websites:events:series', { websiteId, ...date, ...filters }],
|
||||
queryFn: () => get(`/websites/${websiteId}/events/series`, { ...date, ...filters }),
|
||||
queryKey: ['websites:events:series', { websiteId, startAt, endAt, unit, timezone, ...filters }],
|
||||
queryFn: () =>
|
||||
get(`/websites/${websiteId}/events/series`, { startAt, endAt, unit, timezone, ...filters }),
|
||||
enabled: !!websiteId,
|
||||
...options,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,14 +5,16 @@ import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
|||
|
||||
const FUNCTION_NAME = 'getEventData';
|
||||
|
||||
export async function getEventData(...args: [eventId: string]): Promise<EventData[]> {
|
||||
export async function getEventData(
|
||||
...args: [websiteId: string, eventId: string]
|
||||
): Promise<EventData[]> {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(eventId: string) {
|
||||
async function relationalQuery(websiteId: string, eventId: string) {
|
||||
const { rawQuery } = prisma;
|
||||
|
||||
return rawQuery(
|
||||
|
|
@ -29,14 +31,15 @@ async function relationalQuery(eventId: string) {
|
|||
data_type as dataType,
|
||||
created_at as createdAt
|
||||
from event_data
|
||||
where event_id = {{eventId::uuid}}
|
||||
website_id = {{websiteId::uuid}}
|
||||
event_id = {{eventId::uuid}}
|
||||
`,
|
||||
{ eventId },
|
||||
{ websiteId, eventId },
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(eventId: string): Promise<EventData[]> {
|
||||
async function clickhouseQuery(websiteId: string, eventId: string): Promise<EventData[]> {
|
||||
const { rawQuery } = clickhouse;
|
||||
|
||||
return rawQuery(
|
||||
|
|
@ -53,9 +56,10 @@ async function clickhouseQuery(eventId: string): Promise<EventData[]> {
|
|||
data_type as dataType,
|
||||
created_at as createdAt
|
||||
from event_data
|
||||
where event_id = {eventId:UUID}
|
||||
where website_id = {websiteId:UUID}
|
||||
and event_id = {eventId:UUID}
|
||||
`,
|
||||
{ eventId },
|
||||
{ websiteId, eventId },
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,10 @@ export async function getEventDataEvents(
|
|||
async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||
const { rawQuery, parseFilters } = prisma;
|
||||
const { event } = filters;
|
||||
const { queryParams } = parseFilters(filters);
|
||||
const { queryParams } = parseFilters({
|
||||
...filters,
|
||||
websiteId,
|
||||
});
|
||||
|
||||
if (event) {
|
||||
return rawQuery(
|
||||
|
|
@ -75,7 +78,10 @@ async function clickhouseQuery(
|
|||
): Promise<{ eventName: string; propertyName: string; dataType: number; total: number }[]> {
|
||||
const { rawQuery, parseFilters } = clickhouse;
|
||||
const { event } = filters;
|
||||
const { queryParams } = parseFilters(filters);
|
||||
const { filterQuery, cohortQuery, queryParams } = parseFilters({
|
||||
...filters,
|
||||
websiteId,
|
||||
});
|
||||
|
||||
if (event) {
|
||||
return rawQuery(
|
||||
|
|
@ -87,9 +93,16 @@ async function clickhouseQuery(
|
|||
string_value as propertyValue,
|
||||
count(*) as total
|
||||
from event_data
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and event_name = {event:String}
|
||||
join website_event
|
||||
on website_event.event_id = event_data.event_id
|
||||
and website_event.website_id = event_data.website_id
|
||||
and website_event.website_id = {websiteId:UUID}
|
||||
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
${cohortQuery}
|
||||
where event_data.website_id = {websiteId:UUID}
|
||||
and event_data.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and event_data.event_name = {event:String}
|
||||
${filterQuery}
|
||||
group by data_key, data_type, string_value, event_name
|
||||
order by 1 asc, 2 asc, 3 asc, 5 desc
|
||||
limit 500
|
||||
|
|
@ -107,8 +120,15 @@ async function clickhouseQuery(
|
|||
data_type as dataType,
|
||||
count(*) as total
|
||||
from event_data
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
join website_event
|
||||
on website_event.event_id = event_data.event_id
|
||||
and website_event.website_id = event_data.website_id
|
||||
and website_event.website_id = {websiteId:UUID}
|
||||
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
${cohortQuery}
|
||||
where event_data.website_id = {websiteId:UUID}
|
||||
and event_data.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
${filterQuery}
|
||||
group by data_key, data_type, event_name
|
||||
order by 1 asc, 2 asc
|
||||
limit 500
|
||||
|
|
|
|||
|
|
@ -64,10 +64,15 @@ async function clickhouseQuery(
|
|||
data_type = 4, toString(date_trunc('hour', date_value)),
|
||||
string_value) as "value",
|
||||
count(*) as "total"
|
||||
from event_data website_event
|
||||
from event_data
|
||||
join website_event
|
||||
on website_event.event_id = event_data.event_id
|
||||
and website_event.website_id = event_data.website_id
|
||||
and website_event.website_id = {websiteId:UUID}
|
||||
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
${cohortQuery}
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
where event_data.website_id = {websiteId:UUID}
|
||||
and event_data.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
${filterQuery}
|
||||
group by data_key, data_type, value
|
||||
order by 2 desc
|
||||
|
|
|
|||
|
|
@ -71,10 +71,15 @@ async function clickhouseQuery(
|
|||
event_id,
|
||||
data_key,
|
||||
count(*) as "total"
|
||||
from event_data website_event
|
||||
from event_data
|
||||
join website_event
|
||||
on website_event.event_id = event_data.event_id
|
||||
and website_event.website_id = event_data.website_id
|
||||
and website_event.website_id = {websiteId:UUID}
|
||||
and website_event.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
${cohortQuery}
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
where event_data.website_id = {websiteId:UUID}
|
||||
and event_data.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
${filterQuery}
|
||||
group by event_id, data_key
|
||||
) as t
|
||||
|
|
|
|||
|
|
@ -11,10 +11,7 @@ interface WebsiteEventData {
|
|||
}
|
||||
|
||||
export async function getEventDataValues(
|
||||
...args: [
|
||||
websiteId: string,
|
||||
filters: QueryFilters & { eventName?: string; propertyName?: string },
|
||||
]
|
||||
...args: [websiteId: string, filters: QueryFilters & { propertyName?: string }]
|
||||
): Promise<WebsiteEventData[]> {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
|
|
@ -24,7 +21,7 @@ export async function getEventDataValues(
|
|||
|
||||
async function relationalQuery(
|
||||
websiteId: string,
|
||||
filters: QueryFilters & { eventName?: string; propertyName?: string },
|
||||
filters: QueryFilters & { propertyName?: string },
|
||||
) {
|
||||
const { rawQuery, parseFilters, getDateSQL } = prisma;
|
||||
const { filterQuery, joinSessionQuery, cohortQuery, queryParams } = parseFilters({
|
||||
|
|
@ -63,7 +60,7 @@ async function relationalQuery(
|
|||
|
||||
async function clickhouseQuery(
|
||||
websiteId: string,
|
||||
filters: QueryFilters & { eventName?: string; propertyName?: string },
|
||||
filters: QueryFilters & { propertyName?: string },
|
||||
): Promise<{ value: string; total: number }[]> {
|
||||
const { rawQuery, parseFilters } = clickhouse;
|
||||
const { filterQuery, cohortQuery, queryParams } = parseFilters({ ...filters, websiteId });
|
||||
|
|
@ -85,7 +82,7 @@ async function clickhouseQuery(
|
|||
where event_data.website_id = {websiteId:UUID}
|
||||
and event_data.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and event_data.data_key = {propertyName:String}
|
||||
and event_data.event_name = {eventName:String}
|
||||
and event_data.event_name = {event:String}
|
||||
${filterQuery}
|
||||
group by value
|
||||
order by 2 desc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue