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

Brandon/mixpanel #38

Merged
merged 3 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion lib/core/environment/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Config {
await HiveDataBaseService.init();
}
await Pref.init();
await MixpanelService.init();

// TODO(fauzi): Implement notification plugin
// await notificationPlugin.init();
Expand All @@ -55,6 +56,7 @@ class Config {
}

static bool get isDevelopment => appFlavor == Flavor.development;

static BaseConfig get baseConfig => _baseConfig()!;

static BaseConfig? _baseConfig() {
Expand All @@ -74,8 +76,10 @@ class Config {

class BaseConfig {
const BaseConfig({
required this.endpoints, this.assetAbsolutePath = Constants.assetPath,
required this.endpoints,
this.assetAbsolutePath = Constants.assetPath,
});

final String assetAbsolutePath;
final BaseEndpoints endpoints;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/core/environment/secrets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import 'package:envied/envied.dart';

part 'secrets.g.dart';

@Envied(name: 'Secret', path: '.env.example')
@Envied(name: 'Secret', path: '.env')
abstract class Secret {
@EnviedField(varName: 'BASE_URL_DEV')
static const String baseUrlDev = _Secret.baseUrlDev;
@EnviedField(varName: 'BASE_URL_PROD')
static const String baseUrlProd = _Secret.baseUrlProd;
@EnviedField(varName: 'MIXPANEL_TOKEN')
static const String mixpanelToken = _Secret.mixpanelToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:ulaskelas/features/leaderboard/presentation/widgets/_widgets.dar
import 'package:ulaskelas/features/matkul/bookmarks/data/models/_models.dart';
import 'package:ulaskelas/features/matkul/form/data/models/_models.dart';
import 'package:ulaskelas/features/matkul/search/data/models/_models.dart';
import 'package:ulaskelas/services/_services.dart';
import 'package:ulaskelas/services/launch_service.dart';

part 'review_card.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ part of '_widgets.dart';

class TitleAndBookMark extends StatelessWidget {
const TitleAndBookMark({
required this.course, super.key,
required this.course,
super.key,
});

final CourseModel course;
Expand Down Expand Up @@ -36,6 +37,7 @@ class TitleAndBookMark extends StatelessWidget {
shortName: course.shortName,
);
bookmarkRM.setState((s) => s.toggleBookmark(bookmark));
MixpanelService.track('bookmark_course');
},
child: Icon(
Icons.bookmark,
Expand Down
3 changes: 3 additions & 0 deletions lib/services/_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:intl/intl.dart';
import 'package:logger/logger.dart';
import 'package:mixpanel_flutter/mixpanel_flutter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:share/share.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:ulaskelas/core/_core.dart';
import 'package:ulaskelas/core/environment/secrets.dart';

part 'date_service.dart';
part 'delay_service.dart';
Expand All @@ -19,3 +21,4 @@ part 'file_service.dart';
part 'hive_db_service.dart';
part 'pref_service.dart';
part 'share_service.dart';
part 'mixpanel_service.dart';
30 changes: 30 additions & 0 deletions lib/services/mixpanel_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
part of '_services.dart';

class MixpanelService {
static Mixpanel? _mixpanel;

static Future<void> init() async {
Logger().i('Initializing Mixpanel Service');
_mixpanel = await Mixpanel.init(
Secret.mixpanelToken,
trackAutomaticEvents: true,
);
}

static Future<Mixpanel> get instance async {
return _mixpanel ??= await Mixpanel.init(
Secret.mixpanelToken,
trackAutomaticEvents: true,
);
}

static void track(String eventName, {Map<String, String>? params}) {
_mixpanel!.track(eventName, properties: params);
Logger().i(
'''
Track Events: $eventName,
Parameters: $params
'''
);
}
}
6 changes: 4 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import FlutterMacOS
import Foundation

import firebase_analytics
import firebase_core
import firebase_crashlytics
import package_info
import path_provider_macos
import shared_preferences_macos
import path_provider_foundation
import shared_preferences_foundation
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseAnalyticsPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAnalyticsPlugin"))
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
FLTFirebaseCrashlyticsPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCrashlyticsPlugin"))
FLTPackageInfoPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlugin"))
Expand Down
62 changes: 39 additions & 23 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.18.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -467,10 +467,10 @@ packages:
dependency: "direct main"
description:
name: intl
sha256: a3715e3bc90294e971cb7dc063fbf3cd9ee0ebf8604ffeafabd9e6f16abbdbe6
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
url: "https://pub.dev"
source: hosted
version: "0.18.0"
version: "0.18.1"
io:
dependency: transitive
description:
Expand Down Expand Up @@ -515,18 +515,18 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
material_design_icons_flutter:
dependency: "direct main"
description:
Expand All @@ -539,10 +539,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
mime:
dependency: transitive
description:
Expand All @@ -551,6 +551,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"
navigation_builder:
dependency: transitive
description:
Expand Down Expand Up @@ -651,10 +659,10 @@ packages:
dependency: transitive
description:
name: platform
sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76"
sha256: ae68c7bfcd7383af3629daafb32fb4e8681c7154428da4febcff06200585f102
url: "https://pub.dev"
source: hosted
version: "3.1.0"
version: "3.1.2"
plugin_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -816,18 +824,18 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
states_rebuilder:
dependency: "direct main"
description:
Expand All @@ -840,10 +848,10 @@ packages:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
stream_transform:
dependency: transitive
description:
Expand Down Expand Up @@ -880,10 +888,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.1"
timing:
dependency: transitive
description:
Expand Down Expand Up @@ -1024,10 +1032,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f6deed8ed625c52864792459709183da231ebf66ff0cf09e69b573227c377efe
sha256: c538be99af830f478718b51630ec1b6bee5e74e52c8a802d328d9e71d35d2583
url: "https://pub.dev"
source: hosted
version: "11.3.0"
version: "11.10.0"
watcher:
dependency: transitive
description:
Expand All @@ -1036,6 +1044,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.3.0"
web_socket_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -1117,5 +1133,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.10.0"
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies:
# envify: ^2.0.3
envied: ^0.3.0+3
html: ^0.15.4
mixpanel_flutter: ^2.2.0

dev_dependencies:
flutter_test:
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

#include "generated_plugin_registrant.h"

#include <firebase_core/firebase_core_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FirebaseCorePluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
firebase_core
url_launcher_windows
)

Expand Down
Loading