: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-vision): add tag vocabulary explainer and clear all (#81425)
Arno Hillen87fde1031b2b
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerTemplatePicker.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerTemplatePicker.tsxindex 7da5bbcee45f..675c853a6591 100644--- a/products/replay_vision/frontend/replay_scanners/components/ScannerTemplatePicker.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerTemplatePicker.tsx@@ -21,6 +21,7 @@ import { ScannerTypeBadge } from '../../components/ScannerTypeBadge'import { replayScannerLogic } from '../replayScannerLogic'import { ScannerTemplate, ScannerTemplateIcon, defaultScannerTemplates } from '../scannerTemplates'import { scannerTypeOutputHint } from '../types'+import { scannerStartSearchParams } from './scannerStartParams'const TEMPLATE_ICONS: Record<ScannerTemplateIcon, JSX.Element> = {warning: <IconWarning />,@@ -38,8 +39,9 @@ export function TemplateCard({ template }: { template: ScannerTemplate | 'blank'const start = (): void => {const templateKey = isBlank ? null : template.keyreplayScannerLogic({ id: 'new' }).actions.startFromTemplate(templateKey)- const params = isBlank ? searchParams : { ...searchParams, template: template.key }- router.actions.push(combineUrl(urls.replayVisionScannerDetails('new'), params).url)+ router.actions.push(+ combineUrl(urls.replayVisionScannerDetails('new'), scannerStartSearchParams(searchParams, templateKey)).url+ )}const handleClick = (): void => {diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerTypeConfigEditor.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerTypeConfigEditor.tsxindex 38f1380fdfbd..d4ceda7fd719 100644--- a/products/replay_vision/frontend/replay_scanners/components/ScannerTypeConfigEditor.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerTypeConfigEditor.tsx@@ -1,4 +1,5 @@import { useActions, useValues } from 'kea'+import { router } from 'kea-router'import { useCallback } from 'react'import { IconAI, IconPlus, IconX } from '@posthog/icons'@@ -174,12 +175,18 @@ function ClassifierTagSuggestions({ scannerId }: { scannerId: string }): JSX.Elefunction ClassifierTagsField({ scannerId }: { scannerId: string }): JSX.Element {const logic = replayScannerLogic({ id: scannerId })const { scanner, isNew, goalDraft, tagSuggestionsLoading } = useValues(logic)- const { loadTagSuggestions } = useActions(logic)+ const { loadTagSuggestions, clearClassifierTags } = useActions(logic)+ const { searchParams } = useValues(router)const config = scanner?.scanner_config as ClassifierScannerConfig | undefinedconst hasPrompt = !!config?.prompt?.trim()+ const hasTags = (config?.tags ?? []).length > 0// The draft already filled these in, so the offer is more of them, not a first set.const categoriesWereDrafted = isNew && !!goalDraft && !!config?.tags?.length+ // The param only survives on a new scanner whose config a valid template prefilled: the picker+ // drops it when the blank card is chosen, and loadScanner strips it on load when a goal draft+ // outranks the template or the key is unknown.+ const startedFromTemplate = isNew && typeof searchParams.template === 'string'return (<div className="space-y-2">@@ -188,17 +195,32 @@ function ClassifierTagsField({ scannerId }: { scannerId: string }): JSX.Elementlabel={<span className="flex w-full flex-wrap items-center justify-between gap-2">Categories- <LemonButton- size="xsmall"- type="secondary"- icon={<IconAI />}- loading={tagSuggestionsLoading}- disabledReason={hasPrompt ? undefined : 'Add a prompt first so suggestions match your goal'}- onClick={() => loadTagSuggestions()}- data-attr="replay-vision-suggest-tags-with-ai"- >- {categoriesWereDrafted ? 'Suggest more categories' : 'Suggest categories with PostHog AI'}- </LemonButton>+ <span className="flex flex-wrap items-center gap-1">+ <LemonButton+ size="xsmall"+ type="secondary"+ disabledReason={hasTags ? undefined : 'No categories to clear'}+ onClick={() => clearClassifierTags()}+ data-attr="replay-vision-clear-categories"+ >+ Clear all+ </LemonButton>+ <LemonButton+ size="xsmall"+ type="secondary"+ icon={<IconAI />}+ loading={tagSuggestionsLoading}+ disabledReason={+ hasPrompt ? undefined : 'Add a prompt first so suggestions match your goal'+ }+ onClick={() => loadTagSuggestions()}+ data-attr="replay-vision-suggest-tags-with-ai"+ >+ {categoriesWereDrafted+ ? 'Suggest more categories'+ : 'Suggest categories with PostHog AI'}+ </LemonButton>+ </span></span>}>@@ -213,6 +235,11 @@ function ClassifierTagsField({ scannerId }: { scannerId: string }): JSX.Element/>)}</LemonField>+ <div className="text-xs text-muted">+ The classifier sorts each session it scans into these categories.+ {startedFromTemplate &&+ " The template's categories are examples. Edit or clear them to fit your product."}+ </div><ClassifierTagSuggestions scannerId={scannerId} /></div>)diff --git a/products/replay_vision/frontend/replay_scanners/components/scannerStartParams.test.ts b/products/replay_vision/frontend/replay_scanners/components/scannerStartParams.test.tsnew file mode 100644index 000000000000..430416116d1e--- /dev/null+++ b/products/replay_vision/frontend/replay_scanners/components/scannerStartParams.test.ts@@ -0,0 +1,26 @@+import { scannerStartSearchParams } from './scannerStartParams'++describe('scannerStartSearchParams', () => {+ // A card starts the flow with whatever query string the previous step left behind, so carrying+ // the whole thing lets a `template` key outlive its template: downstream readers take it as the+ // source of the config, locking the type selector and captioning the categories as the+ // template's. The editor only strips the key once, on first load, so the picker has to.+ it.each<[string, Record<string, unknown>, string | null, Record<string, unknown>]>([+ ['blank card drops a stale template key', { template: 'dead_end' }, null, {}],+ [+ 'template card replaces a stale template key',+ { template: 'dead_end' },+ 'user_intent',+ { template: 'user_intent' },+ ],+ ['blank card keeps unrelated params', { template: 'dead_end', experiment: '7' }, null, { experiment: '7' }],+ [+ 'template card keeps unrelated params',+ { experiment: '7' },+ 'user_intent',+ { experiment: '7', template: 'user_intent' },+ ],+ ])('%s', (_name, searchParams, templateKey, expected) => {+ expect(scannerStartSearchParams(searchParams, templateKey)).toEqual(expected)+ })+})diff --git a/products/replay_vision/frontend/replay_scanners/components/scannerStartParams.ts b/products/replay_vision/frontend/replay_scanners/components/scannerStartParams.tsnew file mode 100644index 000000000000..5be7884e4b63--- /dev/null+++ b/products/replay_vision/frontend/replay_scanners/components/scannerStartParams.ts@@ -0,0 +1,13 @@+/**+ * Search params to carry into the editor when a template card starts the flow. The chosen card owns+ * the `template` key outright: the blank card must not inherit one an earlier pick left in the URL,+ * because downstream readers treat it as the source of the config, so a stale key locks the type+ * selector and makes the editor claim the template supplied the categories.+ */+export function scannerStartSearchParams(+ searchParams: Record<string, unknown>,+ templateKey: string | null+): Record<string, unknown> {+ const { template: _staleTemplate, ...params } = searchParams+ return templateKey ? { ...params, template: templateKey } : params+}diff --git a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.tsindex 2849feb4d8a9..941a9b508878 100644--- a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts+++ b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts@@ -353,6 +353,31 @@ describe('replayScannerLogic', () => {})})+ describe('clearClassifierTags', () => {+ it('empties the categories of a classifier scanner', async () => {+ logic.actions.setScannerType('classifier')+ logic.actions.setScannerValues({+ scanner_config: {+ prompt: 'Categorize intent',+ tags: ['checkout', 'pricing'],+ multi_label: true,+ } as ClassifierScanner['scanner_config'],+ })+ await expectLogic(logic, () => logic.actions.clearClassifierTags()).toMatchValues({+ scanner: expect.objectContaining({+ scanner_config: expect.objectContaining({ tags: [] }),+ }),+ })+ })++ it('is a no-op for non-classifier scanners', async () => {+ // Default scanner is a monitor, so clearing must not add a tags field to its config.+ await expectLogic(logic, () => logic.actions.clearClassifierTags()).toMatchValues({+ scanner: expect.objectContaining({ scanner_type: 'monitor', scanner_config: { prompt: '' } }),+ })+ })+ })+describe('tag suggestions', () => {const setupClassifier = (): void => {logic.actions.setScannerType('classifier')diff --git a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.tsindex 8416dc5b16cf..c1cfdac9c51e 100644--- a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts+++ b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts@@ -363,6 +363,9 @@ export interface replayScannerLogicActions {appendClassifierTags: (tags: string[]) => {tags: string[]}+ clearClassifierTags: () => {+ value: true+ }clearObservationFilters: () => {value: true}@@ -727,6 +730,7 @@ export const replayScannerLogic = kea<replayScannerLogicType>([// Fired only after an actual API write, unlike submitScannerSuccess (which the advance path emits too).scannerSaved: (scanner: ScannerFormValues) => ({ scanner }),appendClassifierTags: (tags: string[]) => ({ tags }),+ clearClassifierTags: true,acceptTagSuggestion: (tag: string) => ({ tag }),acceptAllTagSuggestions: true,dismissTagSuggestions: true,@@ -1744,6 +1748,16 @@ export const replayScannerLogic = kea<replayScannerLogicType>([}},+ clearClassifierTags: () => {+ const scanner = values.scanner+ if (!scanner || scanner.scanner_type !== 'classifier') {+ return+ }+ if ((scanner.scanner_config.tags ?? []).length > 0) {+ actions.setScannerValue(['scanner_config', 'tags'], [])+ }+ },+acceptTagSuggestion: ({ tag }) => actions.appendClassifierTags([tag]),acceptAllTagSuggestions: () => {// Read the suggestions before dismiss clears them.