Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics blocks Android App

I use Google Analytics in my Android App and it works well. After updating the SDK (google play service) to the current version (6587000) the app hangs up at startup at following line 8 of 10 times:

GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); 

There is no error in console. I added Achievements and Leaderboards too, but Analytics is called first. I also changed the context, but that works sometimes and sometimes not.

The only time I get a reproducable result is, when I remove following lines from AndroidManifest.xml. Then there is no freeze at startup anymore.

<meta-data          android:name="com.google.android.gms.analytics.globalConfigResource"         android:resource="@xml/analytics_global_config" /> 

But my configuration is correct:

<?xml version="1.0" encoding="utf-8" ?> <resources>   <string name="ga_appName">TestAppName</string>   <string name="ga_appVersion">Version1.0</string>   <string name="ga_logLevel">verbose</string>   <integer name="ga_dispatchPeriod">1000</integer>   <bool name="ga_dryRun">true</bool> </resources> 

And if I change the configuration there is the same result: 8 of 10 times the App freezes at startup.

Does someone have a clue what the problem is or what else I can check to make my app running again without freezing at startup?

like image 891
Wolfgang Pürstner Avatar asked Dec 17 '14 19:12

Wolfgang Pürstner


People also ask

Can Google Analytics be used for Mobile Apps?

Use Tag Manager with Google Analytics and Firebase. To get the latest mobile app report features in Google Analytics, use Firebase in your Android and iOS apps. Once enabled in your app, Google Analytics will automatically collect and report on built-in events and user properties.

How do I add Google Analytics to my Android app?

Get the project If this is your first time using a Google services sample, check out the google-services repository. Open Android Studio. Select File > Open, browse to where you cloned the google-services repository, and open google-services/android/analytics .

Can Google Analytics be blocked?

Google Analytics and Google Tag Manager calls are blocked by many adblockers too. This makes site owners wonder whether Google Analytics is still useful and whether its stats are accurate. The level of Google Analytics blockage varies by industry, audience, the device used and the individual website.


1 Answers

i had similar i removed the below code and application runs..

<meta-data          android:name="com.google.android.gms.analytics.globalConfigResource"         android:resource="@xml/analytics_global_config" /> 

and add following code for getTracker class... build the GoogleAnalytics using java code rather than XML approch

synchronized Tracker getTracker(TrackerName trackerId) {         Log.d(TAG, "getTracker()");         if (!mTrackers.containsKey(trackerId)) {             GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);              // Global GA Settings             // <!-- Google Analytics SDK V4 BUG20141213 Using a GA global xml freezes the app! Do config by coding. -->             analytics.setDryRun(false);              analytics.getLogger().setLogLevel(Logger.LogLevel.INFO);             //analytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);              // Create a new tracker             Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(R.xml.ga_tracker_config) : null;             if (t != null) {                 t.enableAdvertisingIdCollection(true);             }             mTrackers.put(trackerId, t);         }         return mTrackers.get(trackerId);     } 
like image 91
Munawwar Hussain Shelia Avatar answered Sep 28 '22 21:09

Munawwar Hussain Shelia