在颤动调试构建中禁用分析的规范方法
Canonical way to disable analytics in flutter debug build
我有一个使用 firebase
和 google analytics
的 flutter 应用程序。我关于 active users
的数据是错误的,因为我在模拟器中进行了大量测试,并且 google 分析认为那里的安装是真实用户。由于我经常重新安装该应用程序进行测试,因此似乎每次都将其计为新用户。
作为解决方案,我想在调试模式下构建应用程序时禁用 google 分析,并且仅在使用 --release
构建它时激活它。
有谁知道如何使用 flutter 应用实现这一点?
从另一个答案中查看。要在您的应用中禁用 Firebase Analytics 收集数据,请参阅此处的说明。
总而言之,要暂时禁用,请在 GoogleServices-Info.plist 文件中将 FIREBASE_ANALYTICS_COLLECTION_ENABLED 设置为 NO。要永久禁用,请在同一个 plist 文件中将 FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED 设置为 YES。
.
也许不是您想要的,但您可以删除调试设备的所有 IP 地址,以免在 Google 分析中被跟踪。这里根据this page的说明:
Exclude Your IP Address From Google Analytics
- Login to Google Analytics and select your profile
- Select the Admin menu
- Under Account select All Filters
- Click Add Filter
- Give the filter a name (can be anything, I use the IP address)
- Leave Filter Type as predefined
- It should read: Exclude + traffic from the IP addresses + that are equal to
- Enter your IP address
我假设您在 Flutter 中使用 Firebase Analytics(我认为 Flutter 没有 GA)。您可以在设置 MaterialApp
的 navigatorObservers
和创建 FirebaseAnalyticsObserver
实例时使用 kReleaseMode
标志。这是我在我的应用程序中执行此操作的方法(请注意,我还使用允许用户打开 on/off 分析的首选项,以及不支持 Firebase 的桌面平台,这就是我专门检查 Web 的原因,iOS 和 Android 平台):
MaterialApp(
...
navigatorObservers: preferences.isAnalyticsEnabled &&
kReleaseMode &&
(kIsWeb || Platform.isAndroid || Platform.isIOS)
? [
FirebaseAnalyticsObserver(analytics: FirebaseAnalytics()),
]
: [],
...
我有一个使用 firebase
和 google analytics
的 flutter 应用程序。我关于 active users
的数据是错误的,因为我在模拟器中进行了大量测试,并且 google 分析认为那里的安装是真实用户。由于我经常重新安装该应用程序进行测试,因此似乎每次都将其计为新用户。
作为解决方案,我想在调试模式下构建应用程序时禁用 google 分析,并且仅在使用 --release
构建它时激活它。
有谁知道如何使用 flutter 应用实现这一点?
从另一个答案中查看。要在您的应用中禁用 Firebase Analytics 收集数据,请参阅此处的说明。
总而言之,要暂时禁用,请在 GoogleServices-Info.plist 文件中将 FIREBASE_ANALYTICS_COLLECTION_ENABLED 设置为 NO。要永久禁用,请在同一个 plist 文件中将 FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED 设置为 YES。
也许不是您想要的,但您可以删除调试设备的所有 IP 地址,以免在 Google 分析中被跟踪。这里根据this page的说明:
Exclude Your IP Address From Google Analytics
- Login to Google Analytics and select your profile
- Select the Admin menu
- Under Account select All Filters
- Click Add Filter
- Give the filter a name (can be anything, I use the IP address)
- Leave Filter Type as predefined
- It should read: Exclude + traffic from the IP addresses + that are equal to
- Enter your IP address
我假设您在 Flutter 中使用 Firebase Analytics(我认为 Flutter 没有 GA)。您可以在设置 MaterialApp
的 navigatorObservers
和创建 FirebaseAnalyticsObserver
实例时使用 kReleaseMode
标志。这是我在我的应用程序中执行此操作的方法(请注意,我还使用允许用户打开 on/off 分析的首选项,以及不支持 Firebase 的桌面平台,这就是我专门检查 Web 的原因,iOS 和 Android 平台):
MaterialApp(
...
navigatorObservers: preferences.isAnalyticsEnabled &&
kReleaseMode &&
(kIsWeb || Platform.isAndroid || Platform.isIOS)
? [
FirebaseAnalyticsObserver(analytics: FirebaseAnalytics()),
]
: [],
...