ball 项目提交
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using Firebase;
|
||||
using Firebase.Analytics;
|
||||
using Firebase.Extensions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BallKingdomCrush
|
||||
{
|
||||
public class FireBaseManger: MonoBehaviour
|
||||
{
|
||||
|
||||
public static bool IsReady { get; private set; } = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
|
||||
{
|
||||
if (task.Result == DependencyStatus.Available)
|
||||
{
|
||||
Debug.Log("Firebase 初始化成功");
|
||||
|
||||
// 启用 Analytics
|
||||
FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
|
||||
|
||||
IsReady = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Firebase 依赖错误: " + task.Result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Max 广告的收益上传Firebase
|
||||
/// </summary>
|
||||
/// <param name="adUnitId"></param>
|
||||
/// <param name="adInfo"></param>
|
||||
public static void OnAdRevenuePaid(string adUnitId, MaxSdkBase.AdInfo adInfo)
|
||||
{
|
||||
|
||||
if (!IsReady)
|
||||
{
|
||||
Debug.LogWarning("Firebase 未初始化完成,丢弃本次广告打点");
|
||||
return;
|
||||
}
|
||||
|
||||
double revenue = adInfo.Revenue; // 收入,单位是美元 (USD)
|
||||
string networkName = adInfo.NetworkName;
|
||||
string adFormat = adInfo.AdFormat;
|
||||
string adUnitIdentifier = adInfo.AdUnitIdentifier;
|
||||
|
||||
Debug.Log($"AppLovin 广告收入: {revenue} USD, 网络: {networkName}, 广告位: {adUnitId}");
|
||||
|
||||
// 上报到 Firebase
|
||||
var impressionParameters = new[] {
|
||||
new Firebase.Analytics.Parameter("ad_platform", "AppLovin"),
|
||||
new Firebase.Analytics.Parameter("ad_source", networkName),
|
||||
new Firebase.Analytics.Parameter("ad_unit_name", adUnitIdentifier),
|
||||
new Firebase.Analytics.Parameter("ad_format", adFormat),
|
||||
new Firebase.Analytics.Parameter("value", revenue),
|
||||
new Firebase.Analytics.Parameter("currency", "USD"), // All AppLovin revenue is sent in USD
|
||||
};
|
||||
Firebase.Analytics.FirebaseAnalytics.LogEvent("ad_impression", impressionParameters);
|
||||
|
||||
Debug.Log("已上报 ad_impression 事件到 Firebase");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 支付的收益上传Firebase
|
||||
/// </summary>
|
||||
public static void OnPayRevenueEvent(double value)
|
||||
{
|
||||
|
||||
if (!IsReady)
|
||||
{
|
||||
Debug.LogWarning("Firebase 未初始化完成,丢弃本次支付打点");
|
||||
return;
|
||||
}
|
||||
Debug.Log($"AppLovin 支付收入: {value} USD");
|
||||
|
||||
// var impressionParameters = new[] {
|
||||
// new Firebase.Analytics.Parameter("value", value),
|
||||
// new Firebase.Analytics.Parameter("currency", "USD"), // All AppLovin revenue is sent in USD
|
||||
// };
|
||||
//
|
||||
// Firebase.Analytics.FirebaseAnalytics.LogEvent("purchase", impressionParameters);
|
||||
|
||||
// 上报到 Firebase 保持标准格式
|
||||
var parameters = new[] {
|
||||
new Parameter(FirebaseAnalytics.ParameterValue, value),
|
||||
new Parameter(FirebaseAnalytics.ParameterCurrency, "USD")
|
||||
};
|
||||
FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventPurchase, parameters);
|
||||
|
||||
|
||||
Debug.Log("已上报 purchase 事件到 Firebase");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user