Mixpanel Analytics Implementation
What you'll learn
- Generating the Mixpanel vendor implementation
- Configuring your project token via
app_config - Understanding the async init pattern (
@preResolve) used by this package
Prerequisites
- Analytics SDK installed in your monorepo
- A Mixpanel account — copy your Project Token from Project Settings
Step 1: Generate the Brick
archipelago generate mixpanel_analytics_implYou will be prompted for:
- appName —
MyApp(must match your monorepo app name) - isForMonorepo —
true
The brick is generated into infrastructure/mixpanel_analytics_impl/.
Step 2: Add the Project Token to app_config
Open your app_config package and add the token to AppEnv:
// lib/src/app_env.dart
class AppEnv {
// existing fields …
final String mixpanelToken; // from Mixpanel → Project Settings → Project Token
}Populate the value for each environment (dev, staging, prod).
Step 3: Register the Module
import 'package:mixpanel_analytics_impl/mixpanel_analytics_impl.dart';
await initMixpanelAnalyticsImplModule(getIt);Mixpanel.init() is async. The MixpanelRegisterModule is annotated with @preResolve, so injectable awaits the Future<Mixpanel> before the rest of the DI graph is built — no manual sequencing required on your side.
The implementation is registered as @Named(AnalyticInjectorKey.mixpanelImpl) and is picked up automatically by the analytics_sdk orchestrator via getIt.getAll<AnalyticVendor>().
Step 4: Verify Events Flow
Trigger a tracked event and open the Mixpanel dashboard → Events feed. In development, enable trackAutomaticEvents: true (the default) to see session events alongside your custom ones.
Key behaviours to know:
- User ID —
identify()is called under the hood when you callsetUserId. - User properties — written via the People API (
getPeople().set(key, value)). - Logout — calling the SDK's
reset()clears the identity.
Next Steps
- Set up the Analytics SDK for the full multi-vendor architecture