From 26e0f4d3bbfa78ef1486b17681d1bed60697d2a2 Mon Sep 17 00:00:00 2001 From: liyi Date: Thu, 24 Jul 2025 11:28:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=B0=83=E6=95=B4firebase=E5=BF=85?= =?UTF-8?q?=E9=A1=BB=E5=9C=A8Android=E5=92=8C=E7=94=9F=E4=BA=A7=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=89=8D=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/apm/firebase/firebase_helper.dart | 36 ++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/apm/firebase/firebase_helper.dart b/lib/apm/firebase/firebase_helper.dart index cb354174..e49d3842 100644 --- a/lib/apm/firebase/firebase_helper.dart +++ b/lib/apm/firebase/firebase_helper.dart @@ -71,21 +71,45 @@ class FirebaseHelper { } Future initSdk() async { - FirebaseAnalytics.instance.setAnalyticsCollectionEnabled(true); + const bool isProductVmMode = bool.fromEnvironment('dart.vm.product'); + if (F.isProductionEnv && + isProductVmMode && + defaultTargetPlatform == TargetPlatform.android) { + FirebaseAnalytics.instance.setAnalyticsCollectionEnabled(true); + } } Future login(String userId) async { - FirebaseAnalytics.instance.setUserId(id: userId); + const bool isProductVmMode = bool.fromEnvironment('dart.vm.product'); + if (F.isProductionEnv && + isProductVmMode && + defaultTargetPlatform == TargetPlatform.android) { + FirebaseAnalytics.instance.setUserId(id: userId); + } } Future trackEvent( - String eventName, Map? parameters) async { - FirebaseAnalytics.instance - .logEvent(name: eventName, parameters: parameters); + String eventName, + Map? parameters, + ) async { + const bool isProductVmMode = bool.fromEnvironment('dart.vm.product'); + if (F.isProductionEnv && + isProductVmMode && + defaultTargetPlatform == TargetPlatform.android) { + FirebaseAnalytics.instance.logEvent( + name: eventName, + parameters: parameters, + ); + } } Future logout() async { - FirebaseAnalytics.instance.setUserId(id: ''); + const bool isProductVmMode = bool.fromEnvironment('dart.vm.product'); + if (F.isProductionEnv && + isProductVmMode && + defaultTargetPlatform == TargetPlatform.android) { + FirebaseAnalytics.instance.setUserId(id: ''); + } } } //