0

我们如何使用谷歌分析 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);
    }
}
4

1 回答 1

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());
于 2015-01-05T19:19:19.913 回答