Skip to content

AppAmbit Analytics Flutter

Submit Analytics Events

Use this class to send analytics events from your Flutter application. To get started, make sure you've added the module to your app. For setup instructions, refer to the Getting Started guide.

AppAmbit Analytics gives you insight into user behavior and engagement, helping you improve your application experience. The SDK automatically collects session data and device details such as model and OS version. You can also define custom events to track interactions that matter to you. All collected data is accessible through the AppAmbit portal for analysis.

Session and Device Information

After integrating AppAmbit Analytics and starting the SDK, it will begin tracking user sessions and device information (e.g., OS version, device model) automatically—no extra code required, unless Analytics.enableManualSession() is called.

Manual Management for Session

Info

Manual mode is disabled by default, if you need more control over sessions, events and logs you can do so by following the steps below.

In case you want to handle your session manually you must call enableManualSession, before you start using AppAmbit

Dart

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  //Uncomment the line for automatic session management
  AppambitSdk.enableManualSession();
  AppambitSdk.start(appKey: '<YOUR-APPKEY>');
  runApp(const MyApp());
}

Warning

If this option is enabled no event, log or crash will be sent or saved locally until a session is started manually using AppambitSdk.startSession(); anywhere in your code where you need it.

Start Session

If you already called enableManualSession, you can now start a session manually, calling StartSession:

Dart

await AppambitSdk.startSession();

If the method is called again before ending the session the call will be ignored.

End Session

If you already called EnableManualSession, and you already started a session, you can now end the session session manually, calling EndSession:

Dart

await AppambitSdk.endSession();

If the method is called again before ending the session the call will be ignored.

Generate a Test Event

AppAmbit Analytics includes an API to trigger a test event, useful for verifying SDK integration.

Dart

await AppambitSdk.generateTestEvent();

Custom Events

Track custom events to capture meaningful user interactions. Once the SDK is initialized, use the trackEvent() method to track your events with properties. You can send up to 150 distinct event names. Also, there's a maximum limit of 120 characters per event name and 80 characters per event property name and event property value.

Dart

await AppambitSdk.trackEvent('ButtonClicked', <String, String>{'Count': '41'});

Properties are optional. The following code is for send a simple event without additional data:

Dart

await AppambitSdk.trackEvent("ButtonClicked", {});