2
0

🖐️ Analytics drop off rates

This commit is contained in:
Baptiste Arnaud
2022-01-03 17:39:59 +01:00
parent 1093453c07
commit 6322402c96
38 changed files with 876 additions and 147 deletions

View File

@ -0,0 +1,45 @@
import { Stats } from 'bot-engine'
import useSWR from 'swr'
import { fetcher } from './utils'
export const useStats = ({
typebotId,
onError,
}: {
typebotId?: string
onError: (error: Error) => void
}) => {
const { data, error, mutate } = useSWR<{ stats: Stats }, Error>(
typebotId ? `/api/typebots/${typebotId}/results/stats` : null,
fetcher
)
if (error) onError(error)
return {
stats: data?.stats,
isLoading: !error && !data,
mutate,
}
}
export type AnswersCount = { blockId: string; totalAnswers: number }
export const useAnswersCount = ({
typebotId,
onError,
}: {
typebotId?: string
onError: (error: Error) => void
}) => {
const { data, error, mutate } = useSWR<
{ answersCounts: AnswersCount[] },
Error
>(
typebotId ? `/api/typebots/${typebotId}/results/answers/count` : null,
fetcher
)
if (error) onError(error)
return {
answersCounts: data?.answersCounts,
isLoading: !error && !data,
mutate,
}
}