我已经尝试向我的游戏添加分析两天了,第二天我终于能够构建项目,但出现了另一个问题,我的事件没有显示在 FireBase RealTime 控制台中。我不知道该怎么办,下面的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase.Extensions;
using Firebase.Analytics;
public class Analytics : MonoBehaviour
{
private void Awake()
{
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
{
var dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available)
{
// Create and hold a reference to your FirebaseApp,
// where app is a Firebase.FirebaseApp property of your application class.
Firebase.FirebaseApp app = Firebase.FirebaseApp.DefaultInstance;
FirebaseAnalytics.LogEvent("first_open");
FirebaseAnalytics.LogEvent("test_event");
FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventAppOpen);
// Set a flag here to indicate whether Firebase is ready to use by your app.
Debug.Log("FBReady");
}
else
{
UnityEngine.Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
// Firebase Unity SDK is not safe to use here.
}
});
}
private void Start()
{
FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventAppOpen);
FirebaseAnalytics.LogEvent("first_open");
FirebaseAnalytics.LogEvent("GameStart");
FirebaseAnalytics.LogEvent("test_event");
FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventLevelStart);
Events();
}
public void EventTriggerTest()
{
FirebaseAnalytics.LogEvent("TestEvent");
Debug.Log("EventWasLoged");
}
public void EventTriggerTest(int number)
{
FirebaseAnalytics.LogEvent("TestEventParam", new Parameter[]
{
new Parameter("ButtonNumber",number)
});
Debug.Log("EventParamWasLoged");
}
public void Events()
{
Firebase.Analytics.FirebaseAnalytics.LogEvent(
Firebase.Analytics.FirebaseAnalytics.EventSelectContent,
new Firebase.Analytics.Parameter(
Firebase.Analytics.FirebaseAnalytics.ParameterItemId, "0"),
new Firebase.Analytics.Parameter(
Firebase.Analytics.FirebaseAnalytics.ParameterItemName, "name"),
new Firebase.Analytics.Parameter(
Firebase.Analytics.FirebaseAnalytics.UserPropertySignUpMethod, "Google"),
new Firebase.Analytics.Parameter(
"user_id", "0"));
}
}
重新安装后第一次启动时,我只看到first_open事件,但没有看到绑定到按钮和start方法的事件。我在某处读到,你需要等待 24 小时才能在 FireBase 中显示,我找到了一种调试方法,但我不明白在哪里插入这些启用调试的行,所以我陷入困境,我只能等待 24 小时按下按钮并希望事件会出现
adb shell setprop debug.firebase.analytics.app PACKAGE_NAME
我找到了解决方案,
if(AnalyticsConnected)// 布尔值 ...LogEvent(“测试事件”)
3.我添加协程,它从 Start() 开始并重复直到 Firebase.FirebaseApp.CheckAndFixDependenciesAsync() ...返回 false