diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.TemplateDefine.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.TemplateDefine.cs index 0fe981a..606ffd3 100644 --- a/Runtime/GuruCore/Runtime/Analytics/Analytics.TemplateDefine.cs +++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.TemplateDefine.cs @@ -1,5 +1,4 @@ -using System.Data.Odbc; -using JetBrains.Annotations; + namespace Guru { @@ -296,10 +295,10 @@ namespace Guru /// /// /// - /// - public static void Tch001IAPRev(double value, string productId, string orderId, string orderType, string timestamp, bool isSandbox = false) + /// + public static void Tch001IAPRev(double value, string productId, string orderId, string orderType, string timestamp, bool isTest = false) { - TchRevEvent(EventTchAdRev001Impression, IAPPlatform, value, orderType, productId, orderId, timestamp, isSandbox? "true" : "false"); + TchRevEvent(EventTchAdRev001Impression, IAPPlatform, value, orderType, productId, orderId, timestamp, isTest); } /// @@ -313,10 +312,10 @@ namespace Guru /// /// // public static void Tch02IAPRev(double value, string productId, string orderId, string orderType, string timestamp) - public static void Tch02IAPRev(double value, string productId, string orderId, string orderType, string timestamp, bool isSandbox = false) + public static void Tch02IAPRev(double value, string productId, string orderId, string orderType, string timestamp, bool isTest = false) { if (!EnableTch02Event) return; - TchRevEvent(EventTchAdRev02Impression, IAPPlatform, value, orderType, productId, orderId, timestamp, isSandbox? "true" : "false"); + TchRevEvent(EventTchAdRev02Impression, IAPPlatform, value, orderType, productId, orderId, timestamp, isTest); } /// @@ -365,9 +364,9 @@ namespace Guru /// /// /// - /// + /// private static void TchRevEvent(string evtName, string platform, double value, - string orderType = "", string productId = "", string orderId = "", string timestamp = "", string sandbox = "") + string orderType = "", string productId = "", string orderId = "", string timestamp = "", bool isTest = false) { var data = new Dictionary() { @@ -376,7 +375,10 @@ namespace Guru { ParameterCurrency, USD }, }; + string sandbox = isTest ? "true" : "false"; + //--------- Extra data for IAP receipt --------------- + if(!string.IsNullOrEmpty(orderType)) data["order_type"] = orderType; if(!string.IsNullOrEmpty(productId)) data["product_id"] = productId; if(!string.IsNullOrEmpty(orderId)) data["order_id"] = orderId; @@ -631,22 +633,38 @@ 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, isTest); + // TCH 020 Tch02IAPRev(usdPrice, productId, orderId, orderType, orderDate, isTest); + // Facebook Track IAP Purchase FBPurchase(usdPrice, USD, "iap", IAPPlatform); if (orderData.orderType == 1) { // sub_pruchase : Firebase + Guru + Adjust - SubPurchase(usdPrice, productId, orderId, orderDate, isTest); + SubPurchase(usdPrice, productId, orderId, orderDate, productToken, receipt); } else { // iap_purchase : Firebase + Guru + Adjust - IAPPurchase(usdPrice, productId, orderId, orderDate, isTest); + IAPPurchase(usdPrice, productId, orderId, orderDate, productToken, receipt); } // IAP Ret true : Firebase + Guru + Adjust @@ -665,20 +683,34 @@ namespace Guru /// /// /// - public static void IAPPurchase(double value, string productId, string orderId, string orderDate, bool isSandbox = false) + /// + /// + public static void IAPPurchase(double value, string productId, string orderId, string orderDate, + string purchaseToken = "", string receipt = "") { - IAPPurchaseReport(EventIAPPurchase, value, productId, orderId, "IAP", orderDate, isSandbox); + IAPPurchaseReport(EventIAPPurchase, value, productId, orderId, "IAP", orderDate, purchaseToken, receipt); } - public static void SubPurchase(double value, string productId, string orderId, string orderDate, bool isSandbox = false) + /// + /// SUB 订阅上报 + /// + /// + /// + /// + /// + /// + /// + public static void SubPurchase(double value, string productId, string orderId, string orderDate, + string purchaseToken = "", string receipt = "") { - IAPPurchaseReport(EventSubPurchase, value, productId, orderId, "SUB", orderDate, isSandbox); + 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, bool isSandbox = false) + private static void IAPPurchaseReport(string eventName, double value, string productId, + string orderId, string orderType, string orderDate, string purchaseToken = "", string receipt = "") { - LogEvent(eventName, new Dictionary() + + var dict = new Dictionary() { [ParameterPlatform] = IAPPlatform, [ParameterValue] = value, @@ -686,13 +718,14 @@ namespace Guru [ParameterProductId] = productId, ["order_id"] = orderId, ["order_type"] = orderType, - ["trans_ts"] = orderDate, - ["sandbox"] = isSandbox? "true": "false" - }, new EventSetting() - { - EnableFirebaseAnalytics = true, - EnableAdjustAnalytics = true, - }); + ["trans_ts"] = orderDate + }; + + // 上报Firebase + 自打点 + LogEvent(eventName, dict, new EventSetting() { EnableFirebaseAnalytics = true }); + + // 上报 Adjust 支付事件 + LogAdjustRevenueEvent(eventName, value, productId, orderId, purchaseToken, receipt, dict); } #endregion diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.cs index 3af502a..42f1631 100644 --- a/Runtime/GuruCore/Runtime/Analytics/Analytics.cs +++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.cs @@ -250,6 +250,44 @@ namespace Guru } } + /// + /// 上报 Adjust 事件 + /// + /// + /// + /// + /// + /// + /// + /// + /// + internal static bool LogAdjustRevenueEvent(string eventName, double usdPrice, + string productId = "", string transactionId = "", string purchaseToken = "", string receipt = "", + Dictionary 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 通用打点 diff --git a/Runtime/GuruCore/Runtime/IPM/Scripts/Requests/DeviceInfoUploadRequest.cs b/Runtime/GuruCore/Runtime/IPM/Scripts/Requests/DeviceInfoUploadRequest.cs index 55e28a8..1f6ddf1 100644 --- a/Runtime/GuruCore/Runtime/IPM/Scripts/Requests/DeviceInfoUploadRequest.cs +++ b/Runtime/GuruCore/Runtime/IPM/Scripts/Requests/DeviceInfoUploadRequest.cs @@ -31,10 +31,10 @@ namespace Guru protected override void RequestSuccessCallBack(string response) { - this.Log("@@@ Send OK!"); + UnityEngine.Debug.Log("[SDK] --- Send DeviceData Success"); IPMConfig.IS_UPLOAD_DEVICE_SUCCESS = true; } - + /// /// 设置是否打开推送 ///