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(replay): make trigger-groups SDK banner traffic-aware (#65669)

Kim Svatos Duganf803c2a78693
diff --git a/frontend/src/scenes/settings/environment/ReplayTriggers.tsx b/frontend/src/scenes/settings/environment/ReplayTriggers.tsx
index 5811c0dbad72..c375a27eb87f 100644
--- a/frontend/src/scenes/settings/environment/ReplayTriggers.tsx
+++ b/frontend/src/scenes/settings/environment/ReplayTriggers.tsx
@@ -9,6 +9,7 @@ import { FeatureFlagTrigger, Trigger, TriggerType } from 'lib/components/Ingesti
import { PayGateMini } from 'lib/components/PayGateMini/PayGateMini'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { humanFriendlyNumber } from 'lib/utils/numbers'
import { pluralize } from 'lib/utils/strings'
import {
ReplayPlatform,
@@ -505,24 +506,28 @@ function LegacyRecordingConditions(): JSX.Element {
}
function SdkCompatibilityBanner(): JSX.Element {
- const { shouldMinimizeLegacyConditions, hasOutdatedWebSdk } = useValues(replayTriggersLogic)
+ const { shouldMinimizeLegacyConditions, hasOutdatedWebSdk, outdatedWebTraffic } = 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.
+ Your recent web SDK traffic is effectively all on v{TRIGGER_GROUPS_MIN_SDK_VERSION}+, so trigger groups
+ apply to essentially every session. The legacy recording conditions below are kept only as a fallback
+ for older SDKs.
</LemonBanner>
)
}
if (hasOutdatedWebSdk) {
+ const pct = outdatedWebTraffic.share < 0.01 ? '<1' : Math.round(outdatedWebTraffic.share * 100).toString()
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 type="info">
+ About <strong>{pct}%</strong> of recent web traffic (
+ {humanFriendlyNumber(outdatedWebTraffic.outdatedCount)}{' '}
+ {pluralize(outdatedWebTraffic.outdatedCount, 'event', 'events', false)}) is on a posthog-js before v
+ {TRIGGER_GROUPS_MIN_SDK_VERSION}. Those sessions still record using the legacy recording conditions
+ below — upgrade to v{TRIGGER_GROUPS_MIN_SDK_VERSION}+ for full trigger-group coverage. Both
+ configurations are sent meanwhile, so nothing is lost.
</LemonBanner>
)
}
diff --git a/frontend/src/scenes/settings/environment/replayTriggersLogic.test.ts b/frontend/src/scenes/settings/environment/replayTriggersLogic.test.ts
index decf017b0fb4..5777a4284397 100644
--- a/frontend/src/scenes/settings/environment/replayTriggersLogic.test.ts
+++ b/frontend/src/scenes/settings/environment/replayTriggersLogic.test.ts
@@ -1,29 +1,140 @@
-import { hasOutdatedWebSdk, legacyConditionsAreInactive, TRIGGER_GROUPS_MIN_SDK_VERSION } from './replayTriggersLogic'
+import {
+ hasOutdatedWebSdk,
+ legacyConditionsAreInactive,
+ outdatedWebTrafficShare,
+ TRIGGER_GROUPS_MIN_SDK_VERSION,
+ WebRelease,
+} from './replayTriggersLogic'
describe('replayTriggersLogic', () => {
describe('legacyConditionsAreInactive', () => {
- it.each([
+ it.each<[string, WebRelease[], boolean]>([
['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)
+ [
+ 'only new versions',
+ [
+ { version: '1.369.0', count: 100 },
+ { version: '1.400.1', count: 100 },
+ ],
+ true,
+ ],
+ [
+ 'only old versions',
+ [
+ { version: '1.300.0', count: 100 },
+ { version: '1.368.9', count: 100 },
+ ],
+ false,
+ ],
+ [
+ 'tiny outdated tail stays inactive',
+ [
+ { version: '1.300.0', count: 6 },
+ { version: '1.400.0', count: 100000 },
+ ],
+ true,
+ ],
+ [
+ 'outdated share above threshold is not inactive',
+ [
+ { version: '1.300.0', count: 30 },
+ { version: '1.400.0', count: 70 },
+ ],
+ false,
+ ],
+ ['exactly the minimum version', [{ version: TRIGGER_GROUPS_MIN_SDK_VERSION, count: 100 }], true],
+ [
+ 'unparseable version counts as outdated',
+ [
+ { version: 'not-a-version', count: 50 },
+ { version: '1.400.0', count: 50 },
+ ],
+ false,
+ ],
+ ])('%s -> %s', (_description, releases, expected) => {
+ expect(legacyConditionsAreInactive(releases)).toBe(expected)
})
})
describe('hasOutdatedWebSdk', () => {
- it.each([
+ it.each<[string, WebRelease[], boolean]>([
['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)
+ [
+ 'only new versions',
+ [
+ { version: '1.369.0', count: 100 },
+ { version: '1.400.1', count: 100 },
+ ],
+ false,
+ ],
+ [
+ 'only old versions',
+ [
+ { version: '1.300.0', count: 100 },
+ { version: '1.368.9', count: 100 },
+ ],
+ true,
+ ],
+ [
+ 'tiny outdated tail does not warn',
+ [
+ { version: '1.300.0', count: 6 },
+ { version: '1.400.0', count: 100000 },
+ ],
+ false,
+ ],
+ [
+ 'outdated share above threshold warns',
+ [
+ { version: '1.300.0', count: 30 },
+ { version: '1.400.0', count: 70 },
+ ],
+ true,
+ ],
+ ['exactly the minimum version', [{ version: TRIGGER_GROUPS_MIN_SDK_VERSION, count: 100 }], false],
+ [
+ 'unparseable version counts as outdated',
+ [
+ { version: 'not-a-version', count: 50 },
+ { version: '1.400.0', count: 50 },
+ ],
+ true,
+ ],
+ ])('%s -> %s', (_description, releases, expected) => {
+ expect(hasOutdatedWebSdk(releases)).toBe(expected)
+ })
+ })
+
+ describe('outdatedWebTrafficShare', () => {
+ it.each<[string, WebRelease[], { outdatedCount: number; totalCount: number; share: number }]>([
+ ['no web data', [], { outdatedCount: 0, totalCount: 0, share: 0 }],
+ [
+ 'just below the 5% threshold',
+ [
+ { version: '1.300.0', count: 4 },
+ { version: '1.400.0', count: 96 },
+ ],
+ { outdatedCount: 4, totalCount: 100, share: 0.04 },
+ ],
+ [
+ 'at the 5% threshold',
+ [
+ { version: '1.300.0', count: 5 },
+ { version: '1.400.0', count: 95 },
+ ],
+ { outdatedCount: 5, totalCount: 100, share: 0.05 },
+ ],
+ ])('%s', (_description, releases, expected) => {
+ expect(outdatedWebTrafficShare(releases)).toEqual(expected)
+ })
+
+ it('treats the 5% threshold as inclusive for warnings', () => {
+ const atThreshold: WebRelease[] = [
+ { version: '1.300.0', count: 5 },
+ { version: '1.400.0', count: 95 },
+ ]
+ expect(hasOutdatedWebSdk(atThreshold)).toBe(true)
+ expect(legacyConditionsAreInactive(atThreshold)).toBe(false)
})
})
})
diff --git a/frontend/src/scenes/settings/environment/replayTriggersLogic.ts b/frontend/src/scenes/settings/environment/replayTriggersLogic.ts
index 5d8f28c78e60..534b3ef0a36a 100644
--- a/frontend/src/scenes/settings/environment/replayTriggersLogic.ts
+++ b/frontend/src/scenes/settings/environment/replayTriggersLogic.ts
@@ -17,18 +17,25 @@ 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'
+/**
+ * Share of recent web traffic that must be on outdated SDKs before we warn / keep the legacy UI prominent.
+ * Below this we treat traffic as effectively all-new, so a long tail of stray old-version events doesn't
+ * raise an alarm. Lower than the backend's 20% outdated-traffic alert because trigger coverage gaps matter
+ * more in this context.
+ */
+export const OUTDATED_TRAFFIC_SHARE_THRESHOLD = 0.05
+
+export interface WebRelease {
+ version: string
+ count: number
+}
+
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 {
@@ -38,16 +45,42 @@ function webSdkPredatesTriggerGroups(version: string): boolean {
}
}
-export function legacyConditionsAreInactive(webVersions: string[]): boolean {
- if (webVersions.length === 0) {
+/**
+ * Weighs recent web traffic by event volume rather than treating every distinct version equally. The SDK Doctor
+ * data is a rolling ~7-day window, so this answers "how much recent traffic is on SDKs that predate trigger
+ * groups". Returns zeros when there's no web data (e.g. a brand-new or self-hosted team).
+ */
+export function outdatedWebTrafficShare(releases: WebRelease[]): {
+ outdatedCount: number
+ totalCount: number
+ share: number
+} {
+ const totalCount = releases.reduce((sum, r) => sum + r.count, 0)
+ if (totalCount === 0) {
+ return { outdatedCount: 0, totalCount: 0, share: 0 }
+ }
+ const outdatedCount = releases
+ .filter((r) => webSdkPredatesTriggerGroups(r.version))
+ .reduce((sum, r) => sum + r.count, 0)
+ return { outdatedCount, totalCount, share: outdatedCount / totalCount }
+}
+
+/**
+ * True when the team's recent web SDK traffic is effectively all on versions that understand trigger groups, so
+ * the legacy recording conditions only serve a negligible tail of older SDKs. Returns false when there's no web
+ * data — we never minimize the legacy UI without positive evidence.
+ */
+export function legacyConditionsAreInactive(releases: WebRelease[]): boolean {
+ const { totalCount, share } = outdatedWebTrafficShare(releases)
+ if (totalCount === 0) {
return false
}
- return !webVersions.some(webSdkPredatesTriggerGroups)
+ return share < OUTDATED_TRAFFIC_SHARE_THRESHOLD
}
-/** 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)
+/** True when a meaningful share of recent web traffic is on SDKs that predate trigger-group support. */
+export function hasOutdatedWebSdk(releases: WebRelease[]): boolean {
+ return outdatedWebTrafficShare(releases).share >= OUTDATED_TRAFFIC_SHARE_THRESHOLD
}
function ensureAnchored(url: string): string {
@@ -215,13 +248,16 @@ export const replayTriggersLogic = kea<replayTriggersLogicType>([
selectors({
shouldMinimizeLegacyConditions: [
(s) => [s.augmentedData],
- (augmentedData): boolean =>
- legacyConditionsAreInactive((augmentedData?.web?.allReleases ?? []).map((r) => r.version)),
+ (augmentedData): boolean => legacyConditionsAreInactive(augmentedData?.web?.allReleases ?? []),
],
hasOutdatedWebSdk: [
(s) => [s.augmentedData],
- (augmentedData): boolean =>
- hasOutdatedWebSdk((augmentedData?.web?.allReleases ?? []).map((r) => r.version)),
+ (augmentedData): boolean => hasOutdatedWebSdk(augmentedData?.web?.allReleases ?? []),
+ ],
+ outdatedWebTraffic: [
+ (s) => [s.augmentedData],
+ (augmentedData): { outdatedCount: number; totalCount: number; share: number } =>
+ outdatedWebTrafficShare(augmentedData?.web?.allReleases ?? []),
],
isAddUrlTriggerConfigFormVisible: [
(s) => [s.editUrlTriggerIndex],