Composables
useMixpanel
Access the Mixpanel browser client from the Nuxt app.
useMixpanel() returns the browser SDK client provided by the module. It is auto-imported in the Nuxt app.
Usage
const mixpanel = useMixpanel()
The same client is available as useNuxtApp().$mixpanel. Call the composable in component setup or a Nuxt plugin.
Type
Signature
function useMixpanel(): MixpanelClient
Type import
import type { MixpanelClient } from 'mixpanel-nuxt/config'
Return value
MixpanelClient exposes the Mixpanel browser SDK, including its method options and callbacks.
Read methods include undefined in their return types because the client can be inactive. get_distinct_id() returns string | undefined; Promise-based feature flag reads also include absent values.
Inactive client
The client is inactive during SSR or when client.enabled is false.
| Operation | Behavior |
|---|---|
| Tracking and state changes | Discarded; nothing is queued for the browser. |
| Synchronous reads | Return undefined. |
| Asynchronous reads | Resolve to undefined. |
| Tracking callbacks | Not invoked. |
A Promise waiting for a tracking callback remains pending when the client is inactive.
See Browser integration for component and plugin examples and server rendering for hydration behavior.