1

I've been searching online for a few days but I couldn't find it. It was available in v3 but the only code available for managing the session manually in v4 is for starting a new one only and rely on the session timeout for the ending.

4

1 回答 1

3

公共 Android v4 api 不支持结束会话,但您可以使用Measurement Protocol中的会话控制结束参数来完成相同的操作。您可以通过将 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);

通过查看 logcat 的“Sending hit”行来验证 sc 参数是否已发送,并确保它具有 sc=end 参数。它应该看起来像这样:

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,
于 2014-12-04T16:00:09.377 回答