2
0

📈 Track custom domain and WA enabled events

This commit is contained in:
Baptiste Arnaud
2024-02-02 14:49:41 +01:00
parent 4122d73908
commit b9183f9a36
4 changed files with 39 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import {
} from '@typebot.io/schemas' } from '@typebot.io/schemas'
import { isDefined } from '@typebot.io/lib/utils' import { isDefined } from '@typebot.io/lib/utils'
import { isWriteWorkspaceForbidden } from '@/features/workspace/helpers/isWriteWorkspaceForbidden' import { isWriteWorkspaceForbidden } from '@/features/workspace/helpers/isWriteWorkspaceForbidden'
import { trackEvents } from '@typebot.io/lib/telemetry/trackEvents'
const inputShape = { const inputShape = {
data: true, data: true,
@ -77,6 +78,14 @@ export const createCredentials = authenticatedProcedure
id: true, id: true,
}, },
}) })
if (credentials.type === 'whatsApp')
await trackEvents([
{
workspaceId: workspace.id,
userId: user.id,
name: 'WhatsApp credentials created',
},
])
return { credentialsId: createdCredentials.id } return { credentialsId: createdCredentials.id }
}) })

View File

@ -6,6 +6,7 @@ import { customDomainSchema } from '@typebot.io/schemas/features/customDomains'
import got, { HTTPError } from 'got' import got, { HTTPError } from 'got'
import { env } from '@typebot.io/env' import { env } from '@typebot.io/env'
import { isWriteWorkspaceForbidden } from '@/features/workspace/helpers/isWriteWorkspaceForbidden' import { isWriteWorkspaceForbidden } from '@/features/workspace/helpers/isWriteWorkspaceForbidden'
import { trackEvents } from '@typebot.io/lib/telemetry/trackEvents'
export const createCustomDomain = authenticatedProcedure export const createCustomDomain = authenticatedProcedure
.meta({ .meta({
@ -75,6 +76,17 @@ export const createCustomDomain = authenticatedProcedure
}, },
}) })
await trackEvents([
{
name: 'Custom domain added',
userId: user.id,
workspaceId,
data: {
domain: name,
},
},
])
return { customDomain } return { customDomain }
}) })

View File

@ -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( const subscriptionUpdatedEventSchema = workspaceEvent.merge(
z.object({ z.object({
name: z.literal('Subscription updated'), name: z.literal('Subscription updated'),
@ -142,6 +157,8 @@ export const eventSchema = z.discriminatedUnion('name', [
workspacePastDueEventSchema, workspacePastDueEventSchema,
workspaceNotPastDueEventSchema, workspaceNotPastDueEventSchema,
userUpdatedEventSchema, userUpdatedEventSchema,
customDomainAddedEventSchema,
whatsAppCredentialsCreatedEventSchema,
]) ])
export type TelemetryEvent = z.infer<typeof eventSchema> export type TelemetryEvent = z.infer<typeof eventSchema>

View File

@ -142,7 +142,7 @@ export const incomingMessageSchema = z.discriminatedUnion('type', [
type: z.literal('location'), type: z.literal('location'),
location: z.object({ location: z.object({
latitude: z.number(), latitude: z.number(),
longitude: z.number() longitude: z.number(),
}), }),
timestamp: z.string(), timestamp: z.string(),
}), }),