Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.8 KB
Raw Blame
import { useActions, useValues } from 'kea'

import { IconSparkles } from '@posthog/icons'
import { LemonButton, LemonButtonProps } from '@posthog/lemon-ui'

import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { useOpenAi } from 'scenes/max/useOpenAi'

import { todayShellLogic } from '~/layout/today/todayShellLogic'

import { customerAnalyticsDashboardEventsLogic } from '../scenes/CustomerAnalyticsConfigurationScene/events/customerAnalyticsDashboardEventsLogic'

type ConfigureWithAIButtonProps = LemonButtonProps & {
    prompt: string
    event?: string
    eventToHighlight?: string
    children?: React.ReactNode
}

export function ConfigureWithAIButton({
    prompt,
    event,
    eventToHighlight,
    children,
    ...props
}: ConfigureWithAIButtonProps): JSX.Element | null {
    const { openAi } = useOpenAi()
    const { todayRailEnabled } = useValues(todayShellLogic)
    const { addEventToHighlight } = useActions(customerAnalyticsDashboardEventsLogic)
    const { reportCustomerAnalyticsDashboardConfigureEventWithAIClicked } = useActions(eventUsageLogic)

    const handleClick = (): void => {
        openAi(prompt)
        if (eventToHighlight) {
            addEventToHighlight(eventToHighlight)
        }
        reportCustomerAnalyticsDashboardConfigureEventWithAIClicked({ event: event || eventToHighlight })
    }

    if (todayRailEnabled) {
        return null
    }

    return (
        <LemonButton
            size="small"
            type="tertiary"
            icon={<IconSparkles className="text-accent" />}
            tooltip="Configure with PostHog AI"
            onClick={handleClick}
            className="border border-accent border-dashed p-1"
            data-attr="customer-analytics-configure-event-with-ai"
            noPadding
            {...props}
        >
            {children}
        </LemonButton>
    )
}