add revenue table and save

This commit is contained in:
Francis Cao 2025-06-09 11:59:39 -07:00
parent 883fd2580f
commit 49b4948d0f
4 changed files with 105 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import kafka from '@/lib/kafka';
import prisma from '@/lib/prisma';
import { uuid } from '@/lib/crypto';
import { saveEventData } from './saveEventData';
import { saveRevenue } from './saveRevenue';
export interface SaveEventArgs {
websiteId: string;
@ -130,6 +131,20 @@ async function relationalQuery({
eventData,
createdAt,
});
const { revenue, currency } = eventData;
if (revenue > 0 && currency) {
await saveRevenue({
websiteId,
sessionId,
eventId: websiteEventId,
eventName: eventName?.substring(0, EVENT_NAME_LENGTH),
currency,
revenue,
createdAt,
});
}
}
}