当前,我在这样的应用程序类中初始化Firebase Analytics:
public class App extends MultiDexApplication {
public static FirebaseAnalytics mFirebaseAnalytics;
@Override
public void onCreate() {
super.onCreate();
// Obtain the FirebaseAnalytics instance.
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
}
public static FirebaseAnalytics getFirebaseAnalytics() {
return mFirebaseAnalytics;
}
}
我有一个处理程序类FirebaseHandler
,用于处理所有日志记录:
public class FirebaseHandler {
/**
* Log an event to Firebase, without a bundle.
*/
public static void logEvent(String event) {
App.getFirebaseAnalytics().logEvent(event, null);
}
/**
* Log an event to Firebase, with a bundle
*/
public static void logEvent(String event, Bundle bundle) {
// I've removed some other code which makes checks on the bundle here
App.getFirebaseAnalytics().logEvent(event, bundle);
}
}
然后,当我想在活动中记录一个事件时,请执行以下操作:
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.SOURCE, "TestSource");
bundle.putString(FirebaseAnalytics.Param.MEDIUM, "TestMedium");
bundle.putString(FirebaseAnalytics.Param.CAMPAIGN, "TestCampaign");
FirebaseHandler.logEvent(FirebaseAnalytics.Event.CAMPAIGN_DETAILS, bundle);
FirebaseHandler.logEvent(FirebaseAnalytics.Event.APP_OPEN, bundle);
但是,我注意到这实际上并没有在Google Analytics(分析)中记录事件的参数,但是当我将最后两行更改为以下内容时,它会起作用:
App.getFirebaseAnalytics().logEvent(FirebaseAnalytics.Event.CAMPAIGN_DETAILS, bundle);
App.getFirebaseAnalytics().logEvent(FirebaseAnalytics.Event.APP_OPEN, bundle);
这是为什么?发生了什么事情,导致参数无法记录在第一个代码块中,但没有记录在第二个代码块中?