mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-18 15:23:38 +01:00
Update queries to calculate correct metrics.
This commit is contained in:
parent
1dfa6d8b16
commit
a24bee815c
@ -333,12 +333,32 @@ export function getPageviews(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRankings(website_id, start_at, end_at, type, table, domain) {
|
export function getSessionMetrics(website_id, start_at, end_at, field) {
|
||||||
const filter = domain ? `and ${type} not like '%${domain}%'` : '';
|
return rawQuery(
|
||||||
|
`
|
||||||
|
select ${field} x, count(*) y
|
||||||
|
from session
|
||||||
|
where session_id in (
|
||||||
|
select session_id
|
||||||
|
from pageview
|
||||||
|
where website_id=$1
|
||||||
|
and created_at between $2 and $3
|
||||||
|
)
|
||||||
|
group by 1
|
||||||
|
order by 2 desc
|
||||||
|
`,
|
||||||
|
website_id,
|
||||||
|
start_at,
|
||||||
|
end_at,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPageviewMetrics(website_id, start_at, end_at, field, table, domain) {
|
||||||
|
const filter = domain ? `and ${field} not like '%${domain}%'` : '';
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
`
|
`
|
||||||
select distinct ${type} x, count(*) y
|
select ${field} x, count(*) y
|
||||||
from ${table}
|
from ${table}
|
||||||
where website_id=$1
|
where website_id=$1
|
||||||
and created_at between $2 and $3
|
and created_at between $2 and $3
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { getRankings } from 'lib/queries';
|
import { getPageviewMetrics, getSessionMetrics } from 'lib/queries';
|
||||||
import { ok, badRequest, methodNotAllowed, unauthorized } from 'lib/response';
|
import { ok, badRequest, methodNotAllowed, unauthorized } from 'lib/response';
|
||||||
import { DOMAIN_REGEX } from 'lib/constants';
|
import { DOMAIN_REGEX } from 'lib/constants';
|
||||||
import { allowQuery } from 'lib/auth';
|
import { allowQuery } from 'lib/auth';
|
||||||
@ -33,30 +33,32 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
const { id, type, start_at, end_at, domain } = req.query;
|
const { id, type, start_at, end_at, domain } = req.query;
|
||||||
|
|
||||||
|
if (domain && !DOMAIN_REGEX.test(domain)) {
|
||||||
|
return badRequest(res);
|
||||||
|
}
|
||||||
|
|
||||||
const websiteId = +id;
|
const websiteId = +id;
|
||||||
const startDate = new Date(+start_at);
|
const startDate = new Date(+start_at);
|
||||||
const endDate = new Date(+end_at);
|
const endDate = new Date(+end_at);
|
||||||
|
|
||||||
if (
|
if (sessionColumns.includes(type)) {
|
||||||
type !== 'event' &&
|
const data = await getSessionMetrics(websiteId, startDate, endDate, type);
|
||||||
!sessionColumns.includes(type) &&
|
|
||||||
!pageviewColumns.includes(type) &&
|
return ok(res, data);
|
||||||
domain &&
|
|
||||||
DOMAIN_REGEX.test(domain)
|
|
||||||
) {
|
|
||||||
return badRequest(res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const rankings = await getRankings(
|
if (type === 'event' || pageviewColumns.includes(type)) {
|
||||||
websiteId,
|
const data = await getPageviewMetrics(
|
||||||
startDate,
|
websiteId,
|
||||||
endDate,
|
startDate,
|
||||||
getColumn(type),
|
endDate,
|
||||||
getTable(type),
|
getColumn(type),
|
||||||
domain,
|
getTable(type),
|
||||||
);
|
domain,
|
||||||
|
);
|
||||||
|
|
||||||
return ok(res, rankings);
|
return ok(res, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return methodNotAllowed(res);
|
return methodNotAllowed(res);
|
||||||
|
Loading…
Reference in New Issue
Block a user