开发者

Implementing Google Analytics in Android app having multiple activities

I am facing problem in getting correct stats from GA when implementing it in my Androi开发者_如何学God app. Here is the scenario:

I have an Android app which is already live there in the market. This app was developed by other programmers. In this app there are 5 activities, in which first activity is the Launcher activity having Tabhost and other 4 activities are displayed in different tabs. The GA implementation in this app is done by defining a Private Static Tracker object in Globals.java, and tracker.start("UA-profile1", 60, this); is used in onCreate of Launcher activity where "UA-profile1" is the UA ID of profile that was created on GA website by old programmers team, and 60 seconds is the time interval for dispatching the events/pageviews. Tracker.Stop is used in onDestroy of Launcher activity. Tracker.TrackPageView is used on appropriate places in all activities. This approach is working fine.

Now, I am developing the update version of this app. Now, there are around 12 activities. I am not using Tabhost, and each activity is a SingleTask activity, and I am not maintaining stack of activities. So, user can exit app anytime by pressing device Back button. I have implemented both Flurry and GA in this update version. The approach that I have used for GA, is that I am creating Tracker object in every activity, and in onCreate I am using tracker.start("UA-profile2", 10, this); where "UA-profile2" is the UA ID of profile that I have created on GA website, and 10 seconds is the time interval for dispatching the events/pageviews. In onDestroy I am using Tracker.Stop. I have built the apk and uploaded it on Market. Now, when my users are updating the app, and using it consistently, since Flurry analytics is showing an upward trend in all graphs, but when I go to see GA stats, I find that in old profile the graph is going down which is fine since my users are migrating to new version, but when I see new profile, the graph is not increasing.

When I googled about implementation of GA with multiple activities, some people suggested that we should use a static tracker object instead of creating it in every activity. There is not more details about this on Google Analytics website.

So, I want to know if the approach 1 (using an Static Tracker object for whole application) is correct and the approach 2 (creating Tracker object for each activity) is wrong? or there might be some other issue.

Please help, Thanks,

James


Both approaches should work, but the static tracker is the only approach which will track multiple activities under the same "visit".

See these answers:
Google Analytics in Android app - dealing with multiple activities and
Google Analytics for Android using multiple Activities

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜