mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 07:07:17 +01:00
Add funnel queries
This commit is contained in:
parent
37b94e5b96
commit
d01aa5cd52
7 changed files with 268 additions and 6 deletions
50
pages/api/reports/funnel.ts
Normal file
50
pages/api/reports/funnel.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { canViewWebsite } from 'lib/auth';
|
||||
import { useCors, useAuth } from 'lib/middleware';
|
||||
import { NextApiRequestQueryBody } from 'lib/types';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { ok, methodNotAllowed, unauthorized } from 'next-basics';
|
||||
import { getPageviewFunnel } from 'queries';
|
||||
|
||||
export interface FunnelRequestBody {
|
||||
websiteId: string;
|
||||
urls: string[];
|
||||
window: number;
|
||||
startAt: number;
|
||||
endAt: number;
|
||||
}
|
||||
|
||||
export interface FunnelResponse {
|
||||
urls: string[];
|
||||
window: number;
|
||||
startAt: number;
|
||||
endAt: number;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<any, FunnelRequestBody>,
|
||||
res: NextApiResponse<FunnelResponse>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const { websiteId, urls, window, startAt, endAt } = req.body;
|
||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = getPageviewFunnel(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
urls,
|
||||
windowMinutes: window,
|
||||
});
|
||||
|
||||
return ok(res);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue