Mixpanel
The Mixpanel plugin connects Funnel to Mixpanel product analytics. It forwards Funnel’s
GA4-standard events to Mixpanel through window.mixpanel, converting each event name to Title
Case (add_to_cart → Add To Cart).
What it tracks
Section titled “What it tracks”Every Funnel event is forwarded with a Title-Cased name:
| Funnel event (GA4) | Mixpanel event |
|---|---|
page_view |
Page View |
view_item |
View Item |
add_to_cart |
Add To Cart |
purchase |
Purchase |
| …every other event | Title Case of the GA4 name |
Event parameters pass through as-is; an items array is flattened into Mixpanel-friendly
properties. Each event sets $insert_id from Funnel’s eventId so duplicate sends are
deduplicated server-side.
Before you start
Section titled “Before you start”- A Mixpanel project token.
- The Mixpanel base snippet loaded in your page, so
window.mixpanelexists before Funnel runs.
Install & initialize
Section titled “Install & initialize”import { Funnel } from "@sunwjy/funnel-client";import { createMixpanelPlugin } from "@sunwjy/funnel-client/mixpanel";
export const funnel = new Funnel({ plugins: [createMixpanelPlugin()], debug: true,});
funnel.initialize({ mixpanel: { token: "your_project_token", // forwarded to mixpanel.init(token, config) (optional) config: { api_host: "https://api-eu.mixpanel.com" }, },});consentRequired: true is optional. When set, events are dropped until analytics_storage
is granted through funnel.setConsent(...).
Track an event
Section titled “Track an event”funnel.track("purchase", { currency: "USD", value: 99, transaction_id: "T-3003",});This calls mixpanel.track("Purchase", { currency: "USD", value: 99, transaction_id: "T-3003", $insert_id: "..." }).
Verify
Section titled “Verify”- Set
debug: trueon the Funnel to log each dispatch in the console. - Pass
config: { debug: true }to Mixpanel to see its own console output. - Watch Events in the Mixpanel dashboard, or use Live View for real-time events.
- SSR safe. When
window(orwindow.mixpanel) is absent, the plugin does nothing. funnel.setUser(...)callsmixpanel.identify(user_id)andmixpanel.people.set(...), mappingemail/phone_number/first_name/last_nameto Mixpanel’s$email/$phone/$first_name/$last_name. Other properties pass through unchanged.funnel.resetUser()callsmixpanel.reset()(logout).- Use
config.api_hostfor EU data residency (https://api-eu.mixpanel.com).