Group analytics

Last updated:

Note: This is a paid feature and is not available on the open-source or free cloud plan. Learn more here.

Groups enables you to associate events with an group/entity - such as a company, community, or project. You can then analyze these events as if they were sent by that entity in insights, feature flags, and experiments.

Here are some of the questions that group analytics can help answer:

  • How many companies signed up in the last month?
  • What kind of communities are using my product the most?
  • Which projects is this person associated with?

Understanding group analytics

Before we learn how to use groups, it's best to get some information about how they behave within PostHog.

At a high-level, a group is simply a way to take a set of events, and 'group' them together under a specific 'type' of entity. This 'entity' can be anything you like (organizations, companies, posts, projects, etc.) and depends entirely on your application.

One very common use case is to create groups that contain events that are sent as part of a larger group of users. This could be things such as making groups for each company that uses your app, to creating a separate group for each community within your app.

Note: While groups are often thought of as representing groups of users, it's important to keep in mind that groups aggregate events and not users directly.

Groups vs group types

When considering group analytics, it is also important to make the distinction between 'Group types' and 'Groups'. A 'group type' is the name for given to the kind of object you are aggregating on (company, project, post), whereas a group is a particular member of that type.

Tip: If you're familiar with object-oriented thinking, you can think of each 'group type' as a class, with each 'group' being a unique instance of that class.

A simple example of a group type might be a company, in which case each group would be a specific company such as PostHog, Google, IBM, etc. There's a hard limit of 5 group types within PostHog, although within each group type you can have unlimited groups.

Another important concept to remember here is that a single event belongs to only a single group per group type. For example, let's say you have a project shared event for when a user shares a project. This event could be associated with both a company and a project, but it can't be associated with two separate companies or two separate projects.

Groups vs cohorts

While groups and cohorts may seem almost identical at first, it's important to understand the differences between them. When comparing, it's important to remember that groups aggregate based on events, not users. While it is possible to view persons that are related to a group, they aren't directly 'members' in the same way as cohorts.

Cohorts represent a singular list of users, whereas groups represent many separate lists of events all under a specific group type.

Following the company example again, you can have a cohort of users which belong to a certain company (e.g. Company A). However, this only represents a single company, and you would need to keep creating new cohorts as users from other organizations signed up, which is not practical. In this case, it's best to create a group type company, and then specify which company each event you send is related to.

Getting started

This section will give an overview of setting up your first group within PostHog.

Creating groups

Groups and group types are defined directly from our libraries when sending events. In the examples below, we'll be tracking a company whose ID in the product is 42dlsfj23f. That's why we'll be using group type company and group key 42dlsfj23f.

We advise against using the name of the company (or any other group) as they key, because that's rarely guaranteed to be unique, and conflicts can affect the quality of analytics data.

// All events for that session will be associated with company `42dlsfj23f`
posthog.group('company', '42dlsfj23f');
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 ID 42dlsfj23f, and the event beep that we sent will be attached to this newly created group.

Setting and updating group properties

Every group can have properties associated with it.

Continuing with the previous example of using company as our group type, we might want to add company_name, date_joined, and user_count as additional fields.

Note: You must include at least one group property for a group to be visible in the "Persons & Groups" tab

posthog.group('company', '42dlsfj23f', {
name: 'PostHog',
user_count: 33,
date_joined: '2020-01-23T00:00:00.000Z'
});

Properties on groups behave in the exact same way as properties on persons within insights. 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 no name property is 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

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 now click on a specific group to see information such as all the events that have been sent by this group.

Under 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 from different types that have shared events.

Analyzing group insights

Using groups in insights works in almost the exact same way as with users, and works by aggregating events and properties based on unique groups. Within a trends insight, you can select which of your group types you would like to view, which will display the count of unique organizations that performed a certain event in a given period.

Organizations signed up in last week

To see a concrete example of groups in action, let's say that we wanted to see a graph showing how many different organizations have signed up recently. Within an insight, we would expand the menu next to the event we've chosen, which should show a list of all the group types you have available.

Selecting 'Unique organizations', this will show us a graph with the total number of organizations that have signed up, as opposed to individual users.

View Groups

Organization signup funnel

Another place where group analytics can be used is within funnels. For example, you may want to understand how an organization moves from their first visit to eventually signing up, which we can do by setting the 'Aggregating by' field to 'Unique organizations'.

This will show 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 groups dropped of at a specific step in exactly the same way as with users.

View Groups

Renaming group types

You can change how group types are displayed in your Insights interface and throughout PostHog from the Project settings.

Integrating groups with feature flags

Similar to insights, where you're aggregating events by group type, you can have Feature Flags that work on groups. This allows you to rollout a feature by company, instead of users. Preventing disruption when two users at the same company see a different experience.

You can use feature flags as you normally would, except you need to select the group type you wish to "Match by", using the drop down by release conditions.

You will also need to update your event tracking code (covered below), for the feature flag to be able 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
}

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 'Persons & groups'
  • Groups cannot be directly deleted

Further reading

Want more? Check out Frontend vs Backend Group Analytics.

Questions?

Was this page useful?

Next article

Lifecycle

The lifecycle tool is designed to enable you to understand how your active users break down, highlighting those who have recently stopped being active or those who have just become active for the first time. One of the most powerful insights you can get from this graph is understanding what's below the surface of your user growth. For instance you could be having stellar growth due to marketing efforts but bleeding users, unable to retain them. As you can imagine, this could lead to huge trouble…

Read next article