I’ve been trying to add analytics to my game for 2 days now, on the second day I was finally able to build the project, but another problem arose, my events are not displayed in the FireBase RealTime Console. I don’t know what to do, code below
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"));
}
}
At the first launch after reinstallation, I only see the first_open event, but I don’t see my events that I bound to the buttons and to the start method. I read somewhere that you need to wait 24 hours for it to display in FireBase, I found a debugging method, but I don’t understand where to insert these lines that enable Debug, so I’m stuck, I can only wait 24 hours from pressing the buttons and hope that events will appear
adb shell setprop debug.firebase.analytics.app PACKAGE_NAME
2
Answers
I found solution,
if(AnalyticsConnected)// bool value ...LogEvent ("TestEvent")
3.I add Coroutine, which start in Start() and repeat until Firebase.FirebaseApp.CheckAndFixDependenciesAsync() ... Return false
Glad to hear you were able to get this to work.
For those coming to this question later, this is the basic method of initializing Firebase in Unity.
For anyone wondering about debugging GA4 in Unity the command listed above is slightly incorrect.
The command is (as stated above)
BUT,
PACKAGE_NAME
must be replaced with your Android App’s Package name.For Android, this command must be issued to a shell connected to your Android app via Android Debug Bridge
Once this is done, you can use
adb logcat
to debug your Android app.