Analytics Implementations
mixpanel_analytics_impl Free
- Tier
- Freeversion 1.2.6
- Command
archipelago generate mixpanel_analytics_impl- Generates
infrastructure/mixpanel_analytics_impl
- Generates first
- analytics_sdkwhen needed and missing, so there is nothing to install first
- Depends on
- shared_app_configgenerate these first
Mixpanel Analytics vendor implementation for the analytics_api contract.
Variables
| Variable | Type | Default | Description |
|---|---|---|---|
| appName | string | — | The name of your application |
| isForMonorepo | boolean | true | Whether this is being generated as part of a monorepo |
Install
Interactive
archipelago generate mixpanel_analytics_implNon-interactive (CI)
archipelago generate mixpanel_analytics_impl --config my_config.jsonNeeds analytics_sdk (4.0.0 or newer); pre_gen generates it first when infrastructure/analytics_api is missing. post_gen adds this package to the workspace, adds it as a dependency of the app's pubspec.yaml, and registers MixpanelAnalyticsImplPackageModule in the app's injector.dart.
Architecture
This brick generates a single vendor implementation package that plugs into the analytics_sdk orchestration layer:
MixpanelAnalyticsVendor— ImplementsAnalyticVendorusingMixpanel, registered as an eager@Singleton(as: AnalyticVendor)namedAnalyticInjectorKey.mixpanelImpl; its constructor registers the vendor key withAnalyticVendorRegistry. There is noRegisterModule: the vendor creates its ownMixpanelinstance (see below)- MicroPackage DI — Standard
@InjectableInit.microPackage()entry point, declared asMixpanelAnalyticsImplPackageModuleunder this package'sarchipelago: di_modulesmanifest and wired into the app bypost_gen
The vendor reads the project token from app_config (AppEnv.mixpanelToken). Automatic event tracking is enabled by default via trackAutomaticEvents: true.
Deferred, consent-gated initialization
Mixpanel.init is async and starts collecting automatic events as soon as it resolves. To keep that behind analytics consent, MixpanelAnalyticsVendor creates and caches its own Mixpanel instance inside initialize(), which AnalyticsInitializer calls only after consent is granted. Until then track, setUserId and the other methods are no-ops. setCollectionEnabled maps to optOutTracking / optInTracking, so revoking consent stops automatic events.
Generated Structure
infrastructure/
└── mixpanel_analytics_impl/
├── lib/
│ ├── mixpanel_analytics_impl.dart # Package barrel export
│ └── src/
│ ├── mixpanel_analytics_vendor.dart # AnalyticVendor impl
│ └── di/
│ ├── injector.dart # microPackage DI entry
│ └── injector.module.dart # pre-built generated output, committed
├── test/src/
├── pubspec.yaml
└── README.mdKey Features
- People API integration —
setUserPropertyuses_mixpanel.getPeople().set(key, value), writing directly to Mixpanel's People profiles for user-level analytics - User identification —
setUserIdcallsmixpanel.identify(userId), linking events to a known user in Mixpanel - Properties pass-through —
data.paramsare forwarded directly tomixpanel.trackwith no transformation - Reset —
mixpanel.reset()clears the current user identity and starts a new anonymous session - Automatic events — SDK-level automatic event collection is enabled (
trackAutomaticEvents: true) once consent is granted andinitialize()runs - Named DI — Registered under
AnalyticInjectorKey.mixpanelImplfor unambiguous resolution alongside other vendors
Configuration
The following environment value must be present in app_config (AppEnv):
| Key | Description |
|---|---|
mixpanelToken | Mixpanel project token from the Mixpanel dashboard |
This is injected at build time via app_config — no runtime secrets are needed in this package.
Dependencies
| Package | Version | Purpose |
|---|---|---|
mixpanel_flutter | ^2.13.0 | Mixpanel Flutter SDK |
analytics_api | workspace | Vendor contract (AnalyticVendor, TrackData) |
app_config | workspace | Access to AppEnv for the project token |
dependencies | workspace | Shared DI annotations (injectable) |
Platform Setup
None required — mixpanel_flutter works out of the box on both platforms.
Changelog
Run archipelago brick info mixpanel_analytics_impl to see the latest published version. Enterprise customers can read the full CHANGELOG.md in the brick source repository.
Adding this brick to a project generated without Mixpanel also declares mixpanelToken/MIXPANEL_TOKEN in shared/app_config (Env, AppEnv, every .env* file), so no manual edit is needed.