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(replay-vision): capture enable/disable direction on scanner toggle (#65063)

Paul D'Ambrabf46f897028a
diff --git a/frontend/src/lib/lemon-ui/LemonSwitch/LemonSwitch.test.tsx b/frontend/src/lib/lemon-ui/LemonSwitch/LemonSwitch.test.tsx
new file mode 100644
index 000000000000..80e6760a0867
--- /dev/null
+++ b/frontend/src/lib/lemon-ui/LemonSwitch/LemonSwitch.test.tsx
@@ -0,0 +1,37 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render, screen } from '@testing-library/react'
+
+import { LemonSwitch } from './LemonSwitch'
+
+describe('LemonSwitch', () => {
+ afterEach(() => {
+ cleanup()
+ })
+
+ it.each([
+ { value: true, expected: 'true' },
+ { value: false, expected: 'false' },
+ { value: 'image', expected: 'image' },
+ ])('forwards data-ph-capture-attribute-* ($value) onto the clickable element', ({ value, expected }) => {
+ render(
+ <LemonSwitch
+ checked={false}
+ onChange={() => {}}
+ data-attr="my-switch"
+ data-ph-capture-attribute-will-be-enabled={value}
+ />
+ )
+
+ const button = screen.getByRole('switch')
+ expect(button).toHaveAttribute('data-ph-capture-attribute-will-be-enabled', expected)
+ })
+
+ it('renders without capture attributes', () => {
+ render(<LemonSwitch checked={true} onChange={() => {}} data-attr="my-switch" />)
+
+ const button = screen.getByRole('switch')
+ expect(button).toHaveAttribute('data-attr', 'my-switch')
+ expect(button).not.toHaveAttribute('data-ph-capture-attribute-will-be-enabled')
+ })
+})
diff --git a/frontend/src/lib/lemon-ui/LemonSwitch/LemonSwitch.tsx b/frontend/src/lib/lemon-ui/LemonSwitch/LemonSwitch.tsx
index 3405ac46a76e..d9f0fa81a536 100644
--- a/frontend/src/lib/lemon-ui/LemonSwitch/LemonSwitch.tsx
+++ b/frontend/src/lib/lemon-ui/LemonSwitch/LemonSwitch.tsx
@@ -27,6 +27,8 @@ export interface LemonSwitchProps {
sliderColorOverrideChecked?: string
sliderColorOverrideUnchecked?: string
loading?: boolean
+ /** Forwarded to the switch element so autocapture can read them off the click. Autocapture only fires on the interactive (`onChange`) variant, which renders a button; a read-only switch renders a div and these never reach an autocapture event. */
+ [captureAttribute: `data-ph-capture-attribute-${string}`]: string | boolean | undefined
}
/** Counter used for collision-less automatic switch IDs. */
@@ -52,6 +54,7 @@ export const LemonSwitch: React.FunctionComponent<LemonSwitchProps & React.RefAt
sliderColorOverrideChecked,
sliderColorOverrideUnchecked,
loading = false,
+ ...captureAttributes
},
ref
): JSX.Element {
@@ -97,6 +100,7 @@ export const LemonSwitch: React.FunctionComponent<LemonSwitchProps & React.RefAt
data-attr={dataAttr}
disabled={isDisabled}
{...conditionalProps}
+ {...captureAttributes}
>
<div className="LemonSwitch__handle">
{loading && (
diff --git a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.tsx b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.tsx
index 5a7ee7c75e69..47d7c172c165 100644
--- a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.tsx
+++ b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.tsx
@@ -86,6 +86,7 @@ export function ReplayScannersScene(): JSX.Element {
size="small"
data-attr="vision-scanner-toggle-enabled"
data-ph-capture-attribute-scanner-type={scanner.scanner_type}
+ data-ph-capture-attribute-will-be-enabled={!scanner.enabled}
/>
</AccessControlAction>
<span className={`inline-block min-w-[4.5rem] ${scanner.enabled ? 'text-success' : 'text-muted'}`}>
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerConfigReadonly.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerConfigReadonly.tsx
index 3a7e60ca505d..299429b92d4f 100644
--- a/products/replay_vision/frontend/replay_scanners/components/ScannerConfigReadonly.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerConfigReadonly.tsx
@@ -163,6 +163,7 @@ export function ScannerConfigReadonly({ scanner }: { scanner: ReplayScanner }):
loading={togglingEnabled}
data-attr="vision-scanner-toggle-enabled"
data-ph-capture-attribute-scanner-type={scanner.scanner_type}
+ data-ph-capture-attribute-will-be-enabled={!scanner.enabled}
/>
</AccessControlAction>
<span className="text-muted text-xs">