Skip to content

Data Collection Custom Rules

View

Automatic Collection

Method 1: Collection via routes

Add FTRouteObserver to MaterialApp.navigatorObservers, and set the pages to navigate to in MaterialApp.routes. The key in routes is the page name (view_name).

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomeRoute(),
      navigatorObservers: [
        FTRouteObserver(),
      ],
      routes: <String, WidgetBuilder>{
        'logging': (BuildContext context) => Logging(),
        'rum': (BuildContext context) => RUM(),
        'tracing_custom': (BuildContext context) => CustomTracing(),
        'tracing_auto': (BuildContext context) => AutoTracing(),
      },
    );
  }
}

Navigator.pushNamed(context, "logging");

Method 2: Collection via FTMaterialPageRoute

Add FTRouteObserver to MaterialApp.navigatorObservers. Use the custom FTMaterialPageRoute to parse the page name from the widget's runtimeType, where the widget class name is the page name (view_name).

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomeRoute(),
      navigatorObservers: [
        FTRouteObserver(),
      ],
    );
  }
}

Navigator.of(context).push(
  FTMaterialPageRoute(builder: (context) => new NoRouteNamePage()),
);

Refer to the example here.

Method 3: Collection via RouteSettings.name

Define a custom RouteSettings.name in a Route type page. FTRouteObserver will prioritize obtaining this value. This method is also applicable to Dialog type pages, such as showDialog(), showTimePicker(), etc.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomeRoute(),
      navigatorObservers: [
        FTRouteObserver(),
      ],
    );
  }
}

Navigator.of(context).push(
  MaterialPageRoute(
    builder: (context) => new NoRouteNamePage(),
    settings: RouteSettings(name: "RouteSettingName"),
  ),
);

The above three methods can be used in combination within a single project.

Sleep and Wake Event Collection

For versions below 0.5.1-pre.1, if you need to collect application sleep and wake behaviors, add the following code:

class _HomeState extends State<HomeRoute> {
  @override
  void initState() {
    FTLifeRecycleHandler().initObserver();
  }

  @override
  void dispose() {
    FTLifeRecycleHandler().removeObserver();
  }
}

Automatic Collection Filtering

Only supported in version 0.5.0-pre.1 and above.

FTRouteObserver

MaterialApp(
  navigatorObservers: [
    FTRouteObserver(routeFilter: (Route? route, Route? previousRoute) {
      if (filterConfig) {
        return true;
      }
      return false;
    }),
  ],
)
Field Type Required Description
routeFilter RouteFilter No Page method callback. Can be used to judge based on the entering and previous route specifics. Returns true to filter data meeting the condition.

FTDialogRouteFilterObserver

Filters DialogRoute type pages, such as showDialog(), showTimePicker(), etc.

MaterialApp(
  navigatorObservers: [
    FTDialogRouteFilterObserver(filterOnlyNoSettingName: true),
  ],
)

showAboutDialog(
  context: context,
  routeSettings: RouteSettings(name: "About"),
);
Field Type Required Description
filterOnlyNoSettingName bool No Only filters Route pages where RouteSettings.name is null.

Resource

Automatic Collection Filtering

You can filter Resource data that does not need to be collected via the isInTakeUrl callback in FTRUMManager().setConfig(...).

await FTRUMManager().setConfig(
  androidAppId: appAndroidId,
  iOSAppId: appIOSId,
  isInTakeUrl: (url) {
    return url.startsWith("https://url.rule");
  },
);