Reputation: 4822
I have a flutter app using firebase
and google analytics
. My data about active users
is wrong as I am testing a lot in emulators and google analytics thinks that the installs there are real users. As I often reinstall the app for testing it somehow seems to count it as a new user every time.
As a solution, I'd like to disable google analytics when building the app in debug mode and only activate it when I build it with --release
.
Does anyone know how do achieve this with a flutter app?
Upvotes: 2
Views: 6039
Reputation: 2906
Maybe not what you are looking for, but you can remove all the ip-addresses of your debug devices from getting tracked in Google Analytics.
UPDATE: the original answer was for Universal Analytics only. Updated the answer to also include Google Analytics 4 properties.
For the old Universal Analytics properties, the instructions according to this page are:
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
For the new Google Analytics 4 properties, you can filter out "internal traffic" by following the instructions on this page:
- In Admin, click Data Streams in the Property column.
- Click Web and then click a web data stream.
- In the web stream details, click Configure tag settings (at the bottom).
- Click Define internal traffic.
- Click Create.
- Enter a name for the rule.
- traffic_type is the only event parameter for which you can define a value. internal is the default value, but you can enter a new value (e.g., emea_headquarters) to represent a location from which internal traffic originates.
- Under IP address > Match type, select one of the operators (e.g., IP address equals).
- Under IP address, enter an address or range of addresses that identify traffic from the location you identified in Step 8. You can enter IPv4 or IPv6 addresses.
- Click Create
Note: before step 4 you might need to first click on "Show more" to see the "Define internal traffic" button.
Upvotes: 1
Reputation: 4652
I assume you're using Firebase Analytics in Flutter (I don't think there's GA for Flutter). You can use kReleaseMode
flag when setting navigatorObservers
of MaterialApp
and creating FirebaseAnalyticsObserver
instance. Here's how I do it in my app (notice that I also use preferences which allow user to turn on/off analytics, as well as desktop platforms where there's no Firebase support which is why I specifically check for Web, iOS and Android platforms):
MaterialApp(
...
navigatorObservers: preferences.isAnalyticsEnabled &&
kReleaseMode &&
(kIsWeb || Platform.isAndroid || Platform.isIOS)
? [
FirebaseAnalyticsObserver(analytics: FirebaseAnalytics()),
]
: [],
...
Upvotes: 9
Reputation:
Check this out from another answer. To disable the collection of data by Firebase Analytics in your app, see the instructions here.
In summary, to disable temporarily, set FIREBASE_ANALYTICS_COLLECTION_ENABLED to NO in the GoogleServices-Info.plist file. To disable permanently, set FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED to YES in the same plist file.
Upvotes: 0