2
0

📈 Send onboarding replies to PostHog

This commit is contained in:
Baptiste Arnaud
2024-02-02 11:58:32 +01:00
parent ce79e897a7
commit fd4867f3ae
12 changed files with 99 additions and 36 deletions

View File

@@ -45,7 +45,12 @@ export const trackEvents = async (events: TelemetryEvent[]) => {
client.capture({
distinctId: event.userId,
event: event.name,
properties: 'data' in event ? event.data : undefined,
properties:
event.name === 'User updated'
? { $set: event.data }
: 'data' in event
? event.data
: undefined,
groups,
})
})

View File

@@ -51,6 +51,7 @@ model User {
image String? @db.VarChar(1000)
company String?
onboardingCategories Json
referral String?
graphNavigation GraphNavigation?
preferredAppAppearance String?
accounts Account[]

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "referral" TEXT;

View File

@@ -47,6 +47,7 @@ model User {
image String?
company String?
onboardingCategories Json
referral String?
graphNavigation GraphNavigation?
preferredAppAppearance String?
accounts Account[]

View File

@@ -37,6 +37,18 @@ const userCreatedEventSchema = userEvent.merge(
})
)
const userUpdatedEventSchema = userEvent.merge(
z.object({
name: z.literal('User updated'),
data: z.object({
name: z.string().optional(),
onboardingCategories: z.array(z.string()).optional(),
referral: z.string().optional(),
company: z.string().optional(),
}),
})
)
const typebotCreatedEventSchema = typebotEvent.merge(
z.object({
name: z.literal('Typebot created'),
@@ -129,6 +141,7 @@ export const eventSchema = z.discriminatedUnion('name', [
subscriptionAutoUpdatedEventSchema,
workspacePastDueEventSchema,
workspaceNotPastDueEventSchema,
userUpdatedEventSchema,
])
export type TelemetryEvent = z.infer<typeof eventSchema>

View File

@@ -14,6 +14,7 @@ export const userSchema = z.object({
image: z.string().nullable(),
company: z.string().nullable(),
onboardingCategories: z.array(z.string()),
referral: z.string().nullable(),
graphNavigation: z.nativeEnum(GraphNavigation),
preferredAppAppearance: z.string().nullable(),
displayedInAppNotifications: displayedInAppNotificationsSchema.nullable(),