fix: 修复 Adjust 事件重复上报以及为调用接口导致 revenue 没有正确上报的 BUG

Signed-off-by: huyufei <yufei.hu@castbox.fm>
hotfix/v1.0.12.2
胡宇飞 2024-07-01 09:49:52 +08:00
parent 4a5229780a
commit 3d9d027e89
2 changed files with 79 additions and 13 deletions

View File

@ -1,4 +1,4 @@
using JetBrains.Annotations;
namespace Guru
{
@ -621,6 +621,22 @@ namespace Guru
string scene = orderData.scene;
bool isFree = orderData.isFree;
string offerId = orderData.offerId;
string transactionId = "";
string productToken = "";
string receipt = "";
if (orderData is GoogleOrderData gdata)
{
productToken = gdata.token;
}
else if (orderData is AppleOrderData adata)
{
receipt = adata.receipt;
}
// TCH 001
Tch001IAPRev(usdPrice, productId, orderId, orderType, orderDate);
// TCH 020
@ -631,12 +647,12 @@ namespace Guru
if (orderData.orderType == 1)
{
// sub_pruchase : Firebase + Guru + Adjust
SubPurchase(usdPrice, productId, orderId, orderDate);
SubPurchase(usdPrice, productId, orderId, orderDate, productToken, receipt);
}
else
{
// iap_purchase : Firebase + Guru + Adjust
IAPPurchase(usdPrice, productId, orderId, orderDate);
IAPPurchase(usdPrice, productId, orderId, orderDate, productToken, receipt);
}
// IAP Ret true : Firebase + Guru + Adjust
@ -655,20 +671,24 @@ namespace Guru
/// <param name="productId"></param>
/// <param name="orderId"></param>
/// <param name="orderDate"></param>
public static void IAPPurchase(double value, string productId, string orderId, string orderDate)
public static void IAPPurchase(double value, string productId, string orderId, string orderDate,
string purchaseToken = "", string receipt = "")
{
IAPPurchaseReport(EventIAPPurchase, value, productId, orderId, "IAP", orderDate);
IAPPurchaseReport(EventIAPPurchase, value, productId, orderId, "IAP", orderDate, purchaseToken, receipt);
}
public static void SubPurchase(double value, string productId, string orderId, string orderDate)
public static void SubPurchase(double value, string productId, string orderId, string orderDate,
string purchaseToken = "", string receipt = "")
{
IAPPurchaseReport(EventSubPurchase, value, productId, orderId, "SUB", orderDate);
IAPPurchaseReport(EventSubPurchase, value, productId, orderId, "SUB", orderDate, purchaseToken, receipt);
}
private static void IAPPurchaseReport(string eventName, double value, string productId, string orderId, string orderType, string orderDate)
private static void IAPPurchaseReport(string eventName, double value, string productId, string orderId, string orderType, string orderDate,
string purchaseToken = "", string receipt = "")
{
LogEvent(eventName, new Dictionary<string, dynamic>()
var dict = new Dictionary<string, dynamic>()
{
[ParameterPlatform] = IAPPlatform,
[ParameterValue] = value,
@ -677,11 +697,19 @@ namespace Guru
["order_id"] = orderId,
["order_type"] = orderType,
["trans_ts"] = orderDate
}, new EventSetting()
};
// 上报Firebase + 自打点
LogEvent(eventName, dict, new EventSetting() { EnableFirebaseAnalytics = true, });
// 上报 Adjust 支付事件
if (value > 0)
{
EnableFirebaseAnalytics = true,
EnableAdjustAnalytics = true,
});
// 根据事件名称来获取对应的事件Tokeniap_purchase/sub_purchase
LogAdjustRevenueEvent(eventName, value, productId, orderId, purchaseToken, receipt, dict);
}
}
#endregion

View File

@ -248,6 +248,44 @@ namespace Guru
}
}
/// <summary>
/// 上报 Adjust 事件
/// </summary>
/// <param name="eventName"></param>
/// <param name="productId"></param>
/// <param name="receipt"></param>
/// <param name="data"></param>
/// <param name="usdPrice"></param>
/// <param name="transactionId"></param>
/// <param name="purchaseToken"></param>
/// <returns></returns>
internal static bool LogAdjustRevenueEvent(string eventName, double usdPrice,
string productId = "", string transactionId = "", string purchaseToken = "", string receipt = "",
Dictionary<string, object> data = null )
{
AdjustEvent adjustEvent = Analytics.CreateAdjustEvent(eventName);
if (adjustEvent != null)
{
adjustEvent.setRevenue(usdPrice, USD);
if (!string.IsNullOrEmpty(productId)) adjustEvent.setProductId(productId);
if (!string.IsNullOrEmpty(transactionId)) adjustEvent.setTransactionId(transactionId);
if (!string.IsNullOrEmpty(purchaseToken)) adjustEvent.setPurchaseToken(purchaseToken);
if (!string.IsNullOrEmpty(receipt)) adjustEvent.setReceipt(receipt);
if (data != null && data.Count > 0)
{
foreach (var kv in data)
{
adjustEvent.AddEventParameter(kv.Key, kv.Value.ToString());
}
}
Adjust.trackEvent(adjustEvent);
return true;
}
return false;
}
#endregion
#region 通用打点