How do I track users if they are part of multiple organizations?

If your business has users who are part of multiple organizations, tracking them can be tricky, as you ideally want to include them in data about each organization, not only about their most recent organization.

For example, let’s say user Aaron works at multiple sites: Site A, Site B, and Site C. When looking at data for the event “Work,” you would probably like Aaron to show up as working on all sites, not just the last site he was working on.

Implementation requirements

In order to be able to track users who are part of multiple organizations properly:

  • Use mixpanel.people.union() to capture all of the sites Aaron has worked on, which will merge a value to a list or create that value if necessary, so what you end up with is a list that you can continue to build on of all sites or organizations of which that user is (or has been) a part. Using a mixpanel.people.set call to set these sites as properties on Aaron’s people profile would cause previous sites to get overwritten each time Aaron worked at a new site, which is not the desired behavior.

  • Register super properties. What if, instead of looking at Aaron based on any site he’s worked at, we want Aaron to be included in a report only under sites/organizations he had worked at when that event was fired? To accomplish this, you’ll also want to register a super property in tandem with calling mixpanel.people.union. That way, you can use the event property for site/organization when you’re looking for membership at the time an event was fired, and you can use the people property when looking to segment by all membership.

See detailed implementation and examples in JavaScript, Objective-C (iOS), and Java (Android).

Using organization/membership data in reports

Once you have structured your Mixpanel data in this way, you can use organization membership to answer the following questions:

  1. Which organizations are doing a particular event the most/least?
    • Just like any other property, you can segment by organization.
    • Using the event property will now give you data based on the membership stats at the time that particular event was fired.
    • Using the people property will give you data based on current membership.
  2. What events are the most popular among users in a particular organization?
    • Use MY TOP EVENTS in Segmentation to look at a group of events combined with the Organization filter to specify a particular team/organization and look at its data.
  3. How can I create a cohort of users in either organization A OR organization B?

Implementation examples

Jane works at McDonald's. Michael works at KFC. Samantha works at both McDonald's and KFC. Matthew doesn’t work anywhere. See example implementation:


JavaScript:

//jane works at McDonalds
mixpanel.identify("jane");
mixpanel.people.union({
    "organizations": ["McDonalds"],
    "$name": "jane"
});
mixpanel.register({
    "organizations": ["McDonalds"]
});
mixpanel.track("did some work", {});

//michael works at KFC
mixpanel.identify("michael");
mixpanel.people.union({
    "organizations": ["KFC"],
    "$name": "michael"
});
mixpanel.register({
    "organizations": ["KFC"]
});
mixpanel.track("did some work", {});

//samantha works at both KFC and McDonalds
mixpanel.identify("samantha");
mixpanel.people.union({
    "organizations": ["McDonalds", "KFC"],
    "$name": "samantha"
});
mixpanel.register({
    "organizations": ["McDonalds", "KFC"]
});
mixpanel.track("did some work", {});


//if samantha joins another team you can call union on the individual item (or the full list)
mixpanel.people.union({
    "organizations": ["Little Caesars"],
});

//register needs to be called on the entire list
mixpanel.register({
    "organizations": ["McDonalds", "KFC", "Little Caesars"]
});


//matthew doesn't work anywhere
mixpanel.identify("matthew");
mixpanel.people.union({
    "organizations": [],
    "$name": "matthew"
});
mixpanel.register({
    "organizations": []
});
mixpanel.track("did some work", {});


Objective-C (iOS):

//jane works at McDonalds
[mixpanel identify:@"jane"];

[mixpanel.people.union:@{
    @"organizations": @["McDonalds"],
    @"$name": @"jane"
}];
[mixpanel registerSuperProperties:@{
    @"organizations": @["McDonalds"]
}];
[mixpanel track:@"did some work", @{}];

//michael works at KFC
[mixpanel identify:@"michael"];
[mixpanel.people.union:@{
    @"organizations": @["KFC"],
    @"$name": @"michael"
}];
[mixpanel registerSuperProperties:@{
    @"organizations": @["KFC"]
}];
[mixpanel track:"did some work", @{}];

//samantha works at both KFC and McDonalds
[mixpanel identify:@"samantha"];
[mixpanel.people.union:@{
    @"organizations": ["McDonalds", "KFC"],
    @"$name": @"samantha"
}];
[mixpanel registerSuperProperties:@{
    @"organizations": @["McDonalds", "KFC"]
}];
[mixpanel track:"did some work", @{}];


//if samantha joins another team you can call union on the individual item (or the full list)
[mixpanel.people.union:@{
    @"organizations": @["Little Caesars"],
}];

//register needs to be called on the entire list
[mixpanel registerSuperProperties:@{
    @"organizations": @["McDonalds", "KFC", "Little Caesars"]
}];


//matthew doesn't work anywhere
[mixpanel identify:@"matthew"];
[mixpanel.people.union:@{
    @"organizations": @[],
    @"$name": @"matthew"
}];
[mixpanel registerSuperProperties:@{
    @"organizations": @[]
}];
[mixpanel track:@"did some work", @{}];


Java (Android):

//jane works at McDonalds
mixpanel.getPeople().identify("jane");
mixpanel.getPeople().union({
    "organizations": ["McDonalds"],
    "$name": "jane"
});
mixpanel.registerSuperProperties({
    "organizations": ["McDonalds"]
});
mixpanel.track("did some work", {});

//michael works at KFC
mixpanel.getPeople().identify("michael");
mixpanel.getPeople().union({
    "organizations": ["KFC"],
    "$name": "michael"
});
mixpanel.registerSuperProperties({
    "organizations": ["KFC"]
});
mixpanel.track("did some work", {});

//samantha works at both KFC and McDonalds
mixpanel.getPeople().identify("samantha");
mixpanel.getPeople().union({
    "organizations": ["McDonalds", "KFC"],
    "$name": "samantha"
});
mixpanel.registerSuperProperties({
    "organizations": ["McDonalds", "KFC"]
});
mixpanel.track("did some work", {});


//if samantha joins another team you can call union on the individual item (or the full list)
mixpanel.getPeople().union({
    "organizations": ["Little Caesars"],
});

//registerSuperProperties needs to be called on the entire list
mixpanel.registerSuperProperties({
    "organizations": ["McDonalds", "KFC", "Little Caesars"]
});


//matthew doesn't work anywhere
mixpanel.getPeople().identify("matthew");
mixpanel.getPeople().union({
    "organizations": [],
    "$name": "matthew"
});
mixpanel.registerSuperProperties({
    "organizations": []
});
mixpanel.track("did some work", {});