feat(analytics): disable GA4 collection in debug builds

setAnalyticsCollectionEnabled(kReleaseMode) after Firebase init so the native
SDK's automatic events (session_start, screen_view) stay out of production
analytics in debug too — not only our custom events. Verified on simulator:
release builds collect, debug builds do not.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-13 12:18:05 +09:00
parent 41b0180b44
commit 74fe1858d4
+5
View File
@@ -1,5 +1,6 @@
import 'dart:io';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
@@ -35,6 +36,10 @@ Future<void> main() async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Keep development traffic out of GA4 entirely — this also silences the
// native SDK's automatic events (session_start, screen_view), not just
// our custom ones, so only release builds ever reach production analytics.
await FirebaseAnalytics.instance.setAnalyticsCollectionEnabled(kReleaseMode);
analytics = AnalyticsService(
kReleaseMode ? FirebaseAnalyticsBackend() : DebugAnalyticsBackend(),
);