Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Created July 18, 2024 06:37
Show Gist options
  • Save shohan4556/8f77065ade95e065d0d7a69ad2ece7fc to your computer and use it in GitHub Desktop.
Save shohan4556/8f77065ade95e065d0d7a69ad2ece7fc to your computer and use it in GitHub Desktop.
using UnityEngine;
using Firebase.Extensions;
using Firebase;
public interface IAnalyticsEvents
{
public abstract void CurrentGameType(string gameType);
public abstract void OnLevelComplete();
public abstract void OnSessionStart(string gameType);
public abstract void OnSessionEnd(string gameType);
public abstract void OnSettings();
public abstract void OnOnlineMultiplayer();
public abstract void OnBlueToothMultiplayer();
public abstract void OnSingleKill(string PlayerType);
public abstract void OnDoubleKill(string PlayerType);
public abstract void OnTrippleKill(string PlayerType);
}
public class FirebaseAnalyticsController : MonoBehaviour, IAnalyticsEvents
{
public static FirebaseAnalyticsController Instance;
private FirebaseApp app;
private const string EventType_Event = "Event";
private const string EventType_Progress = "Progress";
private const string EventGameType = "16_Guti_GameType";
private const string EventLevelComplete = "16_Guti_LevelComplete";
private const string EventSessionStart = "16_Guti_SessionStart";
private const string EventSessionEnd = "16_Guti_SessionStart";
private const string EventSettings = "16_Guti_Settings";
private const string EventOnlineMultiplayer = "16_Guti_OnlineMultiplayer";
private const string EventBlueToothMultiplayer = "16_Guti_BlueToothMultiplayer";
private const string EventSingleKill = "16_Guti_SingleKill";
private const string EventDoubleKill = "16_Guti_DoubleKill";
private const string EventTrippleKill = "16_Guti_TrippleKill";
public bool isFirebaseReady;
void Start()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(Instance);
}
else
{
Destroy(Instance);
}
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.
app = Firebase.FirebaseApp.DefaultInstance;
isFirebaseReady = true;
Debug.Log("<color=green>Firebase Ready</color>");
// Set a flag here to indicate whether Firebase is ready to use by your app.
}
else
{
UnityEngine.Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
// Firebase Unity SDK is not safe to use here.
}
});
}
public void CurrentGameType(string gameType)
{
if (isFirebaseReady)
{
Debug.Log("Log event :" + EventGameType);
Firebase.Analytics.FirebaseAnalytics.LogEvent(EventType_Event, EventGameType, gameType);
}
else
{
Debug.Log("Firebase not ready");
}
}
public void OnLevelComplete()
{
if (isFirebaseReady)
{
Debug.Log("Log event :" + EventLevelComplete);
Firebase.Analytics.FirebaseAnalytics.LogEvent(EventType_Progress, EventLevelComplete, "FirstGamePlayed");
}
else
{
Debug.Log("Firebase not ready");
}
}
public void OnSessionEnd(string gameType)
{
if (isFirebaseReady)
{
Debug.Log("Log event :" + EventSessionEnd);
Firebase.Analytics.FirebaseAnalytics.LogEvent(EventType_Event, EventSessionEnd, gameType);
}
else
{
Debug.Log("Firebase not ready");
}
}
public void OnSessionStart(string gameType)
{
if (isFirebaseReady)
{
Debug.Log("Log event :" + EventSessionStart);
Firebase.Analytics.FirebaseAnalytics.LogEvent(EventType_Event, EventSessionStart, gameType);
}
else
{
Debug.Log("Firebase not ready");
}
}
public void OnSettings()
{
if (isFirebaseReady)
{
Debug.Log("Log event :" + EventSessionEnd);
Firebase.Analytics.FirebaseAnalytics.LogEvent(EventType_Event, EventSettings, "Pressed");
}
else
{
Debug.Log("Firebase not ready");
}
}
public void OnOnlineMultiplayer()
{
if (isFirebaseReady)
{
Debug.Log("Log event :" + EventOnlineMultiplayer);
Firebase.Analytics.FirebaseAnalytics.LogEvent(EventType_Event, EventOnlineMultiplayer, "Pressed");
}
else
{
Debug.Log("Firebase not ready");
}
}
public void OnBlueToothMultiplayer()
{
if (isFirebaseReady)
{
Debug.Log("Log event :" + EventBlueToothMultiplayer);
Firebase.Analytics.FirebaseAnalytics.LogEvent(EventType_Event, EventBlueToothMultiplayer, "Pressed");
}
else
{
Debug.Log("Firebase not ready");
}
}
public void OnSingleKill(string PlayerType)
{
if (isFirebaseReady)
{
Debug.Log("Log event :" + EventSingleKill);
Firebase.Analytics.FirebaseAnalytics.LogEvent(EventType_Event, EventSingleKill, PlayerType);
}
else
{
Debug.Log("Firebase not ready");
}
}
public void OnDoubleKill(string PlayerType)
{
if (isFirebaseReady)
{
Debug.Log("Log event :" + EventDoubleKill);
Firebase.Analytics.FirebaseAnalytics.LogEvent(EventType_Event, EventDoubleKill, PlayerType);
}
else
{
Debug.Log("Firebase not ready");
}
}
public void OnTrippleKill(string PlayerType)
{
if (isFirebaseReady)
{
Debug.Log("Log event :" + EventTrippleKill);
Firebase.Analytics.FirebaseAnalytics.LogEvent(EventType_Event, EventTrippleKill, PlayerType);
}
else
{
Debug.Log("Firebase not ready");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment