using System; using System.Collections; using System.Collections.Generic; using UnityEngine; #if UNITY_PURCHASE namespace WZ { public static class IAPEvent { public static void LogPurchaseInit() { var eventName = "Purchase_Init"; FireBaseAnalyticsManager.Instance.LogEvent(eventName); ShuShuEvent.Instance.Track(eventName); } public static void LogPurchaseInit(bool success, string message = "") { var eventName = success ? "Purchase_Init_Success" : "Purchase_Init_Fail"; if (success) { FireBaseAnalyticsManager.Instance.LogEvent(eventName); ShuShuEvent.Instance.Track(eventName); } else { FireBaseAnalyticsManager.Instance.LogEvent(eventName, new Dictionary { { "fail_reason", message } }); ShuShuEvent.Instance.Track(eventName, new Dictionary { { "fail_reason", message } }); } } public static void LogPurchaseSuccess(PurchaseInfo info,string environment) { // 总支付次数 int payTimes = PlayerPrefsUtils.GetPlayerPrefsInt("PAY_TIME", 0); if (!info.orderAlreadyExists) { payTimes += 1; } float fPrice; if (!float.TryParse(info.price, out fPrice)) { fPrice = 0.0f; } var args = new Dictionary { { "IAP", info.productName }, { "product_id", info.productID }, { "currency", info.currency }, { "Price", fPrice }, { "order_id", info.orderID }, { "game_extra", info.gameExtra }, { "is_first", PlayerPrefsUtils.GetPlayerPrefsInt(First_Purchase, 0) == 0}, { "payment_type", "GooglePlay" }, { "product_type", info.productType }, { "orderAlreadyExists", info.orderAlreadyExists } }; if (string.IsNullOrEmpty(environment)) environment = ""; var eventName = environment.Equals("sandbox") ? "IAP_Success_Sandbox" : "IAP_Success"; FireBaseAnalyticsManager.Instance.LogEvent(eventName, args); ShuShuEvent.Instance.Track(eventName, args); // 首次订单 设置支付次数/累计支付次数/累计支付金额 if (!info.orderAlreadyExists) { fPrice = fPrice + PlayerPrefsUtils.GetPlayerPrefsFloat(PURCHASE_PRICE, 0.0f); PlayerPrefsUtils.SavePlayerPrefsFloat(PURCHASE_PRICE, fPrice); ShuShuEvent.Instance.UserSet(new Dictionary() { { "total_pay_amount", fPrice }, { "total_pay_times", payTimes } }); ShuShuEvent.Instance.SetSuperProperties(new Dictionary() { { "pay_times", payTimes } }); PlayerPrefsUtils.SavePlayerPrefsInt(First_Purchase, 1); ShuShuEvent.Instance.UserSet(new Dictionary() { { "first_pay_time", DateTime.Now } }, true); } PlayerPrefsUtils.SavePlayerPrefsInt(PAY_TIME, payTimes); } public static void LogPurchaseFail(PurchaseInfo info) { var eventName = "IAP_Fail"; float fPrice; if (!float.TryParse(info.price, out fPrice)) { fPrice = 0.0f; } var para = new Dictionary { { "IAP", info.productName }, { "product_id", info.productID }, { "currency", info.currency }, { "pay_amount", fPrice }, { "order_id", info.orderID }, { "game_extra", info.gameExtra ?? ""}, { "payment_type", "GooglePlay" }, { "fail_reason", info.failReason } }; FireBaseAnalyticsManager.Instance.LogEvent(eventName, para); ShuShuEvent.Instance.Track(eventName, para); } public static void LogIAPButtonClick(PurchaseInfo info) { var eventName = "IAP_Button_Click"; float fPrice; if (!float.TryParse(info.price, out fPrice)) { fPrice = 0.0f; } var args = new Dictionary { { "IAP", info.productName}, { "product_id", info.productID}, { "currency", info.currency }, { "Price", fPrice }, { "game_extra", info.gameExtra}, { "payment_type", "GooglePlay" }, }; FireBaseAnalyticsManager.Instance.LogEvent(eventName, args); ShuShuEvent.Instance.Track(eventName, args); } public static void LogClientComplete(PurchaseInfo info) { var eventName = "Client_Finish_Channel"; float fPrice; if (!float.TryParse(info.price, out fPrice)) { fPrice = 0.0f; } var para = new Dictionary { { "IAP", info.productName }, { "product_id", info.productID }, { "currency", info.currency }, { "Price", fPrice }, { "order_id", info.orderID }, { "game_extra", info.gameExtra ?? ""}, { "payment_type", "GooglePlay" }, { "product_type",info.productType}, { "is_first", PlayerPrefsUtils.GetPlayerPrefsInt(First_Purchase, 0) == 0 } }; FireBaseAnalyticsManager.Instance.LogEvent(eventName, para); ShuShuEvent.Instance.Track(eventName, para); } public static void LogSaveOrderBySdk(PurchaseInfo info) { var eventName = "IAP_SDK_Save_Order"; float fPrice; if (!float.TryParse(info.price, out fPrice)) { fPrice = 0.0f; } var para = new Dictionary { { "IAP", info.productName }, { "product_id", info.productID }, { "currency", info.currency }, { "price", fPrice }, { "order_id", info.orderID }, { "game_extra", info.gameExtra ?? ""}, { "payment_type", "GooglePlay" }, { "product_type",info.productType}, { "is_first", PlayerPrefsUtils.GetPlayerPrefsInt(First_Purchase, 0) == 0 } }; FireBaseAnalyticsManager.Instance.LogEvent(eventName, para); ShuShuEvent.Instance.Track(eventName, para); } public static void LogStarVerifyOrderBySdk(PurchaseInfo info) { var eventName = "IAP_Cache_Order"; float fPrice; if (!float.TryParse(info.price, out fPrice)) { fPrice = 0.0f; } var para = new Dictionary { { "IAP", info.productName }, { "product_id", info.productID }, { "currency", info.currency }, { "price", fPrice }, { "order_id", info.orderID }, { "game_extra", info.gameExtra}, { "payment_type", "GooglePlay" }, { "product_type",info.productType}, { "is_first", PlayerPrefsUtils.GetPlayerPrefsInt(First_Purchase, 0) == 0 } }; FireBaseAnalyticsManager.Instance.LogEvent(eventName, para); ShuShuEvent.Instance.Track(eventName, para); } public static void LogRemoveOrderBySdk(PurchaseInfo info) { var eventName = "IAP_SDK_Remove_Order"; float fPrice; if (!float.TryParse(info.price, out fPrice)) { fPrice = 0.0f; } var para = new Dictionary { { "price", fPrice }, { "product_id", info.productID }, { "IAP", info.productName }, { "order_id", info.orderID }, { "currency", info.currency }, { "payment_method", "googleplay" }, { "game_extra", info.gameExtra}, { "product_type", info.productType} }; FireBaseAnalyticsManager.Instance.LogEvent(eventName, para); ShuShuEvent.Instance.Track(eventName, para); } public static void LogChecingOrderBySdk(string _productName, string _productId, string _orderId, string gameExtra01, string gameExtra02) { var eventName = "IAP_Checking_Order"; string price = IAPPurchaseManager.Instance.GetProductInfoByID(_productId).metadata.localizedPrice.ToString(); string currency = IAPPurchaseManager.Instance.GetProductInfoByID(_productId).metadata.isoCurrencyCode; string productType = IAPPurchaseManager.Instance.GetProductInfoByID(_productId).definition.type.ToString(); float fPrice; if (!float.TryParse(price, out fPrice)) { fPrice = 0.0f; } var para = new Dictionary { { "IAP", _productName }, { "product_id", _productId }, { "currency", currency }, { "price", fPrice }, { "order_id", _orderId }, { "is_first", PlayerPrefsUtils.GetPlayerPrefsInt(First_Purchase, 0) == 0 }, { "payment_type", "GooglePlay" }, { "product_type", productType }, { "game_extra01", gameExtra01 }, { "game_extra02", gameExtra02 } }; FireBaseAnalyticsManager.Instance.LogEvent(eventName, para); ShuShuEvent.Instance.Track(eventName, para); } public static string First_Purchase = "First_purchase"; public static string PAY_TIME = "PAY_TIME"; public static string PURCHASE_PRICE = "PURCHASE_PRICE"; } } #endif