Skip to content
Back to archipelago.banuacoder.com

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 ​

VariableTypeDefaultDescription
appNamestring—The name of your application
isForMonorepobooleantrueWhether this is being generated as part of a monorepo

Install ​

Interactive ​

bash
archipelago generate mixpanel_analytics_impl

Non-interactive (CI) ​

bash
archipelago generate mixpanel_analytics_impl --config my_config.json

Needs 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 — Implements AnalyticVendor using Mixpanel, registered as an eager @Singleton(as: AnalyticVendor) named AnalyticInjectorKey.mixpanelImpl; its constructor registers the vendor key with AnalyticVendorRegistry. There is no RegisterModule: the vendor creates its own Mixpanel instance (see below)
  • MicroPackage DI — Standard @InjectableInit.microPackage() entry point, declared as MixpanelAnalyticsImplPackageModule under this package's archipelago: di_modules manifest and wired into the app by post_gen

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

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 ​

text
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.md

Key Features ​

  • People API integration — setUserProperty uses _mixpanel.getPeople().set(key, value), writing directly to Mixpanel's People profiles for user-level analytics
  • User identification — setUserId calls mixpanel.identify(userId), linking events to a known user in Mixpanel
  • Properties pass-through — data.params are forwarded directly to mixpanel.track with 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 and initialize() runs
  • 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.13.0Mixpanel Flutter SDK
analytics_apiworkspaceVendor contract (AnalyticVendor, TrackData)
app_configworkspaceAccess to AppEnv for the project token
dependenciesworkspaceShared 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.