Skip to content

Commit

Permalink
feat: initialize mixpanel
Browse files Browse the repository at this point in the history
Signed-off-by: Aman <[email protected]>
  • Loading branch information
aman-singh7 committed Jan 16, 2024
1 parent 16885b1 commit ce22431
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/data/constants/env_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
12 changes: 12 additions & 0 deletions lib/domain/amenity/mixpanel_service.dart
Original file line number Diff line number Diff line change
@@ -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<Mixpanel> init() async {
instance ??= await Mixpanel.init(EnvironmentConfig.MIXPANEL_PROJECT_KEY,
trackAutomaticEvents: true);
return instance!;
}
}
3 changes: 3 additions & 0 deletions lib/presentation/app/bloc/app_bloc.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -70,6 +71,8 @@ class AppBloc extends Bloc<AppEvent, AppState> {

FutureOr<void> _onNavigateToHome(
NavigateToHomeScreen event, Emitter<AppState> emit) {
assert(state.user != null);
MixpanelManager.instance?.identify(state.user!.enrNo.toString());
emit(state.copyWith(navigateTo: NavigateTo.showHomeScreen));
}

Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ce22431

Please sign in to comment.