From 19d51274abe30afbd4f44aa0591e1126ed6f1307 Mon Sep 17 00:00:00 2001 From: huyufei Date: Sat, 11 May 2024 13:09:57 +0800 Subject: [PATCH] =?UTF-8?q?+=20=E4=B8=BA=E6=89=93=E7=82=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=B7=BB=E5=8A=A0=20extra=20=E5=8F=82=E6=95=B0,=20?= =?UTF-8?q?=E6=96=B9=E4=BE=BF=E9=A1=B9=E7=9B=AE=E7=BB=84=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyufei --- .../Runtime/Analytics/Analytics.Economic.cs | 11 +- .../Analytics/Analytics.TemplateDefine.cs | 121 ++++++++++++------ 2 files changed, 90 insertions(+), 42 deletions(-) diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.Economic.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.Economic.cs index cc3b5d2..ec4aef9 100644 --- a/Runtime/GuruCore/Runtime/Analytics/Analytics.Economic.cs +++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.Economic.cs @@ -87,9 +87,9 @@ namespace Guru string category = "", string itemName = "", string levelName = "0", - string scene = "") + string scene = "", Dictionary extra = null) { - var data = new Dictionary() + var data = new Dictionary() { { ParameterVirtualCurrencyName, currencyName }, { ParameterValue, value }, @@ -101,6 +101,7 @@ namespace Guru }; if(!string.IsNullOrEmpty(scene)) data[ParameterScene] = scene; // 获取的虚拟货币或者道具的场景 + if (extra != null) data.AddRange(extra, isOverride: true); LogEvent(EventEarnVirtualCurrency, data, new EventSetting() { EnableFirebaseAnalytics = true }); @@ -114,9 +115,10 @@ namespace Guru string category = "", string itemName = "", string levelName = "0", - string scene = "") + string scene = "" + , Dictionary extra = null) { - var data = new Dictionary() + var data = new Dictionary() { { ParameterVirtualCurrencyName, currencyName }, { ParameterValue, value }, @@ -125,6 +127,7 @@ namespace Guru { ParameterItemCategory, category }, { ParameterItemName, itemName }, }; + if (extra != null) data.AddRange(extra, isOverride: true); if(!string.IsNullOrEmpty(scene)) data[ParameterScene] = scene; // 获取的虚拟货币或者道具的场景 diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.TemplateDefine.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.TemplateDefine.cs index a179229..9f6b56e 100644 --- a/Runtime/GuruCore/Runtime/Analytics/Analytics.TemplateDefine.cs +++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.TemplateDefine.cs @@ -9,30 +9,38 @@ namespace Guru public static partial class Analytics { #region 游戏通用打点 - /// - /// 当玩家在游戏中升级时触发 - /// - /// level (等级)从1开始 标准点 - /// 升级的角色,如果没有可不选 - public static void LevelUp(int level, string character) + + /// + /// 当玩家在游戏中升级时触发 + /// + /// level (等级)从1开始 标准点 + /// 升级的角色,如果没有可不选 + /// + public static void LevelUp(int level, string character, Dictionary extra = null) { - LogEvent(EventLevelUp, new Dictionary() - { - { ParameterLevel, level }, - { ParameterCharacter, character } - }); + var dict = new Dictionary() + { + { ParameterLevel, level }, + { ParameterCharacter, character } + }; + if (extra != null) dict.AddRange(extra, isOverride:true); + + LogEvent(EventLevelUp, dict); } /// /// 玩家已完成解锁成就时触发。 /// /// 这里的成就ID值项目方自行定义 - public static void UnlockAchievement(string achievementID) + public static void UnlockAchievement(string achievementID, Dictionary extra = null) { - LogEvent(EventUnlockAchievement, new Dictionary() - { - { ParameterAchievementId, achievementID }, - }); + var dict = new Dictionary() + { + { ParameterAchievementId, achievementID }, + }; + if (extra != null) dict.AddRange(extra, isOverride:true); + + LogEvent(EventUnlockAchievement, dict); } /// @@ -53,24 +61,33 @@ namespace Guru /// /// 玩家已开始挑战某个关卡时触发。 /// - /// 关卡名称 /// 关卡数 - /// - /// - /// - /// + /// 关卡名称 + /// 关卡类型 + /// 关卡配置表 ID + /// 启动方式 + /// 是否是重玩 + /// 额外数据 public static void LogLevelStart(int level, string levelName, - string itemCategory = "main", string itemId = "", string startType = "play", bool isReplay = false) + string levelType = "main", string levelConfigId = "", string startType = "play", bool isReplay = false, + Dictionary extra = null) { - LogEvent(EventLevelStart, new Dictionary() + Dictionary dataDict = new Dictionary() { { ParameterLevel, level }, { ParameterLevelName, levelName }, - { ParameterItemCategory, itemCategory }, - { ParameterItemId, itemId }, + { ParameterItemCategory, levelType }, + { ParameterItemId, levelConfigId }, { ParameterStartType, startType }, { ParameterReplay, isReplay ? "true" : "false" }, - }); + }; + + if (extra != null) + { + dataDict.AddRange(extra, isOverride:true); + } + + LogEvent(EventLevelStart, dataDict); } /// @@ -81,7 +98,7 @@ namespace Guru /// 关卡名称 /// 关卡数 [Obsolete("Obsolete method, please use instead. will be discard in next version.")] - public static void LevelStart(string itemCategory, string itemID, string levelName, int level, bool isReplay, bool isContinue) + internal static void LevelStart(string itemCategory, string itemID, string levelName, int level, bool isReplay, bool isContinue) { string startType = "play"; @@ -114,8 +131,10 @@ namespace Guru /// 游戏步数【可选】 /// 游戏分数【可选】 /// 重玩标记【可选】 - public static void LevelEnd(string itemCategory, string itemID, string levelName, int level, - ELevelResult result, int? duration = null, int? step = null, int? score = null, bool isReplay = false) + [Obsolete("Obsolete method, please use instead. will be discard in next version.")] + internal static void LevelEnd(string itemCategory, string itemID, string levelName, int level, + ELevelResult result, int? duration = null, int? step = null, int? score = null, bool isReplay = false, + Dictionary extra = null) { var dict = new Dictionary() { @@ -134,6 +153,8 @@ namespace Guru dict[ParameterStep] = step.Value; if(score != null) dict[ParameterScore] = score.Value; + + if(extra != null) dict.AddRange(extra, isOverride:true); LogEvent(EventLevelEnd, dict); @@ -145,10 +166,22 @@ namespace Guru } } - + + /// + /// 关卡结束(Firebase标准事件) + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// public static void LogLevelEnd(int level, string result, string levelName = "", string itemCategory = "main", string itemId = "", - int? duration = null, int? step = null, int? score = null ) + int? duration = null, int? step = null, int? score = null, Dictionary extra = null) { bool isSuccess = result.Equals("success"); @@ -169,6 +202,8 @@ namespace Guru if(score != null) dict[ParameterScore] = score.Value; + if(extra != null) dict.AddRange(extra, isOverride:true); + LogEvent(EventLevelEnd, dict); if (isSuccess) @@ -235,7 +270,8 @@ namespace Guru /// 金币获取的方式,通过IAP购买的方式,固定使用参数值,其余场景自行定义。 /// 玩家当前剩余的虚拟货币数量 /// 购买商品的product_id(购买时传参) - public static void EarnVirtualCurrency(string virtual_currency_name, int value, string item_category, int balance, string sku) + public static void EarnVirtualCurrency(string virtual_currency_name, int value, string item_category, + int balance, string sku, Dictionary extra = null) { var dict = new Dictionary() { @@ -245,6 +281,8 @@ namespace Guru ["balance"] = balance, ["sku"] = sku, }; + if(extra != null) dict.AddRange(extra, isOverride: true); + LogEvent(EventEarnVirtualCurrency, dict); } @@ -255,15 +293,19 @@ namespace Guru /// 虚拟货币的数量 /// 虚拟货币花费场景 /// 玩家当前剩余的虚拟货币数量 - public static void SpendVirtualCurrency(string virtual_currency_name, int value, string item_category, int balance) + public static void SpendVirtualCurrency(string virtual_currency_name, int value, string item_category, + int balance, Dictionary extra = null) { - LogEvent(EventSpendVirtualCurrency, new Dictionary() + var dict = new Dictionary() { [ParameterVirtualCurrencyName] = virtual_currency_name, [ParameterValue] = value, [ParameterItemCategory] = item_category, ["balance"] = balance, - }); + }; + if(extra != null) dict.AddRange(extra, isOverride: true); + + LogEvent(EventSpendVirtualCurrency, dict); } #endregion @@ -275,15 +317,18 @@ namespace Guru /// 本次行为变化前体力 /// 本次行为带来的体力 /// 本次行为变化后体力 - public static void HitPoints(string item_category, int hp_before, int hp, int hp_after) + public static void HitPoints(string item_category, int hp_before, int hp, int hp_after, Dictionary extra = null) { - LogEvent("hit_points", new Dictionary() + var dict = new Dictionary() { [ParameterItemCategory] = item_category, ["hp_before"] = hp_before, ["hp"] = hp, ["hp_after"] = hp_after, - }); + }; + if(extra != null) dict.AddRange(extra, isOverride: true); + + LogEvent("hit_points", dict); } #endregion