feat(results): 🛂 Limit analytics
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
import { VStack, Tag, Text } from '@chakra-ui/react'
|
import { VStack, Tag, Text, Tooltip } from '@chakra-ui/react'
|
||||||
import { useGraph } from 'contexts/GraphContext'
|
import { useGraph } from 'contexts/GraphContext'
|
||||||
import { useTypebot } from 'contexts/TypebotContext'
|
import { useTypebot } from 'contexts/TypebotContext'
|
||||||
|
import { useUser } from 'contexts/UserContext'
|
||||||
import React, { useMemo } from 'react'
|
import React, { useMemo } from 'react'
|
||||||
import { AnswersCount } from 'services/analytics'
|
import { AnswersCount } from 'services/analytics'
|
||||||
import {
|
import {
|
||||||
@ -8,17 +9,26 @@ import {
|
|||||||
computeSourceCoordinates,
|
computeSourceCoordinates,
|
||||||
computeDropOffPath,
|
computeDropOffPath,
|
||||||
} from 'services/graph'
|
} from 'services/graph'
|
||||||
|
import { isFreePlan } from 'services/user'
|
||||||
import { byId, isDefined } from 'utils'
|
import { byId, isDefined } from 'utils'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
blockId: string
|
blockId: string
|
||||||
answersCounts: AnswersCount[]
|
answersCounts: AnswersCount[]
|
||||||
|
onUnlockProPlanClick?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DropOffEdge = ({ answersCounts, blockId }: Props) => {
|
export const DropOffEdge = ({
|
||||||
|
answersCounts,
|
||||||
|
blockId,
|
||||||
|
onUnlockProPlanClick,
|
||||||
|
}: Props) => {
|
||||||
|
const { user } = useUser()
|
||||||
const { sourceEndpoints, graphPosition, blocksCoordinates } = useGraph()
|
const { sourceEndpoints, graphPosition, blocksCoordinates } = useGraph()
|
||||||
const { publishedTypebot } = useTypebot()
|
const { publishedTypebot } = useTypebot()
|
||||||
|
|
||||||
|
const isUserOnFreePlan = isFreePlan(user)
|
||||||
|
|
||||||
const totalAnswers = useMemo(
|
const totalAnswers = useMemo(
|
||||||
() => answersCounts.find((a) => a.blockId === blockId)?.totalAnswers,
|
() => answersCounts.find((a) => a.blockId === blockId)?.totalAnswers,
|
||||||
[answersCounts, blockId]
|
[answersCounts, blockId]
|
||||||
@ -77,10 +87,14 @@ export const DropOffEdge = ({ answersCounts, blockId }: Props) => {
|
|||||||
fill="none"
|
fill="none"
|
||||||
/>
|
/>
|
||||||
<foreignObject
|
<foreignObject
|
||||||
width="80"
|
width="100"
|
||||||
height="80"
|
height="80"
|
||||||
x={labelCoordinates.x - 20}
|
x={labelCoordinates.x - 30}
|
||||||
y={labelCoordinates.y + 80}
|
y={labelCoordinates.y + 80}
|
||||||
|
>
|
||||||
|
<Tooltip
|
||||||
|
label="Unlock Drop-off rate by upgrading to Pro plan"
|
||||||
|
isDisabled={!isUserOnFreePlan}
|
||||||
>
|
>
|
||||||
<VStack
|
<VStack
|
||||||
bgColor={'red.500'}
|
bgColor={'red.500'}
|
||||||
@ -90,10 +104,16 @@ export const DropOffEdge = ({ answersCounts, blockId }: Props) => {
|
|||||||
justifyContent="center"
|
justifyContent="center"
|
||||||
w="full"
|
w="full"
|
||||||
h="full"
|
h="full"
|
||||||
|
filter={isUserOnFreePlan ? 'blur(4px)' : ''}
|
||||||
|
onClick={isUserOnFreePlan ? onUnlockProPlanClick : undefined}
|
||||||
|
cursor={isUserOnFreePlan ? 'pointer' : 'auto'}
|
||||||
>
|
>
|
||||||
<Text>{dropOffRate}%</Text>
|
<Text>{isUserOnFreePlan ? 'X' : dropOffRate}%</Text>
|
||||||
<Tag colorScheme="red">{totalDroppedUser} users</Tag>
|
<Tag colorScheme="red">
|
||||||
|
{isUserOnFreePlan ? 'n' : totalDroppedUser} users
|
||||||
|
</Tag>
|
||||||
</VStack>
|
</VStack>
|
||||||
|
</Tooltip>
|
||||||
</foreignObject>
|
</foreignObject>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
@ -9,8 +9,13 @@ import { Edge } from './Edge'
|
|||||||
type Props = {
|
type Props = {
|
||||||
edges: EdgeProps[]
|
edges: EdgeProps[]
|
||||||
answersCounts?: AnswersCount[]
|
answersCounts?: AnswersCount[]
|
||||||
|
onUnlockProPlanClick?: () => void
|
||||||
}
|
}
|
||||||
export const Edges = ({ edges, answersCounts }: Props) => {
|
export const Edges = ({
|
||||||
|
edges,
|
||||||
|
answersCounts,
|
||||||
|
onUnlockProPlanClick,
|
||||||
|
}: Props) => {
|
||||||
return (
|
return (
|
||||||
<chakra.svg
|
<chakra.svg
|
||||||
width="full"
|
width="full"
|
||||||
@ -29,6 +34,7 @@ export const Edges = ({ edges, answersCounts }: Props) => {
|
|||||||
key={answerCount.blockId}
|
key={answerCount.blockId}
|
||||||
answersCounts={answersCounts}
|
answersCounts={answersCounts}
|
||||||
blockId={answerCount.blockId}
|
blockId={answerCount.blockId}
|
||||||
|
onUnlockProPlanClick={onUnlockProPlanClick}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<marker
|
<marker
|
||||||
|
@ -13,10 +13,12 @@ import { AnswersCount } from 'services/analytics'
|
|||||||
export const Graph = ({
|
export const Graph = ({
|
||||||
typebot,
|
typebot,
|
||||||
answersCounts,
|
answersCounts,
|
||||||
|
onUnlockProPlanClick,
|
||||||
...props
|
...props
|
||||||
}: {
|
}: {
|
||||||
typebot?: Typebot | PublicTypebot
|
typebot?: Typebot | PublicTypebot
|
||||||
answersCounts?: AnswersCount[]
|
answersCounts?: AnswersCount[]
|
||||||
|
onUnlockProPlanClick?: () => void
|
||||||
} & FlexProps) => {
|
} & FlexProps) => {
|
||||||
const { draggedStepType, setDraggedStepType, draggedStep, setDraggedStep } =
|
const { draggedStepType, setDraggedStepType, draggedStep, setDraggedStep } =
|
||||||
useStepDnd()
|
useStepDnd()
|
||||||
@ -99,7 +101,11 @@ export const Graph = ({
|
|||||||
transform,
|
transform,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Edges edges={typebot?.edges ?? []} answersCounts={answersCounts} />
|
<Edges
|
||||||
|
edges={typebot?.edges ?? []}
|
||||||
|
answersCounts={answersCounts}
|
||||||
|
onUnlockProPlanClick={onUnlockProPlanClick}
|
||||||
|
/>
|
||||||
{typebot?.blocks.map((block, idx) => (
|
{typebot?.blocks.map((block, idx) => (
|
||||||
<BlockNode block={block as Block} blockIndex={idx} key={block.id} />
|
<BlockNode block={block as Block} blockIndex={idx} key={block.id} />
|
||||||
))}
|
))}
|
||||||
|
@ -20,7 +20,6 @@ export enum LimitReached {
|
|||||||
BRAND = 'Remove branding',
|
BRAND = 'Remove branding',
|
||||||
CUSTOM_DOMAIN = 'Custom domain',
|
CUSTOM_DOMAIN = 'Custom domain',
|
||||||
FOLDER = 'Create folders',
|
FOLDER = 'Create folders',
|
||||||
ANALYTICS = 'Unlock analytics',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpgradeModalProps = {
|
type UpgradeModalProps = {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Flex, useToast } from '@chakra-ui/react'
|
import { Flex, useDisclosure, useToast } from '@chakra-ui/react'
|
||||||
import { StatsCards } from 'components/analytics/StatsCards'
|
import { StatsCards } from 'components/analytics/StatsCards'
|
||||||
import { Graph } from 'components/shared/Graph'
|
import { Graph } from 'components/shared/Graph'
|
||||||
|
import { UpgradeModal } from 'components/shared/modals/UpgradeModal.'
|
||||||
import { GraphProvider } from 'contexts/GraphContext'
|
import { GraphProvider } from 'contexts/GraphContext'
|
||||||
import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
|
import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
|
||||||
import { Stats } from 'models'
|
import { Stats } from 'models'
|
||||||
@ -8,6 +9,7 @@ import React from 'react'
|
|||||||
import { useAnswersCount } from 'services/analytics'
|
import { useAnswersCount } from 'services/analytics'
|
||||||
|
|
||||||
export const AnalyticsContent = ({ stats }: { stats?: Stats }) => {
|
export const AnalyticsContent = ({ stats }: { stats?: Stats }) => {
|
||||||
|
const { isOpen, onOpen, onClose } = useDisclosure()
|
||||||
const { typebot, publishedTypebot } = useTypebot()
|
const { typebot, publishedTypebot } = useTypebot()
|
||||||
|
|
||||||
const toast = useToast({
|
const toast = useToast({
|
||||||
@ -31,6 +33,7 @@ export const AnalyticsContent = ({ stats }: { stats?: Stats }) => {
|
|||||||
<Graph
|
<Graph
|
||||||
flex="1"
|
flex="1"
|
||||||
typebot={publishedTypebot}
|
typebot={publishedTypebot}
|
||||||
|
onUnlockProPlanClick={onOpen}
|
||||||
answersCounts={[
|
answersCounts={[
|
||||||
{ ...answersCounts[0], totalAnswers: stats?.totalStarts },
|
{ ...answersCounts[0], totalAnswers: stats?.totalStarts },
|
||||||
...answersCounts?.slice(1),
|
...answersCounts?.slice(1),
|
||||||
@ -38,6 +41,7 @@ export const AnalyticsContent = ({ stats }: { stats?: Stats }) => {
|
|||||||
/>
|
/>
|
||||||
</GraphProvider>
|
</GraphProvider>
|
||||||
)}
|
)}
|
||||||
|
<UpgradeModal onClose={onClose} isOpen={isOpen} />
|
||||||
<StatsCards stats={stats} pos="absolute" top={10} />
|
<StatsCards stats={stats} pos="absolute" top={10} />
|
||||||
</Flex>
|
</Flex>
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user