> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corsair.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Mixpanel plugin

> Product analytics with Mixpanel - ingest events and user or group profiles, run Insights, funnel, retention and segmentation reports, export raw events, and manage annotations, Lexicon schemas, feature flags, experiments, warehouse imports, data pipelines, service accounts and GDPR requests.

Use **Mixpanel** through Corsair: one client, typed API calls.

Create a service account in Mixpanel (Project Settings, Service Accounts)
with a role that fits what the agent should do: Consumer to read, Admin or
Owner to import events and manage annotations, Lexicon, flags and
experiments. Connect with:

* **api\_key**: the service account secret.
* **service\_account\_username**: its username (`name.xxxxxx.mp-service-account`).
* **project\_id**: the project id (Project Settings, Overview).
* **region**: `us` (default), `eu` or `in`, matching the project's data
  residency. Every API switches to that region's hosts.
* **project\_token** (optional): needed for `events.track`, profile and group
  updates, identity calls and GDPR, which authenticate with the token.
* **gdpr\_token** (optional): the GDPR API OAuth token from Personal Settings,
  Data & Privacy. A service account gets 401 on the GDPR API.

Plan limits seen on a free project (11-24): the Query API reports
(insights, funnels, retention, segmentation, event counts, activity stream,
cohorts, JQL) answer 402 `plan_restricted`; `profiles.query` and raw export
work. Data Pipelines is a paid add-on (401), and the Platform API data
definitions answer 404 until Mixpanel enables them for the project.
Organization-level service account calls need an organization admin or
owner service account (403 otherwise).

* **Rate limits.** The Query API allows 60 queries per hour and 5 at once;
  raw export 60 per hour and 3 per second. Core retries a 429 using
  Retry-After; nothing else is retried.
* **Errors** come back as core `ApiError`s with Mixpanel's message and
  `error_code`. Request bodies (tokens, profiles, events) are stripped from
  the error, and secrets Mixpanel echoes are redacted.

**What you get:**

* 119 typed API operations

## Setup

**1. Install**

```bash npm theme={null}
npm install corsair @corsair-dev/mixpanel better-sqlite3
npm install --save-dev @types/better-sqlite3
```

```bash yarn theme={null}
yarn add corsair @corsair-dev/mixpanel better-sqlite3
yarn add --dev @types/better-sqlite3
```

```bash pnpm theme={null}
pnpm install corsair @corsair-dev/mixpanel better-sqlite3
pnpm install --save-dev @types/better-sqlite3
```

```bash bun theme={null}
bun add corsair @corsair-dev/mixpanel better-sqlite3
bun add --dev @types/better-sqlite3
```

**2. Add the plugin**

```ts corsair.ts theme={null}
import Database from 'better-sqlite3';
import { createCorsair } from 'corsair';
import { mixpanel } from '@corsair-dev/mixpanel';

export const corsair = createCorsair({
	plugins: [
		mixpanel(),
	],
	database: new Database('corsair.db'),
	kek: process.env.CORSAIR_KEK!,
	multiTenancy: true,
	hub: {
		projectApiKey: process.env.CORSAIR_API_KEY!,
		signingSecret: process.env.CORSAIR_SIGNING_SECRET!,
	},
});
```

With `multiTenancy: true`, scope calls with `corsair.withTenant(id)`. See [Quick start](https://docs.corsair.dev/quick-start.md) for KEK + Hub keys, and [Multi-tenancy](https://docs.corsair.dev/concepts/multi-tenancy.md) for account isolation.

**3. Choose authentication**

> [tab] API Key (Recommended)
>
> Store the Mixpanel API key before the first call: `pnpm corsair setup --plugin=mixpanel --tenant=acme api_key=<your-key>` (leave out `--tenant` without `multiTenancy`), or pass it as `key` in the plugin options. With Hub, each tenant enters their own key on the connect page. See [API key auth](https://docs.corsair.dev/concepts/api-key).
>
> ```ts theme={null}
> mixpanel()
> ```
>
> More: [API Key](https://docs.corsair.dev/concepts/api-key)

**4. Connect a tenant**

Mint a connect link and send the tenant to it. Hub hosts the page and delivers the result to your app — see [Connect / OAuth](https://docs.corsair.dev/management/connect).

```ts theme={null}
const { connectUrl } = await corsair.manage.connect.createLink({
	plugin: 'mixpanel',
	tenantId: 'acme',
});
// redirect the user's browser to connectUrl
```

## Example API calls

**Find profiles on a plan**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.mixpanel.api.profiles.query({
	where: 'properties["plan"] == "pro"',
	output_properties: ['$email', 'plan'],
});
```

**Import a signed-up event**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.mixpanel.api.events.import({
	events: [{
		event: 'Signed up',
		properties: {
			time: 1618716477000,
			distinct_id: '91304156-cafc-4673-a237-623d1129c801',
			$insert_id: '29fc2962-6d9c-455d-95ad-95b84f09b9e4',
			referrer: 'friend',
		},
	}],
});
```

See the full list on the [API](https://docs.corsair.dev/plugins/mixpanel/api.md) page.

## What's next

> [card] [API reference](https://docs.corsair.dev/plugins/mixpanel/api.md)
>
> Every `mixpanel.api.*` operation with input and output types.

> [card] [Connect / OAuth](https://docs.corsair.dev/management/connect)
>
> createLink, Hub delivery, and tenant connect flows.

> [card] [Use with agents](https://docs.corsair.dev/mcp-adapters/mcp-adapters)
>
> Expose this plugin's operations as MCP tools.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.