From c1f95acffe4be1ca81356931b5342d37c2dc32f8 Mon Sep 17 00:00:00 2001 From: sush67 Date: Mon, 14 Jun 2021 20:42:39 +0530 Subject: [PATCH] firabase analytics --- lib/dashboard.dart | 3 + lib/helpers/constants.dart | 4 + lib/helpers/route_page.dart | 2 + lib/main.dart | 9 + lib/services/analytics/analytic_service.dart | 230 ++++++++++++++++++ lib/services/analytics/locator.dart | 7 + lib/services/auth_service.dart | 11 +- lib/views/auth/login_view.dart | 9 +- lib/views/auth/signup_view.dart | 10 + lib/views/cart_view.dart | 7 +- lib/views/change_username_password.dart | 7 + lib/views/get_user_details_view.dart | 7 +- lib/views/home_view.dart | 16 +- lib/views/profile/orders.dart | 7 + lib/views/profile/profile_view.dart | 7 + lib/views/profile/settings/about.dart | 7 + .../profile/settings/address_screen.dart | 7 + lib/views/profile/settings/faqs_screen.dart | 7 + .../profile/settings/github_webview.dart | 11 +- .../profile/settings/manage_address.dart | 7 + .../settings/notifications_toggle.dart | 7 + .../settings/privacy_policy_screen.dart | 7 + lib/views/profile/settings/settings_view.dart | 7 + lib/views/profile/wishlist.dart | 7 + lib/views/search_view.dart | 8 + lib/views/terms_conditions_view.dart | 7 + lib/widgets/payment/payment_successful.dart | 3 + lib/widgets/payment/payment_window.dart | 4 + lib/widgets/product/product_page.dart | 7 + pubspec.yaml | 2 + 30 files changed, 425 insertions(+), 9 deletions(-) create mode 100644 lib/services/analytics/analytic_service.dart create mode 100644 lib/services/analytics/locator.dart diff --git a/lib/dashboard.dart b/lib/dashboard.dart index a3b67bb..ffe3eb6 100644 --- a/lib/dashboard.dart +++ b/lib/dashboard.dart @@ -1,10 +1,13 @@ import 'package:flutter/material.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; import 'package:provider/provider.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/views/cart_view.dart'; import 'package:relic_bazaar/views/home_view.dart'; import 'package:relic_bazaar/views/search_view.dart'; import 'helpers/ad_state.dart'; +import 'helpers/constants.dart'; import 'views/profile/profile_view.dart'; import 'widgets/bottom_nav_bar.dart'; diff --git a/lib/helpers/constants.dart b/lib/helpers/constants.dart index 836a410..ca544d7 100644 --- a/lib/helpers/constants.dart +++ b/lib/helpers/constants.dart @@ -35,5 +35,9 @@ class RelicColors { static const Color warningColor = Color(0xffE04A3A); } +// ignore: avoid_classes_with_only_static_members +class UserDetails{ + static String uid=''; +} const String svgIv5cq2 = ''; diff --git a/lib/helpers/route_page.dart b/lib/helpers/route_page.dart index 14bc18d..c8f4a4e 100644 --- a/lib/helpers/route_page.dart +++ b/lib/helpers/route_page.dart @@ -27,6 +27,7 @@ import 'package:relic_bazaar/views/unknown_view.dart'; import 'package:relic_bazaar/widgets/payment/payment_successful.dart'; import 'package:relic_bazaar/widgets/product/product_page.dart'; + class RoutePage { static Route generateRoute(RouteSettings settings) { switch (settings.name) { @@ -34,6 +35,7 @@ class RoutePage { return SlideLeftRoute( page: const Cart(), ); + case RouteConstant.getUserDetailsView: return SlideLeftRoute( page: GetUserDetailsView(), diff --git a/lib/main.dart b/lib/main.dart index 935ad71..71f194e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,6 +8,8 @@ import 'package:relic_bazaar/dashboard.dart'; import 'package:relic_bazaar/helpers/ad_state.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/helpers/route_page.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/views/auth/login_view.dart'; import 'package:relic_bazaar/views/get_user_details_view.dart'; @@ -29,6 +31,8 @@ Future main() async { _remoteConfigService = await RemoteConfigService.getInstance(); await _remoteConfigService.initialize(); + //locator + await setUpLocator(); runApp( Provider.value( value: adState, @@ -38,6 +42,7 @@ Future main() async { } class MyApp extends StatelessWidget { + //initializing firebase analytics @override Widget build(BuildContext context) { return GestureDetector( @@ -49,6 +54,10 @@ class MyApp extends StatelessWidget { } }, child: MaterialApp( + //observers for the app + navigatorObservers: [ + locator().getAnalyticsObserver(), + ], builder: (BuildContext context, Widget child) { return ScrollConfiguration( behavior: CustomScrollBehavior(), diff --git a/lib/services/analytics/analytic_service.dart b/lib/services/analytics/analytic_service.dart new file mode 100644 index 0000000..e12b48d --- /dev/null +++ b/lib/services/analytics/analytic_service.dart @@ -0,0 +1,230 @@ +import 'package:firebase_analytics/firebase_analytics.dart'; +import 'package:firebase_analytics/observer.dart'; +import 'package:flutter/cupertino.dart'; + +class AnalyticsService { + + final FirebaseAnalytics _analytics = FirebaseAnalytics(); + FirebaseAnalyticsObserver getAnalyticsObserver() => + FirebaseAnalyticsObserver(analytics: _analytics); + + //how to add analytics to a new screen? + //create a Future async function + //create an instance of analyticservice inside the required file like: + // final AnalyticsService analyticsService = locator(); + //call the function with required parameters + Future logLogin({@required String userId}) async { + await _analytics.logEvent( + name: 'Login', + parameters: { + 'userId': userId, + }); + } + Future loginError({@required String userId}) async { + await _analytics.logEvent( + name: 'LoginError', + parameters: { + 'userId': userId, + }); + } + + Future logSignUp({@required String userId}) async { + await _analytics.logEvent( + name: 'SignUp', + parameters: { + 'userId': userId, + }); + } + + Future logSignOut({@required String userId}) async { + await _analytics.logEvent( + name: "SignOut", + parameters: { + 'userId': userId, + }); + } + + Future backToShop({@required String userId}) async { + await _analytics.logEvent( + name: "BackToShop", + parameters: { + 'userId': userId, + } + ); + } + + Future home({@required String userId}) async { + await _analytics.logEvent( + name: "Home", + parameters: { + 'userId': userId, + } + ); + } + + Future search({@required String userId}) async { + await _analytics.logEvent( + name: "SearchScreen", + parameters: { + 'userId': userId, + } + ); + } + Future profilePage({@required String userId}) async { + await _analytics.logEvent( + name: "ProfilePage", + parameters: { + 'userId': userId, + } + ); + } + Future about({@required String userId}) async { + await _analytics.logEvent( + name: "About", + parameters: { + 'userId': userId, + } + ); + } + Future dashboard({@required String userId}) async { + await _analytics.logEvent( + name: "Dashboard", + parameters: { + 'userId': userId, + } + ); + } + Future productPage({@required String userId}) async { + await _analytics.logEvent( + name: "Product Page", + parameters: { + 'userId': userId, + } + ); + } + Future wishList({@required String userId}) async { + await _analytics.logEvent( + name: "Wishlist", + parameters: { + 'userId': userId, + } + ); + } + Future manageAddress({@required String userId}) async { + await _analytics.logEvent( + name: "Manage Address", + parameters: { + 'userId': userId, + } + ); + } + Future order({@required String userId}) async { + await _analytics.logEvent( + name: "Order", + parameters: { + 'userId': userId, + } + ); + } + Future changeUsername({@required String userId}) async { + await _analytics.logEvent( + name: "Change Usename", + parameters: { + 'userId': userId, + } + ); + } + Future settings({@required String userId}) async { + await _analytics.logEvent( + name: "Settings", + parameters: { + 'userId': userId, + } + ); + } + + Future privacyPolicy({@required String userId}) async { + await _analytics.logEvent( + name: "Privacy Policy", + parameters: { + 'userId': userId, + } + ); + } + Future notification({@required String userId}) async { + await _analytics.logEvent( + name: "ToggleNotification", + parameters: { + 'userId': userId, + } + ); + } + Future termsAndConditions({@required String userId}) async { + await _analytics.logEvent( + name: "TermsConditions", + parameters: { + 'userId': userId, + } + ); + } + Future getUserDetails({@required String userId}) async { + await _analytics.logEvent( + name: "GetUserDetails", + parameters: { + 'userId': userId, + } + ); + } + Future faq({@required String userId}) async { + await _analytics.logEvent( + name: "FAQ", + parameters: { + 'userId': userId, + } + ); + } + Future successPayment({@required String userId}) async { + await _analytics.logEvent( + name: "SuccessfulPayment", + parameters: { + 'userId': userId, + } + ); + } + Future gitWebView({@required String userId}) async { + await _analytics.logEvent( + name: "GitWebView", + parameters: { + 'userId': userId, + } + ); + } + Future drawer({@required String userId}) async { + await _analytics.logEvent( + name: "MenuOpened", + parameters: { + 'userId': userId, + } + ); + } + Future visitCartClicked({@required String userId}) async { + await _analytics.logEvent( + name: "VisitCart", + parameters: { + 'userId': userId, + } + ); + } + Future cartScreen({@required String userId}) async { + await _analytics.logEvent( + name: "CartScreen", + parameters: { + 'userId': userId, + } + ); + } + Future setUserProperties({@required String userId}) async { + await _analytics.setUserId(userId); + } + +} diff --git a/lib/services/analytics/locator.dart b/lib/services/analytics/locator.dart new file mode 100644 index 0000000..56395b0 --- /dev/null +++ b/lib/services/analytics/locator.dart @@ -0,0 +1,7 @@ +import 'package:get_it/get_it.dart'; +import 'analytic_service.dart'; + +GetIt locator = GetIt.instance; +void setUpLocator(){ + locator.registerLazySingleton(() => AnalyticsService()); +} \ No newline at end of file diff --git a/lib/services/auth_service.dart b/lib/services/auth_service.dart index 104ee29..12d38ea 100644 --- a/lib/services/auth_service.dart +++ b/lib/services/auth_service.dart @@ -2,10 +2,14 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:google_sign_in/google_sign_in.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; +import 'package:relic_bazaar/helpers/constants.dart'; + +import 'analytics/analytic_service.dart'; +import 'analytics/locator.dart'; class AuthenticationService { final FirebaseAuth _auth = FirebaseAuth.instance; - + final AnalyticsService analyticsService = locator(); static Future addUserToFirebase({ String uid, String email, @@ -55,6 +59,7 @@ class AuthenticationService { final User currentUser = FirebaseAuth.instance.currentUser; assert(user.uid == currentUser.uid); await addUserToFirebase(uid: user.uid, email: user.email); + UserDetails.uid = user.uid; await updateUserInFirebase( uid: user.uid, imageUrl: user.photoURL, @@ -90,6 +95,7 @@ class AuthenticationService { password: password, ); final User user = newUser.user; + UserDetails.uid = user.uid; await addUserToFirebase( uid: user.uid, email: user.email, @@ -122,6 +128,7 @@ class AuthenticationService { await _auth.signInWithEmailAndPassword(email: email, password: password); } on FirebaseAuthException catch (e) { String errorTemp; + await analyticsService.loginError(userId: UserDetails.uid); switch (e.code) { case 'invalid-email': errorTemp = 'Invalid Email'; @@ -135,6 +142,7 @@ class AuthenticationService { default: errorTemp = 'Invalid request. Please try again later'; } + return errorTemp; } return null; @@ -148,6 +156,7 @@ class AuthenticationService { } Future logout() async { + await analyticsService.logSignOut(userId: UserDetails.uid); await userSignOut(); await signOutGoogle(); } diff --git a/lib/views/auth/login_view.dart b/lib/views/auth/login_view.dart index 676aa24..e6a3c0d 100644 --- a/lib/views/auth/login_view.dart +++ b/lib/views/auth/login_view.dart @@ -1,7 +1,10 @@ +import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:modal_progress_hud/modal_progress_hud.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/helpers/input_validators.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/services/auth_service.dart'; import 'package:relic_bazaar/widgets/show_error_dialog.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; @@ -16,6 +19,7 @@ class LoginScreen extends StatefulWidget { class LoginScreenState extends State { final GlobalKey _formKey = GlobalKey(); + final AnalyticsService analyticsService = locator(); String _email, _password; FocusNode _emailFocusNode, _passwordFocusNode, _loginFocusNode; @@ -158,7 +162,7 @@ class LoginScreenState extends State { Flexible( flex: 2, child: InkWell( - onTap: () { + onTap: () async{ _formKey.currentState.save(); _inputValidator( email: _email, @@ -271,6 +275,9 @@ class LoginScreenState extends State { setState(() { _loading = false; }); + final FirebaseAuth _auth = FirebaseAuth.instance; + UserDetails.uid = await _auth.currentUser.uid; + await analyticsService.logLogin(userId: UserDetails.uid); if (_errorMessage != null) { showErrorDialog( errorMessage: _errorMessage, diff --git a/lib/views/auth/signup_view.dart b/lib/views/auth/signup_view.dart index abf61d3..8029a7e 100644 --- a/lib/views/auth/signup_view.dart +++ b/lib/views/auth/signup_view.dart @@ -1,6 +1,10 @@ +import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:modal_progress_hud/modal_progress_hud.dart'; +import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/helpers/input_validators.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; import 'package:relic_bazaar/services/auth_service.dart'; import 'package:relic_bazaar/widgets/show_error_dialog.dart'; @@ -15,6 +19,7 @@ class SignUpScreen extends StatefulWidget { class SignUpScreenState extends State { final GlobalKey _formKey = GlobalKey(); + final AnalyticsService analyticsService = locator(); bool showPassword = true, showConfirmPassword = true, _loading = false; String _email, _password, _confirmPassword; @@ -308,6 +313,11 @@ class SignUpScreenState extends State { email: email, password: password, ); + + final FirebaseAuth _auth = FirebaseAuth.instance; + UserDetails.uid = await _auth.currentUser.uid; + // print(UserDetails.uid); + await analyticsService.logSignUp(userId: UserDetails.uid); setState(() { _loading = false; }); diff --git a/lib/views/cart_view.dart b/lib/views/cart_view.dart index 7c6f461..3662b59 100644 --- a/lib/views/cart_view.dart +++ b/lib/views/cart_view.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/payment/cart_item.dart'; import 'package:relic_bazaar/widgets/payment/payment_window.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; @@ -21,6 +23,8 @@ class _CartState extends State { Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; + final AnalyticsService analyticsService = locator(); + return Padding( padding: const EdgeInsets.symmetric( horizontal: 12, @@ -46,7 +50,8 @@ class _CartState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ GestureDetector( - onTap: () { + onTap: () async{ + await analyticsService.backToShop(userId: UserDetails.uid); setState(() { widget.pageController.jumpTo(0); }); diff --git a/lib/views/change_username_password.dart b/lib/views/change_username_password.dart index 3f711c1..ffdd373 100644 --- a/lib/views/change_username_password.dart +++ b/lib/views/change_username_password.dart @@ -1,6 +1,8 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; import 'package:relic_bazaar/widgets/text_field_decoration.dart'; @@ -48,6 +50,7 @@ class ChangeUsernameState extends State { Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; + analyticsUpdate(); return Scaffold( appBar: AppBar( backgroundColor: RelicColors.backgroundColor, @@ -183,4 +186,8 @@ class ChangeUsernameState extends State { ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.changeUsername(userId: UserDetails.uid); + } } diff --git a/lib/views/get_user_details_view.dart b/lib/views/get_user_details_view.dart index 5bd2223..ab17770 100644 --- a/lib/views/get_user_details_view.dart +++ b/lib/views/get_user_details_view.dart @@ -4,8 +4,11 @@ import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:image_picker/image_picker.dart'; import 'package:modal_progress_hud/modal_progress_hud.dart'; +import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/helpers/input_validators.dart'; import 'package:relic_bazaar/model/user_model.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/services/cloud_storage_service.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; import 'package:relic_bazaar/widgets/show_error_dialog.dart'; @@ -18,6 +21,7 @@ class GetUserDetailsView extends StatefulWidget { class _GetUserDetailsViewState extends State { final GlobalKey _formKey = GlobalKey(); + final AnalyticsService analyticsService = locator(); final FocusNode _nameFocusNode = FocusNode(), _phoneNumberFocusNode = FocusNode(); @@ -169,7 +173,8 @@ class _GetUserDetailsViewState extends State { height: _height * 0.07, width: _width * 0.4, child: TextButton( - onPressed: () { + onPressed: () async{ + await analyticsService.getUserDetails(userId: UserDetails.uid); _formKey.currentState.save(); _inputValidator( name: _name, diff --git a/lib/views/home_view.dart b/lib/views/home_view.dart index 8786559..c6a21a7 100644 --- a/lib/views/home_view.dart +++ b/lib/views/home_view.dart @@ -3,6 +3,8 @@ import 'package:flutter/material.dart'; import 'package:relic_bazaar/helpers/app_icons.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/model/product_model.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/services/product_service.dart'; import 'package:relic_bazaar/views/drawer_view.dart'; import 'package:relic_bazaar/widgets/product/product_card.dart'; @@ -20,6 +22,7 @@ class Home extends StatefulWidget { class _HomeState extends State { final GlobalKey _drawerKey = GlobalKey(); + final AnalyticsService analyticsService = locator(); void _openDrawer() { _drawerKey.currentState.openDrawer(); @@ -35,6 +38,7 @@ class _HomeState extends State { Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; + analyticsUpdate(); return Scaffold( key: _drawerKey, drawer: DrawerWidget( @@ -129,7 +133,8 @@ class _HomeState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ GestureDetector( - onTap: () { + onTap: () async { + await analyticsService.drawer(userId: UserDetails.uid); _openDrawer(); }, child: const RelicBazaarStackedView( @@ -141,7 +146,10 @@ class _HomeState extends State { ), ), GestureDetector( - onTap: _goToCart, + onTap: () async { + await analyticsService.visitCartClicked(userId: UserDetails.uid); + _goToCart(); + }, child: const RelicBazaarStackedView( upperColor: Colors.white, width: 35, @@ -194,4 +202,8 @@ class _HomeState extends State { textAlign: TextAlign.left, ); } + + void analyticsUpdate() async { + await analyticsService.home(userId: UserDetails.uid); + } } diff --git a/lib/views/profile/orders.dart b/lib/views/profile/orders.dart index ef80222..accc743 100644 --- a/lib/views/profile/orders.dart +++ b/lib/views/profile/orders.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/back_button.dart'; import 'package:relic_bazaar/widgets/payment/order_item.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; @@ -9,6 +11,7 @@ class Order extends StatelessWidget { Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; + analyticsUpdate(); return Scaffold( appBar: AppBar( elevation: 0, @@ -81,4 +84,8 @@ class Order extends StatelessWidget { ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.order(userId: UserDetails.uid); + } } diff --git a/lib/views/profile/profile_view.dart b/lib/views/profile/profile_view.dart index e1244ff..c65e3fb 100644 --- a/lib/views/profile/profile_view.dart +++ b/lib/views/profile/profile_view.dart @@ -3,6 +3,8 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/model/user_model.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/services/db_userdata.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; @@ -123,6 +125,7 @@ class TopSection extends StatelessWidget { final String joiningDate = DateFormat.yMMMM() .format(_currentUser.metadata.creationTime) .toUpperCase(); + analyticsUpdate(); return Stack( children: [ Row( @@ -195,4 +198,8 @@ class TopSection extends StatelessWidget { ], ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.profilePage(userId: UserDetails.uid); + } } diff --git a/lib/views/profile/settings/about.dart b/lib/views/profile/settings/about.dart index 1fd76ec..3046934 100644 --- a/lib/views/profile/settings/about.dart +++ b/lib/views/profile/settings/about.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/back_button.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; @@ -8,6 +10,7 @@ class AboutScreen extends StatelessWidget { Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; + analyticsUpdate(); return Scaffold( appBar: AppBar( leading: appBarBackButton(context), @@ -191,4 +194,8 @@ class AboutScreen extends StatelessWidget { ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.about(userId: UserDetails.uid); + } } diff --git a/lib/views/profile/settings/address_screen.dart b/lib/views/profile/settings/address_screen.dart index f236b44..a81fd8d 100644 --- a/lib/views/profile/settings/address_screen.dart +++ b/lib/views/profile/settings/address_screen.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/model/address_model.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/back_button.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; @@ -14,6 +16,7 @@ class _AddressScreenState extends State { Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; + analyticsUpdate(); return Scaffold( appBar: AppBar( centerTitle: true, @@ -85,4 +88,8 @@ class _AddressScreenState extends State { ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.manageAddress(userId: UserDetails.uid); + } } diff --git a/lib/views/profile/settings/faqs_screen.dart b/lib/views/profile/settings/faqs_screen.dart index af6d292..f76817f 100644 --- a/lib/views/profile/settings/faqs_screen.dart +++ b/lib/views/profile/settings/faqs_screen.dart @@ -1,6 +1,8 @@ import 'package:advance_pdf_viewer/advance_pdf_viewer.dart'; import 'package:flutter/material.dart'; import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/back_button.dart'; class FaqsScreen extends StatefulWidget { @@ -41,6 +43,7 @@ class _FaqsScreenState extends State { @override Widget build(BuildContext context) { + analyticsUpdate(); return Scaffold( appBar: AppBar( backgroundColor: RelicColors.backgroundColor, @@ -60,4 +63,8 @@ class _FaqsScreenState extends State { ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.faq(userId: UserDetails.uid); + } } diff --git a/lib/views/profile/settings/github_webview.dart b/lib/views/profile/settings/github_webview.dart index 3400c8a..f8b7c50 100644 --- a/lib/views/profile/settings/github_webview.dart +++ b/lib/views/profile/settings/github_webview.dart @@ -1,14 +1,15 @@ //Packages import 'package:flutter/material.dart'; +import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/back_button.dart'; import 'package:webview_flutter/webview_flutter.dart'; -//Files -import '../../../helpers/constants.dart'; - class GithubWebView extends StatelessWidget { @override Widget build(BuildContext context) { + analyticsUpdate(); return Scaffold( appBar: AppBar( backgroundColor: RelicColors.backgroundColor, @@ -23,4 +24,8 @@ class GithubWebView extends StatelessWidget { ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.gitWebView(userId: UserDetails.uid); + } } diff --git a/lib/views/profile/settings/manage_address.dart b/lib/views/profile/settings/manage_address.dart index 7e0d017..c8e9e19 100644 --- a/lib/views/profile/settings/manage_address.dart +++ b/lib/views/profile/settings/manage_address.dart @@ -3,6 +3,8 @@ import 'package:geocoder/geocoder.dart'; import 'package:geolocator/geolocator.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/model/address_model.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/address_text_field.dart'; import 'package:relic_bazaar/widgets/back_button.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; @@ -45,6 +47,7 @@ class _ManageAddressState extends State { final double width = MediaQuery.of(context).size.width; final double height = MediaQuery.of(context).size.height; + analyticsUpdate(); final List steps = [ Step( title: const Text('Info'), @@ -321,4 +324,8 @@ class _ManageAddressState extends State { ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.wishList(userId: UserDetails.uid); + } } diff --git a/lib/views/profile/settings/notifications_toggle.dart b/lib/views/profile/settings/notifications_toggle.dart index da2f44a..b0ada13 100644 --- a/lib/views/profile/settings/notifications_toggle.dart +++ b/lib/views/profile/settings/notifications_toggle.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/back_button.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; @@ -13,6 +15,7 @@ class _NotificationToggleState extends State { @override Widget build(BuildContext context) { + analyticsUpdate(); return Scaffold( appBar: AppBar( backgroundColor: RelicColors.backgroundColor, @@ -74,4 +77,8 @@ class _NotificationToggleState extends State { ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.notification(userId: UserDetails.uid); + } } diff --git a/lib/views/profile/settings/privacy_policy_screen.dart b/lib/views/profile/settings/privacy_policy_screen.dart index c735217..2391ab0 100644 --- a/lib/views/profile/settings/privacy_policy_screen.dart +++ b/lib/views/profile/settings/privacy_policy_screen.dart @@ -1,11 +1,14 @@ import 'package:flutter/material.dart'; import 'package:flutter_html/flutter_html.dart'; import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; class PrivacyPolicyScreen extends StatelessWidget { @override Widget build(BuildContext context) { + analyticsUpdate(); final Widget html = Html(data: """

Last updated: April 09, 2021

This Privacy Policy describes Our policies and procedures on the collection, use and disclosure of Your information when You use the Service and tells You about Your privacy rights and how the law protects You.

@@ -178,4 +181,8 @@ class PrivacyPolicyScreen extends StatelessWidget { ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.privacyPolicy(userId: UserDetails.uid); + } } diff --git a/lib/views/profile/settings/settings_view.dart b/lib/views/profile/settings/settings_view.dart index 4840148..62cc609 100644 --- a/lib/views/profile/settings/settings_view.dart +++ b/lib/views/profile/settings/settings_view.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/services/auth_service.dart'; import 'package:relic_bazaar/widgets/back_button.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; @@ -30,6 +32,7 @@ class _SettingsState extends State { @override Widget build(BuildContext context) { + analyticsUpdate(); return Scaffold( appBar: AppBar( backgroundColor: RelicColors.backgroundColor, @@ -134,4 +137,8 @@ class _SettingsState extends State { ), )); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.settings(userId: UserDetails.uid); + } } diff --git a/lib/views/profile/wishlist.dart b/lib/views/profile/wishlist.dart index 180d514..2db67b2 100644 --- a/lib/views/profile/wishlist.dart +++ b/lib/views/profile/wishlist.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/back_button.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; import 'package:relic_bazaar/widgets/payment/order_item.dart'; @@ -16,6 +18,7 @@ class _WishlistState extends State { Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; + analyticsUpdate(); return Scaffold( appBar: AppBar( elevation: 0, @@ -82,4 +85,8 @@ class _WishlistState extends State { ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.wishList(userId: UserDetails.uid); + } } diff --git a/lib/views/search_view.dart b/lib/views/search_view.dart index ffe5f7f..220016d 100644 --- a/lib/views/search_view.dart +++ b/lib/views/search_view.dart @@ -1,6 +1,9 @@ import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/services/remote_config.dart'; import 'package:relic_bazaar/widgets/search_bar.dart'; import 'package:carousel_slider/carousel_slider.dart'; @@ -35,6 +38,7 @@ class _SearchState extends State { @override Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; + analyticsUpdate(); return SafeArea( child: Column( children: [ @@ -76,4 +80,8 @@ class _SearchState extends State { ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.search(userId: UserDetails.uid); + } } diff --git a/lib/views/terms_conditions_view.dart b/lib/views/terms_conditions_view.dart index f8b25cf..0081543 100644 --- a/lib/views/terms_conditions_view.dart +++ b/lib/views/terms_conditions_view.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; class TermsConditionsView extends StatelessWidget { @@ -7,6 +9,7 @@ class TermsConditionsView extends StatelessWidget { Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; + analyticsUpdate(); return Scaffold( body: SafeArea( child: SingleChildScrollView( @@ -208,4 +211,8 @@ As long as the website and the information and services on the website are provi ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.termsAndConditions(userId: UserDetails.uid); + } } diff --git a/lib/widgets/payment/payment_successful.dart b/lib/widgets/payment/payment_successful.dart index 785c439..f695f0f 100644 --- a/lib/widgets/payment/payment_successful.dart +++ b/lib/widgets/payment/payment_successful.dart @@ -1,9 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; class PaymentSuccessful extends StatelessWidget { + const PaymentSuccessful({ Key key, }) : super(key: key); diff --git a/lib/widgets/payment/payment_window.dart b/lib/widgets/payment/payment_window.dart index 5e6b2f3..7138234 100644 --- a/lib/widgets/payment/payment_window.dart +++ b/lib/widgets/payment/payment_window.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:relic_bazaar/helpers/constants.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/retro_button.dart'; import 'package:razorpay_flutter/razorpay_flutter.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -50,7 +52,9 @@ class _PaymentWindowState extends State { } Future _handlePaymentSuccess(PaymentSuccessResponse response) async { + final AnalyticsService analyticsService = locator(); Fluttertoast.showToast(msg: 'SUCCESS: ${response.paymentId}'); + await analyticsService.successPayment(userId: UserDetails.uid); Navigator.of(context).pushNamed(RouteConstant.PAYMENT_SUCCESSFULL); } diff --git a/lib/widgets/product/product_page.dart b/lib/widgets/product/product_page.dart index e4003a6..20dea2a 100644 --- a/lib/widgets/product/product_page.dart +++ b/lib/widgets/product/product_page.dart @@ -4,6 +4,8 @@ import 'package:provider/provider.dart'; import 'package:relic_bazaar/helpers/ad_state.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/model/product_model.dart'; +import 'package:relic_bazaar/services/analytics/analytic_service.dart'; +import 'package:relic_bazaar/services/analytics/locator.dart'; import 'package:relic_bazaar/widgets/back_button.dart'; import '../../helpers/app_icons.dart'; import '../retro_button.dart'; @@ -42,6 +44,7 @@ class _ProductPageState extends State { Widget build(BuildContext context) { final double height = MediaQuery.of(context).size.height; final double width = MediaQuery.of(context).size.width; + analyticsUpdate(); return Scaffold( appBar: AppBar( elevation: 0.0, @@ -332,4 +335,8 @@ class _ProductPageState extends State { ), ); } + void analyticsUpdate()async{ + final AnalyticsService analyticsService = locator(); + await analyticsService.productPage(userId: UserDetails.uid); + } } diff --git a/pubspec.yaml b/pubspec.yaml index ab4730e..e881c19 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -46,6 +46,8 @@ dependencies: image_picker: any firebase_storage: 7.0.0 intl: ^0.16.0 + firebase_analytics: + get_it: ^6.1.1 dev_dependencies: flutter_test: