Flutter App Access¶
Collect metrics from Flutter apps and analyze app-side performance through visualizations.
Reading Path¶
- First-time access: first choose an access method; for manual access, see Quick Start
- Full access: continue reading this document
- Initialization parameters: see SDK Initialization, RUM Configuration, Log Configuration, and Trace Configuration
- Custom capabilities: see Using Custom Tags, Custom Rules for Data Collection, and Data Masking
- Advanced scenarios: see WebView Data Monitoring, Native and Flutter Hybrid Development, Flutter Session Replay, and Publish Package Related Configuration
- Flutter Web projects: the current Flutter SDK does not provide a Web bridge. Use the Browser RUM SDK as described in Web App Access
- Troubleshooting: see Troubleshooting
- Data model: see Application Data Collection
Prerequisites¶
Note: If you have enabled the RUM Headless service, the prerequisites have already been configured for you. You can access your app directly.
When using a local environment deployment, you must complete the following data receiver configuration. When using the public DataWay, you do not need to deploy DataKit yourself.
- Install DataKit
- Configure the RUM Collector
- Configure DataKit to be publicly accessible and install the IP geolocation database
App Access¶
Note
The current Flutter version supports only the Android and iOS platforms.
- Go to RUM > Create App > Android/iOS
- Create two apps, one for Flutter Android and one for Flutter iOS, so that RUM data from the Android and iOS platforms can be received separately
- Enter the corresponding app name and app ID for each platform's app
- In Choose Access Method, select Agent Auto Access or Manual Access, then complete the Access Configuration.
Flutter Web Projects¶
ft_mobile_agent_flutter currently provides only native Android/iOS bridging capabilities and does not provide a Flutter Web bridge.
If your app runs on Flutter Web, create a Web type RUM app and use the Browser RUM SDK as described in Web App Access. This approach is Browser RUM SDK access; it does not use the Android/iOS native bridging APIs described later in this document, and you do not need to call ft_mobile_agent_flutter in Dart code to initialize Web RUM.
For Flutter Web projects, the integration point is usually web/index.html in the project root directory, where you can load the Browser RUM SDK or your own initialization script before the Flutter startup script. Do not modify the build/web directory, which is a Flutter build artifact and is regenerated when you run flutter build web.
Choose an Access Method¶
On the app configuration page, select Agent Auto Access or Manual Access, then complete the Access Configuration. For existing apps, you can go directly to the configuration page to continue access.
| Access Method | Use Cases | Entry Point |
|---|---|---|
| Agent Auto Access | You want a coding assistant to analyze the project and complete SDK integration | Copy the prompt generated in the console and give it to the coding assistant in your app code repository to execute |
| Manual Access | You prefer to install the SDK and configure parameters yourself | Confirm the data reporting method, then complete configuration following this document and Quick Start |
Agent Auto Access¶
- On the configuration page of the current app, select Agent Auto Access.
- Copy the complete prompt from Access Configuration and make sure it uses the access information of the current app.
- Open a coding assistant in your app code repository, paste the prompt, and let the Agent analyze the project and complete the SDK configuration according to the access guide.
- Build and run the app, trigger operations such as page views, and confirm in the Explorer of the current app that data is received.
When using a cross-platform framework, tell the Agent the framework and target platforms, and provide the app information for each platform separately.
If the page indicates that your personal API Key or temporary authorization code is not ready, complete it as prompted and then copy the prompt again.
Manual Access¶
On the app configuration page, select Manual Access and confirm the data reporting method:
- Public DataWay: receives RUM data directly; no need to install the DataKit collector
- Local environment deployment: receives RUM data after the prerequisites are met
Complete SDK installation, initialization, and verification as described in Installation and Quick Start. If you already have an SDK configuration, check it and reuse it first to avoid initializing twice.
Installation¶
Pub.Dev: ft_mobile_agent_flutter
Source code: https://github.com/GuanceCloud/datakit-flutter
Demo: https://github.com/GuanceCloud/datakit-flutter/example
Run the following in your project directory:
This adds the dependency to the package's pubspec.yaml:
dependencies:
ft_mobile_agent_flutter: [latest_version]
# For Flutter 2.0 compatible versions, use the following reference
ft_mobile_agent_flutter:
git:
url: https://github.com/GuanceCloud/datakit-flutter.git
ref: [github_legacy_lastest_tag]
Import it in your Dart code:
Starting with
ft_mobile_agent_flutter0.5.7, Session Replay is provided by the standalone packageft_session_replay_flutter. To enable Session Replay, continue reading Flutter Session Replay.
Additional Android Configuration¶
- Configure the Gradle Plugin ft-plugin to collect app launch events and Android native events (page navigation, click events, native network requests, WebView data)
- To count launch count and launch time, you need to customize
Applicationaccording to the Flutter version, overrideonCreate()and callsuper.onCreate(), then declare it inAndroidManifest.xml. - The custom
Applicationmust participate inft-plugininstrumentation. Do not place it in thecom.ft.sdkpackage or its subpackages, which are excluded by default by the plugin, and do not skip this class through exclusion rules. Foreground/background state recording also depends on correct integration.
Flutter 3.28.x and earlier versions use the old approach:
import io.flutter.app.FlutterApplication
/**
* Add a custom Application here if you need to count [launch count] and [launch time]
*/
class CustomApplication : FlutterApplication() {
override fun onCreate() {
super.onCreate()
}
}
Flutter 3.29.0 and later versions use the new approach:
import android.app.Application
/**
* Add a custom Application here if you need to count [launch count] and [launch time]
*/
class CustomApplication : Application() {
override fun onCreate() {
super.onCreate()
}
}
Notes for Flutter 3.29.0 and later
Flutter 3.29.0 removes the v1 Android embedding, including io.flutter.app.FlutterApplication, so starting from this version use the new approach above. To collect Android app launch events, ft-plugin needs to insert launch listener code into the onCreate() of the custom Application. Extend android.app.Application (or androidx.multidex.MultiDexApplication) directly; otherwise app launch events such as launch_cold may not be collected.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flutter.agent_example">
<application android:name=".CustomApplication">
//...
</application>
</manifest>
iOS Integration¶
SDK 0.5.8 and later support Swift Package Manager and require iOS 15.0 or later.
The SDK provides both CocoaPods and Swift Package Manager integration. The iOS native dependency is upgraded to GuanceSDK1.6.9, which is declared and resolved by the Flutter plugin. If your project still directly depends on the old FTMobileSDK, check and migrate these dependencies to avoid linking two sets of SDKs at the same time.
CocoaPods¶
Set the platform version in the app's ios/Podfile and the Deployment Target of the app and related Extensions in Xcode to 15.0 or later:
Run flutter pub get in the app directory, then run pod install in the ios directory to update the plugin and native SDK dependencies.
Swift Package Manager¶
With Flutter 3.44 or later, enable Swift Package Manager in the app's pubspec.yaml:
After running flutter pub get, complete Flutter's Swift Package Manager integration with flutter run or flutter build ios; make sure the Deployment Target of the Xcode app and related Extensions is not lower than 15.0. You do not need to manually add the plugin's native SDK to the app Target again.
Detailed Configuration¶
Advanced Scenarios¶
- Using Custom Tags
- Custom Rules for Data Collection
- Data Masking
- Dynamic Configuration and Dynamic Update Address
- WebView Data Monitoring
- Native and Flutter Hybrid Development
- Flutter Session Replay
- Publish Package Related Configuration
Field Conflicts¶
- Special key:
track_id, used for tracing - When a custom tag added via
globalContexthas the same name as an SDK's own tag, the SDK's tag overrides the value you set -
It is recommended to prefix tag names with a project abbreviation, for example
custom_tag_name -
For
keyvalues used in the project, refer to the Android constant definitions: Constants.java