feat: add screen view observer firebase analytic
This commit is contained in:
parent
70dc4ccbef
commit
47c9386eb2
|
@ -1,7 +1,10 @@
|
||||||
|
import 'package:auto_route/auto_route.dart';
|
||||||
import 'package:component_library/component_library.dart';
|
import 'package:component_library/component_library.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:golek_flutter_new/routes/app_router.gr.dart';
|
import 'package:golek_flutter_new/routes/app_router.gr.dart';
|
||||||
|
import 'package:golek_flutter_new/screen_view_observer.dart';
|
||||||
|
import 'package:monitoring/monitoring.dart';
|
||||||
|
|
||||||
import 'l10n/app_localizations.dart';
|
import 'l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
@ -16,6 +19,7 @@ class _GolekTrukState extends State<GolekTruk> {
|
||||||
final _lightTheme = LightGolekThemeData();
|
final _lightTheme = LightGolekThemeData();
|
||||||
final _darkTheme = DarkGolekThemeData();
|
final _darkTheme = DarkGolekThemeData();
|
||||||
final _appRouter = AppRouter();
|
final _appRouter = AppRouter();
|
||||||
|
final _analyticsService = AnalyticsService();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -40,7 +44,13 @@ class _GolekTrukState extends State<GolekTruk> {
|
||||||
],
|
],
|
||||||
backButtonDispatcher: RootBackButtonDispatcher(),
|
backButtonDispatcher: RootBackButtonDispatcher(),
|
||||||
routeInformationParser: _appRouter.defaultRouteParser(),
|
routeInformationParser: _appRouter.defaultRouteParser(),
|
||||||
routerDelegate: _appRouter.delegate(),
|
routerDelegate: AutoRouterDelegate(
|
||||||
|
_appRouter,
|
||||||
|
navigatorObservers: () => [
|
||||||
|
AutoRouteObserver(),
|
||||||
|
ScreenViewObserver(analyticsService: _analyticsService)
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
import 'package:auto_route/auto_route.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:monitoring/monitoring.dart';
|
||||||
|
|
||||||
|
class ScreenViewObserver extends AutoRouterObserver {
|
||||||
|
final AnalyticsService analyticsService;
|
||||||
|
|
||||||
|
ScreenViewObserver({required this.analyticsService});
|
||||||
|
|
||||||
|
void _sendScreenView(PageRoute<dynamic> route) {
|
||||||
|
final String? screenName = route.settings.name;
|
||||||
|
|
||||||
|
if (screenName != null) {
|
||||||
|
analyticsService.setCurrentScreen(screenName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didPush(Route route, Route? previousRoute) {
|
||||||
|
super.didPush(route, previousRoute);
|
||||||
|
if (route is PageRoute) {
|
||||||
|
_sendScreenView(route);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didPop(Route route, Route? previousRoute) {
|
||||||
|
super.didPop(route, previousRoute);
|
||||||
|
if (previousRoute is PageRoute && route is PageRoute) {
|
||||||
|
_sendScreenView(previousRoute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue