如何手动结束Android版Google analytics v4中的会话?

如何手动结束Android版Google analytics v4中的会话?,android,google-analytics,google-analytics-firebase,Android,Google Analytics,Google Analytics Firebase,我已经在网上搜索了几天,但是我找不到它。但在v4中,可用于手动管理会话的唯一代码仅适用于,并依赖于会话超时来结束会话。公共Android v4 api不支持结束会话,但您可以通过测量协议完成相同的操作。您可以将sc=end添加到您的跟踪器: analytics = GoogleAnalytics.getInstance(getApplicationContext()); // TODO: Remove this line before shipping analytics.getLogger(

我已经在网上搜索了几天,但是我找不到它。但在v4中,可用于手动管理会话的唯一代码仅适用于,并依赖于会话超时来结束会话。

公共Android v4 api不支持结束会话,但您可以通过测量协议完成相同的操作。您可以将sc=end添加到您的跟踪器:

analytics = GoogleAnalytics.getInstance(getApplicationContext());

// TODO: Remove this line before shipping
analytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);

tracker = analytics.newTracker(TRACKER_ID);
Map<String, String> hit = new HitBuilders.ScreenViewBuilder().build();
hit.put("&sc", "end");
tracker.send(hit);

这证明有效吗?如果我发送sc=start(连同页面视图),我可以在我的在线ga控制台的实时概览中看到点击,并且活动用户的nbr从0变为1(当然是测试配置文件);当发送sc=end(再次使用另一个页面视图)时,我在时间线上也看到了这个特定的点击,但活动用户的nbr仅在通常的超时后下降到零…我相信活动用户仅在一段时间内计数,而不是实际的活动用户。这是因为,当用户不再处于活动状态时,应用程序可能没有机会让服务器知道其未处于活动状态(例如,当设备崩溃或失去连接时)。
V/GAV4﹕ Thread[GAThread,5,main]: Sending hit to store  PATH: https:  PARAMS: v=1,  ul=en-us,  t=screenview,  ht=1417708068636,  sr=800x1216,  a=1647515955,  an=Analytics Playground,  sc=end,  tid=UA-xxxxxxxx-1,  aid=com.example.analyticsplayground,  cid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,  av=1.0,  _u=.nK-AL,