using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
public class TDAA_SDKManager : MonoBehaviour
|
{
|
private static TDAA_SDKManager _Ins;
|
public static TDAA_SDKManager 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 TalkingDataPlugin.GetDeviceId();
|
}
|
|
/// <summary>
|
/// 初始化
|
/// </summary>
|
/// <param name="channelId">渠道id</param>
|
public void SDKInit(string channelId)
|
{
|
Debug.Log("Unity SDK init begin channelId:" + channelId);
|
TalkingDataPlugin.BackgroundSessionEnabled();
|
TalkingDataPlugin.SessionStarted("41F4DA3B72CF48D2ADAB761E6C17D12D", channelId);
|
TalkingDataPlugin.SetExceptionReportEnabled(true);
|
Debug.Log("Unity SDK init completed ");
|
}
|
|
//注册
|
public void OnRegister()
|
{
|
TalkingDataPlugin.OnRegister(GetDeviceId(), TalkingDataAccountType.ANONYMOUS, "testwgname");
|
}
|
|
/// <summary>
|
/// 登录
|
/// </summary>
|
public void Login()
|
{
|
TalkingDataPlugin.OnLogin(GetDeviceId(), TalkingDataAccountType.ANONYMOUS, "testwgname");
|
}
|
|
/*
|
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)
|
{
|
OnRegister();
|
|
Debug.LogError("注册人数统计");
|
//只记录一次
|
Dictionary<string, object> dic = new Dictionary<string, object>
|
{
|
{ "ArriveBattle", "Done"},
|
};
|
OnEvent("注册人数统计", dic);
|
isFirstStart = false;
|
PlayerPrefs.SetInt(firstStart, 1);
|
Statistics(3);//埋点
|
}
|
Login();
|
}
|
|
|
/// <summary>
|
/// 启动漏斗流统计(去重)
|
///(1)成功加载登陆界面的人数 启动首页
|
///(2)点击登陆按钮的人数 点击登录
|
///(3)成功生成注册信息的人数 登录成功
|
///(4)成功加载游戏战斗界面的人数 跳转页面
|
///(5)成功进入到新手引导step_1的人数 新手引导1
|
///(6)成功完成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>
|
{
|
{ "已完成", 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(key, 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>
|
/// <param name="actionId">事件名称</param>
|
/// <param name="eventLabel">暂时没有找到什么作用</param>
|
/// <param name="dic">需要传递的值</param>
|
private void OnEvent(string actionId, Dictionary<string, object> dic, string eventLabel = "")
|
{
|
//示例:
|
// Dictionary<string, object> dic = new Dictionary<string, object>
|
// {
|
// { "StringValue", "Pi" },
|
// { "NumberValue", 3.14 }
|
// };
|
// TalkingDataGA.OnEvent("action_id", dic);
|
|
//TalkingDataGA.OnEvent(actionId, dic);
|
TalkingDataPlugin.TrackEventWithParameters(actionId, null, dic);
|
}
|
|
private void OnDestroy()
|
{
|
Debug.Log("onDestroy");
|
TalkingDataPlugin.SessionStoped();
|
}
|
}
|