using System.Collections.Generic; using UnityEngine; public class GA_SDK_Manager : MonoBehaviour { private static GA_SDK_Manager _Ins; public static GA_SDK_Manager Ins { get { return _Ins; } } //用来记录是否首次登录 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() { return TalkingDataGA.GetDeviceId(); } /// /// 初始化 /// /// 渠道id 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 "); } TDGAAccount account;//当前账户 /// /// 登录,使用自定义的 /// /// public void Login(string deviceID) { account = TDGAAccount.SetAccount(TalkingDataGA.GetDeviceId()); 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 dic = new Dictionary { { "ArriveBattle", "Done"}, }; OnEvent("注册人数统计", dic); isFirstStart = false; PlayerPrefs.SetInt(firstStart, 1); } } /// /// 启动漏斗流统计(去重) ///(1)成功加载启动页的人数 ///(2)成功加载登陆界面的人数 启动首页 ///(3)点击登陆按钮的人数 点击登录 ///(4)成功生成注册信息的人数 登录成功 ///(5)成功加载游戏战斗界面的人数 跳转页面 ///(6)成功进入到新手引导step_1的人数 新手引导1 ///(7)成功完成step_1的人数 完成新手引导1 /// /// 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 dic = new Dictionary { { key, 1} }; // Dictionary dic = new Dictionary // { // { "成功加载登陆界面的人数", 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 dic = new Dictionary { { "Guide", step.ToString()} }; OnEvent("引导步数统计", dic); guideStep = step; PlayerPrefs.SetInt(guideStepStr, step); } } //5.每次游玩过程中,点击【重新开始】按钮的次数,每次重新开始记做一轮 public void OnClickRestartBtn() { Debug.LogError("重新开始按钮次数"); Dictionary dic = new Dictionary { { "OnClickRestartBtn", 1} }; OnEvent("重新开始按钮次数", dic); } //7.每一轮游戏中成功使用技能宝石的次数 public void OnUseSkill(int count) { Debug.LogError("每一轮游戏中成功使用技能宝石的次数:" + count); Dictionary dic = new Dictionary { { "使用次数", count+"次"} }; OnEvent("每一轮游戏中成功使用技能宝石的次数", dic); } //8.每一轮游戏中成功开启的塔位置数量 public void OnOpenTower(int towerCount) { Debug.LogError("每一轮游戏中成功开启的塔位置数量:" + towerCount); Dictionary dic = new Dictionary { { "购买次数", towerCount+"次"} }; OnEvent("每一轮游戏中成功开启的塔位置数量", dic); } //9.每一轮游戏中成功购买塔的数量 public void OnClickTowerBuyBtn(int buyCount) { Debug.LogError("每一轮游戏中成功购买塔的数量:" + buyCount); Dictionary dic = new Dictionary { { "购买次数", buyCount+"次"} }; OnEvent("每一轮游戏中成功购买塔的数量", dic); } //10.玩家在结算界面点击【对pvp感兴趣】按钮次数 public void OnClickPVPBtn() { Debug.LogError("对pvp感兴趣"); Dictionary dic = new Dictionary { { "OnClickPVPBtn", 1} }; OnEvent("对pvp感兴趣", dic); } /// /// 11.玩家打到第x关y波的人数(去重) 这里只穿最大值 /// /// 第几关 /// 第几波 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 dic = new Dictionary { { "MaxWave", $"第{level}关{wave}波"} }; OnEvent("玩家最高打到第x关y波", dic); } } /// /// 12.玩家达到第x关y波的次数(不去重) /// /// 第几关 /// 第几波 public void WaveDone(int level, int wave) { Debug.LogError($"玩家达到第{level}关{wave}波"); Dictionary dic = new Dictionary { { $"第{level}关{wave}波", 1} }; OnEvent("玩家完成第x关y波的次数", dic); } /// /// 使用自定义事件 /// /// 事件名称 /// 需要传递的值 private void OnEvent(string actionId, Dictionary dic) { //示例: // Dictionary dic = new Dictionary // { // { "StringValue", "Pi" }, // { "NumberValue", 3.14 } // }; // TalkingDataGA.OnEvent("action_id", dic); TalkingDataGA.OnEvent(actionId, dic); } private void OnDestroy() { Debug.Log("onDestroy"); TalkingDataGA.OnEnd(); } }