OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
fix: always use currentDeviceId on client request to make sure they arrive in same group
Carl-Gerhard Lindesvärd5b2f09f29c4c
diff --git a/apps/api/src/controllers/event.controller.ts b/apps/api/src/controllers/event.controller.tsindex 7a01737f8..04c3d1961 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.tsindex 6ce64949c..05b24e5f5 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: {