The Alibaba Cloud Real User Monitoring (RUM) Flutter plugin supports the Android, iOS, and HarmonyOS platforms. After integration, RUM collects performance data and user interactions from your Flutter application.
Prerequisites
Before you begin, make sure you have:
| Requirement | Minimum version | Where to check |
|---|---|---|
| Flutter | 3.0.0 | flutter --version |
| Android | API 24 (Android 7.0) | minSdkVersion in android/app/build.gradle |
| iOS | 12.0 | platform :ios in ios/Podfile |
Quick start
The following example shows the minimum code to initialize RUM in a Flutter application:
# pubspec.yaml
dependencies:
alibabacloud_rum_flutter_plugin: ^2.1.0// main.dart
import 'package:alibabacloud_rum_flutter_plugin/alibabacloud_rum_flutter_plugin.dart';
void main() {
AlibabaCloudRUM().start(MyApp());
}Run flutter packages get, then start the application. A successful integration produces the following log in the DEBUG CONSOLE:
[INFO][AlibabaCloudRUM]: alibabacloud_rum_flutter_plugin start successFor the full setup, including action capture and native SDK integration, continue with the steps below.
Step 1: Install the Flutter plugin
Add the RUM plugin dependency to
pubspec.yaml:dependencies: flutter: sdk: flutter alibabacloud_rum_flutter_plugin: ^2.1.0From the root of your Flutter project, install the dependency:
flutter packages getiOS only: In the
iosdirectory, install the CocoaPods dependencies:cd ios && pod install
Step 2: Initialize the SDK
Import the RUM plugin in
main.dart:import 'package:alibabacloud_rum_flutter_plugin/alibabacloud_rum_flutter_plugin.dart';In
main.dart, replace the defaultrunApp()call withAlibabaCloudRUM().start():Method Required Description AlibabaCloudRUM().start()Yes Initializes the RUM SDK and wraps the root widget AlibabaCloudRUM().setUserName()No Associates monitoring data with a specific user identity void main() { // Replace runApp(MyApp()) with AlibabaCloudRUM().start() AlibabaCloudRUM().start(MyApp()); // Optional: set a custom username for user-level tracking AlibabaCloudRUM().setUserName("xxxxxx"); }
Step 3: Capture action events (optional)
To track user interactions such as clicks, wrap your widget tree with AlibabaCloudActionCapture:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AlibabaCloudActionCapture(
child: Scaffold(
appBar: AppBar(
title: const Text('AlibabaCloudRUM'),
),
body: // Your other code
));
}
}Step 4: Integrate native SDKs
Integrating the Alibaba Cloud RUM SDK into a Flutter project requires you to integrate both the Flutter plugin and the native SDKs for Android, iOS, and HarmonyOS. For integration instructions, see the following documents:
| Platform | Integration guide |
|---|---|
| Android | Connect to an Android application |
| iOS | Connect to an iOS application |
Verify the integration
Start the application. A successful integration produces the following message in the DEBUG CONSOLE:
[INFO][AlibabaCloudRUM]: alibabacloud_rum_flutter_plugin start successExample output:
flutter: [2024-05-27 16:43:39][INFO][AlibabaCloudRUM]: alibabacloud_rum_flutter_plugin start success