Group analytics

Last updated:

Note: This feature is only available on our paid plan. See our pricing page for more.

What are groups in PostHog?

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 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.

  3. 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.

  4. For a social media app like Twitter, you can create a post group type. This enables you to measure average number of replies per post, or total count of unique posters per month.

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.

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. If your only goal is to create a list of users with something in common, we recommend cohorts instead of groups.```

How to create groups

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

In the example below, 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 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.

// All events for that session will be associated with company `company_id_on_your_db`
posthog.group('company', 'company_id_in_your_db');
posthog.capture('user_signed_up')

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

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.

A single event can only belong to a single group per group type. To elaborate what we mean, we'll continue using the example above:

  • It is NOT possible to assign the a single user_signed_up event to two companies at the same time.
  • It is possible to assign this event to a different group type, for example channel or post, in addition to the company group type.
// ❌ 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')

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.

Setting and updating group properties

In the same way that every user 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 "Persons & Groups" tab.

posthog.group('company', 'company_id_in_your_db', {
name: 'PostHog',
subscription: "subscription",
date_joined: '2020-01-23T00:00:00.000Z'
});

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.

Using groups in PostHog

Once you have set up your groups, you can use groups in PostHog to:

For detailed information on how to use groups in PostHog, as well as their limitations, check out our full groups docs.

Questions?

Was this page useful?

Next article

Estimating Usage & Costs

It can be daunting to figure out how much a usage-based platform like PostHog will cost, but there are simple ways to estimate your usage and costs. This guide explains why we price based on usage, how to estimate your usage, and tips on how to reduce your costs. Why do we price based on usage? Really it comes down to this: The more you use PostHog, the more value you get, and the more it costs us to process and store your data. Thus, we charge based on usage. What about charging by monthly…

Read next article