Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

feature(api): add event types endpoint

Alexander Klein67551fb12946
diff --git a/pages/api/website/[id]/event-types.js b/pages/api/website/[id]/event-types.js
new file mode 100644
index 000000000..9b461cb8b
--- /dev/null
+++ b/pages/api/website/[id]/event-types.js
@@ -0,0 +1,25 @@
+import { getEventTypes } from 'lib/queries';
+import { ok, methodNotAllowed, unauthorized } from 'lib/response';
+import { allowQuery } from 'lib/auth';
+
+export default async (req, res) => {
+ if (req.method === 'GET') {
+ if (!(await allowQuery(req))) {
+ return unauthorized(res);
+ }
+
+ const { id, start_at, end_at, url } = req.query;
+
+ const websiteId = +id;
+ const startDate = new Date(+start_at);
+ const endDate = new Date(+end_at);
+
+ const eventTypes = await getEventTypes(websiteId, startDate, endDate, undefined, undefined, {
+ url,
+ });
+
+ return ok(res, eventTypes);
+ }
+
+ return methodNotAllowed(res);
+};