mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 06:37:18 +01:00
UTM report.
This commit is contained in:
parent
e602aedd21
commit
bca9c87021
25 changed files with 379 additions and 39 deletions
|
|
@ -27,7 +27,7 @@ const schema: YupRequest = {
|
|||
websiteId: yup.string().uuid().required(),
|
||||
type: yup
|
||||
.string()
|
||||
.matches(/funnel|insights|retention/i)
|
||||
.matches(/funnel|insights|retention|utm/i)
|
||||
.required(),
|
||||
name: yup.string().max(200).required(),
|
||||
description: yup.string().max(500),
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ const schema = {
|
|||
name: yup.string().max(200).required(),
|
||||
type: yup
|
||||
.string()
|
||||
.matches(/funnel|insights|retention/i)
|
||||
.matches(/funnel|insights|retention|utm/i)
|
||||
.required(),
|
||||
description: yup.string().max(500),
|
||||
parameters: yup
|
||||
|
|
|
|||
54
src/pages/api/reports/utm.ts
Normal file
54
src/pages/api/reports/utm.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { canViewWebsite } from 'lib/auth';
|
||||
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
||||
import { NextApiRequestQueryBody } from 'lib/types';
|
||||
import { TimezoneTest } from 'lib/yup';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getUTM } from 'queries';
|
||||
import * as yup from 'yup';
|
||||
|
||||
export interface UTMRequestBody {
|
||||
websiteId: string;
|
||||
dateRange: { startDate: string; endDate: string; timezone: string };
|
||||
}
|
||||
|
||||
const schema = {
|
||||
POST: yup.object().shape({
|
||||
websiteId: yup.string().uuid().required(),
|
||||
dateRange: yup
|
||||
.object()
|
||||
.shape({
|
||||
startDate: yup.date().required(),
|
||||
endDate: yup.date().required(),
|
||||
timezone: TimezoneTest,
|
||||
})
|
||||
.required(),
|
||||
}),
|
||||
};
|
||||
|
||||
export default async (req: NextApiRequestQueryBody<any, UTMRequestBody>, res: NextApiResponse) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
await useValidate(schema, req, res);
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const {
|
||||
websiteId,
|
||||
dateRange: { startDate, endDate, timezone },
|
||||
} = req.body;
|
||||
|
||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const data = await getUTM(websiteId, {
|
||||
startDate: new Date(startDate),
|
||||
endDate: new Date(endDate),
|
||||
timezone,
|
||||
});
|
||||
|
||||
return ok(res, data);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue