Skip to content

Commit

Permalink
refactor(service): mixpanel service implementation (#41)
Browse files Browse the repository at this point in the history
* fix: change secrets env target path

* feat(service): initializing mixpanel service

* refactor(service): mixpanel service implementation

* fix(review): remove hardcoded year dropdown

---------

Co-authored-by: Veloraine <[email protected]>
Co-authored-by: Yudha Haris Purnama <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2023
1 parent 7b82379 commit c1eccfb
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 110 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.ristek.ulaskelas"
minSdkVersion 19
targetSdkVersion 30
minSdkVersion 26
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
Expand Down
2 changes: 2 additions & 0 deletions lib/app_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:ristek_material_component/ristek_material_component.dart';
import 'package:ulaskelas/core/_core.dart';
import 'package:ulaskelas/core/bases/widgets/confirmation_modal_dialog.dart';
import 'package:ulaskelas/core/theme/_theme.dart';
import 'package:ulaskelas/services/_services.dart';
import 'package:ulaskelas/services/launch_service.dart';
import 'package:ulaskelas/services/versioning/check_version.dart';

Expand All @@ -27,6 +28,7 @@ class _AppWrapperState extends State<AppWrapper> {
@override
void initState() {
super.initState();
MixpanelService.track('open_app');
splashTime();
}

Expand Down
3 changes: 3 additions & 0 deletions lib/authentication_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:ristek_material_component/ristek_material_component.dart';
import 'package:states_rebuilder/states_rebuilder.dart';
import 'package:ulaskelas/features/matkul/bookmarks/domain/entities/query_bookmark.dart';
import 'package:ulaskelas/services/_services.dart';

import 'core/bases/states/_states.dart';
import 'core/constants/_constants.dart';
Expand Down Expand Up @@ -69,6 +70,7 @@ Aplikasi ulasan mata kuliah Fasilkom UI.\nMasuk dan buat ulasanmu sekarang!''',
}

Future<void> _ssoLogin() async {
MixpanelService.track('login');
if (authRM.state.isLoading) {
return;
}
Expand All @@ -81,6 +83,7 @@ Aplikasi ulasan mata kuliah Fasilkom UI.\nMasuk dan buat ulasanmu sekarang!''',
await Future.delayed(const Duration(seconds: 1));
await authRM.setState((s) => s.ssoLogin());
if (authRM.state.isLogin) {
MixpanelService.track('login_success');
await profileRM.state.retrieveData();
await bookmarkRM.state.retrieveData(QueryBookmark());
if (profileRM.state.profile.isBlocked ?? false) {
Expand Down
2 changes: 2 additions & 0 deletions lib/core/bases/states/_states.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import 'package:ulaskelas/onboarding_page.dart';
import 'package:ulaskelas/services/_services.dart';
import 'package:universal_html/html.dart';

import '../../utils/util.dart';

part 'auth_state.dart';
part 'cleaner.dart';
part 'global_state.dart';
Expand Down
26 changes: 26 additions & 0 deletions lib/core/bases/states/navigation_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class NavigationServiceState implements Navigation {
}

Future<bool?> goToFilterPage() {
MixpanelService.track('open_course_filter');
return nav.push<bool>(
const FilterPage(),
RouteName.mainPage,
Expand All @@ -88,6 +89,7 @@ class NavigationServiceState implements Navigation {
int courseId,
String courseCode,
) {
MixpanelService.track('view_course');
return nav.push<void>(
DetailMatkulPage(
courseId: courseId,
Expand Down Expand Up @@ -116,7 +118,18 @@ class NavigationServiceState implements Navigation {
Future<void> goToAllReviewMatkulPage({
required int courseId,
required String courseCode,
required CourseModel course,
}) {
MixpanelService.track(
'view_all_reviews',
params: {
'course_id': course.code.toString(),
'course_name': course.name.toString(),
'review_count': course.reviewCount.toString(),
'course_rating_avg':
course.ratingAverage.toString(),
},
);
return nav.push<void>(
AllReviewMatkulPage(
courseId: courseId,
Expand All @@ -134,13 +147,15 @@ class NavigationServiceState implements Navigation {
}

Future<void> goToHomeDaftarMatkul() {
MixpanelService.track('view_this_semester_courses');
return nav.push<void>(
const HomeCourseListPage(),
RouteName.homeDaftarMatkul,
);
}

Future<void> goToHomeDaftarUlasan() {
MixpanelService.track('view_all_reviews');
return nav.push<void>(
const HomeDaftarUlasanPage(),
RouteName.homeDaftarUlasan,
Expand Down Expand Up @@ -190,6 +205,7 @@ class NavigationServiceState implements Navigation {
}

Future<void> goToSearchCourseCalculatorPage() {
MixpanelService.track('calculator_add_course');
return nav.push<void>(
const SearchCourseCalculator(),
RouteName.searchCourseCalculator,
Expand All @@ -202,6 +218,16 @@ class NavigationServiceState implements Navigation {
required double totalScore,
required double totalPercentage,
}) {
MixpanelService.track(
'calculator_view_course',
params: {
'course_id': courseName,
'final_letter_grade': getFinalGrade(
totalScore,
),
'final_grade': totalScore.toString(),
},
);
return nav.push<void>(
CalculatorComponentPage(
calculatorId: calculatorId,
Expand Down
6 changes: 1 addition & 5 deletions lib/features/home/presentation/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,7 @@ class _HomePageState extends BaseStateful<HomePage> {
style: FontTheme.poppins14w700black(),
),
InkWell(
onTap: () {
nav.goToHomeDaftarUlasan();

MixpanelService.track('view_all_reviews');
},
onTap: () => nav.goToHomeDaftarUlasan(),
child: Text(
'Lihat Semua',
style: FontTheme.poppins13w400purple(),
Expand Down
30 changes: 7 additions & 23 deletions lib/features/kalkulator/presentation/pages/kalkulator_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ Kamu Belum memiliki kalkulator nilai tersimpan. Silakan tambahkan terlebih dahul
width: double.infinity,
text: 'Tambah Mata Kuliah',
backgroundColor: BaseColors.purpleHearth,
onPressed: () {
nav.goToSearchCourseCalculatorPage();
// ignore: lines_longer_than_80_chars
MixpanelService.track('calculator_add_course');
},
onPressed: () => nav.goToSearchCourseCalculatorPage(),
),
],
),
Expand Down Expand Up @@ -117,23 +113,12 @@ Kamu Belum memiliki kalkulator nilai tersimpan. Silakan tambahkan terlebih dahul
final calculator = calculators[index];
return CardCalculator(
model: calculator,
onTap: () {
nav.goToComponentCalculatorPage(
calculatorId: calculator.id!,
courseName: calculator.courseName!,
totalScore: calculator.totalScore!,
totalPercentage: calculator.totalPercentage!,
);
MixpanelService.track(
'calculator_view_course',
params: {
'course_id': calculator.courseName!,
'final_letter_grade': getFinalGrade(
calculator.totalScore!,),
'final_grade': calculator.totalScore.toString(),
},
);
},
onTap: () => nav.goToComponentCalculatorPage(
calculatorId: calculator.id!,
courseName: calculator.courseName!,
totalScore: calculator.totalScore!,
totalPercentage: calculator.totalPercentage!,
),
);
},
separatorBuilder: (BuildContext context, int index) =>
Expand Down Expand Up @@ -170,5 +155,4 @@ Kamu Belum memiliki kalkulator nilai tersimpan. Silakan tambahkan terlebih dahul
bool scrollCondition() {
throw UnimplementedError();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class _ComponentFormPageState extends BaseStateful<ComponentFormPage> {
text: 'Simpan',
onTap: () async {
await onSubmitCallBack(context);
MixpanelService.track('calculator_add_course_component');
},
),
),
Expand Down Expand Up @@ -91,6 +90,7 @@ class _ComponentFormPageState extends BaseStateful<ComponentFormPage> {
if (componentFormRM.state.isLoading) {
return;
}
MixpanelService.track('calculator_add_course_component');
if (componentFormRM.state.formKey.currentState!.validate()) {
// progressDialogue(context);
await componentFormRM.state.submitForm(widget.calculatorId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,11 @@ class _CalculatorComponentPageState
nav.pop();
calculatorRM.setState(
(s) => s.deleteCalculator(
QueryCalculator(id: widget.calculatorId),
query: QueryCalculator(id: widget.calculatorId,),
courseName: widget.courseName,
totalScore: widget.totalScore,
),
);
MixpanelService.track(
'calculator_delete_course_component',
params: {
'course_id': widget.courseName,
'final_letter_grade': widget.totalScore.toString(),
'final_grade': getFinalGrade(widget.totalScore),
},
);
},
child: Text(
'Hapus Kalkulator Mata Kuliah',
Expand Down
3 changes: 3 additions & 0 deletions lib/features/kalkulator/presentation/states/_states.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import 'package:ulaskelas/features/kalkulator/domain/entities/query_calculator.d
import 'package:ulaskelas/features/kalkulator/domain/entities/query_component.dart';
import 'package:ulaskelas/features/kalkulator/domain/repositories/_repositories.dart';

import '../../../../core/utils/util.dart';
import '../../../../services/_services.dart';

part 'calculator_state.dart';
part 'component_state.dart';
part 'component_form_state.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CalculatorState {

late CalculatorRepository _repo;
List<CalculatorModel>? _calculators;

List<CalculatorModel> get calculators => _calculators ?? [];

bool hasReachedMax = false;
Expand Down Expand Up @@ -49,8 +50,20 @@ class CalculatorState {
calculatorRM.notify();
}

Future<void> deleteCalculator(QueryCalculator query) async {
Future<void> deleteCalculator({
required QueryCalculator query,
required String courseName,
required double totalScore,
}) async {
final resp = await _repo.deleteCalculator(query);
MixpanelService.track(
'calculator_delete_course_component',
params: {
'course_id': courseName,
'final_letter_grade': totalScore.toString(),
'final_grade': getFinalGrade(totalScore),
},
);
await resp.fold((failure) {
ErrorMessenger('Kalkulator gagal dihapus').show(ctx!);
}, (result) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ import 'package:ulaskelas/features/matkul/bookmarks/domain/entities/query_bookma
import 'package:ulaskelas/features/matkul/bookmarks/domain/repositories/_repositories.dart';
import 'package:ulaskelas/features/matkul/search/data/models/_models.dart';

import '../../../../../services/_services.dart';

part 'bookmark_state.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BookmarkState {

/// tap to toggle Bookmark
Future<void> toggleBookmark(BookmarkModel bookmark) async {
MixpanelService.track('bookmark_course');
final resp = await _repo.getAllBookmark(QueryBookmark());
resp.fold((failure) {
throw failure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,11 @@ class _DetailMatkulPageState extends BaseStateful<DetailMatkulPage> {
const HeightSpace(16),
if (course.reviewCount! > 3)
InkWell(
onTap: () {
nav.goToAllReviewMatkulPage(
courseId: widget.courseId,
courseCode: widget.courseCode,
);
MixpanelService.track(
'view_all_reviews',
params: {
'course_id': course.code.toString(),
'course_name': course.name.toString(),
'review_count': course.reviewCount.toString(),
'course_rating_avg':
course.ratingAverage.toString(),
},
);
},
onTap: () => nav.goToAllReviewMatkulPage(
courseId: widget.courseId,
courseCode: widget.courseCode,
course: course,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down Expand Up @@ -237,18 +226,7 @@ class _DetailMatkulPageState extends BaseStateful<DetailMatkulPage> {
final review = data.reviews[data.reviews.length - i - 1];
return ReviewCard(
review: review,
onLiked: () {
reviewCourseRM.state.like(review);
MixpanelService.track(
'like_review',
params: {
'course_id': review.courseCode.toString(),
'course_name': review.courseName.toString(),
'review_count': review.likesCount.toString(),
'course_rating_avg': review.ratingAverage.toString(),
},
);
},
onLiked: () => reviewCourseRM.state.like(review),
);
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,11 @@ class _ReviewMatkulFormPageState extends BaseStateful<ReviewMatkulFormPage> {
reviewFormStateData.ratingFitToStudyBook != null &&
reviewFormStateData.ratingBeneficial != null &&
reviewFormStateData.ratingRecommended != null) {
await reviewFormRM.state
.submitForm(widget.course.code!);
await Future.delayed(const Duration(milliseconds: 150));
MixpanelService.track(
'write_review',
params: {
'course_id': widget.course.code.toString(),
'course_name': widget.course.name.toString(),
'created_at': DateTime.now().toString(),
'period_taking':
reviewFormStateData.semester.toString(),
'year_taking': reviewFormStateData.year.toString(),
'avg_rating_given':
reviewFormState.getAvgRating().toString(),
'tags': reviewFormStateData.tagData.toString(),
'anonymous_review':
reviewFormStateData.isAnonymous.toString(),
},
await reviewFormRM.state.submitForm(
course: widget.course,
);
await Future.delayed(const Duration(milliseconds: 150));

reviewFormRM.state.cleanForm();
nav.pop();
await nav.replaceToReviewPendingPage();
Expand Down
3 changes: 3 additions & 0 deletions lib/features/matkul/form/presentation/states/_states.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import 'package:ulaskelas/features/matkul/form/domain/entities/query_search_tag.
import 'package:ulaskelas/features/matkul/form/domain/repositories/_repositories.dart';
import 'package:ulaskelas/features/matkul/search/domain/entities/_entities.dart';

import '../../../../../services/_services.dart';
import '../../../search/data/models/_models.dart';

part 'review_course_form_state.dart';
part 'search_tag_state.dart';
part 'review_course_state.dart';
Loading

0 comments on commit c1eccfb

Please sign in to comment.