mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 06:37:18 +01:00
Display page views and unique visitors.
This commit is contained in:
parent
bdcdcd9d13
commit
ce92c7897d
16 changed files with 162 additions and 44 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import moment from 'moment-timezone';
|
||||
import { getPageviewData } from 'lib/db';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
|
||||
|
|
@ -6,10 +7,14 @@ export default async (req, res) => {
|
|||
|
||||
const { id, start_at, end_at, unit, tz } = req.query;
|
||||
|
||||
if (!moment.tz.zone(tz) || !['hour', 'day'].includes(unit)) {
|
||||
return res.status(400).end();
|
||||
}
|
||||
|
||||
const [pageviews, uniques] = await Promise.all([
|
||||
getPageviewData(+id, new Date(+start_at), new Date(+end_at), tz, unit, '*'),
|
||||
getPageviewData(+id, new Date(+start_at), new Date(+end_at), tz, unit, 'distinct session_id'),
|
||||
]);
|
||||
|
||||
res.status(200).json({ pageviews, uniques });
|
||||
return res.status(200).json({ pageviews, uniques });
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@ export default async (req, res) => {
|
|||
|
||||
const pageviews = await getPageviews(+id, new Date(+start_at), new Date(+end_at));
|
||||
|
||||
res.status(200).json({ pageviews });
|
||||
return res.status(200).json({ pageviews });
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue