Real User Monitoring (RUM) provides a Flutter plugin to monitor iOS and Android applications. This topic shows you how to integrate the Flutter plugin.
Prerequisites
Flutter: 3.0.0+
iOS: 12.0+
Android: 7.0+
Step 1: Integrate the Flutter plugin
Add the dependency to the pubspec.yaml file.
dependencies: flutter: sdk: flutter alibabacloud_rum_flutter_plugin: ^2.3.0In the root directory of your Flutter project, run the following command to install the plugin.
flutter packages getFor iOS applications, run the following command in the
iosdirectory of your project to update the Pod environment.pod installInitialize the Flutter SDK.
In the
main.dartfile, import the following packages.import 'package:alibabacloud_rum_flutter_plugin/alibabacloud_rum_flutter_plugin.dart';Initialize the SDK.
void main() { // Comment out the original runApp() method. // runApp(MyApp()); // (Required) Initialize the SDK. AlibabaCloudRUM().start(MyApp()); // (Optional) Set a custom username. AlibabaCloudRUM().setUserName("xxxxxx"); }
(Optional) Collect action events.
The RUM Flutter plugin supports capturing action events, such as clicks, in Flutter. You need to configure and use
AlibabaCloudActionCaptureto capture user click events. The following is an example:class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return AlibabaCloudActionCapture( child: Scaffold( appBar: AppBar( title: const Text('AlibabaCloudRUM'), ), body: // Your other code )); } }Verify the plugin integration.
Start the Flutter application. If the
Debug Consolereturns[INFO][AlibabaCloudRUM]: alibabacloud_rum_flutter_plugin start success, the SDK is successfully integrated.Sample output:
flutter: [2024-05-27 16:43:39][INFO][AlibabaCloudRUM]: alibabacloud_rum_flutter_plugin start success
Step 2: Integrate native SDKs
In addition to the Flutter plugin, you must integrate the native SDKs for Android, iOS into your Flutter project. For more information, see the following topics:
Android: Integrate Android applications.