Skip to content

mixpanel_analytics_impl Free

Mixpanel Analytics vendor implementation for the analytics_api contract.

Version: 1.0.0

Variables

VariableTypeDefaultDescription
appNamestringThe name of your application
isForMonorepobooleantrueWhether this is being generated as part of a monorepo

Architecture

This brick generates a single vendor implementation package that plugs into the analytics_sdk orchestration layer:

  • MixpanelAnalyticsVendor — Implements AnalyticVendor using Mixpanel, registered as @Named(AnalyticInjectorKey.mixpanelImpl)
  • MixpanelRegisterModule — Injectable module that asynchronously initializes Mixpanel via Mixpanel.init(AppEnv.mixpanelToken), using @preResolve to ensure the instance is ready before the DI graph is built
  • MicroPackage DI — Standard @InjectableInit.microPackage() entry point for modular registration

The vendor reads the project token from app_config (AppEnv.mixpanelToken). Automatic event tracking is enabled by default via trackAutomaticEvents: true.

Async Initialization

Mixpanel requires async initialization (Mixpanel.init returns a Future<Mixpanel>). The @preResolve annotation on the MixpanelRegisterModule ensures injectable awaits the future before injecting the instance anywhere in the app.

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
    │           └── register_module.dart        # Mixpanel async provider
    └── pubspec.yaml

Key Features

  • People API integrationsetUserProperty uses _mixpanel.getPeople().set(key, value), writing directly to Mixpanel's People profiles for user-level analytics
  • User identificationsetUserId calls mixpanel.identify(userId), linking events to a known user in Mixpanel
  • Properties pass-throughdata.params are forwarded directly to mixpanel.track with no transformation
  • Resetmixpanel.reset() clears the current user identity and starts a new anonymous session
  • Automatic events — SDK-level automatic event collection is enabled (trackAutomaticEvents: true)
  • Named DI — Registered under AnalyticInjectorKey.mixpanelImpl for unambiguous resolution alongside other vendors

Configuration

The following environment value must be present in app_config (AppEnv):

KeyDescription
mixpanelTokenMixpanel project token from the Mixpanel dashboard

This is injected at build time via app_config — no runtime secrets are needed in this package.

Dependencies

PackageVersionPurpose
mixpanel_flutter^2.4.4Mixpanel Flutter SDK
analytics_apiworkspaceVendor contract (AnalyticVendor, TrackData)
app_configworkspaceAccess to AppEnv for the project token
dependenciesworkspaceShared DI annotations (injectable)

Built by Banua Coder