From 74fe1858d4b3d947d049928dcc2b29d5eafa407a Mon Sep 17 00:00:00 2001 From: airkjw Date: Sat, 13 Jun 2026 12:18:05 +0900 Subject: [PATCH] feat(analytics): disable GA4 collection in debug builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- lib/main.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/main.dart b/lib/main.dart index 5c1dc86..b807241 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 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(), );