Skip to content

Commit

Permalink
📈 Add convenient isFirstOfKind field in total results digest
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 14, 2023
1 parent 67cb4b4 commit 25c3679
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/models/features/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}),
})
)
Expand Down
30 changes: 19 additions & 11 deletions packages/scripts/sendTotalResultsDigest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`)
Expand Down

2 comments on commit 25c3679

@vercel
Copy link

@vercel vercel bot commented on 25c3679 Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 25c3679 Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs.typebot.io
docs-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app

Please sign in to comment.