我们如何使用google analytics v4跟踪片段?
这是我的应用程序类:
public class MyApplication extends Application {
private static final String PROPERTY_ID = "UA-XXXXXXX-1";
public static int GENERAL_TRACKER = 0;
public enum TrackerName {
APP_TRACKER
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
public MyApplication() {
super();
}
synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = analytics.newTracker(R.xml.app_tracker);
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
}
答案 0 :(得分:0)
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
TrackerName.APP_TRACKER);
t.setScreenName("FRAGMENT_NAME");
t.send(new HitBuilders.AppViewBuilder().build());
这种方式应该适合您的需要,不是吗?
或者这样:
t.send(new HitBuilders.EventBuilder()
.setCategory("Category")
.setAction("Action_Id")
.setLabel("Label")
.build());