mirror of
https://github.com/umami-software/umami.git
synced 2026-02-20 20:45:39 +01:00
Add event_data base.
This commit is contained in:
parent
72af76a417
commit
15c5cc065e
19 changed files with 395 additions and 45 deletions
71
queries/analytics/eventData/saveEventData.ts
Normal file
71
queries/analytics/eventData/saveEventData.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { EVENT_DATA_TYPE } from 'lib/constants';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import { flattenJSON } from 'lib/eventData';
|
||||
import kafka from 'lib/kafka';
|
||||
import { EventData } from 'lib/types';
|
||||
|
||||
export async function saveEventData(args: {
|
||||
websiteId: string;
|
||||
sessionId: string;
|
||||
eventId: string;
|
||||
revId: number;
|
||||
eventName: string;
|
||||
eventData: EventData;
|
||||
createdAt: string;
|
||||
}) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(data: {
|
||||
websiteId: string;
|
||||
sessionId: string;
|
||||
eventId: string;
|
||||
revId: number;
|
||||
eventName: string;
|
||||
eventData: EventData;
|
||||
createdAt: string;
|
||||
}) {
|
||||
return data;
|
||||
}
|
||||
|
||||
async function clickhouseQuery(data: {
|
||||
websiteId: string;
|
||||
sessionId: string;
|
||||
eventId: string;
|
||||
revId: number;
|
||||
eventName: string;
|
||||
eventData: EventData;
|
||||
createdAt: string;
|
||||
}) {
|
||||
const { websiteId, sessionId, eventId, revId, eventName, eventData, createdAt } = data;
|
||||
|
||||
const { getDateFormat, sendMessages } = kafka;
|
||||
|
||||
const jsonKeys = flattenJSON(eventData);
|
||||
|
||||
const messages = jsonKeys.map(a => ({
|
||||
website_id: websiteId,
|
||||
session_id: sessionId,
|
||||
event_id: eventId,
|
||||
rev_id: revId,
|
||||
event_name: eventName,
|
||||
event_key: a.key,
|
||||
event_string_value:
|
||||
a.eventDataType === EVENT_DATA_TYPE.string ||
|
||||
a.eventDataType === EVENT_DATA_TYPE.boolean ||
|
||||
a.eventDataType === EVENT_DATA_TYPE.array
|
||||
? a.value
|
||||
: null,
|
||||
event_numeric_value: a.eventDataType === EVENT_DATA_TYPE.number ? a.value : null,
|
||||
event_date_value: a.eventDataType === EVENT_DATA_TYPE.date ? getDateFormat(a.value) : null,
|
||||
event_data_type: a.eventDataType,
|
||||
created_at: createdAt,
|
||||
}));
|
||||
|
||||
await sendMessages(messages, 'event_data');
|
||||
|
||||
return data;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue