FirebaseAnalyticsObserver class
A NavigatorObserver that sends events to Firebase Analytics when the currently active PageRoute changes.
When a route is pushed or popped, nameExtractor is used to extract a name from RouteSettings of the now active route and that name is sent to Firebase.
The following operations will result in sending a screen 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);
To use it, add it to the navigatorObservers
of your Navigator, e.g. if
you're using a MaterialApp:
MaterialApp(
home: MyAppHome(),
navigatorObservers: [
FirebaseAnalyticsObserver(analytics: service.analytics),
],
);
You can also track screen views within your PageRoute by implementing
PageRouteAware
and subscribing it to FirebaseAnalyticsObserver. See the
PageRouteObserver
docs for an example.
- Inheritance
-
- Object
- NavigatorObserver
- RouteObserver<
PageRoute> - FirebaseAnalyticsObserver
Constructors
- FirebaseAnalyticsObserver({required FirebaseAnalytics analytics, ScreenNameExtractor nameExtractor = defaultNameExtractor, dynamic onError(PlatformException error)?})
- Creates a NavigatorObserver that sends events to FirebaseAnalytics.
Properties
- analytics → FirebaseAnalytics
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- nameExtractor → ScreenNameExtractor
-
final
-
The navigator that the observer is observing, if any.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
debugObservingRoute(
PageRoute route) → bool -
Whether this observer is managing changes for the specified route.
inherited
-
didPop(
Route route, Route? previousRoute) → void -
The Navigator popped
route
.override -
didPush(
Route route, Route? previousRoute) → void -
The Navigator pushed
route
.override -
didRemove(
Route route, Route? previousRoute) → void -
The Navigator removed
route
.inherited -
didReplace(
{Route? newRoute, Route? oldRoute}) → void -
The Navigator replaced
oldRoute
withnewRoute
.override -
didStartUserGesture(
Route route, Route? previousRoute) → void -
The Navigator's routes are being moved by a user gesture.
inherited
-
didStopUserGesture(
) → void -
User gesture is no longer controlling the Navigator.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
subscribe(
RouteAware routeAware, PageRoute route) → void -
Subscribe
routeAware
to be informed about changes toroute
.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
unsubscribe(
RouteAware routeAware) → void -
Unsubscribe
routeAware
.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited