Gotchas when using Google Analytics for Android SDK [closed]

五迷三道 提交于 2019-12-23 08:38:34

问题


There appear to be many issues with using Google Analytics (libGoogleAnalytics.jar) for Android.

  1. GoogleAnalyticsTracker keeps a static reference to a GoogleAnalyticsTracker instance, which in turn keeps a strong reference to the Context passed into start(), which prevents that context from ever getting garbage collected (basically, a memory leak).
  2. It is unclear how to properly track a user's session across activities. Calling GoogleAnalyticsTracker.start() in each activity's onCreate() results in a new session for each activity. Moving start()/stop() to only a single "master" activity doesn't work, because subsequent activities may try to track pageviews after stop() has been called, resulting in NullPointerExceptions. And moving the start() call to Application.onCreate() and stop() to Application.onTerminate() results in: A) very long-lived sessions since Application.onTerminate() is infrequently called, and B) spurious session starts if you have things like background Services that run periodically.
  3. Fails to log events with names that contain spaces.

The documentation for the library is sparse and doesn't show an example of a multi-activity application.

Looking around StackOverflow and other sites, I've been trying to get a sense of best practices when using GA for Android, especially as pertain to the above issues. Has anyone gotten this figured out?

Also, what other issues are there that I haven't mentioned above?

来源:https://stackoverflow.com/questions/6232177/gotchas-when-using-google-analytics-for-android-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!