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.

feat(experiments): add activity descriptions for excluding variants (#60008)

Rodrigo Iloroaeca3ebbb15f
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 6f59cc68ec31..35f990fd4776 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4891,7 +4891,7 @@ snapshots:
scenes-app-insights-funnels--funnel-left-to-right-edit--light:
hash: v1.k794b7964.6c391cbc05b64230fbd8defdbb960b131fd433409817497873fb9ffc705cd360.dtIb8VK_HAoAvzi8YbVjGpt2Y8yONsVV7mEiD9DrclQ
scenes-app-insights-funnels--funnel-left-to-right-edit-viewports--medium--dark:
- hash: v1.k794b7964.8887db0213a228a0f958496f8de814bd30d4735f99f8dcd886fbc9740a703afd.U7j0SBm9JuPzdVQVGChjxt-Iw1svrkRV06tAv9pg-mM
+ hash: v1.k794b7964.dad9df902a133cafd6b3314a3800fcb45dabbbb59a0766c87c226549392104fc.u8mciTuIKrwI-d3yiUx6dVpr3oLoJJ7tgvRU7hutwhU
scenes-app-insights-funnels--funnel-left-to-right-edit-viewports--medium--light:
hash: v1.k794b7964.1dd3425e658b907855610a715527654f68a242ed0c1427803dcf4d2289806fed.xd6ZnWiKWTOAglDDiM771sUAuByJ76icZNkrOre_orA
scenes-app-insights-funnels--funnel-left-to-right-edit-viewports--superwide--dark:
diff --git a/frontend/src/scenes/experiments/activity-descriptions/experimentChangeDescription.tsx b/frontend/src/scenes/experiments/activity-descriptions/experimentChangeDescription.tsx
index 3b754fd87fcd..752afda874d7 100644
--- a/frontend/src/scenes/experiments/activity-descriptions/experimentChangeDescription.tsx
+++ b/frontend/src/scenes/experiments/activity-descriptions/experimentChangeDescription.tsx
@@ -43,12 +43,36 @@ type AllowedExperimentFields = Pick<
| 'metrics'
| 'metrics_secondary'
| 'exposure_criteria'
+ | 'parameters'
| 'primary_metrics_ordered_uuids'
| 'secondary_metrics_ordered_uuids'
> & {
deleted: boolean
}
+function describeExcludedVariantsChange(before: string[] | undefined, after: string[] | undefined): string | null {
+ const beforeSet = new Set(before ?? [])
+ const afterSet = new Set(after ?? [])
+ const added = [...afterSet].filter((k) => !beforeSet.has(k))
+ const removed = [...beforeSet].filter((k) => !afterSet.has(k))
+
+ if (added.length === 0 && removed.length === 0) {
+ return null
+ }
+ const parts: string[] = []
+ if (added.length === 1) {
+ parts.push(`excluded variant ${added[0]} from analysis`)
+ } else if (added.length > 1) {
+ parts.push(`excluded variants ${added.join(', ')} from analysis`)
+ }
+ if (removed.length === 1) {
+ parts.push(`re-included variant ${removed[0]} in analysis`)
+ } else if (removed.length > 1) {
+ parts.push(`re-included variants ${removed.join(', ')} in analysis`)
+ }
+ return parts.join(' and ')
+}
+
/**
* Detect a pure metric reorder. Returns the description only when the two
* arrays contain the same set of UUIDs in a different order — additions,
@@ -206,6 +230,16 @@ export const getExperimentChangeDescription = (
return changes.filter(Boolean) as (string | JSX.Element)[]
})
+ .with({ field: 'parameters' }, ({ before, after }) => {
+ const summary = describeExcludedVariantsChange(
+ (before as { excluded_variants?: string[] } | null)?.excluded_variants,
+ (after as { excluded_variants?: string[] } | null)?.excluded_variants
+ )
+ if (summary) {
+ return summary
+ }
+ return 'updated parameters'
+ })
.otherwise(({ field, action }) => {
// Fallback for unhandled fields - ensures all activity is visible
const fieldName = field.replace(/_/g, ' ')
diff --git a/frontend/src/scenes/experiments/experimentActivityDescriber.test.tsx b/frontend/src/scenes/experiments/experimentActivityDescriber.test.tsx
index b670113f3a60..b844303d107c 100644
--- a/frontend/src/scenes/experiments/experimentActivityDescriber.test.tsx
+++ b/frontend/src/scenes/experiments/experimentActivityDescriber.test.tsx
@@ -128,4 +128,72 @@ describe('experimentActivityDescriber', () => {
expect(textOf(result)).not.toContain('reordered')
})
})
+
+ describe('excluded_variants describer', () => {
+ it.each([
+ {
+ name: 'single variant added to exclusion list',
+ before: { excluded_variants: [] },
+ after: { excluded_variants: ['test-2'] },
+ expected: 'excluded variant test-2 from analysis',
+ },
+ {
+ name: 'single variant removed from exclusion list',
+ before: { excluded_variants: ['test-2'] },
+ after: { excluded_variants: [] },
+ expected: 're-included variant test-2 in analysis',
+ },
+ {
+ name: 'multiple variants added to exclusion list',
+ before: { excluded_variants: [] },
+ after: { excluded_variants: ['test-2', 'test-3'] },
+ expected: 'excluded variants test-2, test-3 from analysis',
+ },
+ {
+ name: 'multiple variants removed from exclusion list',
+ before: { excluded_variants: ['test-2', 'test-3'] },
+ after: { excluded_variants: [] },
+ expected: 're-included variants test-2, test-3 in analysis',
+ },
+ {
+ name: 'simultaneous add and remove',
+ before: { excluded_variants: ['test-2'] },
+ after: { excluded_variants: ['test-3'] },
+ expected: 'excluded variant test-3 from analysis and re-included variant test-2 in analysis',
+ },
+ {
+ name: 'falls back to updated parameters when excluded_variants is unchanged',
+ before: { excluded_variants: ['test-2'] },
+ after: { excluded_variants: ['test-2'] },
+ expected: 'updated parameters',
+ },
+ {
+ name: 'handles null before payload (fresh record case)',
+ before: null,
+ after: { excluded_variants: ['test-2'] },
+ expected: 'excluded variant test-2 from analysis',
+ },
+ ])('$name', ({ before, after, expected }) => {
+ const result = experimentActivityDescriber(
+ baseLogItem({
+ activity: 'updated',
+ detail: {
+ name: 'Checkout funnel',
+ changes: [
+ {
+ type: ActivityScope.EXPERIMENT,
+ action: 'changed',
+ field: 'parameters',
+ before,
+ after,
+ },
+ ],
+ merge: null,
+ trigger: null,
+ },
+ })
+ )
+ expect(textOf(result)).toContain(expected)
+ })
+ })
})