Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initialize mixpanel #276

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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