FireBase收益上报接口
This commit is contained in:
parent
e334189040
commit
3972dddb25
|
@ -1,5 +1,6 @@
|
|||
|
||||
using Firebase.Analytics;
|
||||
using Newtonsoft.Json;
|
||||
using SDK.Utils;
|
||||
|
||||
/// <summary>
|
||||
|
@ -46,4 +47,64 @@ public class FireBaseAnalyticsManager : NormalSingleton<FireBaseAnalyticsManager
|
|||
{
|
||||
Firebase.Analytics.FirebaseAnalytics.SetUserProperty(name, property);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// FireBase收益上报
|
||||
/// </summary>
|
||||
private void OnAdRevenueEvent(string ad_platform, string ad_source, string ad_unit_name, string ad_format, double revenue)
|
||||
{
|
||||
var impressionParameters = new[] {
|
||||
new Firebase.Analytics.Parameter("ad_platform", ad_platform),
|
||||
new Firebase.Analytics.Parameter("ad_source", ad_source),
|
||||
new Firebase.Analytics.Parameter("ad_unit_name",ad_unit_name),
|
||||
new Firebase.Analytics.Parameter("ad_format", ad_format),
|
||||
new Firebase.Analytics.Parameter("value", revenue),
|
||||
new Firebase.Analytics.Parameter("currency", "USD"), // All AppLovin revenue is sent in USD
|
||||
};
|
||||
|
||||
string name = GetName();
|
||||
Firebase.Analytics.FirebaseAnalytics.LogEvent(name, impressionParameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 收益分离
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private string GetName()
|
||||
{
|
||||
string name = "ad_impression";
|
||||
//获取在线参数
|
||||
string json = FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("revenue_fir");
|
||||
if (string.IsNullOrEmpty(json))
|
||||
{
|
||||
return name;
|
||||
}
|
||||
var revenueAdjs = JsonConvert.DeserializeObject<RevenueAdjItem[]>(json);
|
||||
if (revenueAdjs == null && revenueAdjs.Length == 0)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
int totalRate = 0;
|
||||
//获取全部概率
|
||||
foreach (var item in revenueAdjs)
|
||||
{
|
||||
totalRate += item.rate;
|
||||
}
|
||||
//开始随机
|
||||
int randomValue = UnityEngine.Random.Range(0, totalRate);
|
||||
int accumulatedRate = 0;
|
||||
|
||||
//根据随机值定位
|
||||
foreach (var item in revenueAdjs)
|
||||
{
|
||||
accumulatedRate += item.rate;
|
||||
if (randomValue < accumulatedRate)
|
||||
{
|
||||
return item.name;
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue