diff --git a/lib/apm/apm_helper.dart b/lib/apm/apm_helper.dart new file mode 100644 index 00000000..a52a8b56 --- /dev/null +++ b/lib/apm/apm_helper.dart @@ -0,0 +1,46 @@ +// +import 'firebase/firebase_helper.dart'; + +// +// +import 'umeng/umeng_helper.dart'; +// + +class ApmHelper { + ApmHelper._internal(); + + factory ApmHelper() => _getInstance(); + + static ApmHelper get instance => _getInstance(); + static ApmHelper? _instance; + + // 增加开关 + static bool enabled = false; + + static ApmHelper _getInstance() { + _instance ??= ApmHelper._internal(); + return _instance!; + } + + Future initSdk() async { + // + UmengHelper.instance.initSdk(); + // + // + FirebaseHelper.instance.initSdk(); + // + } + + Future trackEvent(String eventName, + {String? title, + String? screenName, + String? elementContent, + String? operation}) async { + // + UmengHelper.instance.trackEvent(eventName); + // + // + FirebaseHelper.instance.trackEvent(eventName); + // + } +} diff --git a/lib/apm/firebase/firebase_helper.dart b/lib/apm/firebase/firebase_helper.dart new file mode 100644 index 00000000..bd98c650 --- /dev/null +++ b/lib/apm/firebase/firebase_helper.dart @@ -0,0 +1,23 @@ +// +class FirebaseHelper { + FirebaseHelper._internal(); + + factory FirebaseHelper() => _getInstance(); + + static FirebaseHelper get instance => _getInstance(); + static FirebaseHelper? _instance; + + static FirebaseHelper _getInstance() { + _instance ??= FirebaseHelper._internal(); + return _instance!; + } + + Future initSdk() async {} + + Future trackEvent(String eventName, + {String? title, + String? screenName, + String? elementContent, + String? operation}) async {} +} +// diff --git a/lib/apm/umeng/umeng_helper.dart b/lib/apm/umeng/umeng_helper.dart new file mode 100644 index 00000000..b32c81f6 --- /dev/null +++ b/lib/apm/umeng/umeng_helper.dart @@ -0,0 +1,30 @@ +// +import 'package:umeng_common_sdk/umeng_common_sdk.dart'; +import '../../flavors.dart'; + +class UmengHelper { + UmengHelper._internal(); + + factory UmengHelper() => _getInstance(); + + static UmengHelper get instance => _getInstance(); + static UmengHelper? _instance; + + static UmengHelper _getInstance() { + _instance ??= UmengHelper._internal(); + return _instance!; + } + + Future initSdk() async { + UmengCommonSdk.initCommon( + F.umengKey.androidKey, F.umengKey.iosKey, F.umengKey.channel); + UmengCommonSdk.setPageCollectionModeManual(); + } + + Future trackEvent(String eventName, + {String? title, + String? screenName, + String? elementContent, + String? operation}) async {} +} +// diff --git a/lib/flavors.dart b/lib/flavors.dart index 5123fbfa..1ba07b5c 100755 --- a/lib/flavors.dart +++ b/lib/flavors.dart @@ -22,6 +22,20 @@ class StarLockAMapKey { const StarLockAMapKey({required this.iosKey, required this.androidKey}); } +class UmengKey { + //iOS平台的key + final String iosKey; + + //Android平台的key + final String androidKey; + + //channle + final String channel; + + const UmengKey( + {required this.iosKey, required this.androidKey, required this.channel}); +} + typedef dynamic fCallFunction(); class F { @@ -180,6 +194,62 @@ class F { } } + // StarLockAMapKey + static UmengKey get umengKey { + switch (appFlavor) { + case Flavor.local: + return const UmengKey( + androidKey: '671244cf80464b33f6df9648', + iosKey: '671244ae80464b33f6df9646', + channel: 'Product'); + case Flavor.dev: + return const UmengKey( + androidKey: '671244cf80464b33f6df9648', + iosKey: '671244ae80464b33f6df9646', + channel: 'Product'); + case Flavor.pre: + return const UmengKey( + androidKey: '671244cf80464b33f6df9648', + iosKey: '671244ae80464b33f6df9646', + channel: 'Product'); + case Flavor.sky_dev: + return const UmengKey( + androidKey: '671244cf80464b33f6df9648', + iosKey: '671244ae80464b33f6df9646', + channel: 'Product'); + case Flavor.sky_pre: + return const UmengKey( + androidKey: '671244cf80464b33f6df9648', + iosKey: '671244ae80464b33f6df9646', + channel: 'Product'); + case Flavor.sky: + return const UmengKey( + androidKey: '671244cf80464b33f6df9648', + iosKey: '671244ae80464b33f6df9646', + channel: 'Product'); + case Flavor.xhj_dev: + return const UmengKey( + androidKey: '671244cf80464b33f6df9648', + iosKey: '671244ae80464b33f6df9646', + channel: 'Product'); + case Flavor.xhj_pre: + return const UmengKey( + androidKey: '671244cf80464b33f6df9648', + iosKey: '671244ae80464b33f6df9646', + channel: 'Product'); + case Flavor.xhj: + return const UmengKey( + androidKey: '671244cf80464b33f6df9648', + iosKey: '671244ae80464b33f6df9646', + channel: 'Product'); + default: + return const UmengKey( + androidKey: '671244cf80464b33f6df9648', + iosKey: '671244ae80464b33f6df9646', + channel: 'Product'); + } + } + // 是否是生产环境 static bool get isProductionEnv { switch (appFlavor) { diff --git a/lib/main.dart b/lib/main.dart index c5f0db2a..21d3255d 100755 --- a/lib/main.dart +++ b/lib/main.dart @@ -19,6 +19,7 @@ import 'package:star_lock/tools/storage.dart'; import 'package:star_lock/translations/trans_lib.dart'; import 'package:umeng_common_sdk/umeng_common_sdk.dart'; +import 'apm/apm_helper.dart'; import 'app.dart'; import 'app_settings/app_settings.dart'; import 'tools/store_service.dart'; @@ -74,10 +75,7 @@ Future _setCommonServices() async { //关于隐私协议的初始化 Future privacySDKInitialization() async { - UmengCommonSdk.initCommon( - '671244cf80464b33f6df9648', '671244ae80464b33f6df9646', 'Product'); - UmengCommonSdk.setPageCollectionModeManual(); - + ApmHelper.instance.initSdk(); await Get.putAsync(() => PlatformInfoService().init()); await BuglyTool.init(); // 初始化JPush服务 diff --git a/pubspec.yaml b/pubspec.yaml index b2227607..e45ba6ab 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -236,7 +236,7 @@ dependencies: timelines: ^0.1.0 #侧滑删除 flutter_slidable: ^3.0.1 -# audio_service: ^0.18.12 + # audio_service: ^0.18.12 app_settings: ^5.1.1 flutter_local_notifications: ^17.0.0 fluwx: 4.5.5 @@ -245,11 +245,16 @@ dependencies: colorfilter_generator: ^0.0.8 file_picker: ^5.3.1 # 错误日志监控 -# flutter_bugly_plugin: ^0.0.9 + # flutter_bugly_plugin: ^0.0.9 flutter_bugly: ^1.0.2 open_filex: ^4.4.0 + # umeng_common_sdk: 1.2.8 + # + # + firebase_analytics: 11.3.0 + # dependency_overrides: #强制设置google_maps_flutter_ios 为 2.5.2