mirror of
https://github.com/kremalicious/umami.git
synced 2024-06-30 13:41:50 +02:00
Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # components/pages/login/LoginForm.js
This commit is contained in:
commit
53ec66e820
|
@ -211,7 +211,6 @@ export default function EventDataForm({ websiteId, onClose, className }) {
|
||||||
<TextField />
|
<TextField />
|
||||||
</FormInput>
|
</FormInput>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
+
|
|
||||||
<FormButtons className={styles.formButtons}>
|
<FormButtons className={styles.formButtons}>
|
||||||
<Button variant="action" type="submit">
|
<Button variant="action" type="submit">
|
||||||
<FormattedMessage id="label.add-filter" defaultMessage="Add Filter" />
|
<FormattedMessage id="label.add-filter" defaultMessage="Add Filter" />
|
||||||
|
|
|
@ -57,13 +57,11 @@ export default function UsersTable({ columns = defaultColumns, onLoading, onAddK
|
||||||
|
|
||||||
row.action = (
|
row.action = (
|
||||||
<div className={styles.actions}>
|
<div className={styles.actions}>
|
||||||
<Link href={`/users/${row.id}`} shallow>
|
<Link href={`/settings/users/${row.id}`}>
|
||||||
<a>
|
<Button>
|
||||||
<Button>
|
<Icon icon="arrow-right" />
|
||||||
<Icon icon="arrow-right" />
|
Settings
|
||||||
Settings
|
</Button>
|
||||||
</Button>
|
|
||||||
</a>
|
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -19,6 +19,18 @@ const POSTGRESQL_DATE_FORMATS = {
|
||||||
year: 'YYYY-01-01',
|
year: 'YYYY-01-01',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function toUuid(): string {
|
||||||
|
const db = getDatabaseType(process.env.DATABASE_URL);
|
||||||
|
|
||||||
|
if (db === POSTGRESQL) {
|
||||||
|
return '::uuid';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (db === MYSQL) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getDateQuery(field: string, unit: string, timezone?: string): string {
|
function getDateQuery(field: string, unit: string, timezone?: string): string {
|
||||||
const db = getDatabaseType(process.env.DATABASE_URL);
|
const db = getDatabaseType(process.env.DATABASE_URL);
|
||||||
|
|
||||||
|
@ -173,7 +185,7 @@ function parseFilters(
|
||||||
event: { eventName },
|
event: { eventName },
|
||||||
joinSession:
|
joinSession:
|
||||||
os || browser || device || country
|
os || browser || device || country
|
||||||
? `inner join session on ${sessionKey} = session.${sessionKey}`
|
? `inner join session on website_event.${sessionKey} = session.${sessionKey}`
|
||||||
: '',
|
: '',
|
||||||
filterQuery: getFilterQuery(filters, params),
|
filterQuery: getFilterQuery(filters, params),
|
||||||
};
|
};
|
||||||
|
@ -198,6 +210,7 @@ export default {
|
||||||
getFilterQuery,
|
getFilterQuery,
|
||||||
getEventDataColumnsQuery,
|
getEventDataColumnsQuery,
|
||||||
getEventDataFilterQuery,
|
getEventDataFilterQuery,
|
||||||
|
toUuid,
|
||||||
parseFilters,
|
parseFilters,
|
||||||
rawQuery,
|
rawQuery,
|
||||||
};
|
};
|
||||||
|
|
|
@ -77,7 +77,7 @@ export default async (
|
||||||
endDate,
|
endDate,
|
||||||
timezone,
|
timezone,
|
||||||
unit,
|
unit,
|
||||||
count: 'distinct pageview.',
|
count: 'distinct website_event.',
|
||||||
filters: {
|
filters: {
|
||||||
url,
|
url,
|
||||||
os,
|
os,
|
||||||
|
|
|
@ -38,23 +38,23 @@ async function relationalQuery(
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { startDate, endDate, eventName, columns, filters } = data;
|
const { startDate, endDate, eventName, columns, filters } = data;
|
||||||
const { rawQuery, getEventDataColumnsQuery, getEventDataFilterQuery } = prisma;
|
const { toUuid, rawQuery, getEventDataColumnsQuery, getEventDataFilterQuery } = prisma;
|
||||||
const params = [startDate, endDate];
|
const params: any = [websiteId, startDate, endDate, eventName];
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
`select
|
`select
|
||||||
${getEventDataColumnsQuery('event_data', columns)}
|
${getEventDataColumnsQuery('event_data', columns)}
|
||||||
from website_event
|
from website_event
|
||||||
where website_id ='${websiteId}'
|
where website_id = $1${toUuid()}
|
||||||
and created_at between $1 and $2
|
and created_at between $2 and $3
|
||||||
and event_type = ${EVENT_TYPE.customEvent}
|
and event_type = ${EVENT_TYPE.customEvent}
|
||||||
${eventName ? `and eventName = ${eventName}` : ''}
|
${eventName ? `and eventName = $4` : ''}
|
||||||
${
|
${
|
||||||
Object.keys(filters).length > 0
|
Object.keys(filters).length > 0
|
||||||
? `and ${getEventDataFilterQuery('event_data', filters)}`
|
? `and ${getEventDataFilterQuery('event_data', filters)}`
|
||||||
: ''
|
: ''
|
||||||
}`,
|
}`,
|
||||||
params as any,
|
params,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,8 @@ async function relationalQuery(
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { rawQuery, getDateQuery, getFilterQuery } = prisma;
|
const { toUuid, rawQuery, getDateQuery, getFilterQuery } = prisma;
|
||||||
const params = [startDate, endDate];
|
const params: any = [websiteId, startDate, endDate];
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
`select
|
`select
|
||||||
|
@ -54,8 +54,8 @@ async function relationalQuery(
|
||||||
${getDateQuery('created_at', unit, timezone)} t,
|
${getDateQuery('created_at', unit, timezone)} t,
|
||||||
count(*) y
|
count(*) y
|
||||||
from website_event
|
from website_event
|
||||||
where website_id='${websiteId}'
|
where website_id = $1${toUuid()}
|
||||||
and created_at between $1 and $2
|
and created_at between $2 and $3
|
||||||
and event_type = ${EVENT_TYPE.customEvent}
|
and event_type = ${EVENT_TYPE.customEvent}
|
||||||
${getFilterQuery(filters, params)}
|
${getFilterQuery(filters, params)}
|
||||||
group by 1, 2
|
group by 1, 2
|
||||||
|
|
|
@ -34,8 +34,9 @@ async function relationalQuery(
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { startDate, endDate, column, filters = {}, type } = data;
|
const { startDate, endDate, column, filters = {}, type } = data;
|
||||||
const { rawQuery, parseFilters } = prisma;
|
const { rawQuery, parseFilters, toUuid } = prisma;
|
||||||
const params: any = [
|
const params: any = [
|
||||||
|
websiteId,
|
||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
type === 'event' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
type === 'event' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||||
|
@ -46,9 +47,9 @@ async function relationalQuery(
|
||||||
`select ${column} x, count(*) y
|
`select ${column} x, count(*) y
|
||||||
from website_event
|
from website_event
|
||||||
${joinSession}
|
${joinSession}
|
||||||
where website_id='${websiteId}'
|
where website_event.website_id = $1${toUuid()}
|
||||||
and website_event.created_at between $1 and $2
|
and website_event.created_at between $2 and $3
|
||||||
and event_type = $3
|
and event_type = $4
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1
|
group by 1
|
||||||
order by 2 desc`,
|
order by 2 desc`,
|
||||||
|
|
|
@ -45,8 +45,8 @@ async function relationalQuery(
|
||||||
filters = {},
|
filters = {},
|
||||||
sessionKey = 'session_id',
|
sessionKey = 'session_id',
|
||||||
} = data;
|
} = data;
|
||||||
const { getDateQuery, parseFilters, rawQuery } = prisma;
|
const { toUuid, getDateQuery, parseFilters, rawQuery } = prisma;
|
||||||
const params = [startDate, endDate];
|
const params: any = [websiteId, startDate, endDate];
|
||||||
const { filterQuery, joinSession } = parseFilters(filters, params);
|
const { filterQuery, joinSession } = parseFilters(filters, params);
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
|
@ -54,8 +54,8 @@ async function relationalQuery(
|
||||||
count(${count !== '*' ? `${count}${sessionKey}` : count}) y
|
count(${count !== '*' ? `${count}${sessionKey}` : count}) y
|
||||||
from website_event
|
from website_event
|
||||||
${joinSession}
|
${joinSession}
|
||||||
where website.website_id='${websiteId}'
|
where website_event.website_id = $1${toUuid()}
|
||||||
and pageview.created_at between $1 and $2
|
and website_event.created_at between $2 and $3
|
||||||
and event_type = ${EVENT_TYPE.pageView}
|
and event_type = ${EVENT_TYPE.pageView}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1`,
|
group by 1`,
|
||||||
|
@ -90,7 +90,7 @@ async function clickhouseQuery(
|
||||||
${getDateQuery('created_at', unit, timezone)} t,
|
${getDateQuery('created_at', unit, timezone)} t,
|
||||||
count(${count !== '*' ? 'distinct session_id' : count}) y
|
count(${count !== '*' ? 'distinct session_id' : count}) y
|
||||||
from event
|
from event
|
||||||
where website_id = $1
|
where website_id = $1
|
||||||
and rev_id = $2
|
and rev_id = $2
|
||||||
and event_type = ${EVENT_TYPE.pageView}
|
and event_type = ${EVENT_TYPE.pageView}
|
||||||
and ${getBetweenDates('created_at', startDate, endDate)}
|
and ${getBetweenDates('created_at', startDate, endDate)}
|
||||||
|
|
|
@ -20,21 +20,21 @@ async function relationalQuery(
|
||||||
data: { startDate: Date; endDate: Date; field: string; filters: object },
|
data: { startDate: Date; endDate: Date; field: string; filters: object },
|
||||||
) {
|
) {
|
||||||
const { startDate, endDate, field, filters = {} } = data;
|
const { startDate, endDate, field, filters = {} } = data;
|
||||||
const { parseFilters, rawQuery } = prisma;
|
const { toUuid, parseFilters, rawQuery } = prisma;
|
||||||
const params = [startDate, endDate];
|
const params: any = [websiteId, startDate, endDate];
|
||||||
const { filterQuery, joinSession } = parseFilters(filters, params);
|
const { filterQuery, joinSession } = parseFilters(filters, params);
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
`select ${field} x, count(*) y
|
`select ${field} x, count(*) y
|
||||||
from session as x
|
from session as x
|
||||||
where x.session_id in (
|
where x.session_id in (
|
||||||
select pageview.session_id
|
select website_event.session_id
|
||||||
from pageview
|
from website_event
|
||||||
join website
|
join website
|
||||||
on pageview.website_id = website.website_id
|
on website_event.website_id = website.website_id
|
||||||
${joinSession}
|
${joinSession}
|
||||||
where website.website_id='${websiteId}'
|
where website.website_id = $1${toUuid()}
|
||||||
and pageview.created_at between $1 and $2
|
and website_event.created_at between $2 and $3
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
)
|
)
|
||||||
group by 1
|
group by 1
|
||||||
|
|
|
@ -11,16 +11,18 @@ export async function getActiveVisitors(...args: [websiteId: string]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function relationalQuery(websiteId: string) {
|
async function relationalQuery(websiteId: string) {
|
||||||
const date = subMinutes(new Date(), 5);
|
const { toUuid, rawQuery } = prisma;
|
||||||
const params = [date];
|
|
||||||
|
|
||||||
return prisma.rawQuery(
|
const date = subMinutes(new Date(), 5);
|
||||||
|
const params: any = [websiteId, date];
|
||||||
|
|
||||||
|
return rawQuery(
|
||||||
`select count(distinct session_id) x
|
`select count(distinct session_id) x
|
||||||
from pageview
|
from website_event
|
||||||
join website
|
join website
|
||||||
on pageview.website_id = website.website_id
|
on website_event.website_id = website.website_id
|
||||||
where website.website_id = '${websiteId}'
|
where website.website_id = $1${toUuid()}
|
||||||
and pageview.created_at >= $1`,
|
and website_event.created_at >= $2`,
|
||||||
params,
|
params,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import prisma from 'lib/prisma';
|
||||||
import clickhouse from 'lib/clickhouse';
|
import clickhouse from 'lib/clickhouse';
|
||||||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||||
import cache from 'lib/cache';
|
import cache from 'lib/cache';
|
||||||
|
import { EVENT_TYPE } from 'lib/constants';
|
||||||
|
|
||||||
export async function getWebsiteStats(
|
export async function getWebsiteStats(
|
||||||
...args: [websiteId: string, data: { startDate: Date; endDate: Date; filters: object }]
|
...args: [websiteId: string, data: { startDate: Date; endDate: Date; filters: object }]
|
||||||
|
@ -17,8 +18,8 @@ async function relationalQuery(
|
||||||
data: { startDate: Date; endDate: Date; filters: object },
|
data: { startDate: Date; endDate: Date; filters: object },
|
||||||
) {
|
) {
|
||||||
const { startDate, endDate, filters = {} } = data;
|
const { startDate, endDate, filters = {} } = data;
|
||||||
const { getDateQuery, getTimestampInterval, parseFilters, rawQuery } = prisma;
|
const { toUuid, getDateQuery, getTimestampInterval, parseFilters, rawQuery } = prisma;
|
||||||
const params = [startDate, endDate];
|
const params: any = [websiteId, startDate, endDate];
|
||||||
const { filterQuery, joinSession } = parseFilters(filters, params);
|
const { filterQuery, joinSession } = parseFilters(filters, params);
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
|
@ -27,16 +28,16 @@ async function relationalQuery(
|
||||||
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(t.time) as "totaltime"
|
sum(t.time) as "totaltime"
|
||||||
from (
|
from (
|
||||||
select pageview.session_id,
|
select website_event.session_id,
|
||||||
${getDateQuery('pageview.created_at', 'hour')},
|
${getDateQuery('website_event.created_at', 'hour')},
|
||||||
count(*) c,
|
count(*) c,
|
||||||
${getTimestampInterval('pageview.created_at')} as "time"
|
${getTimestampInterval('website_event.created_at')} as "time"
|
||||||
from pageview
|
from website_event
|
||||||
join website
|
join website
|
||||||
on pageview.website_id = website.website_id
|
on website_event.website_id = website.website_id
|
||||||
${joinSession}
|
${joinSession}
|
||||||
where website.website_id='${websiteId}'
|
where website.website_id = $1${toUuid()}
|
||||||
and pageview.created_at between $1 and $2
|
and website_event.created_at between $2 and $3
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1, 2
|
group by 1, 2
|
||||||
) t`,
|
) t`,
|
||||||
|
@ -67,7 +68,7 @@ async function clickhouseQuery(
|
||||||
min(created_at) min_time,
|
min(created_at) min_time,
|
||||||
max(created_at) max_time
|
max(created_at) max_time
|
||||||
from event
|
from event
|
||||||
where event_type = 1
|
where event_type = ${EVENT_TYPE.pageView}
|
||||||
and website_id = $1
|
and website_id = $1
|
||||||
and rev_id = $2
|
and rev_id = $2
|
||||||
and ${getBetweenDates('created_at', startDate, endDate)}
|
and ${getBetweenDates('created_at', startDate, endDate)}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user