Skip to content

Commit

Permalink
馃搱 Track custom domain and WA enabled events
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 2, 2024
1 parent 4122d73 commit b9183f9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@typebot.io/schemas'
import { isDefined } from '@typebot.io/lib/utils'
import { isWriteWorkspaceForbidden } from '@/features/workspace/helpers/isWriteWorkspaceForbidden'
import { trackEvents } from '@typebot.io/lib/telemetry/trackEvents'

const inputShape = {
data: true,
Expand Down Expand Up @@ -77,6 +78,14 @@ export const createCredentials = authenticatedProcedure
id: true,
},
})
if (credentials.type === 'whatsApp')
await trackEvents([
{
workspaceId: workspace.id,
userId: user.id,
name: 'WhatsApp credentials created',
},
])
return { credentialsId: createdCredentials.id }
})

Expand Down
12 changes: 12 additions & 0 deletions apps/builder/src/features/customDomains/api/createCustomDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { customDomainSchema } from '@typebot.io/schemas/features/customDomains'
import got, { HTTPError } from 'got'
import { env } from '@typebot.io/env'
import { isWriteWorkspaceForbidden } from '@/features/workspace/helpers/isWriteWorkspaceForbidden'
import { trackEvents } from '@typebot.io/lib/telemetry/trackEvents'

export const createCustomDomain = authenticatedProcedure
.meta({
Expand Down Expand Up @@ -75,6 +76,17 @@ export const createCustomDomain = authenticatedProcedure
},
})

await trackEvents([
{
name: 'Custom domain added',
userId: user.id,
workspaceId,
data: {
domain: name,
},
},
])

return { customDomain }
})

Expand Down
17 changes: 17 additions & 0 deletions packages/schemas/features/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ const publishedTypebotEventSchema = typebotEvent.merge(
})
)

const customDomainAddedEventSchema = workspaceEvent.merge(
z.object({
name: z.literal('Custom domain added'),
data: z.object({
domain: z.string(),
}),
})
)

const whatsAppCredentialsCreatedEventSchema = workspaceEvent.merge(
z.object({
name: z.literal('WhatsApp credentials created'),
})
)

const subscriptionUpdatedEventSchema = workspaceEvent.merge(
z.object({
name: z.literal('Subscription updated'),
Expand Down Expand Up @@ -142,6 +157,8 @@ export const eventSchema = z.discriminatedUnion('name', [
workspacePastDueEventSchema,
workspaceNotPastDueEventSchema,
userUpdatedEventSchema,
customDomainAddedEventSchema,
whatsAppCredentialsCreatedEventSchema,
])

export type TelemetryEvent = z.infer<typeof eventSchema>
2 changes: 1 addition & 1 deletion packages/schemas/features/whatsapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const incomingMessageSchema = z.discriminatedUnion('type', [
type: z.literal('location'),
location: z.object({
latitude: z.number(),
longitude: z.number()
longitude: z.number(),
}),
timestamp: z.string(),
}),
Expand Down

0 comments on commit b9183f9

Please sign in to comment.