From 1cc976d33bfbe7488c85df9d35f28aa6e4360294 Mon Sep 17 00:00:00 2001
From: wangguan <wangguan@kt007.com>
Date: Tue, 27 Oct 2020 20:38:46 +0800
Subject: [PATCH] 埋点

---
 Assets/Scripts/Common/GameConfig.cs                |    2 
 Assets/Scripts/GameAnalytics_SDK/UI/LoginUI.cs     |   39 ++++-
 Assets/Scripts/GameAnalytics_SDK/GA_SDK_Manager.cs |  285 ++++++++++++++++++++++++++++++++++++++++++++++
 Assets/Materials/Guide/RectGuidance.mat            |    2 
 Assets/Scripts/TowerDefense/UI/EndlessUIStart.cs   |    3 
 Assets/Scripts/Guide/GuideCtrl.cs                  |   18 +++
 6 files changed, 332 insertions(+), 17 deletions(-)

diff --git a/Assets/Materials/Guide/RectGuidance.mat b/Assets/Materials/Guide/RectGuidance.mat
index 7d18417..46f4431 100644
--- a/Assets/Materials/Guide/RectGuidance.mat
+++ b/Assets/Materials/Guide/RectGuidance.mat
@@ -83,7 +83,7 @@
     - _UseUIAlphaClip: 0
     - _ZWrite: 1
     m_Colors:
-    - _Center: {r: -150, g: -198, b: 0, a: 0}
+    - _Center: {r: 6, g: -198, b: 0, a: 0}
     - _Color: {r: 1, g: 1, b: 1, a: 1}
     - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
   m_BuildTextureStacks: []
diff --git a/Assets/Scripts/Common/GameConfig.cs b/Assets/Scripts/Common/GameConfig.cs
index f1dfa0c..11e4672 100644
--- a/Assets/Scripts/Common/GameConfig.cs
+++ b/Assets/Scripts/Common/GameConfig.cs
@@ -10,7 +10,7 @@
         /// <summary>
         /// LoadingScene 载入下一个场景的场景名
         /// </summary>
-        public static string NextSceneName = "GemBattle";
+        public static string NextSceneName = "Endless";
 
         public static bool IsDebug = false;
         public static string TestLoginUrl = "http://10.5.3.227:9000/user/login";
diff --git a/Assets/Scripts/GameAnalytics_SDK/GA_SDK_Manager.cs b/Assets/Scripts/GameAnalytics_SDK/GA_SDK_Manager.cs
index 30cb89a..dbec834 100644
--- a/Assets/Scripts/GameAnalytics_SDK/GA_SDK_Manager.cs
+++ b/Assets/Scripts/GameAnalytics_SDK/GA_SDK_Manager.cs
@@ -11,12 +11,48 @@
             return _Ins;
         }
     }
-    /// <summary>
-    /// Awake is called when the script instance is being loaded.
-    /// </summary>
+    //用来记录是否首次登录
+    bool isFirstStart;
+    string firstStart = "GemBattleFirstStart";
+
+    //漏斗流统计(去重)
+    int statisticsStep;
+    string statisticsStr = "GemBattleStatistics";
+
+    //新手引导
+    int guideStep;
+    string guideStepStr = "GemBattleGuideStep";
+
+    int maxLevel;//达到的最大关
+    int maxWave;//达到最大波次
+
+    string maxLevelStr = "GemBattleMaxLevelStr";
+    string maxWaveStr = "GemBattleMaxWaveStr";
+
     void Awake()
     {
         _Ins = this;
+        //PlayerPrefs.DeleteAll();
+        //Debug.LogError("清除了数据");
+        isFirstStart = PlayerPrefs.GetInt(firstStart) == 0;
+        statisticsStep = PlayerPrefs.GetInt(statisticsStr);
+        guideStep = PlayerPrefs.GetInt(guideStepStr);
+
+        maxLevel = PlayerPrefs.GetInt(maxLevelStr);
+        maxWave = PlayerPrefs.GetInt(maxWaveStr);
+    }
+
+    //清空数据
+    public void Reset()
+    {
+        Debug.LogError("清除了数据");
+        PlayerPrefs.DeleteAll();
+        isFirstStart = PlayerPrefs.GetInt(firstStart) == 0;
+        statisticsStep = PlayerPrefs.GetInt(statisticsStr);
+        guideStep = PlayerPrefs.GetInt(guideStepStr);
+
+        maxLevel = PlayerPrefs.GetInt(maxLevelStr);
+        maxWave = PlayerPrefs.GetInt(maxWaveStr);
     }
 
     public string GetDeviceId()
@@ -48,13 +84,253 @@
         account.SetAccountType(AccountType.ANONYMOUS);
     }
 
+    /*
+    0.注册人数统计:以成功进入到战斗界面为注册成功   ---登录了就跳转页面
+
+    1.启动漏斗流统计(去重)
+    (1)成功加载启动页的人数
+    (2)成功加载登陆界面的人数             启动首页
+    (3)点击登陆按钮的人数                 点击登录
+    (4)成功生成注册信息的人数             登录成功
+    (5)成功加载游戏战斗界面的人数         跳转页面
+    (6)成功进入到新手引导step_1的人数     新手引导1
+    (7)成功完成step_1的人数               完成新手引导1
+
+    2.引导步数统计
+    (1)定义新手引导第n步 = step_n
+    (2)完成step_n,状态记为n
+    (3)需要统计每个玩家的n的值
+    (4)可根据每一个n的值统计人数
+
+    3.玩家每日的启动次数
+
+    4.每次启动的游玩时长,按1min为1个区间,统计各区间每日玩家人数
+
+    5.每次游玩过程中,点击【重新开始】按钮的次数,每次重新开始记做一轮
+
+    7.每一轮游戏中成功使用技能宝石的次数
+
+    8.每一轮游戏中成功开启的塔位置数量
+
+    9.每一轮游戏中成功购买塔的数量
+
+    10.玩家在结算界面点击【对pvp感兴趣】按钮次数
+
+    11.玩家打到第x关y波的人数(去重)
+
+    12.玩家达到第x关y波的次数(不去重)
+    */
+
+
+
+    //0.注册人数统计:以成功进入到战斗界面为注册成功
+    public void ArriveBattle()
+    {
+        if (isFirstStart)
+        {
+            Debug.LogError("注册人数统计");
+            //只记录一次
+            Dictionary<string, object> dic = new Dictionary<string, object>
+            {
+                { "ArriveBattle", "Done"},
+            };
+            OnEvent("注册人数统计", dic);
+            isFirstStart = false;
+            PlayerPrefs.SetInt(firstStart, 1);
+        }
+    }
+
+
+    /// <summary>
+    /// 启动漏斗流统计(去重)
+    ///(1)成功加载启动页的人数
+    ///(2)成功加载登陆界面的人数              启动首页
+    ///(3)点击登陆按钮的人数                  点击登录
+    ///(4)成功生成注册信息的人数              登录成功
+    ///(5)成功加载游戏战斗界面的人数          跳转页面
+    ///(6)成功进入到新手引导step_1的人数      新手引导1
+    ///(7)成功完成step_1的人数               完成新手引导1
+    /// </summary>
+    /// <param name="step"></param>
+    public void Statistics(int step)
+    {
+        if (step > statisticsStep)
+        {
+            string key = "";
+            switch (step)
+            {
+                case 1:
+                    key = "成功加载登陆界面的人数";
+                    break;
+                case 2:
+                    key = "点击登陆按钮的人数";
+                    break;
+                case 3:
+                    key = "成功生成注册信息的人数";
+                    break;
+                case 4:
+                    key = "成功加载游戏战斗界面的人数";
+                    break;
+                case 5:
+                    key = "成功进入到新手引导step_1的人数";
+                    break;
+                case 6:
+                    key = "成功完成step_1的人数";
+                    break;
+            }
+            Dictionary<string, object> dic = new Dictionary<string, object>
+            {
+                { key, 1}
+            };
+
+            // Dictionary<string, object> dic = new Dictionary<string, object>
+            // {
+            //     { "成功加载登陆界面的人数", 0},
+            //     { "点击登陆按钮的人数", 0},
+            //     { "成功生成注册信息的人数", 0},
+            //     { "成功加载游戏战斗界面的人数", 0},
+            //     { "成功进入到新手引导step_1的人数", 0},
+            //     { "成功完成step_1的人数", 0}
+            // };
+            //dic[key] = 1;
+
+            Debug.LogError("漏斗流统计:" + key);
+
+            OnEvent("漏斗流统计", dic);
+            statisticsStep = step;
+            PlayerPrefs.SetInt(statisticsStr, step);
+        }
+    }
+
+    //单人统计一次 历史最高
+    // 2.引导步数统计
+    //(1)定义新手引导第n步 = step_n
+    //(2)完成step_n,状态记为n
+    //(3)需要统计每个玩家的n的值
+    //(4)可根据每一个n的值统计人数
+    public void GuideStep(int step)
+    {
+        if (step > guideStep)
+        {
+            Debug.LogError("引导步数统计:" + step);
+            Dictionary<string, object> dic = new Dictionary<string, object>
+            {
+                { "Guide", step.ToString()}
+            };
+            OnEvent("引导步数统计", dic);
+
+            guideStep = step;
+            PlayerPrefs.SetInt(guideStepStr, step);
+        }
+    }
+
+    //5.每次游玩过程中,点击【重新开始】按钮的次数,每次重新开始记做一轮
+    public void OnClickRestartBtn()
+    {
+        Debug.LogError("重新开始按钮次数");
+        Dictionary<string, object> dic = new Dictionary<string, object>
+        {
+            { "OnClickRestartBtn", 1}
+        };
+        OnEvent("重新开始按钮次数", dic);
+    }
+
+    //7.每一轮游戏中成功使用技能宝石的次数
+    public void OnUseSkill(int count)
+    {
+        Debug.LogError("每一轮游戏中成功使用技能宝石的次数:" + count);
+        Dictionary<string, object> dic = new Dictionary<string, object>
+        {
+            { "使用次数", count+"次"}
+        };
+        OnEvent("每一轮游戏中成功使用技能宝石的次数", dic);
+    }
+
+    //8.每一轮游戏中成功开启的塔位置数量
+    public void OnOpenTower(int towerCount)
+    {
+        Debug.LogError("每一轮游戏中成功开启的塔位置数量:" + towerCount);
+        Dictionary<string, object> dic = new Dictionary<string, object>
+        {
+            { "购买次数", towerCount+"次"}
+        };
+        OnEvent("每一轮游戏中成功开启的塔位置数量", dic);
+    }
+
+    //9.每一轮游戏中成功购买塔的数量
+    public void OnClickTowerBuyBtn(int buyCount)
+    {
+        Debug.LogError("每一轮游戏中成功购买塔的数量:" + buyCount);
+        Dictionary<string, object> dic = new Dictionary<string, object>
+        {
+            { "购买次数", buyCount+"次"}
+        };
+        OnEvent("每一轮游戏中成功购买塔的数量", dic);
+    }
+
+    //10.玩家在结算界面点击【对pvp感兴趣】按钮次数
+    public void OnClickPVPBtn()
+    {
+        Debug.LogError("对pvp感兴趣");
+        Dictionary<string, object> dic = new Dictionary<string, object>
+        {
+            { "OnClickPVPBtn", 1}
+        };
+        OnEvent("对pvp感兴趣", dic);
+    }
+
+
+    /// <summary>
+    /// 11.玩家打到第x关y波的人数(去重) 这里只穿最大值
+    /// </summary>
+    /// <param name="level">第几关</param>
+    /// <param name="wave">第几波</param>
+    public void MaxWave(int level, int wave)
+    {
+        bool canSend = false;
+        if (level >= maxLevel)
+        {
+            if (level > maxLevel)
+            {
+                canSend = true;
+            }
+            else if (level == maxLevel && wave > maxWave)
+            {
+                canSend = true;
+            }
+        }
+        if (canSend)
+        {
+            Debug.LogError($"玩家最高打到第{level}关{wave}波");
+            Dictionary<string, object> dic = new Dictionary<string, object>
+            {
+                { "MaxWave", $"第{level}关{wave}波"}
+            };
+            OnEvent("玩家最高打到第x关y波", dic);
+        }
+    }
+
+    /// <summary>
+    /// 12.玩家达到第x关y波的次数(不去重)
+    /// </summary>
+    /// <param name="level">第几关</param>
+    /// <param name="wave">第几波</param>
+    public void WaveDone(int level, int wave)
+    {
+        Debug.LogError($"玩家达到第{level}关{wave}波");
+        Dictionary<string, object> dic = new Dictionary<string, object>
+        {
+            { $"第{level}关{wave}波", 1}
+        };
+        OnEvent("玩家完成第x关y波的次数", dic);
+    }
 
     /// <summary>
     /// 使用自定义事件
     /// </summary>
     /// <param name="actionId">事件名称</param>
     /// <param name="dic">需要传递的值</param>
-    public void OnEvent(string actionId, Dictionary<string, object> dic)
+    private void OnEvent(string actionId, Dictionary<string, object> dic)
     {
         //示例:
         // Dictionary<string, object> dic = new Dictionary<string, object>
@@ -65,6 +341,7 @@
         // TalkingDataGA.OnEvent("action_id", dic);
 
         TalkingDataGA.OnEvent(actionId, dic);
+
     }
 
     private void OnDestroy()
diff --git a/Assets/Scripts/GameAnalytics_SDK/UI/LoginUI.cs b/Assets/Scripts/GameAnalytics_SDK/UI/LoginUI.cs
index 038712f..5a0c4af 100644
--- a/Assets/Scripts/GameAnalytics_SDK/UI/LoginUI.cs
+++ b/Assets/Scripts/GameAnalytics_SDK/UI/LoginUI.cs
@@ -19,20 +19,22 @@
     void Start()
     {
         GA_SDK_Manager.Ins.SDKInit(ChannelID.Gm.ToString());
+        GA_SDK_Manager.Ins.Statistics(1);//成功加载登陆界面的人数
         isLogining = false;
 
         transform.Find("Panel/Button").GetComponent<Button>().onClick.AddListener(OnClickLoginBtn);
 
-        // if (Application.platform == RuntimePlatform.Android)
-        // {
-        //     GetetDeviceIMEI();//获取安卓手机IMEI
-        // }
-        // else if (Application.platform == RuntimePlatform.WindowsEditor)
-        // {
-        //     imei0 = "MyTestGemBattle1";
-        // }
+        if (Application.platform == RuntimePlatform.Android)
+        {
+            //GetetDeviceIMEI();//获取安卓手机IMEI
+            imei0 = GA_SDK_Manager.Ins.GetDeviceId();//使用设备ID
+        }
+        else if (Application.platform == RuntimePlatform.WindowsEditor)
+        {
+            imei0 = "MyTestGemBattle123";
+        }
 
-        imei0 = GA_SDK_Manager.Ins. GetDeviceId();//使用设备ID
+
 
     }
 
@@ -69,8 +71,8 @@
 
     private void OnClickLoginBtn()
     {
-        Debug.Log("登录");
         LoginRequest();
+        GA_SDK_Manager.Ins.Statistics(2);//埋点
 
     }
 
@@ -82,6 +84,19 @@
     {
         if (!isLogining)
         {
+            Debug.Log("登录");
+            if (Application.platform == RuntimePlatform.WindowsEditor)
+            {
+                Debug.Log("编辑器直接登录");
+
+                GA_SDK_Manager.Ins.Login(imei0);
+                GA_SDK_Manager.Ins.Statistics(3);//埋点
+
+                //StartCoroutine(loginMy());
+                StartCoroutine(LoadScene());
+                return;
+            }
+
             isLogining = true;
             string url = GameConfig.IsDebug ? GameConfig.TestLoginUrl : GameConfig.LoginUrl;
             JsonData data = new JsonData();
@@ -163,9 +178,11 @@
         if (login.Errorcode == 0)
         {
             Debug.Log("--------------------- 登录成功 ---------------------");
-            UserDataMsg userData = login.Userdata;
+            //UserDataMsg userData = login.Userdata;
 
             GA_SDK_Manager.Ins.Login(imei0);
+            GA_SDK_Manager.Ins.Statistics(3);//埋点
+
             //StartCoroutine(loginMy());
             StartCoroutine(LoadScene());
 
diff --git a/Assets/Scripts/Guide/GuideCtrl.cs b/Assets/Scripts/Guide/GuideCtrl.cs
index 6c0e062..2ab64f7 100644
--- a/Assets/Scripts/Guide/GuideCtrl.cs
+++ b/Assets/Scripts/Guide/GuideCtrl.cs
@@ -175,6 +175,8 @@
         if (currentIndex == -1)//初始化本步
         {
             CommonDebugHelper.DebugError("第1步开始");
+            GA_SDK_Manager.Ins.Statistics(5);//埋点
+
             currentIndex = 0;
             needIndex = 2;
             panel.SetGuideUI(true);
@@ -190,6 +192,8 @@
         if (currentIndex == -1)
         {
             CommonDebugHelper.DebugError("第2步开始");
+            GA_SDK_Manager.Ins.Statistics(6);//埋点
+            GA_SDK_Manager.Ins.GuideStep(1);//埋点
 
             currentIndex = 0;
             needIndex = 2;
@@ -235,6 +239,8 @@
         if (currentIndex == -1)
         {
             CommonDebugHelper.DebugError("第3步开始");
+            GA_SDK_Manager.Ins.GuideStep(2);//埋点
+
             currentIndex = 0;
             needIndex = 2;
             panel.Step2(currentIndex);
@@ -255,6 +261,7 @@
         if (currentIndex == -1)
         {
             CommonDebugHelper.DebugError("第4步开始");
+            GA_SDK_Manager.Ins.GuideStep(3);//埋点
 
             currentIndex = 0;
             needIndex = 2;
@@ -286,6 +293,7 @@
         if (currentIndex == -1)
         {
             CommonDebugHelper.DebugError("第5步开始");
+            GA_SDK_Manager.Ins.GuideStep(4);//埋点
 
             currentIndex = 0;
             panel.Step4(currentIndex, allGuideDic[currentStep][currentIndex]);
@@ -305,6 +313,7 @@
         if (currentIndex == -1)
         {
             CommonDebugHelper.DebugError("第6步开始");
+            GA_SDK_Manager.Ins.GuideStep(5);//埋点
 
             EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.CreateFirstWave);
             panel.Step5(currentIndex, "");
@@ -332,6 +341,7 @@
         if (currentIndex == -1)
         {
             CommonDebugHelper.DebugError("第7步开始");
+            GA_SDK_Manager.Ins.GuideStep(6);//埋点
 
             panel.SetGuideUI(false);
             //恢复出怪
@@ -363,6 +373,7 @@
         if (currentIndex == -1)
         {
             CommonDebugHelper.DebugError("第8步开始");
+            GA_SDK_Manager.Ins.GuideStep(7);//埋点
 
             currentIndex = 0;
             needIndex = 1;
@@ -389,6 +400,7 @@
         if (currentIndex == -1)//初始化本步
         {
             CommonDebugHelper.DebugError("第9步开始");
+            GA_SDK_Manager.Ins.GuideStep(8);//埋点
             GameConfig.CanOpenNewTower = false;
 
             currentIndex = 0;
@@ -409,6 +421,7 @@
         if (currentIndex == -1)
         {
             CommonDebugHelper.DebugError("第10步开始");
+            GA_SDK_Manager.Ins.GuideStep(9);//埋点
 
             currentIndex = 0;
             needIndex = 2;
@@ -448,6 +461,7 @@
         if (currentIndex == -1)//初始化本步
         {
             CommonDebugHelper.DebugError("第11步开始");
+            GA_SDK_Manager.Ins.GuideStep(10);//埋点
 
             currentIndex = 0;
             needIndex = 2;
@@ -467,6 +481,7 @@
         if (currentIndex == -1)
         {
             CommonDebugHelper.DebugError("第12步开始");
+            GA_SDK_Manager.Ins.GuideStep(11);//埋点
 
             currentIndex = 0;
             needIndex = 1;
@@ -502,6 +517,7 @@
         if (currentIndex == -1)//初始化本步
         {
             CommonDebugHelper.DebugError("第13步开始");
+            GA_SDK_Manager.Ins.GuideStep(12);//埋点
 
             currentIndex = 0;
             needIndex = 3;
@@ -519,6 +535,8 @@
     private void Finish()
     {
         UnityEngine.Debug.Log("新手指导已经完成了");
+        GA_SDK_Manager.Ins.GuideStep(13);//埋点
+
         GameConfig.CanOpenNewTower = true;
 
         EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.GuideFinish);
diff --git a/Assets/Scripts/TowerDefense/UI/EndlessUIStart.cs b/Assets/Scripts/TowerDefense/UI/EndlessUIStart.cs
index b5114bb..4e3c949 100644
--- a/Assets/Scripts/TowerDefense/UI/EndlessUIStart.cs
+++ b/Assets/Scripts/TowerDefense/UI/EndlessUIStart.cs
@@ -52,6 +52,9 @@
     // Start is called before the first frame update
     void Start()
     {
+        GA_SDK_Manager.Ins.ArriveBattle();//埋点
+        GA_SDK_Manager.Ins.Statistics(4);//埋点
+
         bVibrate = new bool[4];
         bVibrate[0] = bVibrate[1] = bVibrate[2] = bVibrate[3] = false;
 

--
Gitblit v1.9.1