: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
fix(autocapture): use link and button details for SVG clicks (#81199)
Manoel Aranda Neto411dd6c00278
diff --git a/frontend/src/lib/utils/events.test.ts b/frontend/src/lib/utils/events.test.tsindex a680ad8c8b8b..6b9cf2c77b46 100644--- a/frontend/src/lib/utils/events.test.ts+++ b/frontend/src/lib/utils/events.test.ts@@ -218,6 +218,54 @@ describe('events utils', () => {})).toEqual('clicked button with aria label "Close "main" dialog"')})++ it.each([+ [+ 'SVG using link text',+ [{ tag_name: 'svg' } as ElementType, { tag_name: 'a', text: 'View documentation' } as ElementType],+ 'clicked link with text "View documentation"',+ ],+ [+ 'SVG using button aria-label',+ [+ { tag_name: 'svg' } as ElementType,+ {+ tag_name: 'button',+ attributes: { 'attr__aria-label': 'Play video' },+ } as ElementType,+ ],+ 'clicked button with aria label "Play video"',+ ],+ [+ 'labeled SVG inside an unlabeled link',+ [+ {+ tag_name: 'svg',+ attributes: { 'attr__aria-label': 'Documentation' },+ } as ElementType,+ { tag_name: 'a' } as ElementType,+ ],+ 'clicked link with aria label "Documentation"',+ ],+ [+ 'labeled image inside an unlabeled button',+ [+ {+ tag_name: 'img',+ attributes: { 'attr__aria-label': 'Delete' },+ } as ElementType,+ { tag_name: 'button' } as ElementType,+ ],+ 'clicked image with aria label "Delete"',+ ],+ ])('describes a clicked %s', (_, elements, expected) => {+ expect(+ autoCaptureEventToDescription({+ ...baseEvent,+ elements,+ })+ ).toEqual(expected)+ })})describe('getPrimaryPropertyForEvent', () => {diff --git a/frontend/src/lib/utils/events.ts b/frontend/src/lib/utils/events.tsindex f7bc6fab2e2c..24a63f47c7d9 100644--- a/frontend/src/lib/utils/events.ts+++ b/frontend/src/lib/utils/events.ts@@ -111,23 +111,32 @@ export function autoCaptureEventToDescription(}const getVerb = (): string => eventTypeToVerb[event.properties.$event_type] || 'interacted with'+ const targetElement = event.elements?.[0]+ const describedElement =+ event.properties.$event_type === 'click' && targetElement?.tag_name === 'svg'+ ? (event.elements?.find(({ tag_name }) => tag_name === 'a' || tag_name === 'button') ?? targetElement)+ : targetElementconst getTag = (): string => {- if (event.elements?.[0]?.tag_name === 'a') {+ if (describedElement?.tag_name === 'a') {return 'link'- } else if (event.elements?.[0]?.tag_name === 'img') {+ } else if (describedElement?.tag_name === 'img') {return 'image'}- return event.elements?.[0]?.tag_name ?? 'element'+ return describedElement?.tag_name ?? 'element'}const getValue = (): string | null => {if (event.properties.$el_text) {return `${shortForm ? '' : 'with text '}"${event.properties.$el_text}"`- } else if (event.elements?.[0]?.text) {- return `${shortForm ? '' : 'with text '}"${event.elements[0].text}"`- } else if (event.elements?.[0]?.attributes?.['attr__aria-label']) {- return `${shortForm ? '' : 'with aria label '}"${event.elements[0].attributes['attr__aria-label']}"`+ } else if (describedElement?.text) {+ return `${shortForm ? '' : 'with text '}"${describedElement.text}"`+ } else if (describedElement?.attributes?.['attr__aria-label']) {+ return `${shortForm ? '' : 'with aria label '}"${describedElement.attributes['attr__aria-label']}"`+ } else if (describedElement !== targetElement && targetElement?.text) {+ return `${shortForm ? '' : 'with text '}"${targetElement.text}"`+ } else if (describedElement !== targetElement && targetElement?.attributes?.['attr__aria-label']) {+ return `${shortForm ? '' : 'with aria label '}"${targetElement.attributes['attr__aria-label']}"`}return null}