GoogleAnalytics enableAutoActivityTracking 不工作
GoogleAnalytics enableAutoActivityTracking not working
我遇到了与这个问题相同的问题:
enableAutoActivityTracking not automatically tracking activities?
问题是自动跟踪无法使用 Google Analytics。
但是,调用 enableAutoActivityReports
对我来说不起作用。
这是配置XML文件:
<?xml version="1.0" encoding="utf-8"?>
<!-- Google Analytucs property id. -->
<integer name="ga_sessionTimeout">300</integer>
<!-- catch and report uncaught exceptions from the app -->
<bool name="ga_reportUncaughtExceptions">true</bool>
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<!-- The screen names that will appear in reports -->
<screenName name=".LoginActivity">
Login Activity
</screenName>
</resources>
在申请中class:
private Tracker googleAnalyticsTracker;
public synchronized Tracker getGoogleAnalyticsTracker()
{
if (googleAnalyticsTracker == null)
{
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
analytics.enableAutoActivityReports(this);
googleAnalyticsTracker = analytics.newTracker(R.xml.global_tracker);
}
return googleAnalyticsTracker;
}
在 activity 的 onCreate
中:((MyApplication) getApplication()).getGoogleAnalyticsTracker();
但是,在同一个 activity 中,如果我手动发送屏幕视图,我确实会在 GA 控制台中看到它。我是这样做的:
Tracker t = ((MyApplication) getApplication()).getGoogleAnalyticsTracker();
t.setScreenName("Login Screen");
t.send(new HitBuilders.ScreenViewBuilder().build());
您需要报告每个 activity 的启动和停止。
public abstract class TrackableActivity extends AppCompatActivity {
@Override
protected void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
protected void onStop() {
GoogleAnalytics.getInstance(this).reportActivityStop(this);
super.onStop();
}
}
我找不到指定此内容的文档了。我记得我曾经遵循那个。无论如何,从 API documentation 开始,如果您想自动跟踪 activity 低于 14 的 API:
public void reportActivityStart (Activity activity)
If auto activity reports are enabled (see enableAutoActivityReports(Application)
) on a device running API level 14 or above, this method will be a noop.
我遇到了与这个问题相同的问题:
enableAutoActivityTracking not automatically tracking activities?
问题是自动跟踪无法使用 Google Analytics。
但是,调用 enableAutoActivityReports
对我来说不起作用。
这是配置XML文件:
<?xml version="1.0" encoding="utf-8"?>
<!-- Google Analytucs property id. -->
<integer name="ga_sessionTimeout">300</integer>
<!-- catch and report uncaught exceptions from the app -->
<bool name="ga_reportUncaughtExceptions">true</bool>
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<!-- The screen names that will appear in reports -->
<screenName name=".LoginActivity">
Login Activity
</screenName>
</resources>
在申请中class:
private Tracker googleAnalyticsTracker;
public synchronized Tracker getGoogleAnalyticsTracker()
{
if (googleAnalyticsTracker == null)
{
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
analytics.enableAutoActivityReports(this);
googleAnalyticsTracker = analytics.newTracker(R.xml.global_tracker);
}
return googleAnalyticsTracker;
}
在 activity 的 onCreate
中:((MyApplication) getApplication()).getGoogleAnalyticsTracker();
但是,在同一个 activity 中,如果我手动发送屏幕视图,我确实会在 GA 控制台中看到它。我是这样做的:
Tracker t = ((MyApplication) getApplication()).getGoogleAnalyticsTracker();
t.setScreenName("Login Screen");
t.send(new HitBuilders.ScreenViewBuilder().build());
您需要报告每个 activity 的启动和停止。
public abstract class TrackableActivity extends AppCompatActivity {
@Override
protected void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
protected void onStop() {
GoogleAnalytics.getInstance(this).reportActivityStop(this);
super.onStop();
}
}
我找不到指定此内容的文档了。我记得我曾经遵循那个。无论如何,从 API documentation 开始,如果您想自动跟踪 activity 低于 14 的 API:
public void reportActivityStart (Activity activity)
If auto activity reports are enabled (see
enableAutoActivityReports(Application)
) on a device running API level 14 or above, this method will be a noop.