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

@@ -64,11 +64,11 @@ export async function postEvent(
const isGroupQueue = await getRedisCache().exists('group_queue'); const isGroupQueue = await getRedisCache().exists('group_queue');
if (isGroupQueue) { if (isGroupQueue) {
const uaInfo = parseUserAgent(ua, request.body?.properties); const uaInfo = parseUserAgent(ua, request.body?.properties);
const groupId = request.body?.profileId const groupId = uaInfo.isServer
? `${projectId}:${request.body?.profileId}` ? request.body?.profileId
: uaInfo.isServer ? `${projectId}:${request.body?.profileId}`
? `${projectId}:${generateId()}` : `${projectId}:${generateId()}`
: currentDeviceId; : currentDeviceId;
await eventsGroupQueue.add({ await eventsGroupQueue.add({
orderMs: new Date(timestamp).getTime(), orderMs: new Date(timestamp).getTime(),
data: { data: {

View File

@@ -3,6 +3,7 @@ import type { FastifyReply, FastifyRequest } from 'fastify';
import { path, assocPath, pathOr, pick } from 'ramda'; import { path, assocPath, pathOr, pick } from 'ramda';
import { checkDuplicatedEvent } from '@/utils/deduplicate'; import { checkDuplicatedEvent } from '@/utils/deduplicate';
import { logger } from '@/utils/logger';
import { generateId } from '@openpanel/common'; import { generateId } from '@openpanel/common';
import { generateDeviceId, parseUserAgent } from '@openpanel/common/server'; import { generateDeviceId, parseUserAgent } from '@openpanel/common/server';
import { getProfileById, getSalts, upsertProfile } from '@openpanel/db'; import { getProfileById, getSalts, upsertProfile } from '@openpanel/db';
@@ -284,11 +285,11 @@ async function track({
const isGroupQueue = await getRedisCache().exists('group_queue'); const isGroupQueue = await getRedisCache().exists('group_queue');
if (isGroupQueue) { if (isGroupQueue) {
const uaInfo = parseUserAgent(headers['user-agent'], payload.properties); const uaInfo = parseUserAgent(headers['user-agent'], payload.properties);
const groupId = payload.profileId const groupId = uaInfo.isServer
? `${projectId}:${payload.profileId}` ? payload.profileId
: uaInfo.isServer ? `${projectId}:${payload.profileId}`
? `${projectId}:${generateId()}` : `${projectId}:${generateId()}`
: currentDeviceId; : currentDeviceId;
await eventsGroupQueue.add({ await eventsGroupQueue.add({
orderMs: new Date(timestamp).getTime(), orderMs: new Date(timestamp).getTime(),
data: { data: {