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(settings): show one audit logs pay gate on the activity logs page (#94765)

posthog[bot]b087295c9769
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 10511eb4b3f2..d4643ffb44fc 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -8440,6 +8440,10 @@ snapshots:
hash: v1.k794b7964.c9ccaaba4bf03f6923b41fe85e387d17139a6d7d69a6e06913a37cb5dd019532.bpCeuesKb9InCkdPuMqRPNFckeU7o1u6QcQfQf5ogSE
scenes-app-settings-environment--settings-environment-access-control--light:
hash: v1.k794b7964.9ea484177cb94c831f0508e3482b1a876fc2b69db66c95b8f69fe73586909a3b._EvRaax5KzNHywyiNOpnbtVEPebu79kfKuX5zFMrXj0
+ scenes-app-settings-environment--settings-environment-activity-logs--dark:
+ hash: v1.k794b7964.07a7c5284294ab47f8389e75130eb9da6fb7bfe1823be6b5fab8433e108e5512.oRiLyo7NyPY9iXCIWYaZnWfk6ZBFq4caKD2IKjchNRA
+ scenes-app-settings-environment--settings-environment-activity-logs--light:
+ hash: v1.k794b7964.147a8cc5a95a1a486933073ed663e3f0b6252c2061fdabd2f63e1519b891b30b.eq6S9YZ9D9YMyV7CAt1wI7zCreusJVqlbE4aQV4ME_8
scenes-app-settings-environment--settings-environment-autocapture--dark:
hash: v1.k794b7964.8defefc8ee81d152212ad970ee03afd0170e149183c700875620b83c94041edb.1GgekWHSuFhNxSx6MSUDbX9I0RjLB_eJK_x9Y356OXU
scenes-app-settings-environment--settings-environment-autocapture--light:
diff --git a/frontend/src/scenes/settings/Settings.tsx b/frontend/src/scenes/settings/Settings.tsx
index c6b3f1b68bf6..466cbd1285de 100644
--- a/frontend/src/scenes/settings/Settings.tsx
+++ b/frontend/src/scenes/settings/Settings.tsx
@@ -10,6 +10,7 @@ import { LemonButton, LemonDivider, Link } from '@posthog/lemon-ui'
import { AccessDenied } from 'lib/components/AccessDenied'
import { NotFound } from 'lib/components/NotFound'
+import { PayGateMini } from 'lib/components/PayGateMini/PayGateMini'
import { SupportedPlatforms } from 'lib/components/SupportedPlatforms/SupportedPlatforms'
import { TimeSensitiveAuthenticationArea } from 'lib/components/TimeSensitiveAuthentication/TimeSensitiveAuthentication'
import { IconLink } from 'lib/lemon-ui/icons'
@@ -37,6 +38,7 @@ import {
import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
import { inStorybookTestRunner } from 'lib/utils/dom'
import { urls } from 'scenes/urls'
+import { userLogic } from 'scenes/userLogic'
import { ErrorBoundary } from '~/layout/ErrorBoundary'
@@ -413,15 +415,22 @@ export function Settings({
)
}
-function SettingsRenderer(props: SettingsLogicProps & { handleLocally: boolean }): JSX.Element {
- const { settings: allSettings, selectedLevel, selectedSectionId, selectedSetting } = useValues(settingsLogic(props))
+function SettingsRenderer(props: SettingsLogicProps & { handleLocally: boolean }): JSX.Element | null {
+ const {
+ settings: allSettings,
+ selectedLevel,
+ selectedSection,
+ selectedSectionId,
+ selectedSetting,
+ } = useValues(settingsLogic(props))
const { selectSetting } = useActions(settingsLogic(props))
+ const { user } = useValues(userLogic)
const settingsInSidebar = !!selectedSetting && !!props.sectionId
const settings = settingsInSidebar ? [selectedSetting] : allSettings
- return (
+ const content = (
<div className="flex flex-col gap-y-8">
{settings.length ? (
settings.map((x, index) => (
@@ -465,6 +474,23 @@ function SettingsRenderer(props: SettingsLogicProps & { handleLocally: boolean }
)}
</div>
)
+
+ const payGate = selectedSection?.payGate
+ if (!payGate) {
+ return content
+ }
+
+ // One gate for the whole section, so the upsell appears once however many settings the
+ // section holds.
+ return (
+ <PayGateMini
+ feature={payGate.feature}
+ featureDetail={payGate.featureDetail}
+ overrideShouldShowGate={payGate.bypassForImpersonation && user?.is_impersonated}
+ >
+ {content}
+ </PayGateMini>
+ )
}
const depthMap: Record<number, string> = {
diff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsx
index aa8a35017773..d3c9fe6830ff 100644
--- a/frontend/src/scenes/settings/SettingsMap.tsx
+++ b/frontend/src/scenes/settings/SettingsMap.tsx
@@ -50,7 +50,7 @@ import {
DefaultRoleSelector,
RolesAccessControls,
} from '~/layout/navigation-3000/sidepanel/panels/access_control/RolesAccessControls'
-import { AccessControlLevel, AccessControlResourceType, Realm } from '~/types'
+import { AccessControlLevel, AccessControlResourceType, AvailableFeature, Realm } from '~/types'
import { AISection } from 'products/conversations/frontend/scenes/settings/AISection'
import { GeneralSection } from 'products/conversations/frontend/scenes/settings/GeneralSection'
@@ -1530,6 +1530,12 @@ export const SETTINGS_MAP: SettingSection[] = [
level: 'environment',
id: 'environment-activity-logs',
title: 'Activity logs',
+ payGate: {
+ feature: AvailableFeature.AUDIT_LOGS,
+ // pinned: `pay gate shown` property value, so renaming it breaks existing insights
+ featureDetail: 'activity-log-retention',
+ bypassForImpersonation: true,
+ },
settings: [
{
id: 'activity-log-settings',
diff --git a/frontend/src/scenes/settings/environment/ActivityLogSettings.tsx b/frontend/src/scenes/settings/environment/ActivityLogSettings.tsx
index 28298b456a40..1463d284b5d9 100644
--- a/frontend/src/scenes/settings/environment/ActivityLogSettings.tsx
+++ b/frontend/src/scenes/settings/environment/ActivityLogSettings.tsx
@@ -3,7 +3,6 @@ import { useActions, useValues } from 'kea'
import { IconInfo } from '@posthog/icons'
import { LemonButton, LemonSwitch, Tooltip } from '@posthog/lemon-ui'
-import { PayGateMini } from 'lib/components/PayGateMini/PayGateMini'
import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'
import { OrganizationMembershipLevel, TeamMembershipLevel } from 'lib/constants'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
@@ -12,7 +11,8 @@ import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
-import { AvailableFeature } from '~/types'
+// These settings are gated as a whole. The AUDIT_LOGS pay gate is declared on the
+// `environment-activity-logs` section in SettingsMap, not on each component here.
export function ActivityLogSettings(): JSX.Element {
const { user } = useValues(userLogic)
@@ -23,24 +23,17 @@ export function ActivityLogSettings(): JSX.Element {
const effectiveRestriction = user?.is_impersonated ? null : restrictedReason
return (
- <PayGateMini
- feature={AvailableFeature.AUDIT_LOGS}
- featureDetail="activity-log-retention"
- overrideShouldShowGate={user?.is_impersonated}
- >
- <div className="flex">
- <p>
- <LemonButton to={urls.advancedActivityLogs()} type="primary" disabledReason={effectiveRestriction}>
- Browse all activity logs
- </LemonButton>
- </p>
- </div>
- </PayGateMini>
+ <div className="flex">
+ <p>
+ <LemonButton to={urls.advancedActivityLogs()} type="primary" disabledReason={effectiveRestriction}>
+ Browse all activity logs
+ </LemonButton>
+ </p>
+ </div>
)
}
export function ActivityLogOrgLevelSettings(): JSX.Element {
- const { user } = useValues(userLogic)
const { currentTeam } = useValues(teamLogic)
const { updateCurrentTeam } = useActions(teamLogic)
const { reportActivityLogSettingToggled } = useActions(eventUsageLogic)
@@ -53,42 +46,35 @@ export function ActivityLogOrgLevelSettings(): JSX.Element {
}
return (
- <PayGateMini
- feature={AvailableFeature.AUDIT_LOGS}
- featureDetail="activity-log-retention"
- overrideShouldShowGate={user?.is_impersonated}
- >
- <div>
- <p className="flex items-center gap-1">
- Include organization-level activity logs in this project.
- <Tooltip
- title={
- <>
- When enabled, activity logs from organization-level changes (such as organization
- settings, domains, and members) will be included in this project's activity logs page,
- exports, and notifications subscriptions.
- </>
- }
- >
- <IconInfo className="text-lg" />
- </Tooltip>
- </p>
+ <div>
+ <p className="flex items-center gap-1">
+ Include organization-level activity logs in this project.
+ <Tooltip
+ title={
+ <>
+ When enabled, activity logs from organization-level changes (such as organization settings,
+ domains, and members) will be included in this project's activity logs page, exports, and
+ notifications subscriptions.
+ </>
+ }
+ >
+ <IconInfo className="text-lg" />
+ </Tooltip>
+ </p>
- <LemonSwitch
- id="posthog-activity-log-org-level-switch"
- onChange={handleToggle}
- checked={!!currentTeam?.receive_org_level_activity_logs}
- disabledReason={restrictionReason || undefined}
- label="Include organization-level activity"
- bordered
- />
- </div>
- </PayGateMini>
+ <LemonSwitch
+ id="posthog-activity-log-org-level-switch"
+ onChange={handleToggle}
+ checked={!!currentTeam?.receive_org_level_activity_logs}
+ disabledReason={restrictionReason || undefined}
+ label="Include organization-level activity"
+ bordered
+ />
+ </div>
)
}
export function ActivityLogNotifications(): JSX.Element | null {
- const { user } = useValues(userLogic)
const restrictedReason = useRestrictedArea({
scope: RestrictionScope.Project,
minimumAccessLevel: TeamMembershipLevel.Admin,
@@ -99,34 +85,28 @@ export function ActivityLogNotifications(): JSX.Element | null {
}
return (
- <PayGateMini
- feature={AvailableFeature.AUDIT_LOGS}
- featureDetail="activity-log-retention"
- overrideShouldShowGate={user?.is_impersonated}
- >
- <div>
- <p className="flex items-center gap-1">
- Create notifications to get notified of activity logs.
- <Tooltip
- title={
- <>
- You can filter by activity type, resource, and other properties to receive only the
- notifications you need.
- </>
- }
- >
- <IconInfo className="text-lg" />
- </Tooltip>
- </p>
+ <div>
+ <p className="flex items-center gap-1">
+ Create notifications to get notified of activity logs.
+ <Tooltip
+ title={
+ <>
+ You can filter by activity type, resource, and other properties to receive only the
+ notifications you need.
+ </>
+ }
+ >
+ <IconInfo className="text-lg" />
+ </Tooltip>
+ </p>
- <LinkedHogFunctions
- type="internal_destination"
- subTemplateIds={['activity-log']}
- queryParams={{
- returnTo: urls.settings('environment-activity-logs', 'activity-log-notifications'),
- }}
- />
- </div>
- </PayGateMini>
+ <LinkedHogFunctions
+ type="internal_destination"
+ subTemplateIds={['activity-log']}
+ queryParams={{
+ returnTo: urls.settings('environment-activity-logs', 'activity-log-notifications'),
+ }}
+ />
+ </div>
)
}
diff --git a/frontend/src/scenes/settings/stories/SettingsEnvironment.stories.tsx b/frontend/src/scenes/settings/stories/SettingsEnvironment.stories.tsx
index 1b9fda64b541..bac1485c954e 100644
--- a/frontend/src/scenes/settings/stories/SettingsEnvironment.stories.tsx
+++ b/frontend/src/scenes/settings/stories/SettingsEnvironment.stories.tsx
@@ -8,6 +8,7 @@ import { App } from 'scenes/App'
import { urls } from 'scenes/urls'
import { mswDecorator } from '~/mocks/browser'
+import { billingJson } from '~/mocks/fixtures/_billing'
import preflightJson from '~/mocks/fixtures/_preflight.json'
import { SettingSectionId } from '../types'
@@ -117,4 +118,11 @@ export const SettingsEnvironmentIntegrations: Story = { args: { sectionId: 'envi
export const SettingsEnvironmentAccessControl: Story = { args: { sectionId: 'environment-access-control' } }
+export const SettingsEnvironmentActivityLogs: Story = {
+ args: { sectionId: 'environment-activity-logs' },
+ // The mock organization holds no product features, so this section renders its pay gate.
+ // Billing must list the audit logs feature, otherwise the gate falls through to the settings.
+ decorators: [mswDecorator({ get: { '/api/billing/': billingJson } })],
+}
+
export const SettingsEnvironmentDangerZone: Story = { args: { sectionId: 'environment-danger-zone' } }
diff --git a/frontend/src/scenes/settings/types.ts b/frontend/src/scenes/settings/types.ts
index 04fffce47f05..e3b27519c925 100644
--- a/frontend/src/scenes/settings/types.ts
+++ b/frontend/src/scenes/settings/types.ts
@@ -1,7 +1,14 @@
import { PlatformSupportConfig } from 'lib/components/SupportedPlatforms/types'
import { EitherMembershipLevel, FEATURE_FLAGS } from 'lib/constants'
-import { AccessControlLevel, AccessControlResourceType, Realm, TeamPublicType, TeamType } from '~/types'
+import {
+ AccessControlLevel,
+ AccessControlResourceType,
+ AvailableFeature,
+ Realm,
+ TeamPublicType,
+ TeamType,
+} from '~/types'
export type SettingsLogicProps = {
logicKey?: string
@@ -383,4 +390,21 @@ export interface SettingSection extends Pick<Setting, 'flag'> {
* re-auth modal reactively when a write is attempted.
*/
requiresReauthentication?: boolean
+
+ /**
+ * Gate every setting in the section behind one billing feature. The section renders a single
+ * upsell when the feature is unavailable. Use this instead of a `PayGateMini` inside each
+ * setting's component, which stacks one identical upsell card per setting on the page.
+ */
+ payGate?: SettingSectionPayGate
+}
+
+export interface SettingSectionPayGate {
+ feature: AvailableFeature
+
+ /** Identifies this surface in pay gate analytics, since one feature can gate several places. */
+ featureDetail?: string
+
+ /** When true, impersonated staff see the settings rather than the upsell. */
+ bypassForImpersonation?: boolean
}