Finding your Cohort ID in Mixpanel - via the API or the interface

12 May 2021

Mixpanel is a product and website analytics tool that takes a user-centric approach. Whereas Google Analytics doesn't let you capture personally identifiable information (PII) such as name and email address, Mixpanel does - as long as it is properly permissioned, of course.

And part of Mixpanel's user-centric approach is a feature is called 'Cohorts'. This lets you define a group of users with something in common, based on criteria of your choice. This could revolve around event data (what the users have done), profile data (who they are), or a combination of both.

Most commonly I use this feature to create a cohort of internal users which I can then exclude from any reports I generate, to stop them skewing the figures. (I'm lucky that I use Mixpanel on websites that are only accessible to registered users, so all users can be identified by email address.)

Anyway - each cohort you create in Mixpanel has a unique ID, and it may be that you need to find out that ID in order to use it elsewhere. I'm aware of two ways to do this: the usual way (via the API), and an easier way (looking at URL parameters in the Mixpanel interface). I'll run through them both now, and I'm assuming here that you already have a cohort set up.

Using the API / API reference

The usual way to find the ID of a cohort is via the API. The Mixpanel API reference is excellent, acting both as a guide to the API and a tool you can use to query it directly. The section you need in this instance is called 'List Saved Cohorts'. As the reference says:

"The list endpoint returns all of the cohorts in a given project. The JSON formatted return contains the cohort name, id, count, description, creation date, and visibility for every cohort in the project."

This information appears over on the right of the reference screen after you have sent the POST request. When expanded, the return looks like this:

API response in Mixpanel

The Cohort ID is listed simply as "id". So here you can see it is 1234567 (what an amazing occurrence!).

However this method does require some basic understanding of APIs, and you will also need to provide your Project Secret in order to make the POST request. (You can fish this out from Mixpanel in Settings > Project Settings > Overview, where it's called "API Secret").

Using URL parameters in the Mixpanel interface

So here's the easier way to find your Cohort ID.

  1. In the Mixpanel interface, go to Data Management > Cohort
  2. Click on the '...' menu button to the right of your cohort

Cohorts menu button

  1. Right click on 'Visualize Trend' in the menu that pops up
  2. Select 'Copy Link Address' (Chrome browsers) or 'Copy Link' (Edge)

Copy link address

  1. Paste this address into Notepad or a similar text editor

You'll end up with something like this:'line~plotStyle~'standard~analysis~'linear~value~'absolute)~sections~(show~(~(math~'unique~value~(id~1234567~name~'Test*20Cohort~resourceType~'cohorts)~resourceType~'cohorts))~time~(~(dateRangeType~'in*20the*20last~unit~'day~window~(unit~'day~value~30)))))

Find the bit that says "id~" (I've bolded it in my example above). The number immediately following this is your Cohort ID. If you compare it to the number you obtained via the API, you should see it is exactly the same.

Notify of
Inline Feedbacks
View all comments
James Clark
Hi! I'm James Clark and this is my website. I publish all my guides completely free, so if you find them useful then please:
What do you think? Leave a commentx
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram