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:
Brian Cao 2023-03-23 14:01:15 -07:00 committed by GitHub
parent c2789d70bc
commit 9979672de5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 719 additions and 130 deletions

View file

@ -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);