getObserver method

ConvivaObserver getObserver({
  1. ScreenNameExtractor nameExtractor = defaultNameExtractor,
})

Returns a ConvivaObserver for automatically tracking PageViewEvent and ScreenView events from a navigator when the currently active ModalRoute of the navigator changes.

ScreenView events are tracked on all platforms. Optionally, PageViewEvent events may be tracked on Web if TrackerConfiguration.webActivityTracking is configured when creating the tracker.

The nameExtractor function is used to extract a name from RouteSettings of the now active route and that name is used in tracked ScreenView or PageViewEvent events.

The following operations will result in tracking a view event:

Navigator.pushNamed(context, '/contact/123');

Navigator.push<void>(context, MaterialPageRoute(
  settings: RouteSettings(name: '/contact/123'),
  builder: (_) => ContactDetail(123)));

Navigator.pushReplacement<void>(context, MaterialPageRoute(
  settings: RouteSettings(name: '/contact/123'),
  builder: (_) => ContactDetail(123)));

Navigator.pop(context);

If using MaterialApp, add the retrieved observer to navigatorObservers, e.g.:

MaterialApp(
  navigatorObservers: [
    tracker.getObserver()
  ],
  ...
);

If using the Router API with the MaterialApp.router constructor, add the observer to the observers of your Navigator instance, e.g.:

return Navigator(
  observers: [tracker.getObserver()],
  ...
);

You can also trigger view event tracking within your ModalRoute by implementing RouteAware<ModalRoute<dynamic>> and subscribing it to ConvivaObserver. See the RouteObserver<ModalRoute<dynamic>> docs for an example.

Implementation

ConvivaObserver getObserver(
    {ScreenNameExtractor nameExtractor = defaultNameExtractor}) {
  return ConvivaObserver(tracker: this, nameExtractor: nameExtractor);
}