以下行是我的Google Analytics v4设置。一切看起来都很正确。应用程序工作正常,但我无法在Google Analytics控制台上看到实时和其他数据。为什么呢?
GoogleAnal.java
public class GoogleAnal extends Application {
public GoogleAnal() {
super();
}
public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
if(trackerId == TrackerName.APP_TRACKER){
Tracker t = analytics.newTracker(R.xml.app_tracker);
mTrackers.put(trackerId, t);
}
}
return mTrackers.get(trackerId);
}
}
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
....
....
....
Tracker t = ((GoogleAnal) this.getApplication()).getTracker(TrackerName.APP_TRACKER);
t.setScreenName("Screen1");
}
@Override
protected void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
protected void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}