fix: umeng和firebase动态接入方案

This commit is contained in:
Liuyf 2025-01-10 14:39:47 +08:00
parent e066768866
commit 26310031af
6 changed files with 178 additions and 6 deletions

46
lib/apm/apm_helper.dart Normal file
View File

@ -0,0 +1,46 @@
//<com>
import 'firebase/firebase_helper.dart';
//</com>
//<cn>
import 'umeng/umeng_helper.dart';
//</cn>
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<void> initSdk() async {
//<cn>
UmengHelper.instance.initSdk();
//</cn>
//<com>
FirebaseHelper.instance.initSdk();
//</com>
}
Future<void> trackEvent(String eventName,
{String? title,
String? screenName,
String? elementContent,
String? operation}) async {
//<cn>
UmengHelper.instance.trackEvent(eventName);
//</cn>
//<com>
FirebaseHelper.instance.trackEvent(eventName);
//</com>
}
}

View File

@ -0,0 +1,23 @@
//<com>
class FirebaseHelper {
FirebaseHelper._internal();
factory FirebaseHelper() => _getInstance();
static FirebaseHelper get instance => _getInstance();
static FirebaseHelper? _instance;
static FirebaseHelper _getInstance() {
_instance ??= FirebaseHelper._internal();
return _instance!;
}
Future<void> initSdk() async {}
Future<void> trackEvent(String eventName,
{String? title,
String? screenName,
String? elementContent,
String? operation}) async {}
}
//</com>

View File

@ -0,0 +1,30 @@
//<cn>
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<void> initSdk() async {
UmengCommonSdk.initCommon(
F.umengKey.androidKey, F.umengKey.iosKey, F.umengKey.channel);
UmengCommonSdk.setPageCollectionModeManual();
}
Future<void> trackEvent(String eventName,
{String? title,
String? screenName,
String? elementContent,
String? operation}) async {}
}
//</cn>

View File

@ -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) {

View File

@ -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<void> _setCommonServices() async {
//
Future<void> privacySDKInitialization() async {
UmengCommonSdk.initCommon(
'671244cf80464b33f6df9648', '671244ae80464b33f6df9646', 'Product');
UmengCommonSdk.setPageCollectionModeManual();
ApmHelper.instance.initSdk();
await Get.putAsync(() => PlatformInfoService().init());
await BuglyTool.init();
// JPush服务

View File

@ -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
#<cn>
umeng_common_sdk: 1.2.8
#</cn>
#<com>
firebase_analytics: 11.3.0
#</com>
dependency_overrides:
#强制设置google_maps_flutter_ios 为 2.5.2