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.

fix(revenue-analytics): make add-revenue-event entry button work (#59155)

posthog[bot]131dd378dec3
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index fa9288bba418..5307829bac8d 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4099,9 +4099,9 @@ snapshots:
scenes-app-data-management-revenue-analytics--settings--light:
hash: v1.k794b7964.e43a88d9e731fa26b16098ef0f387a29c7cd3e24762f1d6a507dc6d2644e6563.IPgZlzSZVzZuzqsZra04bNAGNGY3X53wuZlJwCcvDsU
scenes-app-data-management-revenue-analytics-event-configuration-modal--default--dark:
- hash: v1.k794b7964.1260ccdaa09ccbea5b044e62ccaa61df66548fed0605c92eb34105bae30bb39b.kaC8bFwhjp23aVTJ5ynR_i7yomCV-R5pw7BUS1CPRiQ
+ hash: v1.k794b7964.b7da818440cce605dcb07bb5f9148080c85cdad96b7546781450122607abd5a2.fnqTch61d1nE8VWTmjOT215WNlzEypscmrtWJ9uxgFo
scenes-app-data-management-revenue-analytics-event-configuration-modal--default--light:
- hash: v1.k794b7964.d9584ffc44a8e22f4ee9915c12ba7bbfb948481f5639e009e7b0d14c19645262.dNmjP0v4qyKL3IMh2UANB5TEqRRYBMC00bVxR29MIno
+ hash: v1.k794b7964.92b5eaed847d1998fea36d7049c7b2b76f43864abd91784b77413bac1e28b453.cqyqE8dtKyCz3l0F9gcTHTOEt6s3Qzb1f-li3OIGkgY
scenes-app-data-warehouse-editor-upstream-graph--empty-state--dark:
hash: v1.k794b7964.0dc97f7b0c3ae81fcac98a415c7882c3a46bd371ce72a78ed05cb64f5e5f286a.l50zfPs-m7SlrgboOciMdUkiowPG7lbs8Bwft1UarRs
scenes-app-data-warehouse-editor-upstream-graph--empty-state--light:
diff --git a/products/revenue_analytics/frontend/settings/EventConfiguration.tsx b/products/revenue_analytics/frontend/settings/EventConfiguration.tsx
index 873f7984efde..caaaf334c09a 100644
--- a/products/revenue_analytics/frontend/settings/EventConfiguration.tsx
+++ b/products/revenue_analytics/frontend/settings/EventConfiguration.tsx
@@ -8,7 +8,6 @@ import { AccessControlAction } from 'lib/components/AccessControlAction'
import { FEATURE_FLAGS } from 'lib/constants'
import { LemonTable } from 'lib/lemon-ui/LemonTable'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
-import { userHasAccess } from 'lib/utils/accessControlUtils'
import { CURRENCY_SYMBOL_TO_EMOJI_MAP, getCurrencySymbol } from 'lib/utils/geography/currency'
import { DataWarehouseManagedViewsetImpactModal } from 'scenes/data-management/managed-viewsets/DataWarehouseManagedViewsetImpactModal'
import { disableDataWarehouseManagedViewsetModalLogic } from 'scenes/data-management/managed-viewsets/disableDataWarehouseManagedViewsetModalLogic'
@@ -21,7 +20,11 @@ import { deleteRevenueEventModalLogic } from './deleteRevenueEventModalLogic'
import { EventConfigurationModal } from './EventConfigurationModal'
import { revenueAnalyticsSettingsLogic } from './revenueAnalyticsSettingsLogic'
-export function EventConfiguration({ buttonRef }: { buttonRef?: React.RefObject<HTMLButtonElement> }): JSX.Element {
+export function EventConfiguration({
+ onOpenEventModal,
+}: {
+ onOpenEventModal?: (event?: RevenueAnalyticsEventItem) => void
+}): JSX.Element {
const { events } = useValues(revenueAnalyticsSettingsLogic)
const { featureFlags } = useValues(featureFlagLogic)
const { views, eventName: eventToBeDeleted } = useValues(deleteRevenueEventModalLogic)
@@ -32,11 +35,14 @@ export function EventConfiguration({ buttonRef }: { buttonRef?: React.RefObject<
const managedViewsetsEnabled = featureFlags[FEATURE_FLAGS.MANAGED_VIEWSETS]
- const [modalState, setModalState] = useState<{
+ const [localModalState, setLocalModalState] = useState<{
isOpen: boolean
event?: RevenueAnalyticsEventItem
}>({ isOpen: false })
+ const openModalForEvent = onOpenEventModal ?? ((event) => setLocalModalState({ isOpen: true, event }))
+ const closeLocalModal = (): void => setLocalModalState({ isOpen: false, event: undefined })
+
const onDeleteEvent = async (): Promise<boolean> => {
if (!eventToBeDeleted) {
return false
@@ -66,12 +72,7 @@ export function EventConfiguration({ buttonRef }: { buttonRef?: React.RefObject<
resourceType={AccessControlResourceType.RevenueAnalytics}
minAccessLevel={AccessControlLevel.Editor}
>
- <LemonButton
- type="primary"
- icon={<IconPlus />}
- onClick={() => setModalState({ isOpen: true })}
- ref={buttonRef}
- >
+ <LemonButton type="primary" icon={<IconPlus />} onClick={() => openModalForEvent()}>
Add Revenue Event
</LemonButton>
</AccessControlAction>
@@ -193,7 +194,7 @@ export function EventConfiguration({ buttonRef }: { buttonRef?: React.RefObject<
size="small"
type="secondary"
icon={<IconGear />}
- onClick={() => setModalState({ isOpen: true, event: item })}
+ onClick={() => openModalForEvent(item)}
tooltip="Edit event configuration"
/>
</AccessControlAction>
@@ -229,14 +230,6 @@ export function EventConfiguration({ buttonRef }: { buttonRef?: React.RefObject<
]}
/>
- {modalState.isOpen &&
- userHasAccess(AccessControlResourceType.RevenueAnalytics, AccessControlLevel.Editor) && (
- <EventConfigurationModal
- event={modalState.event}
- onClose={() => setModalState({ isOpen: false, event: undefined })}
- />
- )}
-
{managedViewsetsEnabled && (
<DataWarehouseManagedViewsetImpactModal
type="EventConfiguration"
@@ -259,6 +252,10 @@ export function EventConfiguration({ buttonRef }: { buttonRef?: React.RefObject<
confirmButtonText="Yes, remove event"
/>
)}
+
+ {!onOpenEventModal && localModalState.isOpen && (
+ <EventConfigurationModal event={localModalState.event} onClose={closeLocalModal} />
+ )}
</SceneSection>
)
}
diff --git a/products/revenue_analytics/frontend/settings/EventConfigurationModal.tsx b/products/revenue_analytics/frontend/settings/EventConfigurationModal.tsx
index 1e966086ef8b..5033bf484ef5 100644
--- a/products/revenue_analytics/frontend/settings/EventConfigurationModal.tsx
+++ b/products/revenue_analytics/frontend/settings/EventConfigurationModal.tsx
@@ -8,7 +8,7 @@ import { CurrencyDropdown } from 'lib/components/BaseCurrency/CurrencyDropdown'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { TaxonomicPopover } from 'lib/components/TaxonomicPopover/TaxonomicPopover'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
-import { userHasAccess } from 'lib/utils/accessControlUtils'
+import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
@@ -51,11 +51,11 @@ export function EventConfigurationModal({ event, onClose }: EventConfigurationMo
const [eventName, setEventName] = useState<string | null>(() => event?.eventName ?? null)
const [originalEvent] = useState<RevenueAnalyticsEventItem | null>(() => (event ? { ...event } : null))
- // Don't show the modal if the user doesn't have access to the revenue analytics resource
- if (!userHasAccess(AccessControlResourceType.RevenueAnalytics, AccessControlLevel.Editor)) {
- onClose()
- return null
- }
+ const accessDeniedReason = getAccessControlDisabledReason(
+ AccessControlResourceType.RevenueAnalytics,
+ AccessControlLevel.Editor
+ )
+ const isReadOnly = !!accessDeniedReason
// Get current event data from store
const currentEvent = eventName ? events.find((e) => e.eventName === eventName) : null
@@ -106,7 +106,13 @@ export function EventConfigurationModal({ event, onClose }: EventConfigurationMo
<LemonModal.Content>
<div className="space-y-4">
- {!originalEvent && (
+ {isReadOnly && (
+ <LemonBanner type="warning" className="text-sm">
+ <strong>Read only:</strong> {accessDeniedReason} Ask a workspace admin to grant you Editor
+ access to Revenue analytics to add or change events.
+ </LemonBanner>
+ )}
+ {!originalEvent && !isReadOnly && (
<LemonBanner type="info" className="text-sm">
<strong>How it works:</strong> PostHog will track this event and use these properties for
revenue calculations. You can always modify these settings later.
@@ -178,14 +184,16 @@ export function EventConfigurationModal({ event, onClose }: EventConfigurationMo
<p className="text-xs text-muted-alt">
Choose the property that tracks the amount of revenue generated by this event.
</p>
- <p className="text-xs text-muted-alt">
- NOTE: We only display <strong>numerical</strong> properties in here. If you're not seeing
- your property here, make sure it's properly set as numeric in the{' '}
- <Link to={urls.propertyDefinitions()} target="_blank">
- Property Definitions
- </Link>{' '}
- page.
- </p>
+ {currentEvent?.eventName && !currentEvent?.revenueProperty && (
+ <LemonBanner type="info" className="text-xs">
+ Only <strong>numeric</strong> properties are listed. If your revenue property is
+ missing, open it in{' '}
+ <Link to={urls.propertyDefinitions()} target="_blank">
+ Property Definitions
+ </Link>{' '}
+ and set its type to <code>Numeric</code>, then reopen this modal.
+ </LemonBanner>
+ )}
</div>
<hr />
@@ -385,7 +393,11 @@ export function EventConfigurationModal({ event, onClose }: EventConfigurationMo
<LemonButton type="secondary" onClick={handleClose}>
Cancel
</LemonButton>
- <LemonButton type="primary" onClick={handleSave} disabledReason={saveEventsDisabledReason}>
+ <LemonButton
+ type="primary"
+ onClick={handleSave}
+ disabledReason={accessDeniedReason || saveEventsDisabledReason}
+ >
{originalEvent ? 'Update Event' : 'Add Event'}
</LemonButton>
</div>
diff --git a/products/revenue_analytics/frontend/settings/ExternalDataSourceConfiguration.tsx b/products/revenue_analytics/frontend/settings/ExternalDataSourceConfiguration.tsx
index 5729c0352209..ef66cc1840f4 100644
--- a/products/revenue_analytics/frontend/settings/ExternalDataSourceConfiguration.tsx
+++ b/products/revenue_analytics/frontend/settings/ExternalDataSourceConfiguration.tsx
@@ -25,11 +25,7 @@ import { revenueAnalyticsSettingsLogic } from './revenueAnalyticsSettingsLogic'
const VALID_REVENUE_SOURCES: ExternalDataSource['source_type'][] = ['Stripe']
-export function ExternalDataSourceConfiguration({
- buttonRef,
-}: {
- buttonRef?: React.RefObject<HTMLButtonElement>
-}): JSX.Element {
+export function ExternalDataSourceConfiguration(): JSX.Element {
const { dataWarehouseSources, dataWarehouseSourcesLoading, joins } = useValues(revenueAnalyticsSettingsLogic)
const { views, source: sourceToBeDisabled } = useValues(disableRevenueSourceModalLogic)
const { featureFlags } = useValues(featureFlagLogic)
@@ -88,7 +84,6 @@ export function ExternalDataSourceConfiguration({
>
<LemonButton
className="my-1"
- ref={buttonRef}
type="primary"
icon={<IconPlus />}
size="small"
diff --git a/products/revenue_analytics/frontend/settings/RevenueAnalyticsSettings.tsx b/products/revenue_analytics/frontend/settings/RevenueAnalyticsSettings.tsx
index 9fe07917baeb..3bae4c5e7313 100644
--- a/products/revenue_analytics/frontend/settings/RevenueAnalyticsSettings.tsx
+++ b/products/revenue_analytics/frontend/settings/RevenueAnalyticsSettings.tsx
@@ -1,5 +1,6 @@
import { useActions, useValues } from 'kea'
-import { useRef, useState } from 'react'
+import { router } from 'kea-router'
+import { useState } from 'react'
import { IconPlus } from '@posthog/icons'
import { LemonTabs, Link } from '@posthog/lemon-ui'
@@ -15,16 +16,19 @@ import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { sceneConfigurations } from 'scenes/scenes'
import { Scene } from 'scenes/sceneTypes'
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 { GoalsConfiguration } from './GoalsConfiguration'
@@ -36,15 +40,16 @@ type Tab = 'events' | 'data-warehouse'
export function RevenueAnalyticsSettings(): JSX.Element {
const [activeTab, setActiveTab] = useState<Tab>('events')
+ 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 eventsButtonRef = useRef<HTMLButtonElement>(null)
- const dataWarehouseTablesButtonRef = useRef<HTMLButtonElement>(null)
-
const managedViewsetsEnabled = featureFlags[FEATURE_FLAGS.MANAGED_VIEWSETS]
const isViewsetEnabled = currentTeam?.managed_viewsets?.['revenue_analytics'] ?? false
@@ -58,6 +63,13 @@ export function RevenueAnalyticsSettings(): JSX.Element {
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>
<SceneTitleSection
@@ -106,10 +118,7 @@ export function RevenueAnalyticsSettings(): JSX.Element {
<LemonButton
type="primary"
icon={<IconPlus />}
- onClick={() => {
- eventsButtonRef.current?.scrollIntoView({ behavior: 'smooth' })
- eventsButtonRef.current?.click()
- }}
+ onClick={() => openEventModal()}
data-attr="create-revenue-event"
>
Add revenue event
@@ -124,10 +133,7 @@ export function RevenueAnalyticsSettings(): JSX.Element {
type="primary"
icon={<IconPlus />}
onClick={() => {
- dataWarehouseTablesButtonRef.current?.scrollIntoView({
- behavior: 'smooth',
- })
- dataWarehouseTablesButtonRef.current?.click()
+ router.actions.push(urls.dataWarehouseSourceNew('stripe'))
}}
data-attr="import-revenue-data-warehouse-tables"
>
@@ -146,10 +152,10 @@ export function RevenueAnalyticsSettings(): JSX.Element {
}
/>
- <ExternalDataSourceConfiguration buttonRef={dataWarehouseTablesButtonRef} />
+ <ExternalDataSourceConfiguration />
<SceneDivider />
- <EventConfiguration buttonRef={eventsButtonRef} />
+ <EventConfiguration onOpenEventModal={openEventModal} />
<SceneDivider />
<LemonTabs
@@ -170,6 +176,10 @@ export function RevenueAnalyticsSettings(): JSX.Element {
/>
</>
)}
+
+ {eventModalState.isOpen && (
+ <EventConfigurationModal event={eventModalState.event} onClose={closeEventModal} />
+ )}
</SceneContent>
)
}
diff --git a/products/revenue_analytics/frontend/settings/revenueAnalyticsSettingsLogic.ts b/products/revenue_analytics/frontend/settings/revenueAnalyticsSettingsLogic.ts
index 5a33d8cefea8..3b89f708c497 100644
--- a/products/revenue_analytics/frontend/settings/revenueAnalyticsSettingsLogic.ts
+++ b/products/revenue_analytics/frontend/settings/revenueAnalyticsSettingsLogic.ts
@@ -248,8 +248,9 @@ export const revenueAnalyticsSettingsLogic = kea<revenueAnalyticsSettingsLogicTy
if (!changesMade) {
return 'No changes to save'
}
- if (config.events.some((event) => !event.revenueProperty)) {
- return 'Revenue property must be set'
+ const eventMissingRevenueProperty = config.events.find((event) => !event.revenueProperty)
+ if (eventMissingRevenueProperty) {
+ return `Select a numeric revenue property for "${eventMissingRevenueProperty.eventName}". If you don't see your property, make sure it's marked as numeric in Property Definitions.`
}
return null