tencent cloud

Tencent Cloud Super App as a Service

Customizing Event Handling

Download
Focus Mode
Font Size
Last updated: 2026-04-07 14:47:10

Event reporting

The superapp can implement the event reporting API to override the internal reporting logic of tcmpp_flutter.
Future<bool> reportEvent(int eventId, String eventName, AppInfo appInfo,
Map<Object?, Object?> params) async {
return false;
}
Example:
@override
Future<bool> reportEvent(int eventId, String eventName, AppInfo appInfo,
Map<Object?, Object?> params) async {
print("reportEvent:$eventName appinfo:$appInfo params:$params");
// TODO: implement reportEvent
return true;
}

Configure event handling

Note

To customize event handling, implement the methods in the TcmppFlutterEventChannel class combined with the EventConfig annotation. This enables listening to event content and customizing the SDK’s internal logic.

Register an event listener

/// Register SDK for message callback event monitoring, which can be marked
/// based on EventConfig annotation to indicate whether to intercept events,
/// such as log events, etc
void registerMessageEventHandler(TcmppFlutterEventChannel handler)
Example:
_tcmppFlutterPlugin.registerMessageEventHandler(TcmppFlutterEventChannelImpl());

Generate a configuration file

Note:
You need to integrate the tcmpp_flutter_builder plug-in to complete the following code generation!
To customize the event handling logic, such as disabling SDK internal log reporting or updating the base library, please add the EventConfig annotation on implemented methods with a boolean value (true or false).
Example:
Use EventConfig with value: true to disable the SDK’s internal log reporting.
@EventConfig(value: true)
@override
Future<void> uploadUserLog(String appId, String logPath) async {
print("SupperAppCustom uploadUserLog:${logPath}");
}
Configure the project:
Add the build_runner plugin under dev_dependencies in your project’s pubspec.yaml file to enable configuration file generation.
Add the generated configuration file path under flutter/assets in pubspec.yaml for use in native compilation.
...
dev_dependencies:
build_runner: ^2.4.6
flutter:
assets:
- lib/generated/tcmpp_event_config.json
Generate the configuration file via command:
Run the following command in your project directory to generate tcmpp_event_config.json:
flutter pub run build_runner build --delete-conflicting-outputs
Example:
{
"isUpdateBaseLib": true,
"uploadUserLog": true,
"reportRealTimeLog": false
}

Real-time log reporting

Superapp can customize real-time event log reporting in mini programs (including logs written via wx.getRealtimeLogManager) by implementing the reportRealTimeLog method of TcmppFlutterEventChannel.
Note:
Combine with EventConfig annotation to define whether the SDK reports internally. If true, the SDK stops internal reporting. If you only need to listen to log callbacks, the annotation is optional.
The API is as follows:
/**
* Real-time log callback
* @param RealTimeLogInfo Log information
*/
Future<void> reportRealTimeLog(RealTimeLogInfo? logInfo) async {}
RealTimeLogInfo
class RealTimeLogInfo {
/// The current page
String page;
/// Base library version
String jsLibVersion;
/// Mini program appid
String appId;
/// Filter keywords
List<String> filterMsgs;
/// Logs
List<LogItem> logs;
}

class LogItem {
/// Log time
int time;
/// Log level
int level;
/// Log information
String msg;
/// Log tag
String tag;
/// Log keywords
String key;
}
Example:
@EventConfig(value: true)
@override
Future<void> reportRealTimeLog(RealTimeLogInfo? logInfo) async {
print("SupperAppCustom reportRealTimeLog:${logInfo}");
}

Internal log reporting

Superapp can customize internal log reporting (including logs written via wx.getLogManager) by implementing the uploadUserLog method. Users can upload printed logs using the button component with open-type="feedback".
Note:
Combine with EventConfig annotation to define whether the SDK reports internally. If true, the SDK stops internal reporting. If you only need to listen to log callbacks, the annotation is optional.
The API is as follows:
Future<void> uploadUserLog(String appId, String logPath) async {}
Example:
@EventConfig(value: true)
@override
Future<void> uploadUserLog(String appId, String logPath) async {
print("SupperAppCustom uploadUserLog:${logPath}");
}

Listen to base library updates

You can listen to base library updates by overriding the uploadUserLog method of TcmppFlutterEventChannel.
Note:
Combine with EventConfig annotation to define whether the SDK updates the base library version. If false, the SDK stops internal updates. If you only need to listen to updates, the annotation is optional.
The API is as follows:
Future<void> isUpdateBaseLib(Map<dynamic, dynamic>? data) async {}
Example:
@EventConfig(value: true)
@override
Future<void> isUpdateBaseLib(Map<dynamic, dynamic>? data) async {
print("isUpdateBaseLib:${data}");
}



Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback