mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 22:57:12 +01:00
Merge branch 'dev' of https://github.com/umami-software/umami into dev
This commit is contained in:
commit
dc3f7d343f
110 changed files with 12564 additions and 27 deletions
|
|
@ -6,7 +6,14 @@ import { loadWebsite } from 'lib/query';
|
|||
import { DEFAULT_CREATED_AT } from 'lib/constants';
|
||||
|
||||
export async function getEventDataFields(
|
||||
...args: [websiteId: string, startDate: Date, endDate: Date, field?: string]
|
||||
...args: [
|
||||
websiteId: string,
|
||||
startDate: Date,
|
||||
endDate: Date,
|
||||
field?: string,
|
||||
event?: string,
|
||||
withEventNames?: boolean,
|
||||
]
|
||||
): Promise<WebsiteEventDataFields[]> {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
|
|
@ -14,12 +21,37 @@ export async function getEventDataFields(
|
|||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, startDate: Date, endDate: Date, field: string) {
|
||||
async function relationalQuery(
|
||||
websiteId: string,
|
||||
startDate: Date,
|
||||
endDate: Date,
|
||||
field: string,
|
||||
event: string,
|
||||
withEventNames: boolean,
|
||||
) {
|
||||
const { toUuid, rawQuery } = prisma;
|
||||
const website = await loadWebsite(websiteId);
|
||||
const resetDate = new Date(website?.resetAt || DEFAULT_CREATED_AT);
|
||||
|
||||
if (field) {
|
||||
if (event) {
|
||||
return rawQuery(
|
||||
`select ed.event_key as field,
|
||||
ed.string_value as value,
|
||||
count(ed.*) as total
|
||||
from event_data as ed
|
||||
join website_event as e on e.event_id = ed.website_event_id
|
||||
where ed.website_id = $1${toUuid()}
|
||||
and ed.event_key = $2
|
||||
and ed.created_at >= $3
|
||||
and ed.created_at between $4 and $5
|
||||
and e.event_name = $6
|
||||
group by ed.event_key, ed.string_value
|
||||
order by 3 desc, 2 desc, 1 asc
|
||||
`,
|
||||
[websiteId, field, resetDate, startDate, endDate, event] as any,
|
||||
);
|
||||
}
|
||||
return rawQuery(
|
||||
`select event_key as field,
|
||||
string_value as value,
|
||||
|
|
@ -31,12 +63,30 @@ async function relationalQuery(websiteId: string, startDate: Date, endDate: Date
|
|||
and created_at between $4 and $5
|
||||
group by event_key, string_value
|
||||
order by 3 desc, 2 desc, 1 asc
|
||||
limit 100
|
||||
`,
|
||||
[websiteId, field, resetDate, startDate, endDate] as any,
|
||||
);
|
||||
}
|
||||
|
||||
if (withEventNames) {
|
||||
return rawQuery(
|
||||
`select
|
||||
ed.event_key as field,
|
||||
ed.data_type as type,
|
||||
count(ed.*) as total,
|
||||
e.event_name as event
|
||||
from event_data as ed
|
||||
join website_event as e on e.event_id = ed.website_event_id
|
||||
where ed.website_id = $1${toUuid()}
|
||||
and ed.created_at >= $2
|
||||
and ed.created_at between $3 and $4
|
||||
group by e.event_name, ed.event_key, ed.data_type
|
||||
order by 3 desc, 2 asc, 1 asc
|
||||
`,
|
||||
[websiteId, resetDate, startDate, endDate] as any,
|
||||
);
|
||||
}
|
||||
|
||||
return rawQuery(
|
||||
`select
|
||||
event_key as field,
|
||||
|
|
@ -48,18 +98,43 @@ async function relationalQuery(websiteId: string, startDate: Date, endDate: Date
|
|||
and created_at between $3 and $4
|
||||
group by event_key, data_type
|
||||
order by 3 desc, 2 asc, 1 asc
|
||||
limit 100
|
||||
`,
|
||||
[websiteId, resetDate, startDate, endDate] as any,
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(websiteId: string, startDate: Date, endDate: Date, field: string) {
|
||||
async function clickhouseQuery(
|
||||
websiteId: string,
|
||||
startDate: Date,
|
||||
endDate: Date,
|
||||
field: string,
|
||||
event: string,
|
||||
withEventNames: boolean,
|
||||
) {
|
||||
const { rawQuery, getDateFormat, getBetweenDates } = clickhouse;
|
||||
const website = await loadWebsite(websiteId);
|
||||
const resetDate = new Date(website?.resetAt || DEFAULT_CREATED_AT);
|
||||
|
||||
if (field) {
|
||||
if (event) {
|
||||
return rawQuery(
|
||||
`select
|
||||
ed.event_key as field,
|
||||
ed.string_value as value,
|
||||
count(ed.*) as total
|
||||
from event_data as ed
|
||||
join website_event as e on e.event_id = ed.website_event_id
|
||||
where ed.website_id = {websiteId:UUID}
|
||||
and ed.event_key = {field:String}
|
||||
and ed.created_at >= ${getDateFormat(resetDate)}
|
||||
and ${getBetweenDates('ed.created_at', startDate, endDate)}
|
||||
and e.event_name = {event:String}
|
||||
group by event_key, string_value
|
||||
order by 3 desc, 2 desc, 1 asc
|
||||
`,
|
||||
{ websiteId, field, event },
|
||||
);
|
||||
}
|
||||
return rawQuery(
|
||||
`select
|
||||
event_key as field,
|
||||
|
|
@ -72,12 +147,30 @@ async function clickhouseQuery(websiteId: string, startDate: Date, endDate: Date
|
|||
and ${getBetweenDates('created_at', startDate, endDate)}
|
||||
group by event_key, string_value
|
||||
order by 3 desc, 2 desc, 1 asc
|
||||
limit 100
|
||||
`,
|
||||
{ websiteId, field },
|
||||
);
|
||||
}
|
||||
|
||||
if (withEventNames) {
|
||||
return rawQuery(
|
||||
`select
|
||||
ed.event_key as field,
|
||||
ed.data_type as type,
|
||||
count(ed.*) as total,
|
||||
e.event_name as event
|
||||
from event_data as ed
|
||||
join website_event as e on e.event_id = ed.website_event_id
|
||||
where ed.website_id = {websiteId:UUID}
|
||||
and ed.created_at >= ${getDateFormat(resetDate)}
|
||||
and ${getBetweenDates('ed.created_at', startDate, endDate)}
|
||||
group by e.event_name, ed.event_key, ed.data_type
|
||||
order by 3 desc, 2 asc, 1 asc
|
||||
`,
|
||||
[websiteId, resetDate, startDate, endDate] as any,
|
||||
);
|
||||
}
|
||||
|
||||
return rawQuery(
|
||||
`select
|
||||
event_key as field,
|
||||
|
|
@ -89,7 +182,6 @@ async function clickhouseQuery(websiteId: string, startDate: Date, endDate: Date
|
|||
and ${getBetweenDates('created_at', startDate, endDate)}
|
||||
group by event_key, data_type
|
||||
order by 3 desc, 2 asc, 1 asc
|
||||
limit 100
|
||||
`,
|
||||
{ websiteId },
|
||||
);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ async function relationalQuery(
|
|||
let excludeDomain = '';
|
||||
|
||||
if (column === 'referrer_domain') {
|
||||
excludeDomain = 'and website_event.referrer_domain != $6';
|
||||
excludeDomain = 'and (website_event.referrer_domain != $6 or website_event.referrer_domain is null)';
|
||||
params.push(website.domain);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue