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 re-setting globalContext after RUM startup does not immediately affect 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 change the file data anywhere in your code.
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 built-in tag, the SDK's tag value will override the user-set value.
  3. Avoid using the same key as in the SDK initialization configuration's globalContext. In case of identical keys, the static tag from the initialization configuration takes precedence over dynamically added tags.
  4. It is recommended to prefix tag names with a project abbreviation, e.g., df_tag_name.
  5. For shared rule explanations, please refer to Conflict Field Descriptions.

Feedback

Is this page helpful? ×