DEV Community

Discussion on: Flutter Firebase Analytics screen tracking with go_router

Collapse
 
ahmedznouda profile image
Ahmed ZNOUDA •

The table of what the observer logs versus what it should is the best part. /a, b, c for one screen is the kind of thing nobody notices until a report looks odd.

Two related things that inflate screen counts, in case they're worth a line:

Firebase also logs screen views on its own, per Activity. In a Flutter app that's a MainActivity screen_view on every launch, next to yours. Setting google_analytics_automatic_screen_reporting_enabled to false in the manifest meta-data (and FirebaseAutomaticScreenReportingEnabled to NO in Info.plist) leaves only the listener's views.

And bottom sheets and dialogs: showModalBottomSheet pushes a route without a page, so it isn't in currentConfiguration and the listener won't see it (nor did the observer, with no name). For a paywall or consent sheet, that's often the screen you most want counted. Do you log those by hand with logScreenView, or leave them out on purpose?

One question on redirects: with an auth redirect from /home to /login, does the delegate notify once with the final configuration, or can a /home view slip through first?

Collapse
 
ybeshkarov profile image
Yevhen Beshkarov • • Edited

Thanks, Ahmed, you were right on both.

I checked the automatic screen views on an Android 12 emulator and an iPhone simulator with the debug logging of Firebase Analytics. Every cold start logged a screen_view with the screen class MainActivity (FlutterViewController on iOS) and no screen name, right before the listener's own view. On Android there was one more each time the app came back from the background. With the two keys you mentioned, only the listener's view was left. The apps that SMF generates didn't turn them off either. That's fixed in a PR that goes out with the next release, and it credits your comment.

As for sheets and dialogs, I don't log them by hand yet. The router's configuration doesn't change when one opens or closes, so the listener logs nothing, and FirebaseAnalyticsObserver skips them too because by default it only logs a PageRoute. So in SMF the paywall that the onboarding pushes as a route without a page isn't counted. For a screen like that I'd call logScreenView when it's shown.

And on redirects, /home doesn't slip through. go_router runs the redirect while it parses the location, before the delegate gets the new configuration. I checked it on go_router 18.1.1: starting at /home while signed out, the listener only sees /login. Signing in then gives /home once, and signing out /login once.

I've added an update to the post with all three. Thanks again for the comment!