mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Updates to reports.
This commit is contained in:
parent
1869a809cf
commit
22d477b98b
22 changed files with 388 additions and 117 deletions
48
queries/analytics/eventData/getEventDataFields.ts
Normal file
48
queries/analytics/eventData/getEventDataFields.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import clickhouse from 'lib/clickhouse';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import prisma from 'lib/prisma';
|
||||
import { WebsiteEventDataMetric } from 'lib/types';
|
||||
import { loadWebsite } from 'lib/query';
|
||||
|
||||
export async function getEventDataFields(
|
||||
...args: [websiteId: string, startDate: Date, endDate: Date]
|
||||
): Promise<WebsiteEventDataMetric[]> {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, startDate: Date, endDate: Date) {
|
||||
const { toUuid, rawQuery } = prisma;
|
||||
const website = await loadWebsite(websiteId);
|
||||
const resetDate = new Date(website?.resetAt || website?.createdAt);
|
||||
const params: any = [websiteId, resetDate, startDate, endDate];
|
||||
|
||||
return rawQuery(
|
||||
`select
|
||||
distinct event_key as eventKey, data_type as eventDataType
|
||||
from event_data
|
||||
where website_id = $1${toUuid()}
|
||||
and created_at >= $2
|
||||
and created_at between $3 and $4`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(websiteId: string, startDate: Date, endDate: Date) {
|
||||
const { rawQuery, getDateFormat, getBetweenDates } = clickhouse;
|
||||
const website = await loadWebsite(websiteId);
|
||||
const resetDate = new Date(website?.resetAt || website?.createdAt);
|
||||
const params = { websiteId };
|
||||
|
||||
return rawQuery(
|
||||
`select
|
||||
distinct event_key as eventKey, data_type as eventDataType
|
||||
from event_data
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at >= ${getDateFormat(resetDate)}
|
||||
and ${getBetweenDates('created_at', startDate, endDate)}`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ export async function saveSessionData(data: {
|
|||
},
|
||||
}),
|
||||
client.sessionData.createMany({
|
||||
data: flattendData,
|
||||
data: flattendData as any,
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ export * from './analytics/event/getEventMetrics';
|
|||
export * from './analytics/event/getEventUsage';
|
||||
export * from './analytics/event/getEvents';
|
||||
export * from './analytics/eventData/getEventData';
|
||||
export * from './analytics/eventData/getEventDataFields';
|
||||
export * from './analytics/eventData/getEventDataUsage';
|
||||
export * from './analytics/event/saveEvent';
|
||||
export * from './analytics/pageview/getPageviewFunnel';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue