为什么屏幕视图会在Android上两次发送到Google Analytics

时间:2015-04-21 20:58:22

标签: java android google-analytics-v4

我正在使用Google Analytics for Android v4。我附加了代码,发生的事情是每次我发送本地点击时,它会被发送两次并在Dashboard上出现两次,用于屏幕名称和一次用于活动包名称,不确定代码是否有错。

global_tracker.xml文件

<?xml version="1.0" encoding="utf-8"?>
    <resources
        xmlns:tools="http://schemas.android.com/tools"
        tools:ignore="TypographyDashes">

        <integer name="ga_sessionTimeout">300</integer>
        <bool name="ga_autoActivityTracking">true</bool>
        <bool name="ga_anonymizeIp">true</bool>
        <string name="ga_trackingId">UA-XXXXXXX-2</string>
        <int name="ga_dispatchPeriod">-10</int>
    </resources>

活动代码

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        webFunction = new WebFunctions();
        dbFunction = new DatabaseFuncitons();
        progressDialog = new ProgressDialog(ActivityLogin.this);

        editTextUsername = (EditText) findViewById(R.id.editTextUsername);
        editTextPassword = (EditText) findViewById(R.id.editTextPassword);

        Tracker t = GoogleAnalytics.getInstance(this).newTracker(R.xml.global_tracker);
        t.setScreenName("/Login");

        t.send(new HitBuilders.ScreenViewBuilder().build());

        GoogleAnalytics.getInstance(getBaseContext()).dispatchLocalHits();

        GoogleAnalytics.getInstance(this).getLogger()
                .setLogLevel(Logger.LogLevel.VERBOSE);
    }

1 个答案:

答案 0 :(得分:1)

代码完全按照你的要求去做。

在这里,你发出一个命中:

t.send(new HitBuilders.ScreenViewBuilder().build());

然后在下一行,你手动调度本地命中:

GoogleAnalytics.getInstance(getBaseContext()).dispatchLocalHits();