Navigation Tracking
Automatically track screen views with Flutter navigation observers.
The Adopture SDK provides built-in observers for both standard Navigator and GoRouter, so you can automatically track screen views without manual Adopture.screen() calls.
Standard Navigator
Add the Adopture navigation observer to your MaterialApp:
MaterialApp(
navigatorObservers: [Adopture.navigationObserver()],
home: HomeScreen(),
);The observer automatically tracks didPush, didPop, and didReplace navigation events as screen views.
GoRouter
Attach the Adopture observer to your GoRouter instance:
final router = GoRouter(
routes: [
GoRoute(path: '/', builder: (_, __) => HomeScreen()),
GoRoute(path: '/settings', builder: (_, __) => SettingsScreen()),
],
);
// Attach observer (no go_router import needed in SDK)
Adopture.observeGoRouter(router);The GoRouter observer provides several features:
- Tracks all route changes including
StatefulShellRoutebranch switches - Smart screen name normalization:
/becomeshome/settings?tab=privacybecomessettings(query parameters are stripped)/users/a1b2c3d4becomesusers/detail(long IDs like UUIDs are normalized)
- The initial route is tracked automatically on attach
Using Both Observers
You can use both the Navigator observer and GoRouter observer together in the same app. Deduplication is handled automatically, so the same screen view is never tracked twice.
Disposing the GoRouter Observer
If you need to stop observing GoRouter changes (for example, when disposing a router):
GoRouterObserver.dispose();