fix: always use currentDeviceId on client request to make sure they arrive in same group

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-10-08 07:46:50 +02:00
parent 174a30d515
commit 5b2f09f29c
2 changed files with 11 additions and 10 deletions

View File

@@ -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: {