: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
feat(replay): collapse legacy recording conditions when only new SDKs seen (#61770)
Kim Svatos Dugan8fd20649d0f7
diff --git a/frontend/src/scenes/settings/environment/ReplayTriggers.tsx b/frontend/src/scenes/settings/environment/ReplayTriggers.tsxindex f71a6db0e62c..94e7c88f7ccc 100644--- a/frontend/src/scenes/settings/environment/ReplayTriggers.tsx+++ b/frontend/src/scenes/settings/environment/ReplayTriggers.tsx@@ -1,6 +1,6 @@import { useActions, useValues } from 'kea'-import { LemonBanner, LemonCollapse, LemonLabel, LemonTab, LemonTabs, Tooltip } from '@posthog/lemon-ui'+import { LemonBanner, LemonCollapse, LemonDivider, LemonLabel, LemonTab, LemonTabs, Tooltip } from '@posthog/lemon-ui'import IngestionControls from 'lib/components/IngestionControls'import { IngestionControlsSummary } from 'lib/components/IngestionControls/Summary'@@ -10,13 +10,17 @@ import { PayGateMini } from 'lib/components/PayGateMini/PayGateMini'import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { pluralize } from 'lib/utils'-import { ReplayPlatform, replayTriggersLogic } from 'scenes/settings/environment/replayTriggersLogic'+import {+ ReplayPlatform,+ replayTriggersLogic,+ TRIGGER_GROUPS_MIN_SDK_VERSION,+} from 'scenes/settings/environment/replayTriggersLogic'import { Since } from 'scenes/settings/environment/SessionRecordingSettings'import { teamLogic } from 'scenes/teamLogic'import { AccessControlResourceType, AvailableFeature, TeamPublicType, TeamType } from '~/types'-export const TRIGGER_GROUPS_MIN_SDK_VERSION = '1.369.0'+export { TRIGGER_GROUPS_MIN_SDK_VERSION }/** Convert the stored sample-rate string (decimal 0–1) to a display percentage (0–100). */function toDisplaySampleRate(rate: string | null | undefined): number {@@ -377,13 +381,133 @@ function useHeaderStatuses(currentTeam: TeamType | TeamPublicType | null): {}}-export function ReplayTriggers(): JSX.Element {+function LegacyRecordingConditions(): JSX.Element {const { selectedPlatform } = useValues(replayTriggersLogic)+ const { currentTeam } = useValues(teamLogic)+ const { featureFlags } = useValues(featureFlagLogic)+ const statuses = useHeaderStatuses(currentTeam)++ const isV2TriggersEnabled = featureFlags[FEATURE_FLAGS.REPLAY_TRIGGERS_V2]++ return (+ <>+ {currentTeam && <RecordingTriggersSummary currentTeam={currentTeam} selectedPlatform={selectedPlatform} />}++ <IngestionControls.MatchTypeSelect />++ <AnyWith100SamplingWarning currentTeam={currentTeam} isV2TriggersEnabled={!!isV2TriggersEnabled} />++ <div>+ <h3 className="text-sm font-semibold mb-2">Recording conditions</h3>+ <LemonCollapse+ multiple+ panels={[+ {+ key: 'url',+ header: <TriggerPanelHeader title="URL matches" status={statuses.urlStatus} showMatchTag />,+ content: <UrlTriggerOptions />,+ },+ {+ key: 'event',+ header: (+ <TriggerPanelHeader title="Event emitted" status={statuses.eventStatus} showMatchTag />+ ),+ content: <EventTriggerOptions />,+ },+ {+ key: 'flag',+ header: (+ <TriggerPanelHeader title="Feature flag" status={statuses.flagStatus} showMatchTag />+ ),+ content: <LinkedFlagSelector />,+ },+ ]}+ />+ </div>++ <div>+ <h3 className="text-sm font-semibold mb-2">Recording limits</h3>+ <LemonCollapse+ multiple+ panels={[+ {+ key: 'sampling',+ header: (+ <TriggerPanelHeader title="Sampling" status={statuses.samplingStatus} showMatchTag />+ ),+ content: <Sampling />,+ },+ {+ key: 'min-duration',+ header: <TriggerPanelHeader title="Minimum duration" status={statuses.minDurationStatus} />,+ content: <MinimumDurationSetting />,+ },+ ]}+ />+ </div>++ <div>+ <h3 className="text-base font-semibold mb-2">+ Recording exclusions <Since web={{ version: '1.171.0' }} />+ </h3>+ <LemonCollapse+ multiple+ panels={[+ {+ key: 'blocklist',+ header: <TriggerPanelHeader title="URL blocklist" status={statuses.blocklistStatus} />,+ content: <UrlBlocklistOptions />,+ },+ ]}+ />+ </div>+ </>+ )+}++function SdkCompatibilityBanner(): JSX.Element {+ const { shouldMinimizeLegacyConditions, hasOutdatedWebSdk } = useValues(replayTriggersLogic)++ if (shouldMinimizeLegacyConditions) {+ return (+ <LemonBanner type="success">+ All your recent web SDK traffic is on v{TRIGGER_GROUPS_MIN_SDK_VERSION}+, so trigger groups apply to+ every session. The legacy recording conditions below are kept only as a fallback for older SDKs.+ </LemonBanner>+ )+ }++ if (hasOutdatedWebSdk) {+ return (+ <LemonBanner type="warning">+ <strong>Some of your web traffic is on an older posthog-js</strong> (before v+ {TRIGGER_GROUPS_MIN_SDK_VERSION}), which uses the legacy recording conditions below. Upgrade posthog-js+ to v{TRIGGER_GROUPS_MIN_SDK_VERSION}+ so trigger groups apply to every session. Until then, both+ configurations are sent for backward compatibility.+ </LemonBanner>+ )+ }++ return (+ <LemonBanner type="warning">+ <strong>JavaScript SDK version compatibility</strong>+ <ul className="list-disc ml-4 mt-2 space-y-1">+ <li>+ SDK versions >= v{TRIGGER_GROUPS_MIN_SDK_VERSION} use trigger groups if configured, otherwise+ fall back to the legacy recording conditions+ </li>+ <li>Both configurations are sent to ensure backward compatibility with all JavaScript SDK versions</li>+ </ul>+ </LemonBanner>+ )+}++export function ReplayTriggers(): JSX.Element {+ const { selectedPlatform, shouldMinimizeLegacyConditions } = useValues(replayTriggersLogic)const { selectPlatform } = useActions(replayTriggersLogic)const { updateCurrentTeam } = useActions(teamLogic)const { currentTeam } = useValues(teamLogic)const { featureFlags } = useValues(featureFlagLogic)- const statuses = useHeaderStatuses(currentTeam)const isV2TriggersEnabled = featureFlags[FEATURE_FLAGS.REPLAY_TRIGGERS_V2]@@ -395,127 +519,49 @@ export function ReplayTriggers(): JSX.Element {<div className="flex flex-col gap-y-4">{isV2TriggersEnabled && (<>- <LemonBanner type="warning">- <strong>JavaScript SDK version compatibility</strong>- <ul className="list-disc ml-4 mt-2 space-y-1">- <li>- SDK versions >= v{TRIGGER_GROUPS_MIN_SDK_VERSION} use trigger groups if- configured, otherwise fall back to the legacy recording conditions- </li>- <li>- Both configurations are sent to ensure backward compatibility with all- JavaScript SDK versions- </li>- </ul>- </LemonBanner>+ <SdkCompatibilityBanner /><TriggerGroupsEditor />-- <h3 className="text-base font-semibold">Legacy recording conditions</h3>- <LemonBanner type="warning">- Used by SDK versions < v{TRIGGER_GROUPS_MIN_SDK_VERSION} and as fallback for newer- versions if trigger groups are not configured.- </LemonBanner></>)}- {currentTeam && (- <RecordingTriggersSummary currentTeam={currentTeam} selectedPlatform={selectedPlatform} />+ {isV2TriggersEnabled && (+ <div className="mt-2">+ <LemonDivider className="mb-4" />+ <h3 className="text-base font-semibold mb-1">Legacy recording conditions</h3>+ </div>)}- <IngestionControls.MatchTypeSelect />-- <AnyWith100SamplingWarning currentTeam={currentTeam} isV2TriggersEnabled={!!isV2TriggersEnabled} />-- <div>- <h3 className="text-sm font-semibold mb-2">Recording conditions</h3>- <LemonCollapse- multiple- panels={[- {- key: 'url',- header: (- <TriggerPanelHeader- title="URL matches"- status={statuses.urlStatus}- showMatchTag- />- ),- content: <UrlTriggerOptions />,- },- {- key: 'event',- header: (- <TriggerPanelHeader- title="Event emitted"- status={statuses.eventStatus}- showMatchTag- />- ),- content: <EventTriggerOptions />,- },- {- key: 'flag',- header: (- <TriggerPanelHeader- title="Feature flag"- status={statuses.flagStatus}- showMatchTag- />- ),- content: <LinkedFlagSelector />,- },- ]}- />- </div>-- <div>- <h3 className="text-sm font-semibold mb-2">Recording limits</h3>+ {isV2TriggersEnabled && shouldMinimizeLegacyConditions ? (<LemonCollapse- multiplepanels={[{- key: 'sampling',+ key: 'legacy-recording-conditions',header: (- <TriggerPanelHeader- title="Sampling"- status={statuses.samplingStatus}- showMatchTag- />+ <span className="text-muted text-sm font-normal">+ Hidden because your web SDKs (v{TRIGGER_GROUPS_MIN_SDK_VERSION}+) use+ trigger groups. Expand to configure fallbacks for older SDK versions.+ </span>),- content: <Sampling />,- },- {- key: 'min-duration',- header: (- <TriggerPanelHeader- title="Minimum duration"- status={statuses.minDurationStatus}- />+ content: (+ <div className="flex flex-col gap-y-4 pt-2">+ <LegacyRecordingConditions />+ </div>),- content: <MinimumDurationSetting />,},]}/>- </div>-- <div>- <h3 className="text-base font-semibold mb-2">- Recording exclusions <Since web={{ version: '1.171.0' }} />- </h3>- <LemonCollapse- multiple- panels={[- {- key: 'blocklist',- header: (- <TriggerPanelHeader title="URL blocklist" status={statuses.blocklistStatus} />- ),- content: <UrlBlocklistOptions />,- },- ]}- />- </div>+ ) : (+ <>+ {isV2TriggersEnabled && (+ <LemonBanner type="warning">+ Used by SDK versions < v{TRIGGER_GROUPS_MIN_SDK_VERSION} and as fallback for+ newer versions if trigger groups are not configured.+ </LemonBanner>+ )}+ <LegacyRecordingConditions />+ </>+ )}</div>),},diff --git a/frontend/src/scenes/settings/environment/replayTriggersLogic.test.ts b/frontend/src/scenes/settings/environment/replayTriggersLogic.test.tsnew file mode 100644index 000000000000..decf017b0fb4--- /dev/null+++ b/frontend/src/scenes/settings/environment/replayTriggersLogic.test.ts@@ -0,0 +1,29 @@+import { hasOutdatedWebSdk, legacyConditionsAreInactive, TRIGGER_GROUPS_MIN_SDK_VERSION } from './replayTriggersLogic'++describe('replayTriggersLogic', () => {+ describe('legacyConditionsAreInactive', () => {+ it.each([+ ['no web data', [], false],+ ['only new versions', ['1.369.0', '1.400.1'], true],+ ['only old versions', ['1.300.0', '1.368.9'], false],+ ['mix of old and new', ['1.368.0', '1.400.0'], false],+ ['exactly the minimum version', [TRIGGER_GROUPS_MIN_SDK_VERSION], true],+ ['unparseable version stays conservative', ['not-a-version', '1.400.0'], false],+ ])('%s -> %s', (_description, versions, expected) => {+ expect(legacyConditionsAreInactive(versions as string[])).toBe(expected)+ })+ })++ describe('hasOutdatedWebSdk', () => {+ it.each([+ ['no web data', [], false],+ ['only new versions', ['1.369.0', '1.400.1'], false],+ ['only old versions', ['1.300.0', '1.368.9'], true],+ ['mix of old and new', ['1.368.0', '1.400.0'], true],+ ['exactly the minimum version', [TRIGGER_GROUPS_MIN_SDK_VERSION], false],+ ['unparseable version stays conservative', ['not-a-version', '1.400.0'], true],+ ])('%s -> %s', (_description, versions, expected) => {+ expect(hasOutdatedWebSdk(versions as string[])).toBe(expected)+ })+ })+})diff --git a/frontend/src/scenes/settings/environment/replayTriggersLogic.ts b/frontend/src/scenes/settings/environment/replayTriggersLogic.tsindex 0cdc8435a5eb..1160ea50b35d 100644--- a/frontend/src/scenes/settings/environment/replayTriggersLogic.ts+++ b/frontend/src/scenes/settings/environment/replayTriggersLogic.ts@@ -4,6 +4,8 @@ import { actionToUrl, router, urlToAction } from 'kea-router'import { subscriptions } from 'kea-subscriptions'import { UrlTriggerConfig } from 'lib/components/IngestionControls/types'+import { compareVersion } from 'lib/utils/semver'+import { sdkDoctorLogic } from 'scenes/onboarding/sdks/sdkDoctorLogic'import { teamLogic } from 'scenes/teamLogic'import { TeamPublicType, TeamType } from '~/types'@@ -12,12 +14,42 @@ import type { replayTriggersLogicType } from './replayTriggersLogicType'export type ReplayPlatform = 'web' | 'mobile'+/** Minimum posthog-js version that understands V2 trigger groups. Older web SDKs fall back to legacy conditions. */+export const TRIGGER_GROUPS_MIN_SDK_VERSION = '1.369.0'+const NEW_URL_TRIGGER = { url: '', matching: 'regex' }export function isStringWithLength(x: unknown): x is string {return typeof x === 'string' && x.trim() !== ''}+/**+ * True when the team's recent web SDK traffic is entirely on versions that understand trigger groups, so the+ * legacy recording conditions only serve SDKs the team no longer runs. The SDK Doctor data is a rolling ~7-day+ * window, so this answers "have only new SDKs been seen recently". Returns false when there's no web data+ * (e.g. a brand-new or self-hosted team) — we never minimize the legacy UI without positive evidence.+ */+// Unparseable versions count as "predates" so we stay conservative (prompt upgrade / keep legacy visible).+function webSdkPredatesTriggerGroups(version: string): boolean {+ try {+ return compareVersion(version, TRIGGER_GROUPS_MIN_SDK_VERSION) < 0+ } catch {+ return true+ }+}++export function legacyConditionsAreInactive(webVersions: string[]): boolean {+ if (webVersions.length === 0) {+ return false+ }+ return !webVersions.some(webSdkPredatesTriggerGroups)+}++/** True when there's web SDK data and at least one version predates trigger-group support. */+export function hasOutdatedWebSdk(webVersions: string[]): boolean {+ return webVersions.some(webSdkPredatesTriggerGroups)+}+function ensureAnchored(url: string): string {url = url.startsWith('^') ? url.substring(1) : urlurl = url.endsWith('$') ? url.substring(0, url.length - 1) : url@@ -55,7 +87,10 @@ export const replayTriggersLogic = kea<replayTriggersLogicType>([setCheckUrlBlocklist: (url: string) => ({ url }),validateUrlInput: (url: string, type: 'trigger' | 'blocklist') => ({ url, type }),}),- connect(() => ({ values: [teamLogic, ['currentTeam']], actions: [teamLogic, ['updateCurrentTeam']] })),+ connect(() => ({+ values: [teamLogic, ['currentTeam'], sdkDoctorLogic, ['augmentedData']],+ actions: [teamLogic, ['updateCurrentTeam']],+ })),reducers({urlTriggerConfig: [null as UrlTriggerConfig[] | null,@@ -178,6 +213,16 @@ export const replayTriggersLogic = kea<replayTriggersLogicType>([],}),selectors({+ shouldMinimizeLegacyConditions: [+ (s) => [s.augmentedData],+ (augmentedData): boolean =>+ legacyConditionsAreInactive((augmentedData?.web?.allReleases ?? []).map((r) => r.version)),+ ],+ hasOutdatedWebSdk: [+ (s) => [s.augmentedData],+ (augmentedData): boolean =>+ hasOutdatedWebSdk((augmentedData?.web?.allReleases ?? []).map((r) => r.version)),+ ],isAddUrlTriggerConfigFormVisible: [(s) => [s.editUrlTriggerIndex],(editUrlTriggerIndex) => editUrlTriggerIndex === -1,