Skip to content
Back to archipelago.banuacoder.com

Analytics Implementations

How to add MoEngage to a Flutter app with analytics_sdk ​

Free Reference for moengage_analytics_impl: every variable, option and package it generates. Command: archipelago generate moengage_analytics_impl

Generate the MoEngage vendor, set the App ID in shared/app_config, know which native init code to leave out, and see how consent controls the SDK.

What you'll learn ​

  • Generating the MoEngage vendor for analytics_sdk
  • Setting the App ID in shared/app_config
  • Knowing which native init code to leave out
  • Seeing how consent controls the SDK

Prerequisites ​

  • Analytics SDK generated in your monorepo
  • A MoEngage account and its App ID (Settings, then App Settings)

Generate analytics_sdk first. This brick does not check for it. The workspace fails to resolve without it.

Step 1: Generate the Brick ​

Skip this step if you chose moengage in analyticsVendors at project creation.

bash
archipelago generate moengage_analytics_impl

The prompts are:

  • appName: the name of your app
  • isForMonorepo: leave this as true

The brick creates infrastructure/moengage_analytics_impl/. The post-generation hook adds the package to the app pubspec.yaml and registers MoengageAnalyticsImplPackageModule in lib/di/injector.dart.

Step 2: Add the App ID ​

Add the ID to the .env files in shared/app_config:

text
MOENGAGE_APP_ID=your-app-id

The vendor reads it as AppEnv.moengageAppId. See shared_app_config.

Step 3: Do Not Add Native Init Code ​

The vendor starts the SDK in Dart. MoEngageAnalyticsVendor.initialize() calls MoEngageFlutter.initialise() with your App ID. AnalyticsInitializer calls it only after analytics consent is granted.

Do not add initialiseDefaultInstance to your Android Application class. Do not add initializeDefaultInstance() to the iOS AppDelegate. Native setup starts the SDK at launch, before consent. The brick generates no native init code.

Push and in-app messages still need the platform steps in the MoEngage Flutter integration guide. Those steps cover Firebase and APNs.

Step 4: Verify Events Flow ​

The vendor registers under AnalyticInjectorKey.moEngageImpl. The tracker finds it through AnalyticVendorRegistry. Grant analytics consent, then track an event. Open Analytics, then Event Analytics, in the MoEngage dashboard.

How the vendor behaves:

  • Event parameters go through MoEProperties.addAttribute(key, value).
  • setUserId calls identifyUser(userId).
  • setUserProperty calls setUserAttribute(key, value).
  • reset() calls logout().
  • Revoking consent calls disableDataTracking. Granting it again calls enableDataTracking.

Next Steps ​