umami/pages/api/collect.js

17 lines
403 B
JavaScript
Raw Normal View History

2020-07-17 10:03:38 +02:00
import { parseCollectRequest } from 'lib/utils';
import { savePageView } from '../../lib/db';
export default async (req, res) => {
const values = parseCollectRequest(req);
2020-07-18 04:15:29 +02:00
if (values.valid) {
2020-07-17 10:03:38 +02:00
const { type, session_id, url, referrer } = values;
if (type === 'pageview') {
await savePageView(session_id, url, referrer);
}
}
2020-07-18 04:15:29 +02:00
res.status(200).json({ status: values.valid });
2020-07-17 10:03:38 +02:00
};