谷歌Analytics(分析)对采用Android多项活动 [英] Google Analytics for Android using multiple Activities

查看:66
本文介绍了谷歌Analytics(分析)对采用Android多项活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的的相应的SDK 的网站。然而,可用很少的文档。我的项目有6个不同的活动,我注意到,在使用在谷歌Analytics(分析)独特的访问为每一个被打开活动网页结果的方法,即使它仍然在同一个会话。显然,谷歌Analytics(分析)为Android从不重用previously使用的会话。

I'm trying to integrate Google Analytics into my Android project using the information on the website of the respective SDK. However, there is very little documentation available. My project has 6 different Activities and I noticed that using the method on the website results in a unique visit in Google Analytics for each Activity that is being opened, even if it's still in the same session. Apparently, Google Analytics for Android never reuses a previously used session.

他们的方法是开始跟踪活动的onCreate,然后停止跟踪的onDestroy。我有这样的问题是,会议将保持活跃,如果用户presses home键,而不是后退按钮,因为活动不会被破坏。因此,我选择了做在onResume和代替的onPause但是这意味着一个新的活动时打开新的会话被打开。

Their method is to start tracking activity in onCreate and then stop tracking in onDestroy. The problem I have with this is that a session will stay active if a user presses the home button instead of the back button, since the Activity will not be destroyed. Therefore I chose to do it in onResume and onPause instead but that means that new sessions gets opened when a new Activity is opened.

有谁知道任何方式在多个活动真正跟踪单个会话?

Does anyone know any way to really track a single session over multiple Activities?

推荐答案

学习的活动的生命周期之后,我来到了以下结论。

After studying the lifecycle of an Activity, I came to the following conclusion.

当从一个活动切换到另一个活动B,A的的onStop方法被称为B的OnStart方法我然后做了每一个(静态)跟踪器是在OnStart方法访问时计数器增加一个引用后。在该方法的onStop,我会先检查引用计数是否为0,并停止跟踪,如果它是。在的onStop方法的结尾,我会减小引用计数器。

When switching from an Activity A to another Activity B, the onStop method of A is called AFTER the onStart method of B. What I then did was increasing a reference counter every time the (static) tracker is accessed in an onStart method. In the onStop method, I would first check whether the reference counter was 0, and stop the tracker if it was. At the end of the onStop method, I would decrease the reference counter.

这似乎在这一刻是工作得很好,当应用程序有多个活动,可以为切入点,法案还应该工作。

This seems to be working quite well at this moment, and should also work when the application has multiple Activities that can act as an entry point.

这篇关于谷歌Analytics(分析)对采用Android多项活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆