Custom Tag Usage¶
Static Usage¶
- Split the original
main.dartinto two parts: one formain()and one for theApp()MaterialAppcomponent. - Create entry files for each environment, e.g.,
main_prod.dart,main_gray.dart. - Configure custom tags in the corresponding environment entry file.
/// main_prod.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await FTMobileFlutter.sdkConfig(
datakitUrl: serverUrl,
debug: true,
);
await FTRUMManager().setConfig(
androidAppId: appAndroidId,
iOSAppId: appIOSId,
globalContext: {CUSTOM_STATIC_TAG: "prod_static_tag"},
);
runApp(MyApp());
}
Dynamic Usage¶
Because resetting globalContext after RUM startup does not immediately apply to the already started configuration, dynamic tags typically take effect on the next application launch via local persistence.
- Save tag data using a file-based data type (e.g.,
SharedPreferencesfromshared_preferences) and read it during SDK configuration.
final prefs = await SharedPreferences.getInstance();
String customDynamicValue =
prefs.getString("customDynamicValue") ?? "not set";
await FTRUMManager().setConfig(
androidAppId: appAndroidId,
iOSAppId: appIOSId,
globalContext: {CUSTOM_DYNAMIC_TAG: customDynamicValue},
);
- Add a method to modify the file data anywhere.
static Future<void> setDynamicParams(String value) async {
final prefs = await SharedPreferences.getInstance();
prefs.setString(CUSTOM_DYNAMIC_TAG, value);
}
- Finally, restart the application.
Notes¶
- Special key:
track_id, used for tracking functionality. - When a user adds a custom tag via
globalContextthat conflicts with an SDK's own tag, the SDK's tag value will override the user-set value. - It is recommended to prefix tag names with a project abbreviation, e.g.,
df_tag_name. - For sharing rule explanations, please refer to Conflict Field Description.