Pixel route.

This commit is contained in:
Mike Cao 2025-08-18 15:49:10 -07:00
parent 3c5c1e48e9
commit 0ac8bd41b6
10 changed files with 139 additions and 64 deletions

View file

@ -11,8 +11,8 @@ export interface SaveEventArgs {
websiteId: string;
sessionId: string;
visitId: string;
eventType: number;
createdAt?: Date;
eventType?: number;
// Page
pageTitle?: string;
@ -115,7 +115,7 @@ async function relationalQuery({
ttclid,
lifatid,
twclid,
eventType: eventType || (eventName ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView),
eventType,
eventName: eventName ? eventName?.substring(0, EVENT_NAME_LENGTH) : null,
tag,
hostname,

View file

@ -1,10 +1,7 @@
import { Prisma } from '@/generated/prisma/client';
import prisma from '@/lib/prisma';
export async function createSession(
data: Prisma.SessionCreateInput,
options = { skipDuplicates: false },
) {
export async function createSession(data: Prisma.SessionCreateInput) {
const {
id,
websiteId,
@ -36,12 +33,7 @@ export async function createSession(
},
});
} catch (e: any) {
// With skipDuplicates flag: ignore unique constraint error and return null
if (
options.skipDuplicates &&
e instanceof Prisma.PrismaClientKnownRequestError &&
e.code === 'P2002'
) {
if (e.message.toLowerCase().includes('unique constraint')) {
return null;
}
throw e;