Open
Description
Full context in this slack thread. Here's a summary:
- Calling
posthog.group()
has a side-effect where subsequent events that captured are associated to the group. - 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. - 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) - @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 - 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:
- User has two tabs open. One on the homepage, one on a "create project" page
- In create project page, user creates new project. So posthog.group() is called.
- User does a bunch of events in the projects, which are correctly associated with the project.
- User switches tab to dashboard. All events from the dashboard are now assocaited with the project 🤦🏻♂️
- 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:
- Call
posthog.group('company', <company_id>)
- 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