Friday, May 18, 2012

Google Analytics in Android app - dealing with multiple activities


I was pretty excited to see how easy it is to set up Google Analytics with my app, but the lack of documentation has me sitting with a few questions. The only information that I can find is right from the documentation here , which only looks at reporting PageViews and Events from one Activity. I want to report PageViews and Events across multiple Activities in my app.



Right now in the onCreate() of all of my activities, I am calling:




tracker = GoogleAnalyticsTracker.getInstance();
tracker.start("UA-xxxxxxxxx", this);



And in the onDestroy() of all of my activities:




tracker.stop();



I then track PageViews and Events as needed, and Dispatch them along with another HTTP request I am performing. But I'm not so sure this is the best way. Should I be calling start() and stop() in each activity, or should I only call start() and stop() in my main launcher activity?


Source: Tips4all

No comments:

Post a Comment