add tag migrations and update send / saveEvent

This commit is contained in:
Francis Cao 2024-10-15 11:29:27 -07:00
parent 6ce9a8cef4
commit bffb98cd51
7 changed files with 102 additions and 1 deletions

View file

@ -96,7 +96,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
}
const { type, payload } = req.body;
const { url, referrer, name: eventName, data, title } = payload;
const { url, referrer, name: eventName, data, title, tag } = payload;
const pageTitle = safeDecodeURI(title);
await useSession(req, res);
@ -143,6 +143,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
eventData: data,
...session,
sessionId: session.id,
tag,
});
} else if (type === COLLECTION_TYPE.identify) {
if (!data) {

View file

@ -28,6 +28,7 @@ export async function saveEvent(args: {
subdivision1?: string;
subdivision2?: string;
city?: string;
tag?: string;
}) {
return runQuery({
[PRISMA]: () => relationalQuery(args),
@ -47,6 +48,7 @@ async function relationalQuery(data: {
pageTitle?: string;
eventName?: string;
eventData?: any;
tag?: string;
}) {
const {
websiteId,
@ -60,6 +62,7 @@ async function relationalQuery(data: {
eventName,
eventData,
pageTitle,
tag,
} = data;
const websiteEventId = uuid();
@ -77,6 +80,7 @@ async function relationalQuery(data: {
pageTitle: pageTitle?.substring(0, PAGE_TITLE_LENGTH),
eventType: eventName ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
eventName: eventName ? eventName?.substring(0, EVENT_NAME_LENGTH) : null,
tag,
},
});
@ -116,6 +120,7 @@ async function clickhouseQuery(data: {
subdivision1?: string;
subdivision2?: string;
city?: string;
tag?: string;
}) {
const {
websiteId,
@ -133,6 +138,7 @@ async function clickhouseQuery(data: {
subdivision1,
subdivision2,
city,
tag,
...args
} = data;
const { insert, getUTCString } = clickhouse;
@ -163,6 +169,7 @@ async function clickhouseQuery(data: {
page_title: pageTitle?.substring(0, PAGE_TITLE_LENGTH),
event_type: eventName ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
event_name: eventName ? eventName?.substring(0, EVENT_NAME_LENGTH) : null,
tag: tag,
created_at: createdAt,
};