I have firebase analytics enabled for my application and I am trying to get the firebase debug-view to show my page changes. With the code below, currently nothing is being tracked, and I don't understand why. I have followed the firebase documentation for tracking page-views, but apparently I'm missing something when it comes to using onGenerateRoute.
My main:
class MyApp extends StatelessWidget {
static FirebaseAnalytics analytics = FirebaseAnalytics();
static FirebaseAnalyticsObserver observer =
FirebaseAnalyticsObserver(analytics: analytics);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "localhour",
onGenerateRoute: router.generateRoute,
initialRoute: '/',
navigatorObservers: <NavigatorObserver>[observer],
),
);
}
}
My generateRoute function:
Route<dynamic> generateRoute(RouteSettings settings) {
switch (settings.name) {
case '/':
return MaterialPageRoute(builder: (context) => RootPage());
break;
case '/login':
return MaterialPageRoute(builder: (context) => LoginPage());
break;
case '/home':
var user = settings.arguments;
return MaterialPageRoute(
builder: (context) => HomePage(
user: user,
));
break;
case '/store':
return MaterialPageRoute(builder: (context) => StorePage());
break;
case '/store-details':
var argument = settings.arguments;
return MaterialPageRoute(
builder: (context) => StoreDetails(
storeDetails: argument,
));
break;
}
}
I have used analytics before to track page changes automatically in a previous app but used the "routes" method in my main function. Can someone explain why I am not getting any feedback using this method above? Do the screens have to be named explicitly? (Which I have also tried, but unsuccessfully)
Hey if you're still looking for an answer to this, it's because your not pushing the name into the MaterialPageRoute.
So in your generateRoute function:
'/login':
return MaterialPageRoute(
builder: (context) => LoginPage(),
settings: RouteSettings(name: settings.name));
break;
That'll push the name to Firebase Analytics for you. Just add it for each case in the switch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With