Skip to content

[go_router] Typed GoRoutes don't have RouteSettings.name, resulting in blank Analytics screen names #120102

@arnab

Description

@arnab

Context

I am using go_router and go_router_builder to use typed GoRoutes as described in the docs.

dependencies:
  ...
  go_router: ^6.0.1
  ...
dev_dependencies:
  ...
  build_runner: ^2.3.3
  go_router_builder: ^1.0.16
  ...

I have set up Firebase/Google Analytics with the package firebase_analytics as described in their docs and have configured an observer as an FirebaseAnalyticsObserver:

@riverpod
GoRouter router(RouterRef ref) {
  final notifier = ref.watch(stateAwareRouterNotifierProvider.notifier);

  return GoRouter(
    navigatorKey: _rootNavigatorKey,
    refreshListenable: notifier,
    debugLogDiagnostics: kDebugMode,
    errorBuilder: (BuildContext context, GoRouterState state) => ErrorRoute(
      error: state.error,
    ).build(context, state),
    initialLocation: HomeScreen.routeName,
    redirect: notifier.redirect,
    routes: [
      ShellRoute(
        navigatorKey: _shellNavigatorKey,
        builder: (BuildContext context, GoRouterState state, Widget child) {
          return AppScaffold(child: child);
        },
        routes: notifier.routes,
      ),
    ],
    observers: [_firebaseAnalyticsObserver()],
  );
}

_firebaseAnalyticsObserver() =>
    FirebaseAnalyticsObserver(analytics: FirebaseAnalytics.instance);

Problem

As noted in Firebase Analytics docs, this is working and producing analytics events. However, I see that screen_names are blank. Previously, when I have used Firebase Analytics with Flutter apps, not using typed GoRoutes, the screen names were captured correctly too.

It looks like FirebaseAnalyticsObserver tries to parse the screen name from the RouteSettings.name:

On debugging I see that the RouteSettings object has name="" when using typed GoRoutes.

Is there something I can do to populate the names?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.7Found to occur in 3.7found in release: 3.8Found to occur in 3.8has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions