Groups
Account-level analytics: assign users to companies and workspaces.
Groups model B2B relationships: companies, workspaces, teams. You assign the current user to groups, attribute events to the active group, and optionally set persistent properties on the group itself.
The browser SDK uses the stored identity automatically. The server SDKs take the distinctId / distinct_id first.
Core concepts
| Term | Meaning |
|---|---|
| Group key | The type of group: company, team, active_team. |
| Group ID | One instance: acme-inc, team-uuid-123. |
| Membership | Which group IDs the user belongs to, per key. |
| Active context | The group the user is currently working in; drives event attribution. |
| Group profile | Persistent properties on a (key, id) pair. |
Membership
add_groupadds a permanent membership (the user joins a group). Idempotent.set_groupswitches the active context for a key. Events fired after the switch attribute to the new group.
await Trodo.add_group('company', 'acme-inc'); // permanent
await Trodo.set_group('active_team', 'team-b-id'); // active context
await Trodo.remove_group('team', 'design');await trodo.add_group('user-42', 'company', 'acme-inc');
await trodo.set_group('user-42', 'active_team', 'team-b-id');
await trodo.remove_group('user-42', 'team', 'design');trodo.add_group('user-42', 'company', 'acme-inc')
trodo.set_group('user-42', 'active_team', 'team-b-id')
trodo.remove_group('user-42', 'team', 'design')Only events fired after a group call are attributed; there's no historical rewrite.
Group profile
get_group(key, id) returns a handle for setting properties on the group entity (not the user, and not event attribution):
const team = Trodo.get_group('team', 'team-a-id');
await team.set({ name: 'Engineering', plan: 'enterprise', seat_count: 50 });
await team.increment('seat_count', 5);
await team.union('tags', ['b2b']);const team = trodo.forUser('user-42').get_group('team', 'team-a-id');
await team.set({ name: 'Engineering', plan: 'enterprise', seat_count: 50 });
await team.increment('seat_count', 5);team = trodo.for_user('user-42').get_group('team', 'team-a-id')
team.set({'name': 'Engineering', 'plan': 'enterprise', 'seat_count': 50})
team.increment('seat_count', 5)The group handle supports set, set_once, increment, append, union, remove, unset, and delete.
Multi-team pattern
Most B2B apps have users in several teams permanently but working in one at a time. Use two keys:
| Key | Method | Purpose |
|---|---|---|
team | add_group | all teams the user permanently belongs to |
active_team | set_group | the current workspace, drives event attribution |
People vs. Groups
| People | Groups | |
|---|---|---|
| Describes | the end user | an org, team, or workspace |
| Browser | Trodo.people.* | Trodo.set_group / add_group / get_group |
| Server | user.people.* | trodo.{set_group, add_group, get_group}(distinctId, …) |