Flutter API Description
Custom User Information
bonree_flutter_plugin supports setting user-related information to fulfill scenarios where performance data needs to be associated with actual users.
There are two ways to set user information:
-
Set User ID: Identify the user using a string.
/// Set User ID
Future<void> setUserID(String userID);-
Interface Description
Parameter Type Description userID String User ID -
Example
Dart
Bonree().setUserID("user-id");
-
-
Set additional user information in the form of a Map.
/// Set Additional Information
Future<void> setExtraInfo(Map<String, dynamic> extraInfo);-
Interface Description
Parameter Type Description extraInfo Map Additional user information. Value must be of type String or int. -
Example
Dart
Bonree().setExtraInfo({"id":"123456", "name":"Tom"});
-
Custom Exceptions
Call the interface with the corresponding parameters to complete the statistics collection for custom exception data.
/// Custom Exception Collection
Future<void> setCustomException(
String exceptionType, String causedBy, String errorDump);
-
Interface Description
Parameter Type Description exceptionType String Exception type. Required parameter. Interface call is invalid if empty or null. causedBy String Cause of the exception errorDump String Exception stack trace -
Example
Dart
Bonree().setCustomException("Custom exception type",
"Caused by customer.",
"Custom error dump 0\nCustom error dump 1");
Note: Even if the correct crash stack trace is passed in the custom exception interface, the platform will not perform symbolication on the crash stack trace.
Custom Views
Call the interface with the corresponding parameters to complete the statistics collection for custom view data.
/// Custom View - Mark View Start (called in pair with the view end method)
Future<void> setCustomPageStart(String pageName, String pageAlias);
/// Custom View - Mark View End (called in pair with the view start method)
Future<void> setCustomPageEnd(String pageName, String pageAlias);
-
Interface Description
Parameter Type Description pageName String Page name. Required parameter. Interface call is invalid if empty or null. pageAlias String Page alias -
Example
Dart
Bonree().setCustomPageStart("page01", "Home Page");
Bonree().setCustomPageEnd("page01", "Home Page");
Note: The start and end recording interfaces for a custom view must be called in pairs, and the
pageNamefor the same view must be consistent to correctly collect and report a complete custom view data.
Custom Events (Full Version)
Call the interface with the corresponding parameters to complete the statistics collection for custom event data.
/// Custom Event Start
Future<void> setCustomEventStartWithID(String eventID, String eventName, {String? label, String? param, Map<String, String>? info});
/// Custom Event End
Future<void> setCustomEventEndWithID(String eventID, String eventName,
{String? label, String? param, Map<String, String>? info});
-
Interface Description
Parameter Type Description eventID String Event ID. Required parameter. Interface call is invalid if empty or null. eventName String Event name param String Event additional information info Map Event business information -
Example
Dart
Bonree().setCustomEventStartWithID("001", "Login", "param", label: "event_label", info: {"info": "bonree"});
// Some code...
Bonree().setCustomEventEndWithID("001", "Login", "param", label: "event_label", info: {"info": "bonree"});
Note: The start and end of a custom event are matched uniquely by
eventID. Please ensure the uniqueness of the event ID for unfinished events.
Custom Events (Simplified Version)
Call the interface with the corresponding parameters to complete the statistics collection for custom event data.
/// Custom Event
Future<void> setCustomEvent(String eventID, String eventName, String param, {String? label, Map<String, String>? info});
-
Interface Description
Parameter Type Description eventID String Event ID. Required parameter. Interface call is invalid if empty or null. eventName String Event name param String Event additional information info Map Event business information -
Example
Dart
Bonree().setCustomEvent("001", "Login", "param", label: "event_label", info: {"info": "bonree"});
Custom Logs
Call the interface with the corresponding parameters to complete the statistics collection for custom log data.
/// Custom Log
Future<void> setCustomLog(String logInfo, String param);
-
Interface Description
Parameter Type Description logInfo String Log information. Required parameter. Interface call is invalid if empty or null. param String Parameter -
Example
Dart
Bonree().setCustomLog("2020-01-01 08:30:00 Print log info.", "param");
Custom Metrics
Call the interface with the corresponding parameters to complete the statistics collection for custom metric data.
Future<void> setCustomMetric(String metricName, int metricValue, String param);
-
Interface Description
Parameter Type Description metricName String Metric name. Required parameter. Interface call is invalid if empty or null. metricValue int Metric value. Required parameter. Interface call is invalid if the metric is empty. param String Parameter -
Example
Dart
Bonree().setCustomMetric("Test Metric 01", 1, "param");
Custom Methods
Future<void> setCustomMethodStart(String methodName, String param);
Future<void> setCustomMethodEnd(String methodName, String param);
-
Interface Description
Parameter Type Description methodName String Method name param String Method parameter -
Example
Dart
static void customMethod() {
Bonree().setCustomMethodStart("methodName", "param");
// .....
Bonree().setCustomMethodEnd("methodName", "param");
}
Custom Cold Launch End
Call this interface at the desired timing to end the cold launch, allowing customization of the cold launch end point.
Future<void> recordCustomLaunchEnd();
-
Example
Bonree().recordCustomLaunchEnd();
Note: To use the custom cold launch end interface, you need to enable this feature by calling the custom cold launch switch interface in the native project.
Custom Cold Launch Switch
Whether to enable the custom cold launch endpoint switch. Call this during (or before) native part initialization.
-
Example
iOS
// Enable custom endpoint
BRSAgent.useCustomLaunch(true)
BRSAgent.start(withAppID:"your appId")Android
Bonree.withAppID("app_id")
.withUseCustomLaunch(true)
.start(getApplicationContext());
For Android cold launch, you need to implement a custom Application class and initialize it in the first line of onCreate:
public class App extends FlutterApplication {
@Override
public void onCreate() {
super.onCreate();
Bonree.withAppID("app_id")
.start(getApplicationContext());
}
}
Flutter View Configuration
Set in the home page's MaterialApp by registering the navigatorObservers navigation observer.
import 'package:bonree_flutter_plugin/bonree_flutter_plugin.dart';
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorObservers: [BonreeNavigationObserver()],
);
}
Static Routing
Set in the home page's MaterialApp, where routes are managed uniformly in the routes collection.
Example:
import 'package:bonree_flutter_plugin/bonree_flutter_plugin.dart';
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorObservers: [BonreeNavigationObserver()],
routes: {
'home_page': (context) => HomePage(),
'first_page': (context) => FirstPage(),
'second_page': (context) => SecondPage(),
'third_page': (context) => ThirdPage(),
},
);
}
Dynamic Routing
Use when navigating with Navigator.push() for dynamic routing.
Two configuration methods:
(1). Import BonreeMaterialPageRoute and pass the routeName parameter, which is the name of the current target page.
Example:
ElevatedButton(
onPressed: () {
Navigator.push(
context,
BonreeMaterialPageRoute(
builder: (context) => SecondPage(),
routeName: 'second_page'));
},
child: Text('Second Page'))
(2). Use Flutter's MaterialPageRoute, set RouteSettings, and pass the name parameter, which is the name of the current target page.
Example:
ElevatedButton(
onPressed: () {
RouteSettings set = RouteSettings(name: "second_page");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecondPage(), settings: set));
},
child: Text('Second Page'))
Flutter Error Callback
Since Flutter's error monitoring cannot be passed layer by layer, after Bonree's Flutter plugin monitors synchronous and asynchronous interfaces, the original error listeners in the application may become ineffective. Therefore, the Flutter plugin provides a unified error callback interface.
/// Error Callback Interface
void onBonreeErrorCallback(
callback(Object error, StackTrace stack, bool isAsync));
-
Interface Description
Parameter Type Description error Object Error cause. stack StackTrace Error stack trace. isAsync bool Whether it is an asynchronous error. -
Example
Dart
Bonree().onBonreeErrorCallback((error, stacktrace, async) {
// Handle error event
// ...
});