Group analytics

Last updated:

|Edit this page

Groups are a powerful feature in PostHog that aggregate events based on entities, such as organizations or companies. They enable you to analyze trends, insights, and dashboards at an entity-level, as opposed to a user-level.

To clarify what we mean, let's look at a few examples:

  1. For B2B SaaS apps, you can create a company group type. This enables you to aggregate events at a company-level, and calculate metrics such as number of daily active companies, company churn rate, or how many companies have adopted a new feature.

  2. For a communication app like Slack, you can create a channel group type. This enables you to measure metrics like average number of messages per channel, number of monthly active channels, or total number of channel participants.

  3. For collaborative, project-based apps like Notion, Jira, or Figma, you can create a project group type. This enables you to calculate metrics like project pageviews, users per project, and project engagement.

Use cases

Building on the examples above, here are a few things you can do with groups:

  1. Track how companies progress through your B2B product's activation steps. For example, you can create a funnel to see:
    • How many companies signed up this month.
    • What percentage completed the onboarding flow.
    • What percentage of new companies interacted with specific features at least once.

  1. If you're building a Slack-like app, you can measure retention of new features by specific channels. For example:
    • Which channels consistently use the video calling feature.
    • How many channels remain active month over month.
    • Compare feature adoption rates between different types of channels (e.g., team channels vs project channels).

  1. For collaborative, project-based apps like Jira, you can target feature flags at a project-level. For example, let's say you've refactored your codebase. You can target the new codebase to only a few projects and measure the impact on performance and errors metrics. Once you've gathered feedback, you can expand to the rest of your projects.

The difference between groups and cohorts

Groups are often confused with cohorts, but they each serve different purposes:

  • Groups aggregate events, and do not necessarily have to be connected to a user.
  • Cohorts represent a specific set of users – e.g., a list of users that all belong to the same company.

If your only goal is to analyze a list of users with something in common, we recommend cohorts instead of groups.

Groups require additional code in your app to set up, while cohorts are created in PostHog and don't require additional code. This makes cohorts easier to use and quicker to get started.

How to create groups

Groups are created and defined in your code when capturing events.

// Option 1 (recommended): Call posthog.group()
// This has the side-effect that all subsequent events in the session are associated to the group
posthog.group('company', 'company_id_in_your_db');
posthog.capture('user_signed_up'); // This event is associated with the company above
// Option 2: Set the group property in posthog.capture()
// This method doesn't have the side-effect of associating the session's events to the group
posthog.capture('user_signed_up', {
'$groups': {
'company': 'company_id_in_your_db'
}
});

In the above example, we create a group type company. Then, for each company, we set the group key as the unique identifier for that specific company. This can be anything that helps you identify it, such as ID or domain.

We now have one company-type group with a key company_id_in_your_db. When we send the event user_signed_up, it will be attached to this newly created group.

Tip: When specifying the group type, use the singular version for clarity (company instead of companies).

Tip: We advise against using the name of the company (or any other group) as the key, because that's rarely guaranteed to be unique, and thus can affect the quality of analytics data. Use a unique string, like an ID.

Group type limit: There's a hard limit of 5 group types within PostHog, although within each group type you can have an unlimited number of groups.

How to set group properties

In the same way that every person can have properties associated with them, every group can have properties associated with it.

Continuing with the previous example of using company as our group type, we'll add company_name, date_joined, and subscription as additional properties.

Note: You must include at least one group property for a group to be visible in the People and groups tab.

// Option 1 (recommended): Set properties in posthog.group()
// This has the side-effect that all subsequent events in the session are associated to the group
posthog.group('company', 'company_id_in_your_db', {
name: 'PostHog',
subscription: "subscription",
date_joined: '2020-01-23'
});
// Option 2:
// Set properties in posthog.capture()
// This method doesn't have the side-effect of associating all future events to the group.
posthog.capture('$groupidentify', {
'$group_type': 'company',
'$group_key': 'company_id_in_your_db',
'$group_set': {
name: 'PostHog',
subscription: "subscription",
date_joined: '2020-01-23'
}
});

Properties on groups behave in the same way as properties on persons. They can also be used within experiments and feature flags to rollout features to specific groups.

Note: The PostHog UI identifies a group using the name property. If the name property is not found, it falls back to the group key.

For more on implementing group analytics, check out our guide on frontend vs backend group analytics implementations.

How to capture group events

Below are code examples of how to do it in our various SDKs. Notice that it is the exact same code as creating a group.

// Option 1 (recommended): Call posthog.group()
// This has the side-effect that all subsequent events in the session are associated to the group
posthog.group('company', 'company_id_in_your_db');
posthog.capture('user_signed_up'); // This event is associated with the company above
// Option 2: Set the group property in posthog.capture()
// This method doesn't have the side-effect of associating the session's events to the group
posthog.capture('user_signed_up', {
'$groups': {
'company': 'company_id_in_your_db'
}
});

Note that it is NOT possible to assign the a single event to two groups of the same type. However, it is possible to assign an event to multiple groups as long as the groups are of different types.

// ❌ Not possible
posthog.group('company', 'company_id_in_your_db');
posthog.group('company', 'another_company_id_in_your_db');
posthog.capture('user_signed_up')
// ✅ Allowed
posthog.group('company', 'company_id_in_your_db');
posthog.group('channel', 'channel_id_in_your_db');
posthog.capture('user_signed_up')

Advanced (server-side only): Capturing group events without a user

If you want to capture group events but don't want to associate them with a specific user, we recommend using a single static string as the distinct ID to capture these events. This can be anything you want, as long as it's the same for every group event:

posthog.capture({
event: 'group_event_name',
distinctId: 'static_string_for_group_events',
groups: { company: 'company_id_in_your_db' }
})

Using groups in PostHog

Now that we have created our first group type, we can take a look at how to use groups within PostHog.

Viewing groups and their properties

To view groups and their properties, head to the "Persons and Groups" tab on the navigation bar.

From here, you can select the group type you are interested in and view the groups and properties (by clicking the chevrons on the left).

View groups

You can also click on a specific group to see information such as all the events that have been sent by this group. From there, in the "Related people & groups" tab, you can also see all of the persons who have sent events that were associated with this group, as well as all the other groups associated with the events.

View related people and groups

How to view group insights

You can use groups in insights to view aggregated events based on group type.

For example, let's say that we wanted to see a graph showing how many different organizations have signed up recently:

To do this, expand the menu next to the event you've chosen. This lists of all the group types available. Next, select the option for "Unique" with your group type name, such as "Unique organizations." This shows a graph with the total number of groups (organizations) that have signed up (as opposed to individual users).

Analyze group insights

Using groups with funnels

Another place where group analytics can be used is within funnels.

For example, you may want to understand how organizations move from their first visit to eventually signing up. You can do this by setting the "Aggregating by" field to "Unique organizations."

This shows how many organizations have made it through, as well as the percentage of organizations that dropped off. It's also possible to see exactly which specific groups dropped off at each step.

Group funnels

Using groups with feature flags

Groups in feature flags enable you to rollout a feature by group type (like company), instead of users.

To do this, create a feature flag as you normally would, and select the group type you wish to "Match by", using the drop down in the "Release conditions" section:

You also need to update your event tracking code for the feature flag to determine the groups of the current user.

// Make sure you have called posthog.group() earlier in that session
if (posthog.isFeatureEnabled('new-groups-feature')) {
// Do something
}

Renaming group types

You can change how group types are displayed in the insights interface and throughout PostHog by in project settings.

Groups in project settings

Limitations

  • A maximum of 5 group types can be created per project.
  • Multiple groups of the same type cannot assigned to a single event (e.g., Company A & Company B).
  • Groups are not currently supported for the following insights:
    • Lifecycle - Expected soon.
    • User paths - These only support user level analytics.
  • Only groups with known properties are shown under People and groups .
  • Currently there is no functionality within the app to delete groups. If you need to delete a group for privacy or security reasons, please use the support modal.

Further reading

Questions?

Was this page useful?

Next article

Product analytics best practices

1. Set up a reverse proxy Tracking and ad blockers can prevent your events from being sent to PostHog. By setting up a reverse proxy, you can send events to PostHog using your own domain. This means that events are less likely to be blocked and you'll capture more data. See our docs on how to set up a reverse proxy for more details on how to do this. 2. Implement a naming convention As your product grows, the amount of analytics data grows with it. Without naming conventions, your data quickly…

Read next article