@@ -14,6 +14,7 @@ export const processTelemetryEvent = authenticatedProcedure
|
||||
path: '/t/process',
|
||||
description:
|
||||
"Only used for the cloud version of Typebot. It's the way it processes telemetry events and inject it to thrid-party services.",
|
||||
tags: ['Telemetry'],
|
||||
},
|
||||
})
|
||||
.input(
|
||||
@@ -26,19 +27,19 @@ export const processTelemetryEvent = authenticatedProcedure
|
||||
message: z.literal('Events injected'),
|
||||
})
|
||||
)
|
||||
.query(async ({ input: { events }, ctx: { user } }) => {
|
||||
.mutation(async ({ input: { events }, ctx: { user } }) => {
|
||||
if (user.email !== env.ADMIN_EMAIL)
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message: 'Only app admin can process telemetry events',
|
||||
})
|
||||
if (!env.POSTHOG_API_KEY)
|
||||
if (!env.NEXT_PUBLIC_POSTHOG_KEY)
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message: 'Server does not have POSTHOG_API_KEY configured',
|
||||
})
|
||||
const client = new PostHog(env.POSTHOG_API_KEY, {
|
||||
host: 'https://eu.posthog.com',
|
||||
const client = new PostHog(env.NEXT_PUBLIC_POSTHOG_KEY, {
|
||||
host: env.NEXT_PUBLIC_POSTHOG_HOST,
|
||||
})
|
||||
|
||||
events.forEach(async (event) => {
|
||||
|
||||
34
apps/builder/src/features/telemetry/posthog.tsx
Normal file
34
apps/builder/src/features/telemetry/posthog.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { env } from '@typebot.io/env'
|
||||
import posthog from 'posthog-js'
|
||||
|
||||
export const initPostHogIfEnabled = () => {
|
||||
if (typeof window === 'undefined') return
|
||||
|
||||
const posthogKey = env.NEXT_PUBLIC_POSTHOG_KEY
|
||||
|
||||
if (!posthogKey) return
|
||||
|
||||
posthog.init(posthogKey, {
|
||||
api_host: env.NEXT_PUBLIC_POSTHOG_HOST,
|
||||
loaded: (posthog) => {
|
||||
if (process.env.NODE_ENV === 'development') posthog.debug()
|
||||
},
|
||||
capture_pageview: false,
|
||||
capture_pageleave: false,
|
||||
autocapture: false,
|
||||
})
|
||||
}
|
||||
|
||||
export const identifyUser = (userId: string) => {
|
||||
if (!posthog.__loaded) return
|
||||
posthog.identify(userId)
|
||||
}
|
||||
|
||||
export const getFeatureFlags = () => {
|
||||
return posthog.__loaded &&
|
||||
posthog.isFeatureEnabled('whatsApp', { send_event: false })
|
||||
? ['whatsApp']
|
||||
: []
|
||||
}
|
||||
|
||||
export { posthog }
|
||||
Reference in New Issue
Block a user