Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listen to pointerdown events instead of click in Autocapture to track dropdown menus target properly #1526

Open
mbektimirov opened this issue Nov 14, 2024 · 0 comments
Labels
SDK Support General SDK issues rather than being related to a feature team

Comments

@mbektimirov
Copy link

The problem

I've trapped into the issue when dropdown menu trigger (implemented with radix dropdown menu) click events are not tracked by PostHog Autocapture. The problem is the target value of a click event is always the html root node. So basically click on the Actions button is not tracked by posthog:

<DropdownMenu.Root onOpenChange={onOpenChange} modal={false}>
  <DropdownMenu.Trigger asChild>
    <Button>Actions</Button>
  </DropdownMenu.Trigger>
  <DropdownMenu.Portal>
    <DropdownMenu.Content asChild>
      <Stack gap={8} {...rootMenuStackProps}>
        <RenderMenu items={items} menuWidth={menuWidth} />
      </Stack>
    </DropdownMenu.Content>
  </DropdownMenu.Portal>
</DropdownMenu.Root>

Reproduction

// output when clicked on Action button: html
document.addEventListener('click', e => console.log(e.target), true) 

// output when clicked on Action button: <span class="..."> -- button child element
document.addEventListener('pointerdown', e => console.log(e.target), true) 

Solution

The solution to this is to track pointerdown events as described in this radix discussion: radix-ui/primitives#2264 (reply in thread)
ChatGPT outlined the root problem very well:

Is there a way to add an option to change click to pointerdown event on PostHog init?

@robbie-c robbie-c added the SDK Support General SDK issues rather than being related to a feature team label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SDK Support General SDK issues rather than being related to a feature team
Projects
None yet
Development

No branches or pull requests

2 participants