diff --git a/packages/models/features/telemetry.ts b/packages/models/features/telemetry.ts index 9e6bcbb332..9c21b56d37 100644 --- a/packages/models/features/telemetry.ts +++ b/packages/models/features/telemetry.ts @@ -73,6 +73,7 @@ const newResultsCollectedEventSchema = typebotEvent.merge( name: z.literal('New results collected'), data: z.object({ total: z.number(), + isFirstOfKind: z.literal(true).optional(), }), }) ) diff --git a/packages/scripts/sendTotalResultsDigest.ts b/packages/scripts/sendTotalResultsDigest.ts index e83d84fe6c..5d9fd90c3b 100644 --- a/packages/scripts/sendTotalResultsDigest.ts +++ b/packages/scripts/sendTotalResultsDigest.ts @@ -52,31 +52,39 @@ export const sendTotalResultsDigest = async () => { }) const resultsWithWorkspaces = results - .flatMap((result) => { + .flatMap((result, resultIndex) => { const workspace = workspaces.find((workspace) => workspace.typebots.some((typebot) => typebot.id === result.typebotId) ) if (!workspace) return return workspace.members .filter((member) => member.role !== WorkspaceRole.GUEST) - .map((member) => ({ + .map((member, memberIndex) => ({ userId: member.userId, workspaceId: workspace.id, typebotId: result.typebotId, totalResultsYesterday: result._count._all, + isFirstOfKind: + resultIndex === 0 && memberIndex === 0 + ? (true as const) + : undefined, })) }) .filter(isDefined) - const events = resultsWithWorkspaces.map((result) => ({ - name: 'New results collected', - userId: result.userId, - workspaceId: result.workspaceId, - typebotId: result.typebotId, - data: { - total: result.totalResultsYesterday, - }, - })) satisfies TelemetryEvent[] + const events = resultsWithWorkspaces.map( + (result) => + ({ + name: 'New results collected', + userId: result.userId, + workspaceId: result.workspaceId, + typebotId: result.typebotId, + data: { + total: result.totalResultsYesterday, + isFirstOfKind: result.isFirstOfKind, + }, + } satisfies TelemetryEvent) + ) await sendTelemetryEvents(events) console.log(`Sent ${events.length} events.`)