From 5b2f09f29c4cd4698382646555249b2afc89b306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Wed, 8 Oct 2025 07:46:50 +0200 Subject: [PATCH] fix: always use currentDeviceId on client request to make sure they arrive in same group --- apps/api/src/controllers/event.controller.ts | 10 +++++----- apps/api/src/controllers/track.controller.ts | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/apps/api/src/controllers/event.controller.ts b/apps/api/src/controllers/event.controller.ts index 7a01737f..04c3d196 100644 --- a/apps/api/src/controllers/event.controller.ts +++ b/apps/api/src/controllers/event.controller.ts @@ -64,11 +64,11 @@ export async function postEvent( const isGroupQueue = await getRedisCache().exists('group_queue'); if (isGroupQueue) { const uaInfo = parseUserAgent(ua, request.body?.properties); - const groupId = request.body?.profileId - ? `${projectId}:${request.body?.profileId}` - : uaInfo.isServer - ? `${projectId}:${generateId()}` - : currentDeviceId; + const groupId = uaInfo.isServer + ? request.body?.profileId + ? `${projectId}:${request.body?.profileId}` + : `${projectId}:${generateId()}` + : currentDeviceId; await eventsGroupQueue.add({ orderMs: new Date(timestamp).getTime(), data: { diff --git a/apps/api/src/controllers/track.controller.ts b/apps/api/src/controllers/track.controller.ts index 6ce64949..05b24e5f 100644 --- a/apps/api/src/controllers/track.controller.ts +++ b/apps/api/src/controllers/track.controller.ts @@ -3,6 +3,7 @@ import type { FastifyReply, FastifyRequest } from 'fastify'; import { path, assocPath, pathOr, pick } from 'ramda'; import { checkDuplicatedEvent } from '@/utils/deduplicate'; +import { logger } from '@/utils/logger'; import { generateId } from '@openpanel/common'; import { generateDeviceId, parseUserAgent } from '@openpanel/common/server'; import { getProfileById, getSalts, upsertProfile } from '@openpanel/db'; @@ -284,11 +285,11 @@ async function track({ const isGroupQueue = await getRedisCache().exists('group_queue'); if (isGroupQueue) { const uaInfo = parseUserAgent(headers['user-agent'], payload.properties); - const groupId = payload.profileId - ? `${projectId}:${payload.profileId}` - : uaInfo.isServer - ? `${projectId}:${generateId()}` - : currentDeviceId; + const groupId = uaInfo.isServer + ? payload.profileId + ? `${projectId}:${payload.profileId}` + : `${projectId}:${generateId()}` + : currentDeviceId; await eventsGroupQueue.add({ orderMs: new Date(timestamp).getTime(), data: {