From dbf525c4848400e31d37e5f90a6b06ba49222af0 Mon Sep 17 00:00:00 2001 From: Zohaib Iqbal Kambrani <> Date: Sun, 1 Aug 2021 12:39:37 +0300 Subject: [PATCH] no message --- ios/Podfile | 1 + lib/analytics/analytic-events.dart | 69 +++++++++++++++++++++++ lib/analytics/google-analytics.dart | 85 +++++++++++++++++++++++++++++ lib/main.dart | 22 +++++--- lib/pages/landing/landing_page.dart | 6 ++ lib/splashPage.dart | 3 + lib/uitl/utils.dart | 19 +++++++ pubspec.yaml | 1 + 8 files changed, 197 insertions(+), 9 deletions(-) create mode 100644 lib/analytics/analytic-events.dart create mode 100644 lib/analytics/google-analytics.dart diff --git a/ios/Podfile b/ios/Podfile index d68afba2..89424e2a 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -3,6 +3,7 @@ # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' +$FirebaseAnalyticsWithoutAdIdSupport = true project 'Runner', { 'Debug' => :debug, diff --git a/lib/analytics/analytic-events.dart b/lib/analytics/analytic-events.dart new file mode 100644 index 00000000..3e107d95 --- /dev/null +++ b/lib/analytics/analytic-events.dart @@ -0,0 +1,69 @@ +import 'package:diplomaticquarterapp/uitl/utils.dart'; + +class _Event{ + String name; + String description; + bool active; + _Event(dynamic map){ + name = map['name']; + description = map['description']; + active = map['active']; + } + + flutterName() => 'f: $name'; +} + +class AnalyticEvents{ + static _Event get(String key) { + var e = _Event(mapping[key]); + if(e == null){ + var label = labelFrom(className: key); // Convert Class Name in to Label (HomeCare -> Home Care) + e = _Event({"name": label, "active":true, "description":key}); + } + return e; + } + + static var mapping = const { + "HomeHealthCarePage" : { + "active" : true, + "name" : "Home Health Care Page", + "description" : "", + }, + "SplashScreen" : { + "active" : true, + "name" : "Splash Screen", + "description" : "", + }, + "LandingPage" : { + "active" : true, + "name" : "Landing Page", + "description" : "", + }, + "WelcomeLogin" : { + "active" : true, + "name" : "Welcome Login", + "description" : "", + }, + "LoginType" : { + "active" : true, + "name" : "Login Type", + "description" : "", + }, + "Login" : { + "active" : true, + "name" : "Login", + "description" : "", + }, + "ForgotPassword" : { + "active" : true, + "name" : "Forgot Password", + "description" : "", + }, + "" : { + "active" : true, + "name" : "", + "description" : "", + }, + }; +} + diff --git a/lib/analytics/google-analytics.dart b/lib/analytics/google-analytics.dart new file mode 100644 index 00000000..f4bf8b72 --- /dev/null +++ b/lib/analytics/google-analytics.dart @@ -0,0 +1,85 @@ +import 'package:diplomaticquarterapp/analytics/analytic-events.dart'; +import 'package:diplomaticquarterapp/routes.dart'; +import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; +import 'package:firebase_analytics/firebase_analytics.dart'; +import 'package:firebase_analytics/observer.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +class Singleton { + const Singleton(); //Constant constructor + + void hello() { print('Hello world'); } +} + +var analytics = FirebaseAnalytics(); + +class GAnalytics{ + const GAnalytics(); + static GAnalytics shared = const GAnalytics(); + NavObserver navObserver() => NavObserver(); +} +// adb shell setprop debug.firebase.analytics.app com.ejada.hmg -> Android +class NavObserver extends RouteObserver>{ + + _sendScreenView(PageRoute route) async{ + + + log(String className){ + var event = AnalyticEvents.get(className); + if(event.active){ + analytics.setCurrentScreen(screenName: event.flutterName(), screenClassOverride: className).catchError( (Object error) { + debugPrint('$FirebaseAnalyticsObserver: $error'); + }, + test: (Object error) { + return error is PlatformException; + }, + ); + } + } + + if(route.settings.name != null && route.settings.name.isNotEmpty && route.settings.name != "null"){ + var class_ = routes[route.settings.name](0); + if(class_ != null) + log(class_.toStringShort()); + + }else if(route is FadePage){ + var class_ = route.page; + if(class_ != null) + log(class_.toStringShort()); + + }else if(route is MaterialPageRoute){ + var class_ = route.builder(null); + if (class_ != null) + log(class_.toStringShort()); + + }else{ + print(""); + } + + } + + @override + void didPush(Route route, Route previousRoute) { + super.didPush(route, previousRoute); + if (route is PageRoute) { + _sendScreenView(route); + } + } + + @override + void didReplace({Route newRoute, Route oldRoute}) { + super.didReplace(newRoute: newRoute, oldRoute: oldRoute); + if (newRoute is PageRoute) { + _sendScreenView(newRoute); + } + } + + @override + void didPop(Route route, Route previousRoute) { + super.didPop(route, previousRoute); + // if (previousRoute is PageRoute && route is PageRoute) { + // _sendScreenView(previousRoute); + // } + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 70ca9d71..bf090720 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,30 +1,29 @@ +import 'package:diplomaticquarterapp/analytics/google-analytics.dart'; import 'package:diplomaticquarterapp/theme/theme_notifier.dart'; import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart'; import 'package:diplomaticquarterapp/routes.dart'; import 'package:diplomaticquarterapp/services/robo_search/event_provider.dart'; import 'package:diplomaticquarterapp/services/robo_search/search_provider.dart'; import 'package:diplomaticquarterapp/theme/theme_value.dart'; -import 'package:diplomaticquarterapp/uitl/HMG_Geofence.dart'; import 'package:diplomaticquarterapp/uitl/LocalNotification.dart'; import 'package:diplomaticquarterapp/uitl/PlatformBridge.dart'; -import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:firebase_analytics/firebase_analytics.dart'; +import 'package:firebase_analytics/observer.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; -import 'package:hexcolor/hexcolor.dart'; import 'package:provider/provider.dart'; - -import 'Constants.dart'; -import 'config/shared_pref_kay.dart'; import 'config/size_config.dart'; -import 'core/model/geofencing/requests/GeoZonesRequestModel.dart'; -import 'core/service/geofencing/GeofencingServices.dart'; import 'core/viewModels/project_view_model.dart'; import 'locator.dart'; import 'pages/pharmacies/compare-list.dart'; +import 'package:firebase_core/firebase_core.dart'; + void main() async { + WidgetsFlutterBinding.ensureInitialized(); + FirebaseApp defaultApp = await Firebase.initializeApp(); + setupLocator(); runApp(MyApp()); } @@ -35,6 +34,7 @@ class MyApp extends StatefulWidget { } class _MyApp extends State { + @override void initState() { // ProjectViewModel projectProvider; @@ -52,6 +52,7 @@ class _MyApp extends State { .showNow(title: "Payload", subtitle: payload, payload: payload); }); + // final themeNotifier = Provider.of(context); precacheImage(AssetImage('assets/images/powerd-by.jpg'), context); return LayoutBuilder( @@ -82,6 +83,9 @@ class _MyApp extends State { ], child: Consumer( builder: (context, projectProvider, child) => MaterialApp( + navigatorObservers: [ + GAnalytics.shared.navObserver() + ], showSemanticsDebugger: false, title: 'Diplomatic Quarter App', locale: projectProvider.appLocal, diff --git a/lib/pages/landing/landing_page.dart b/lib/pages/landing/landing_page.dart index c55b685b..405bac25 100644 --- a/lib/pages/landing/landing_page.dart +++ b/lib/pages/landing/landing_page.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:diplomaticquarterapp/analytics/google-analytics.dart'; import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/model/geofencing/requests/GeoZonesRequestModel.dart'; @@ -31,9 +32,11 @@ import 'package:diplomaticquarterapp/widgets/buttons/floatingActionButton.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart'; import 'package:diplomaticquarterapp/widgets/drawer/app_drawer_widget.dart'; +import 'package:firebase_analytics/observer.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; @@ -95,6 +98,8 @@ class _LandingPageState extends State with WidgetsBindingObserver { }); } + + @override void didChangeAppLifecycleState(AppLifecycleState state) { super.didChangeAppLifecycleState(state); @@ -188,6 +193,7 @@ class _LandingPageState extends State with WidgetsBindingObserver { // if (results[Permission.calendar].isGranted) ; }); requestPermissions(); + // }); // // //_firebase Background message handler diff --git a/lib/splashPage.dart b/lib/splashPage.dart index ef5db7f5..f75680ef 100644 --- a/lib/splashPage.dart +++ b/lib/splashPage.dart @@ -3,9 +3,12 @@ import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; +import 'package:firebase_analytics/observer.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; +import 'analytics/google-analytics.dart'; import 'config/shared_pref_kay.dart'; import 'config/size_config.dart'; import 'core/service/AuthenticatedUserObject.dart'; diff --git a/lib/uitl/utils.dart b/lib/uitl/utils.dart index 67e5c6b9..2d03137d 100644 --- a/lib/uitl/utils.dart +++ b/lib/uitl/utils.dart @@ -616,6 +616,25 @@ openAppStore({String androidPackageName, String iOSAppID}) async{ launch("https://itunes.apple.com/kr/app/apple-store/$iOSAppID)"); } } + +String labelFrom({@required String className}){ + RegExp exp = RegExp(r'(?<=[a-z])[A-Z]'); + + String result = className.replaceAllMapped(exp, (m) { + var str = m.group(0); + if(str != null){ + return ('_' + str); + } + return ""; + }); + + if(result.isEmpty) + return className; + + result = result.replaceAll("_", " "); + return result; +} + /* userBoard.asMap().map((i, element) => MapEntry(i, Stack( GestureDetector(onTap: () { diff --git a/pubspec.yaml b/pubspec.yaml index c109bd0a..55694840 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -52,6 +52,7 @@ dependencies: shared_preferences: ^0.5.8 flutter_flexible_toast: ^0.1.4 firebase_messaging: ^7.0.3 + firebase_analytics: ^6.3.0 cloud_firestore: ^0.14.3 android_intent: ^0.3.7+7 # Progress bar