mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Feat/um 202 event data new (#1841)
* Add event_data base. * Add url_path. * Add eventData back. * Finish event_data relational. * resolve comments.
This commit is contained in:
parent
c2789d70bc
commit
9979672de5
27 changed files with 719 additions and 130 deletions
|
|
@ -34,7 +34,13 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
|
|||
|
||||
const { type, payload } = getJsonBody(req);
|
||||
|
||||
const { url, referrer, eventName, pageTitle } = payload;
|
||||
const { url, referrer, eventName, eventData, pageTitle } = payload;
|
||||
|
||||
// Validate eventData is JSON
|
||||
if (eventData && !(typeof eventData === 'object' && !Array.isArray(eventData))) {
|
||||
return badRequest(res, 'Event Data must be in the form of a JSON Object.');
|
||||
}
|
||||
|
||||
const ignoreIps = process.env.IGNORE_IP;
|
||||
const ignoreHostnames = process.env.IGNORE_HOSTNAME;
|
||||
|
||||
|
|
@ -93,8 +99,8 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
|
|||
referrerDomain = newRef.hostname;
|
||||
referrerQuery = newRef.search.substring(1);
|
||||
} catch {
|
||||
referrerPath = referrer.split('?')[0];
|
||||
referrerQuery = referrer.split('?')[1];
|
||||
referrerPath = referrer?.split('?')[0];
|
||||
referrerQuery = referrer?.split('?')[1];
|
||||
}
|
||||
|
||||
if (process.env.REMOVE_TRAILING_SLASH) {
|
||||
|
|
@ -118,6 +124,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
|
|||
urlQuery,
|
||||
pageTitle,
|
||||
eventName,
|
||||
eventData,
|
||||
});
|
||||
} else {
|
||||
return badRequest(res);
|
||||
|
|
|
|||
60
pages/api/websites/[id]/eventData.ts
Normal file
60
pages/api/websites/[id]/eventData.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { canViewWebsite } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { NextApiRequestQueryBody, WebsiteEventDataMetric } from 'lib/types';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getEventData } from 'queries';
|
||||
|
||||
export interface WebsiteEventDataRequestQuery {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface WebsiteEventDataRequestBody {
|
||||
startAt: string;
|
||||
endAt: string;
|
||||
eventName?: string;
|
||||
urlPath?: string;
|
||||
timeSeries?: {
|
||||
unit: string;
|
||||
timezone: string;
|
||||
};
|
||||
filters: [
|
||||
{
|
||||
eventKey?: string;
|
||||
eventValue?: string | number | boolean | Date;
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<WebsiteEventDataRequestQuery, WebsiteEventDataRequestBody>,
|
||||
res: NextApiResponse<WebsiteEventDataMetric[]>,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
const { id: websiteId } = req.query;
|
||||
|
||||
if (req.method === 'POST') {
|
||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { startAt, endAt, eventName, urlPath, filters } = req.body;
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const events = await getEventData(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
eventName,
|
||||
urlPath,
|
||||
filters,
|
||||
});
|
||||
|
||||
return ok(res, events);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue