Group Analytics Implementation Guide

Customers on an Enterprise or Growth plan can access Data Pipeline as an add-on package. See our pricing page for more details.

Setup

Group Keys in Project Settings

Group keys are project specific, and must be setup before data is sent. To administer group keys, navigate to your Project Settings . Click +Add Group Key under the Group Keys section.

  1. Navigate to your Project Settings (requires project owner or admin permissions)
  2. Click +Add Group Key under the Group Keys section
  3. Fill in the details on the group key (the exact name as data will be ingested) and the display name that will appear in Mixpanel

image

Once you hit save, a new row will appear in the Group Keys section with a new group ID (an ID autogenerated on our end, required for queries). The setup process takes a few minutes, so recently ingested data just after the group key is created might not be associated to a group during this time.

Setup B2B Company Key

  1. Choose which group key will be used as the B2B Company Key. This is the key for which Company Profiles (B2B Company Analytics) will be generated.
  2. Specify the property that should be referenced as the Company name (identifier) throughout the Mixpanel interface.

You can change which group key should be used as the Company Key. To change, first unset the current group key set as Company Key in the project settings, and then set a new group key as the Company Key.

Tracking events for a Group

By default, event data is tracked at a user level, and the association of that event to a group (or multiple groups) depends on: 1) the group key already being defined in project settings AND 2) that the event has the group key(s) in it with its associated values.

To better illustrate the process with an example, if you have an anonymous user triggering an event, then, authenticating, and then triggering other events, you may have a timeline like the picture below:

image

While the pre and post authentication events are tied to the user via ID merge, only events ingested with the group key in it (in this case company_id) would be associated to the group. In this timeline, the journey of the user starts with the initial page_view event, but the journey of the group starts with the login event.

The group key(s) and its value should be present in every event you want associated to the group (much like the ID of a user). In our client-side libraries that support a form of local storage, we have convenience functions that allow you to store the group key(s) and values in the device so every event has that information (after it’s registered and before the user logs out).

mixpanel.track("page_view"); // event while anonymous
mixpanel.identify("existing_user");
mixpanel.add_group("company_id","company 1");
mixpanel.track("login"); //event after authentication and part of the group "company 1"

Do note this is just a convenience function; for server-side libraries, or if there’s no access to local storage, you can send the group key and value in every event tracked. Below you will see the same flow using python.

mp.track('$device:anoymous_id', 'page_view',{'$device_id':'anoymous_id'})
mp.track('existing_user', 'login',{'$device_id':'anoymous_id', '$user_id': 'existing_user', 'company_id': ['company 1']})
mp.track('existing_user', 'page_view',{'$user_id': 'existing_user', 'company_id': ['company 1']})

Attributing Events to Multiple Groups

An event can be attributed to multiple groups. The convenience functions cited above define the group key as a list of strings, so calling it with a value adds to an existing list in local storage, but when tracking manually, you can send a list of strings with each group the event should be associated to.

mixpanel.track("Some Event", { company_id: ["company 1", "company 2", "company 3"] });

Updating Group Profiles

To create or update a group profile, similarly to user profile operations, at least one (1) profile property must be set. A set operation for a group profile that does not exist would create said profile, while it would update an existing profile.

mp.group_set('company_id', 'company 1', {
    'Company Type': 'Analytics',
    'Company name': 'Mixpanel'
})

Upload Group Profiles Using the Users Report

It is possible to create Group Profiles by CSV upload as an alternative to the Groups API. Follow the instructions here to learn how to upload Group Profiles using the Users report.

SDK references for Groups

To view the setup guides for implementing Groups using the Groups API, follow the instructions connected to the SDK you are using found in Mixpanel’s Developer Documentation.

Add Group Key to User’s Profile

Adding <group_key>: <group_id> to user profiles connects user profiles to group profiles. This allows you to view user group profile properties when analyzing by Users in reports; for example, when creating user cohorts based on group profile properties.

This relationship is one-way, meaning that you cannot use user profile properties when analyzing by a Group in reports.

Because a user can be part of multiple groups within a group key, set the value of the user property as a list of string values, i.e., "company_id": ["1", "2"]

Was this page useful?