progNewbie
progNewbie

Reputation: 4822

Canonical way to disable analytics in flutter debug build

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

Answers (3)

Klaassiek
Klaassiek

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

  1. Login to Google Analytics and select your profile
  2. Select the Admin menu
  3. Under Account select All Filters
  4. Click Add Filter
  5. Give the filter a name (can be anything, I use the IP address)
  6. Leave Filter Type as predefined
  7. It should read: Exclude + traffic from the IP addresses + that are equal to
  8. Enter your IP address

For the new Google Analytics 4 properties, you can filter out "internal traffic" by following the instructions on this page:

  1. In Admin, click Data Streams in the Property column.
  2. Click Web and then click a web data stream.
  3. In the web stream details, click Configure tag settings (at the bottom).
  4. Click Define internal traffic.
  5. Click Create.
  6. Enter a name for the rule.
  7. 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.
  8. Under IP address > Match type, select one of the operators (e.g., IP address equals).
  9. 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.
  10. Click Create

Note: before step 4 you might need to first click on "Show more" to see the "Define internal traffic" button.

Upvotes: 1

Maxim Saplin
Maxim Saplin

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

user12244565
user12244565

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.

https://stackoverflow.com/questions/37518212/how-to-disable-remove-firebaseanalytics#:~:text=To%20disable%20the%20collection%20of,in%20the%20same%20plist%20file.

Upvotes: 0

Related Questions