Claude Code for Mixpanel Analytics — Guide
The Setup
You are tracking user behavior with Mixpanel, an event-based analytics platform focused on product analytics. Unlike page-view analytics (Google Analytics), Mixpanel tracks specific user actions — button clicks, feature usage, funnel completion — with rich properties and user identification. Claude Code can add analytics, but it generates Google Analytics page-view tracking instead of Mixpanel’s event-based approach.
What Claude Code Gets Wrong By Default
-
Adds Google Analytics gtag.js tracking. Claude installs
gtag('event', ...)calls. Mixpanel uses its own SDK:mixpanel.track('Event Name', { properties })— the API and data model are completely different. -
Tracks page views only. Claude adds analytics on route changes. Mixpanel focuses on user actions, not page views — track meaningful events like “Signed Up”, “Created Project”, “Completed Purchase” with relevant properties.
-
Ignores user identification. Claude sends anonymous events without identity. Mixpanel connects events to users with
mixpanel.identify(userId)and enriches profiles withmixpanel.people.set({ plan: 'pro' }). -
Sends too many events without a plan. Claude tracks every click and interaction. Mixpanel charges by events — define a tracking plan with specific events and properties before instrumenting, not after.
The CLAUDE.md Configuration
# Mixpanel Analytics Project
## Analytics
- Platform: Mixpanel (event-based product analytics)
- SDK: mixpanel-browser (web) or mixpanel (Node.js)
- Events: user actions with properties
- Users: identified with profiles and properties
## Mixpanel Rules
- Init: mixpanel.init(TOKEN, { track_pageview: false })
- Track: mixpanel.track('Event Name', { key: value })
- Identify: mixpanel.identify(userId) after auth
- People: mixpanel.people.set({ name, email, plan })
- Reset: mixpanel.reset() on logout
- Group: mixpanel.set_group('company', companyId)
## Conventions
- Define tracking plan before implementation
- Event names: Title Case ("Signed Up", "Created Project")
- Properties: snake_case (plan_type, item_count)
- Identify on login, reset on logout
- Use people properties for user attributes
- Super properties for persistent event properties
- Do not track PII in event properties
Workflow Example
You want to instrument a SaaS onboarding flow. Prompt Claude Code:
“Add Mixpanel tracking to our onboarding flow. Track when users start onboarding, complete each step (profile, team, integration), and finish onboarding. Include properties for time spent per step and whether they skipped optional steps. Identify users after signup.”
Claude Code should call mixpanel.identify(userId) after signup, track “Onboarding Started”, “Onboarding Step Completed” with step_name and time_spent_seconds properties, track “Onboarding Step Skipped” for optional steps, and “Onboarding Completed” with total_time_seconds and steps_skipped count.
Common Pitfalls
-
Not calling identify before tracking. Claude tracks events before calling
mixpanel.identify(). Events sent before identification are attributed to an anonymous ID and may not merge correctly with the user profile. Always identify first. -
Duplicate initialization in SPAs. Claude calls
mixpanel.init()on every component render or route change. Initialize Mixpanel once at the application root — multiple init calls can cause duplicate event tracking. -
Sending high-cardinality properties. Claude includes unique IDs or timestamps as event properties. Mixpanel works best with categorical properties (plan_type: “free”) not unique values (session_id: “abc123”) — high-cardinality properties make analysis difficult.