Google Analytics(分析)自动活动检测-您可以从中排除单个活动吗? [英] Google Analytics Automatic Activity Detection - can you exclude a single activity from this?
问题描述
自动活动检测功能非常出色-除了我的MainActivity
是一堆带有导航抽屉的不同片段(例如Google Play音乐或Play商店).我正在使用手动屏幕敲击来跟踪该活动中的片段.
Automatic activity detection is great - except my MainActivity
is a bunch of different fragments with a nav drawer (like Google Play Music or the Play Store). I am using manual screen hitting to track the fragments in that activity.
因此,我的MainActivity
的自动屏幕点击毫无意义,并污染了我的统计信息.我可以排除以这种方式跟踪我的MainActivity
吗?
Therefore, an automatic screen hit for my MainActivity
is meaningless and pollutes my stats. Can I exclude my MainActivity
from being tracked in this manner?
参考: https://developers.google.com/analytics/devguides/collection/android/v4/screens#automatic
推荐答案
只需将enableAutoActivityTracking(false)
设置为在活动中获得的Tracker实例.
Just set enableAutoActivityTracking(false)
to the Tracker instance obtained in the activity.
Assuming that you created a getDefaultTracker()
method in your Application class as described in the official docs, you can create a parent class for your application activities that can change auto-tracking behavior on demand:
public abstract class ParentActivity extends Activity {
Tracker mTracker = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getTracker();
}
/* Obtains Google Analytics Tracker for this activity */
Tracker getTracker() {
if (mTracker == null) {
AnalyticsApplication application = (AnalyticsApplication) getApplication();
mTracker = application.getDefaultTracker();
// Enable or disable auto-tracking for this activity
mTracker.enableAutoActivityTracking(shouldAutoTrack());
}
return mTracker;
}
/* Defines whether this activity should enable auto-track or not. Default is true. */
protected boolean shouldAutoTrack() {
return true;
}
}
您的主要活动仅需扩展ParentActivity并覆盖shouldAutoTrack
方法以返回false:
Your main activity just have to extend ParentActivity and override shouldAutoTrack
method to return false:
public class MainActivity extends ParentActivity {
/* Disable auto-tracking for this activity */
protected boolean shouldAutoTrack() {
return false;
}
}
这篇关于Google Analytics(分析)自动活动检测-您可以从中排除单个活动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!