: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { useState } from 'react'
import { IconPlus } from '@posthog/icons'
import { LemonButton } from '@posthog/lemon-ui'
import { TaxonomicFilter } from 'lib/components/TaxonomicFilter/TaxonomicFilter'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { Popover } from 'lib/lemon-ui/Popover/Popover'
export interface AddEventButtonProps {
onEventSelect: (eventName: string) => void
addButtonText?: string
excludedEvents?: string[]
}
export function AddEventButton({
onEventSelect,
addButtonText,
excludedEvents = [],
}: AddEventButtonProps): JSX.Element {
const [popoverOpen, setPopoverOpen] = useState(false)
return (
<Popover
overlay={
<TaxonomicFilter
groupType={TaxonomicFilterGroupType.Events}
value=""
onChange={(_, value) => {
if (typeof value === 'string') {
const eventName = value
if (!excludedEvents.includes(eventName)) {
onEventSelect(eventName)
}
setPopoverOpen(false)
}
}}
allowNonCapturedEvents
taxonomicGroupTypes={[TaxonomicFilterGroupType.CustomEvents, TaxonomicFilterGroupType.Events]}
// Configures client-side SDK triggers rather than saving a query, so hidden events stay selectable.
includeHiddenEvents
/>
}
visible={popoverOpen}
onClickOutside={() => setPopoverOpen(false)}
placement="bottom-start"
>
<LemonButton
type="secondary"
icon={<IconPlus />}
onClick={() => setPopoverOpen(!popoverOpen)}
size="small"
className="w-fit"
>
{addButtonText ?? 'Add event'}
</LemonButton>
</Popover>
)
}