From ce224312d2c08cd827866656150a979ba1b717f6 Mon Sep 17 00:00:00 2001 From: Aman Date: Tue, 16 Jan 2024 16:31:30 +0530 Subject: [PATCH] feat: initialize mixpanel Signed-off-by: Aman --- lib/data/constants/env_config.dart | 2 ++ lib/domain/amenity/mixpanel_service.dart | 12 ++++++++++++ lib/presentation/app/bloc/app_bloc.dart | 3 +++ pubspec.lock | 8 ++++++++ pubspec.yaml | 1 + 5 files changed, 26 insertions(+) create mode 100644 lib/domain/amenity/mixpanel_service.dart diff --git a/lib/data/constants/env_config.dart b/lib/data/constants/env_config.dart index cc1de10c..cb33130f 100644 --- a/lib/data/constants/env_config.dart +++ b/lib/data/constants/env_config.dart @@ -15,4 +15,6 @@ class EnvironmentConfig { ); static const String SENTRY_DSN = String.fromEnvironment('SENTRY_DSN'); + static const String MIXPANEL_PROJECT_KEY = + String.fromEnvironment('MIXPANEL_PROJECT_KEY'); } diff --git a/lib/domain/amenity/mixpanel_service.dart b/lib/domain/amenity/mixpanel_service.dart new file mode 100644 index 00000000..acef3b61 --- /dev/null +++ b/lib/domain/amenity/mixpanel_service.dart @@ -0,0 +1,12 @@ +import 'package:appetizer/data/constants/env_config.dart'; +import 'package:mixpanel_flutter/mixpanel_flutter.dart'; + +class MixpanelManager { + static Mixpanel? instance; + + static Future init() async { + instance ??= await Mixpanel.init(EnvironmentConfig.MIXPANEL_PROJECT_KEY, + trackAutomaticEvents: true); + return instance!; + } +} diff --git a/lib/presentation/app/bloc/app_bloc.dart b/lib/presentation/app/bloc/app_bloc.dart index 24b50b84..846f04ae 100644 --- a/lib/presentation/app/bloc/app_bloc.dart +++ b/lib/presentation/app/bloc/app_bloc.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:appetizer/data/constants/constants.dart'; import 'package:appetizer/data/services/local/local_storage_service.dart'; +import 'package:appetizer/domain/amenity/mixpanel_service.dart'; import 'package:appetizer/domain/models/user/user.dart'; import 'package:appetizer/domain/repositories/leave/leave_repository.dart'; import 'package:appetizer/domain/repositories/user/user_repository.dart'; @@ -70,6 +71,8 @@ class AppBloc extends Bloc { FutureOr _onNavigateToHome( NavigateToHomeScreen event, Emitter emit) { + assert(state.user != null); + MixpanelManager.instance?.identify(state.user!.enrNo.toString()); emit(state.copyWith(navigateTo: NavigateTo.showHomeScreen)); } diff --git a/pubspec.lock b/pubspec.lock index 617a7071..ce024ffd 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -749,6 +749,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.4" + mixpanel_flutter: + dependency: "direct main" + description: + name: mixpanel_flutter + sha256: "5dc993ade5eaad51ebb6c91230971a3443ac30a3d1d24399bc3db74c5705d400" + url: "https://pub.dev" + source: hosted + version: "2.2.0" month_picker_dialog: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 9d558ab7..3588c6ae 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -45,6 +45,7 @@ dependencies: url_launcher: ^6.1.12 flutter_inappwebview: ^6.0.0 flutter_native_splash: ^2.3.2 + mixpanel_flutter: ^2.2.0 dev_dependencies: auto_route_generator: ^7.1.2