mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 14:47:14 +01:00
Events table.
This commit is contained in:
parent
a19248d713
commit
5e9299be1e
13 changed files with 131 additions and 31 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { getRankings } from 'lib/queries';
|
||||
import { getRankings, getEvents } from 'lib/queries';
|
||||
import { ok, badRequest } from 'lib/response';
|
||||
|
||||
const sessionColumns = ['browser', 'os', 'device', 'country'];
|
||||
|
|
@ -6,14 +6,23 @@ const pageviewColumns = ['url', 'referrer'];
|
|||
|
||||
export default async (req, res) => {
|
||||
const { id, type, start_at, end_at } = req.query;
|
||||
const websiteId = +id;
|
||||
const startDate = new Date(+start_at);
|
||||
const endDate = new Date(+end_at);
|
||||
|
||||
if (!sessionColumns.includes(type) && !pageviewColumns.includes(type)) {
|
||||
if (type !== 'event' && !sessionColumns.includes(type) && !pageviewColumns.includes(type)) {
|
||||
return badRequest(res);
|
||||
}
|
||||
|
||||
if (type === 'event') {
|
||||
const events = await getEvents(websiteId, startDate, endDate);
|
||||
|
||||
return ok(res, events);
|
||||
}
|
||||
|
||||
const table = sessionColumns.includes(type) ? 'session' : 'pageview';
|
||||
|
||||
const rankings = await getRankings(+id, new Date(+start_at), new Date(+end_at), type, table);
|
||||
const rankings = await getRankings(websiteId, startDate, endDate, type, table);
|
||||
|
||||
return ok(res, rankings);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue