为什么在 android 上向 Google Analytics 发送屏幕视图两次
Why a screen view is sent twice to Google Analytics on android
我正在为 Android v4 使用 Google 分析。我附上了代码,发生的事情是每次我发送本地点击时,它被发送两次并在仪表板上出现两次,一次用于屏幕名称,一次用于 Activity 包名称,不确定代码有什么问题。
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>
activity代码
@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);
}
代码完全按照您的要求执行。
这里,你发出一个命中:
t.send(new HitBuilders.ScreenViewBuilder().build());
然后在下一行,您手动调度本地匹配:
GoogleAnalytics.getInstance(getBaseContext()).dispatchLocalHits();
我正在为 Android v4 使用 Google 分析。我附上了代码,发生的事情是每次我发送本地点击时,它被发送两次并在仪表板上出现两次,一次用于屏幕名称,一次用于 Activity 包名称,不确定代码有什么问题。
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>
activity代码
@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);
}
代码完全按照您的要求执行。
这里,你发出一个命中:
t.send(new HitBuilders.ScreenViewBuilder().build());
然后在下一行,您手动调度本地匹配:
GoogleAnalytics.getInstance(getBaseContext()).dispatchLocalHits();