From 8716403033b7c70b00b61bc6c74af04e4d248ecc Mon Sep 17 00:00:00 2001
From: chenxin <chenxin6991@163.com>
Date: Wed, 28 Oct 2020 10:20:07 +0800
Subject: [PATCH] little commit

---
 Assets/Scripts/GameAnalytics_SDK/GA_SDK_Manager.cs |  305 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 301 insertions(+), 4 deletions(-)

diff --git a/Assets/Scripts/GameAnalytics_SDK/GA_SDK_Manager.cs b/Assets/Scripts/GameAnalytics_SDK/GA_SDK_Manager.cs
index 0af8587..c416801 100644
--- a/Assets/Scripts/GameAnalytics_SDK/GA_SDK_Manager.cs
+++ b/Assets/Scripts/GameAnalytics_SDK/GA_SDK_Manager.cs
@@ -1,4 +1,5 @@
-using UnityEngine;
+using System.Collections.Generic;
+using UnityEngine;
 
 public class GA_SDK_Manager : MonoBehaviour
 {
@@ -10,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()
@@ -30,6 +67,7 @@
     public void SDKInit(string channelId)
     {
         Debug.Log("Unity SDK  init begin channelId:" + channelId);
+        TalkingDataGA.BackgroundSessionEnabled();
         TalkingDataGA.OnStart("B220F5C737384030947B202F19E32086", channelId);//appID是定死的
         Debug.Log("Unity SDK  init completed ");
     }
@@ -46,6 +84,265 @@
         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>
+    private void OnEvent(string actionId, Dictionary<string, object> dic)
+    {
+        //示例:
+        // Dictionary<string, object> dic = new Dictionary<string, object>
+        // {
+        //     { "StringValue", "Pi" },
+        //     { "NumberValue", 3.14 }
+        // };
+        // TalkingDataGA.OnEvent("action_id", dic);
+
+        // TalkingDataGA.OnEvent(actionId, dic);
+
+    }
 
     private void OnDestroy()
     {

--
Gitblit v1.9.1