Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable GoogleAnalytics from Android App when testing or developing

I'm using EasyTracker in my Android App and I need a way to disable Analytics tracking when the app is in "development" or "testing" mode (I have a flag in a constants file to discriminate).

What's the best way to do so?

Thanks!

like image 339
MataMix Avatar asked Sep 07 '12 08:09

MataMix


People also ask

How do I turn off firebase Analytics?

If you need to deactivate Analytics collection permanently in a version of your app, set FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED to YES (Boolean) in your app's Info.

Does firebase Analytics Use Ad ID?

By default, the Firebase SDK collects identifiers for mobile devices (for example, Android Advertising ID and Advertising Identifier for iOS) and utilizes technologies similar to cookies. On iOS, the SDK collects the Advertising Identifier if it is available.

How do I activate Google Analytics?

Go to google.com/analytics. To create an account, click Get started today. If you already have a Google Analytics account, click Sign in to Analytics. Set up Analytics on your website and/or app.


3 Answers

Newest version from firebase has this method that can be put inside App class:

FirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(!BuildConfig.DEBUG);

like image 193
smiki Avatar answered Oct 16 '22 14:10

smiki


I believe the correct way to do this with Version 4 of Analytics is with the Opt Out method

GoogleAnalytics.getInstance(this).setAppOptOut(true);

You could set that method to be set if you build in debug mode. ie.

GoogleAnalytics.getInstance(this).setAppOptOut(BuildConfig.DEBUG);

I am using something similiar to allow users to opt-out of analytics.

I found this information at he following link: https://developers.google.com/analytics/devguides/collection/android/v4/advanced

Edit: Just saw the date of the original question, but thought I would add this answer anyway as it was something I was looking for.

like image 17
Talung Avatar answered Oct 19 '22 03:10

Talung


UPDATE: With release of Google Analytics v3 for Android,

The SDK provides a dryRun flag that when set, prevents any data from being sent to Google Analytics. The dryRun flag should be set whenever you are testing or debugging an implementation and do not want test data to appear in your Google Analytics reports.

To set the dry run flag:

// When dry run is set, hits will not be dispatched, but will still be logged as though they were dispatched.

GoogeAnalytics.getInstance(this).setDryRun(true);

+++ My old answer +++

Just comment the following line in your analytics.xml file while you are in development mode.

<string name="ga_trackingId">UA-****</string>

Google Analytics wouldn't be able to find any tracking id, so EasyTracker won't be able to do its job. When you are building the app for release, uncomment the line and you're good to go.

like image 10
Atul Goyal Avatar answered Oct 19 '22 03:10

Atul Goyal