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

[Bug][Groups] It's not possible to opt out subsequent group event capture #1545

Open
Lior539 opened this issue Nov 21, 2024 · 0 comments
Open
Assignees

Comments

@Lior539
Copy link
Contributor

Lior539 commented Nov 21, 2024

Full context in this slack thread. Here's a summary:

  1. Calling posthog.group() has a side-effect where subsequent events that captured are associated to the group.
  2. This is fine if you have a high-level group type like company, since you probably want all the users events to be associated with the company.
  3. However, for lower-level group types (e.g. project in an Asana-like app), you dont want ALL subsequent events to be associated with the group. Instead, you want to explicitly specify which events should be capture (see reason for this below)
  4. @neilkakkar suggested to set the groups property in events to associate events e.g. posthog.capture('new_task_created, { $groups: { project: <project_id> }. This doesnt work as expected . See below for more
  5. Also, if you try to set group properties by manually capturing$groupidentify, all subsequent events are still associated with the group.

e.g. if you call:

    posthog.capture('$groupidentify', {
      '$group_type': 'project',
      '$group_key': newProject.id,
      '$group_set': {
        name: newProjectName
      }
  });

In the above, all subsequent client-side events are then associated with the project.

Why you might not want all subsequent events to be associated with the group

Consider the following scenario:

  1. User has two tabs open. One on the homepage, one on a "create project" page
  2. In create project page, user creates new project. So posthog.group() is called.
  3. User does a bunch of events in the projects, which are correctly associated with the project.
  4. User switches tab to dashboard. All events from the dashboard are now assocaited with the project 🤦🏻‍♂️
  5. User switches back to projects tab. Events should be associated with projects again

Why posthog.capture('new_task_created, { $groups: { project: <project_id> } doesnt work

Setting the $groups key will override any previous posthog.group() calls. For example:

  1. Call posthog.group('company', <company_id>)
  2. Then call posthog.capture('new_task_created, { $groups: { project: <project_id> }

Expected result:
Your event is captured with both the project and the company

Actual result:
Event is only captured with the project. The company is dropped

@Lior539 Lior539 self-assigned this Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant