From dfe969cabe03d783522ba19f72bf367873ea866c Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Thu, 30 Oct 2025 12:53:12 -0700 Subject: [PATCH 1/2] Fixed pixels/links collect. --- src/app/api/send/route.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/api/send/route.ts b/src/app/api/send/route.ts index 3e569988..f5e00c8a 100644 --- a/src/app/api/send/route.ts +++ b/src/app/api/send/route.ts @@ -82,6 +82,8 @@ export async function POST(request: Request) { id, } = payload; + const sourceId = websiteId || pixelId || linkId; + // Cache check let cache: Cache | null = null; @@ -128,13 +130,13 @@ export async function POST(request: Request) { const sessionSalt = hash(startOfMonth(createdAt).toUTCString()); const visitSalt = hash(startOfHour(createdAt).toUTCString()); - const sessionId = id ? uuid(websiteId, id) : uuid(websiteId, ip, userAgent, sessionSalt); + const sessionId = id ? uuid(sourceId, id) : uuid(sourceId, ip, userAgent, sessionSalt); // Create a session if not found if (!clickhouse.enabled && !cache?.sessionId) { await createSession({ id: sessionId, - websiteId, + websiteId: sourceId, browser, os, device, @@ -206,7 +208,7 @@ export async function POST(request: Request) { : EVENT_TYPE.pageView; await saveEvent({ - websiteId: websiteId || linkId || pixelId, + websiteId: sourceId, sessionId, visitId, eventType, @@ -270,6 +272,9 @@ export async function POST(request: Request) { } catch (e) { const error = serializeError(e); + // eslint-disable-next-line no-console + console.log(error); + return serverError({ errorObject: error }); } } From 504c45909072dbb2e6d0c0bdd93160b0f14f0d6e Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Thu, 30 Oct 2025 16:13:36 -0700 Subject: [PATCH 2/2] update schema validation for link/pixel updates --- src/app/api/links/[linkId]/route.ts | 6 +++--- src/app/api/pixels/[pixelId]/route.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/api/links/[linkId]/route.ts b/src/app/api/links/[linkId]/route.ts index cd93b9c6..512f39c9 100644 --- a/src/app/api/links/[linkId]/route.ts +++ b/src/app/api/links/[linkId]/route.ts @@ -24,9 +24,9 @@ export async function GET(request: Request, { params }: { params: Promise<{ link export async function POST(request: Request, { params }: { params: Promise<{ linkId: string }> }) { const schema = z.object({ - name: z.string(), - url: z.string(), - slug: z.string(), + name: z.string().optional(), + url: z.string().optional(), + slug: z.string().min(8).optional(), }); const { auth, body, error } = await parseRequest(request, schema); diff --git a/src/app/api/pixels/[pixelId]/route.ts b/src/app/api/pixels/[pixelId]/route.ts index 0788579f..2f547c04 100644 --- a/src/app/api/pixels/[pixelId]/route.ts +++ b/src/app/api/pixels/[pixelId]/route.ts @@ -24,8 +24,8 @@ export async function GET(request: Request, { params }: { params: Promise<{ pixe export async function POST(request: Request, { params }: { params: Promise<{ pixelId: string }> }) { const schema = z.object({ - name: z.string(), - slug: z.string().min(8), + name: z.string().optional(), + slug: z.string().min(8).optional(), }); const { auth, body, error } = await parseRequest(request, schema);