: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 { useActions, useValues } from 'kea'
import { useEffect } from 'react'
import { IconPauseFilled, IconPlayFilled, IconRefresh, IconTerminal } from '@posthog/icons'
import { LemonButton, Link } from '@posthog/lemon-ui'
import { LiveUserCount } from 'lib/components/LiveUserCount'
import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { usePageVisibility } from 'lib/hooks/usePageVisibility'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { ActivitySceneHeader } from 'scenes/activity/ActivitySceneHeader'
import { sceneConfigurations } from 'scenes/scenes'
import { Scene, SceneExport } from 'scenes/sceneTypes'
import { LiveRecordingsCount } from 'scenes/session-recordings/components/LiveRecordingsCount'
import { SceneContent } from '~/layout/scenes/components/SceneContent'
import { ProductKey } from '~/queries/schema/schema-general'
import { ActivityTab, PropertyOperator } from '~/types'
import { EventName } from 'products/actions/frontend/components/EventName'
import { useAttachedContext } from 'products/posthog_ai/frontend/api/logics'
import { buildLiveEventsAgentContext } from '../activityAgentContext'
import { LiveBotPanel } from './LiveBotPanel'
import { LiveEventsFeed } from './LiveEventsFeed'
import { liveEventsLogic } from './liveEventsLogic'
import { liveEventsTableSceneLogic } from './liveEventsTableSceneLogic'
const LIVE_EVENTS_POLL_INTERVAL_MS = 1500
export const scene: SceneExport = {
component: LiveEventsTable,
logic: liveEventsTableSceneLogic,
productKey: ProductKey.PRODUCT_ANALYTICS,
}
export function LiveEventsTable(): JSX.Element {
const { events, streamPaused, filters } = useValues(liveEventsLogic)
const { pauseStream, resumeStream, setFilters, clearEvents } = useActions(liveEventsLogic)
useAttachedContext(buildLiveEventsAgentContext(filters))
const { isVisible } = usePageVisibility()
useEffect(() => {
if (isVisible) {
resumeStream()
} else {
pauseStream()
}
}, [isVisible, resumeStream, pauseStream])
return (
<SceneContent data-attr="manage-events-table">
<ActivitySceneHeader
activeKey={ActivityTab.LiveEvents}
name={sceneConfigurations[Scene.Activity].name}
description={sceneConfigurations[Scene.Activity].description}
iconType={sceneConfigurations[Scene.LiveEvents].iconType}
banner={
<LemonBanner
type="info"
className="mb-4"
icon={<IconTerminal />}
dismissKey="livestream-tui-banner"
>
Stream live events directly in your terminal with <code>posthog-live</code>.{' '}
<Link to="https://posthog.com/docs/activity#terminal-live-events-posthog-live" target="_blank">
Learn more
</Link>
</LemonBanner>
}
/>
<div className="mb-4 flex w-full justify-between items-center">
<div className="flex gap-2">
<LiveUserCount pollIntervalMs={LIVE_EVENTS_POLL_INTERVAL_MS} showUpdatedTimeInTooltip={false} />
<LiveRecordingsCount />
</div>
<div className="flex gap-2">
<LemonButton
icon={<IconRefresh className="w-4 h-4" />}
type="secondary"
onClick={clearEvents}
size="small"
tooltip="Clear events"
/>
<EventName
value={filters.eventType}
onChange={(value) => setFilters({ ...filters, eventType: value })}
placeholder="Filter by event"
allEventsOption="clear"
// Narrows the live feed in memory rather than saving a query.
includeHiddenEvents
/>
<PropertyFilters
pageKey="live-events"
propertyFilters={filters.properties ?? []}
onChange={(properties) => setFilters({ ...filters, properties })}
taxonomicGroupTypes={[TaxonomicFilterGroupType.EventProperties]}
operatorAllowlist={[PropertyOperator.Exact]}
buttonText="Filter by property"
/>
<LemonButton
icon={
streamPaused ? (
<IconPlayFilled className="w-4 h-4" />
) : (
<IconPauseFilled className="w-4 h-4" />
)
}
type="secondary"
onClick={streamPaused ? resumeStream : pauseStream}
size="small"
>
{streamPaused ? 'Play' : 'Pause'}
</LemonButton>
</div>
</div>
<LiveBotPanel events={events} className="mb-2" />
<LiveEventsFeed events={events} streamPaused={streamPaused} />
</SceneContent>
)
}