Google Analytics会发送错误的会话控制参数

时间:2016-12-07 06:14:21

标签: android session google-analytics

我已在我的Android应用程序中集成了Google Analytics。我们正面临一个问题,Google Analytics会在第二次点击中自动添加“sc = start”。这导致Google Analytics中有2个会话,而用户只执行了一个会话。

我尝试更改分析代码,并尝试打开不同的屏幕。

这是我用来将ScreenView发送到GA的代码:

 public static void sendAnalyticsScreenView(String screenName) {
    Tracker tracker = ErosApplication.getInstance().getTracker();
    if (tracker != null) {
        tracker.setScreenName(screenName);
        Map<String, String> build = new HitBuilders.ScreenViewBuilder().build();
        tracker.send(build);
    }
}

getTracker方法在Application类中定义:

public synchronized Tracker getTracker() {
    if (mTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(ErosApplication.getInstance());
        mTracker = analytics.newTracker(R.xml.app_tracker);
        mTracker.enableAdvertisingIdCollection(true);
    }
    return mTracker;

}

我还尝试在应用程序的onCreate中初始化Google Analytics和Tracker:

 @Override
public void onCreate() {
    ActivityLifecycleCallback.register(this);
    super.onCreate();

    sInstance = this;

    GoogleAnalytics.getInstance(this).initialize();
    getTracker();
}

这是来自GA终端的记录数据:

12-07 11:37:02.861 D/GAv4    (18509): Hit delivery requested: ht=1481090822674, _s=0, _v=ma10.0.84, a=353190215, adid=5b2dae2c-79bd-4412-9c8b-bda72e961564, aid=com.tf.eros.faythTv, an=House of God, ate=1, av=1.4.2, cd=splash_screen, cid=2c02b7ba-9cac-4a10-b360-604a9390c2c1, sf=100.0, sr=1080x1920, t=screenview, tid=UA-80650025-7, ul=en-in, v=1
12-07 11:37:02.921 D/GAv4    (18509): Hit sent to the device AnalyticsService for delivery
12-07 11:37:04.601 D/GAv4    (18509): Hit delivery requested: ht=1481090824407, _s=1, _v=ma10.0.84, a=353190216, adid=5b2dae2c-79bd-4412-9c8b-bda72e961564, aid=com.tf.eros.faythTv, an=House of God, ate=1, av=1.4.2, cd=new_intro, cid=2c02b7ba-9cac-4a10-b360-604a9390c2c1, sc=start, sf=100.0, sr=1080x1920, t=screenview, tid=UA-80650025-7, ul=en-in, v=1

我也试过在同一个地方用闪屏四次调用logScreenView方法,如下所示:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    AnalyticsHelper.logScreenView(getResources().getString(R.string.screen_splash));
    AnalyticsHelper.logScreenView(getResources().getString(R.string.screen_splash));
    AnalyticsHelper.logScreenView(getResources().getString(R.string.screen_splash));
    AnalyticsHelper.logScreenView(getResources().getString(R.string.screen_splash));
} 

终端日志:

12-07 11:42:26.635 D/GAv4    (24760): Hit delivery requested: ht=1481091146460, _s=0, _v=ma10.0.84, a=639766606, adid=5b2dae2c-79bd-4412-9c8b-bda72e961564, aid=com.tf.eros.faythTv, an=House of God, ate=1, av=1.4.2, cd=splash_screen, cid=6e9f3ca7-a87a-47bd-a80d-1619e6d9ac64, sf=100.0, sr=1080x1920, t=screenview, tid=UA-80650025-7, ul=en-in, v=1
12-07 11:42:26.645 D/GAv4    (24760): Hit delivery requested: ht=1481091146461, _s=1, _v=ma10.0.84, a=639766607, adid=5b2dae2c-79bd-4412-9c8b-bda72e961564, aid=com.tf.eros.faythTv, an=House of God, ate=1, av=1.4.2, cd=splash_screen, cid=6e9f3ca7-a87a-47bd-a80d-1619e6d9ac64, sc=start, sf=100.0, sr=1080x1920, t=screenview, tid=UA-80650025-7, ul=en-in, v=1
12-07 11:42:26.665 D/GAv4    (24760): Hit delivery requested: ht=1481091146461, _s=2, _v=ma10.0.84, a=639766608, adid=5b2dae2c-79bd-4412-9c8b-bda72e961564, aid=com.tf.eros.faythTv, an=House of God, ate=1, av=1.4.2, cd=splash_screen, cid=6e9f3ca7-a87a-47bd-a80d-1619e6d9ac64, sf=100.0, sr=1080x1920, t=screenview, tid=UA-80650025-7, ul=en-in, v=1
12-07 11:42:26.665 D/GAv4    (24760): Hit delivery requested: ht=1481091146461, _s=3, _v=ma10.0.84, a=639766609, adid=5b2dae2c-79bd-4412-9c8b-bda72e961564, aid=com.tf.eros.faythTv, an=House of God, ate=1, av=1.4.2, cd=splash_screen, cid=6e9f3ca7-a87a-47bd-a80d-1619e6d9ac64, sf=100.0, sr=1080x1920, t=screenview, tid=UA-80650025-7, ul=en-in, v=1 

GA在第二次通话中添加了“sc = start”参数,导致会话编号错误。请建议解决方案。

1 个答案:

答案 0 :(得分:0)

问题是我在onCreate方法中发送了screenView命中,但它应该从onResume方法发送。将屏幕视图的分析代码从onCreate移动到onResume解决了这个问题。