: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 { router } from 'kea-router'
import { useState } from 'react'
import { IconPlus } from '@posthog/icons'
import { Link } from '@posthog/lemon-ui'
import { AccessControlAction } from 'lib/components/AccessControlAction'
import { BaseCurrency } from 'lib/components/BaseCurrency/BaseCurrency'
import { ProductIntroduction } from 'lib/components/ProductIntroduction/ProductIntroduction'
import { FEATURE_FLAGS } from 'lib/constants'
import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { DefinitionsSceneTabs } from 'scenes/data-management/DefinitionsSceneTabs'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
import { SceneContent } from '~/layout/scenes/components/SceneContent'
import { SceneDivider } from '~/layout/scenes/components/SceneDivider'
import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
import { RevenueAnalyticsEventItem } from '~/queries/schema/schema-general'
import { AccessControlLevel, AccessControlResourceType } from '~/types'
import { sourceManagementLogic } from 'products/data_warehouse/frontend/shared/logics/sourceManagementLogic'
import { DataWarehouseManagedViewsetConfiguration } from './DataWarehouseManagedViewsetConfiguration'
import { EventConfiguration } from './EventConfiguration'
import { EventConfigurationModal } from './EventConfigurationModal'
import { ExternalDataSourceConfiguration } from './ExternalDataSourceConfiguration'
import { FilterTestAccountsConfiguration } from './FilterTestAccountsConfiguration'
import { revenueAnalyticsSettingsLogic } from './revenueAnalyticsSettingsLogic'
export function RevenueAnalyticsSettings(): JSX.Element {
const [eventModalState, setEventModalState] = useState<{
isOpen: boolean
event?: RevenueAnalyticsEventItem
}>({ isOpen: false })
const { events } = useValues(revenueAnalyticsSettingsLogic)
const { dataWarehouseSources, dataWarehouseSourcesLoading } = useValues(sourceManagementLogic)
const { featureFlags } = useValues(featureFlagLogic)
const { currentTeam } = useValues(teamLogic)
const managedViewsetsEnabled = featureFlags[FEATURE_FLAGS.MANAGED_VIEWSETS]
const isViewsetEnabled = currentTeam?.managed_viewsets?.['revenue_analytics'] ?? false
const hasNoEvents = !events.length
const hasNoDataWarehouseSources =
!dataWarehouseSourcesLoading &&
!dataWarehouseSources?.results.filter((source) => source.source_type === 'Stripe').length
const shouldBlockSettings = managedViewsetsEnabled && !isViewsetEnabled
const { reportRevenueAnalyticsSettingsViewed } = useActions(eventUsageLogic)
useOnMountEffect(() => reportRevenueAnalyticsSettingsViewed())
const openEventModal = (event?: RevenueAnalyticsEventItem): void => {
setEventModalState({ isOpen: true, event })
}
const closeEventModal = (): void => {
setEventModalState({ isOpen: false, event: undefined })
}
return (
<SceneContent>
<DefinitionsSceneTabs activeKey="revenue" />
<SceneTitleSection
name="Revenue analytics"
resourceType={{
type: 'revenue_analytics',
}}
/>
{managedViewsetsEnabled && (
<>
<DataWarehouseManagedViewsetConfiguration />
<SceneDivider />
</>
)}
{shouldBlockSettings ? null : (
<>
<AccessControlAction
resourceType={AccessControlResourceType.RevenueAnalytics}
minAccessLevel={AccessControlLevel.Editor}
>
<BaseCurrency />
</AccessControlAction>
<SceneDivider />
<FilterTestAccountsConfiguration />
<SceneDivider />
<ProductIntroduction
thingName="revenue source"
description=""
isEmpty={hasNoEvents && hasNoDataWarehouseSources}
actionElementOverride={
<>
<div className="flex flex-col gap-2">
<AccessControlAction
resourceType={AccessControlResourceType.RevenueAnalytics}
minAccessLevel={AccessControlLevel.Editor}
>
<LemonButton
type="primary"
icon={<IconPlus />}
onClick={() => openEventModal()}
data-attr="create-revenue-event"
>
Add revenue event
</LemonButton>
</AccessControlAction>
<AccessControlAction
resourceType={AccessControlResourceType.RevenueAnalytics}
minAccessLevel={AccessControlLevel.Editor}
>
<LemonButton
type="primary"
icon={<IconPlus />}
onClick={() => {
router.actions.push(urls.dataWarehouseSourceNew('stripe'))
}}
data-attr="import-revenue-data-warehouse-tables"
>
Import revenue data from data warehouse
</LemonButton>
</AccessControlAction>
<span className="text-xs text-muted-alt">
Only Stripe is supported currently. <br />
<Link to="https://posthog.com/roadmap">Request more revenue integrations.</Link>
</span>
</div>
</>
}
/>
<ExternalDataSourceConfiguration />
<SceneDivider />
<EventConfiguration onOpenEventModal={openEventModal} />
</>
)}
{eventModalState.isOpen && (
<EventConfigurationModal event={eventModalState.event} onClose={closeEventModal} />
)}
</SceneContent>
)
}