Skip to content

Custom Tag Usage

Static Usage

  1. Split the original main.dart into two parts: one for main() and one for the App() MaterialApp component.
  2. Create entry files for each environment, e.g., main_prod.dart, main_gray.dart.
  3. 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.

  1. Save tag data using a file-based data type (e.g., SharedPreferences from shared_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},
);
  1. 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);
}
  1. Finally, restart the application.

Notes

  1. Special key: track_id, used for tracking functionality.
  2. When a user adds a custom tag via globalContext that conflicts with an SDK's own tag, the SDK's tag value will override the user-set value.
  3. It is recommended to prefix tag names with a project abbreviation, e.g., df_tag_name.
  4. For sharing rule explanations, please refer to Conflict Field Description.