Merge branch 'dev' into feat/um-185-event-data-redirect

This commit is contained in:
Brian Cao 2023-03-01 16:40:06 -08:00
commit 53a6a8924d
23 changed files with 3791 additions and 98 deletions

View file

@ -10,6 +10,7 @@ export async function saveEvent(args: {
websiteId: string;
url: string;
referrer?: string;
pageTitle?: string;
eventName?: string;
hostname?: string;
browser?: string;
@ -18,6 +19,9 @@ export async function saveEvent(args: {
screen?: string;
language?: string;
country?: string;
subdivision1?: string;
subdivision2?: string;
city?: string;
}) {
return runQuery({
[PRISMA]: () => relationalQuery(args),
@ -30,41 +34,38 @@ async function relationalQuery(data: {
websiteId: string;
url: string;
referrer?: string;
pageTitle?: string;
eventName?: string;
}) {
const { websiteId, id: sessionId, url, eventName, referrer } = data;
const params = {
id: uuid(),
websiteId,
sessionId,
url: url?.substring(0, URL_LENGTH),
referrer: referrer?.substring(0, URL_LENGTH),
eventType: EVENT_TYPE.customEvent,
eventName: eventName?.substring(0, EVENT_NAME_LENGTH),
};
const { websiteId, id: sessionId, url, eventName, referrer, pageTitle } = data;
return prisma.client.websiteEvent.create({
data: params,
data: {
id: uuid(),
websiteId,
sessionId,
url: url?.substring(0, URL_LENGTH),
referrer: referrer?.substring(0, URL_LENGTH),
pageTitle: pageTitle,
eventType: EVENT_TYPE.customEvent,
eventName: eventName?.substring(0, EVENT_NAME_LENGTH),
},
});
}
async function clickhouseQuery(data: {
id: string;
websiteId: string;
url: string;
referrer?: string;
eventName?: string;
hostname?: string;
browser?: string;
os?: string;
device?: string;
screen?: string;
language?: string;
country?: string;
}) {
const { websiteId, id: sessionId, url, eventName, country, ...args } = data;
async function clickhouseQuery(data) {
const {
websiteId,
id: sessionId,
url,
pageTitle,
eventName,
country,
subdivision1,
subdivision2,
city,
...args
} = data;
const { getDateFormat, sendMessage } = kafka;
const website = await cache.fetchWebsite(websiteId);
@ -72,12 +73,16 @@ async function clickhouseQuery(data: {
website_id: websiteId,
session_id: sessionId,
event_id: uuid(),
country: country ? country : null,
subdivision1: subdivision1 ? subdivision1 : null,
subdivision2: subdivision2 ? subdivision2 : null,
city: city ? city : null,
url: url?.substring(0, URL_LENGTH),
page_title: pageTitle,
event_type: EVENT_TYPE.customEvent,
event_name: eventName?.substring(0, EVENT_NAME_LENGTH),
rev_id: website?.revId || 0,
created_at: getDateFormat(new Date()),
country: country ? country : null,
...args,
};

View file

@ -10,6 +10,7 @@ export async function savePageView(args: {
websiteId: string;
url: string;
referrer?: string;
pageTitle?: string;
hostname?: string;
browser?: string;
os?: string;
@ -17,6 +18,9 @@ export async function savePageView(args: {
screen?: string;
language?: string;
country?: string;
subdivision1?: string;
subdivision2?: string;
city?: string;
}) {
return runQuery({
[PRISMA]: () => relationalQuery(args),
@ -29,8 +33,9 @@ async function relationalQuery(data: {
websiteId: string;
url: string;
referrer?: string;
pageTitle?: string;
}) {
const { websiteId, id: sessionId, url, referrer } = data;
const { websiteId, id: sessionId, url, referrer, pageTitle } = data;
return prisma.client.websiteEvent.create({
data: {
@ -39,25 +44,41 @@ async function relationalQuery(data: {
sessionId,
url: url?.substring(0, URL_LENGTH),
referrer: referrer?.substring(0, URL_LENGTH),
pageTitle: pageTitle,
eventType: EVENT_TYPE.pageView,
},
});
}
async function clickhouseQuery(data) {
const { websiteId, id: sessionId, url, referrer, country, ...args } = data;
const website = await cache.fetchWebsite(websiteId);
const {
websiteId,
id: sessionId,
url,
referrer,
pageTitle,
country,
subdivision1,
subdivision2,
city,
...args
} = data;
const { getDateFormat, sendMessage } = kafka;
const website = await cache.fetchWebsite(websiteId);
const message = {
session_id: sessionId,
website_id: websiteId,
session_id: sessionId,
rev_id: website?.revId || 0,
country: country ? country : null,
subdivision1: subdivision1 ? subdivision1 : null,
subdivision2: subdivision2 ? subdivision2 : null,
city: city ? city : null,
url: url?.substring(0, URL_LENGTH),
referrer: referrer?.substring(0, URL_LENGTH),
rev_id: website?.revId || 0,
created_at: getDateFormat(new Date()),
country: country ? country : null,
page_title: pageTitle,
event_type: EVENT_TYPE.pageView,
created_at: getDateFormat(new Date()),
...args,
};

View file

@ -31,8 +31,24 @@ async function clickhouseQuery(data: {
screen?: string;
language?: string;
country?: string;
subdivision1?: string;
subdivision2?: string;
city?: string;
}) {
const { id, websiteId, hostname, browser, os, device, screen, language, country } = data;
const {
id,
websiteId,
hostname,
browser,
os,
device,
screen,
language,
country,
subdivision1,
subdivision2,
city,
} = data;
const { getDateFormat, sendMessage } = kafka;
const website = await cache.fetchWebsite(websiteId);
@ -46,6 +62,9 @@ async function clickhouseQuery(data: {
screen,
language,
country,
subdivision1,
subdivision2,
city,
rev_id: website?.revId || 0,
created_at: getDateFormat(new Date()),
};

View file

@ -31,7 +31,10 @@ async function clickhouseQuery({ id: sessionId }: { id: string }) {
device,
screen,
language,
country
country,
subdivision1,
subdivision2,
city
from event
where session_id = {sessionId:UUID}
limit 1`,

View file

@ -35,7 +35,10 @@ async function clickhouseQuery(websiteId: string, startAt: Date) {
device,
screen,
language,
country
country,
subdivision1,
subdivision2,
city
from event
where website_id = {websiteId:UUID}
and created_at >= {startAt:DateTime('UTC')}`,