Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Google Analytics when in development

My question is pretty simple: is there any way for Google Analytics to be disabled automatically when the application is signed with the debug certificate? Means it should be active only in release version. Thank you in advance.

like image 263
Egor Avatar asked Dec 21 '12 12:12

Egor


People also ask

Can Google Analytics be turned off?

If you're an administrator of Google accounts for an organization, you can control who uses Google Analytics from their account. Just turn Analytics on or off for those people in your Admin console.


1 Answers

If you're using ADT 17 and above, you can utilize the BuildConfig class:

if(BuildConfig.DEBUG) {
    GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(getApplicationContext());
    googleAnalytics.setAppOptOut(true);
}

The BuildConfig class is automatically generated like R.java is. It only contains the DEBUG boolean, which is set to true by default, and to false when you export an apk.

like image 150
Raghav Sood Avatar answered Sep 23 '22 15:09

Raghav Sood