2020-08-25 15:46:38 +08:00
|
|
|
|
ThinkingAnalyticsManager = {}
|
2020-06-30 18:59:44 +08:00
|
|
|
|
local this = ThinkingAnalyticsManager
|
|
|
|
|
|
2020-07-13 12:25:55 +08:00
|
|
|
|
TA_EVENT = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function _DicToStr(data)
|
|
|
|
|
local index = 1
|
|
|
|
|
local str = ""
|
2020-07-17 17:50:05 +08:00
|
|
|
|
local fmt = "%s#%s#%s"
|
2020-07-13 12:25:55 +08:00
|
|
|
|
for key, value in pairs(data) do
|
|
|
|
|
if index ~= 1 then
|
|
|
|
|
str = str .."|"
|
|
|
|
|
end
|
2020-07-27 17:48:33 +08:00
|
|
|
|
local valueType = 0
|
|
|
|
|
if type(value) == "number" then
|
|
|
|
|
valueType = 1
|
|
|
|
|
elseif type(value) == "string" then
|
|
|
|
|
local sl = string.split(value, "#")
|
|
|
|
|
value = sl[1]
|
|
|
|
|
if sl[2] then
|
|
|
|
|
valueType = tonumber(sl[2]) or 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
str = str..string.format(fmt, key, tostring(value), valueType)
|
2020-07-18 19:24:19 +08:00
|
|
|
|
index = index + 1
|
2020-07-13 12:25:55 +08:00
|
|
|
|
end
|
|
|
|
|
return str
|
|
|
|
|
end
|
|
|
|
|
|
2020-06-30 18:59:44 +08:00
|
|
|
|
function this.Initialize()
|
2020-07-23 17:16:47 +08:00
|
|
|
|
|
2020-07-27 14:42:25 +08:00
|
|
|
|
if AppConst.isSDK then
|
|
|
|
|
-- 监听赛季结束事件
|
|
|
|
|
Game.GlobalEvent:AddEvent(GameEvent.Network.OnReceiveHeartBeat, function(network, time)
|
|
|
|
|
if network.type == SocketType.LOGIN then
|
|
|
|
|
this.CalibrateTime(time)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
-- 尝试触发 安装事件(怀疑安装事件是在第一次触发track时触发的)
|
|
|
|
|
App.TAMgr:Init()
|
|
|
|
|
end
|
2020-07-23 17:16:47 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 校对时间
|
|
|
|
|
function this.CalibrateTime(time)
|
|
|
|
|
if AppConst.isSDK then
|
|
|
|
|
App.TAMgr:CalibrateTime(time*1000)
|
|
|
|
|
end
|
2020-06-30 18:59:44 +08:00
|
|
|
|
end
|
|
|
|
|
|
2020-07-23 17:16:47 +08:00
|
|
|
|
|
2020-07-13 12:25:55 +08:00
|
|
|
|
-- 设置访客Id
|
|
|
|
|
function this.SetDistinctId(distinctId)
|
|
|
|
|
if AppConst.isSDK then
|
|
|
|
|
App.TAMgr:SetDistinctId(distinctId)
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-06-30 18:59:44 +08:00
|
|
|
|
|
2020-07-13 12:25:55 +08:00
|
|
|
|
-- 获取访客Id
|
2020-07-25 18:31:06 +08:00
|
|
|
|
function this.GetDistinctId()
|
2020-07-13 12:25:55 +08:00
|
|
|
|
if AppConst.isSDK then
|
2020-07-25 18:31:06 +08:00
|
|
|
|
return App.TAMgr:GetDistinctId()
|
2020-07-13 12:25:55 +08:00
|
|
|
|
end
|
|
|
|
|
return ""
|
|
|
|
|
end
|
2021-01-20 15:34:33 +08:00
|
|
|
|
-- 获取设备Id
|
|
|
|
|
function this.GetDeviceId()
|
|
|
|
|
if AppConst.isSDK then
|
2021-03-02 15:18:06 +08:00
|
|
|
|
if ServerConfigManager.IsSettingActive(ServerConfigManager.SettingConfig.ThinkAnalysis_GetDeviceID) then
|
2021-01-20 15:34:33 +08:00
|
|
|
|
return App.TAMgr:GetDeviceId()
|
|
|
|
|
end
|
|
|
|
|
return AndroidDeviceInfo.Instance:GetDeviceID()
|
|
|
|
|
end
|
|
|
|
|
return ""
|
|
|
|
|
end
|
|
|
|
|
|
2020-07-13 12:25:55 +08:00
|
|
|
|
|
|
|
|
|
-- 登录
|
|
|
|
|
function this.Login(accountId)
|
|
|
|
|
if AppConst.isSDK then
|
|
|
|
|
App.TAMgr:Login(accountId)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
-- 登出
|
|
|
|
|
function this.Logout()
|
|
|
|
|
if AppConst.isSDK then
|
|
|
|
|
App.TAMgr:Logout()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 静态数据设置
|
|
|
|
|
local _SuperPropertise = {}
|
|
|
|
|
function this.SetSuperProperties(data)
|
|
|
|
|
if AppConst.isSDK then
|
|
|
|
|
for key, value in pairs(data) do
|
|
|
|
|
_SuperPropertise[key] = value
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local sData = _DicToStr(_SuperPropertise)
|
2020-07-18 19:24:19 +08:00
|
|
|
|
Log("打点静态数据:"..sData)
|
2020-07-13 12:25:55 +08:00
|
|
|
|
App.TAMgr:SetSuperProperties(sData)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
-- 清除静态数据
|
|
|
|
|
function this.ClearSuperProperties()
|
|
|
|
|
if AppConst.isSDK then
|
|
|
|
|
_SuperPropertise = {}
|
|
|
|
|
App.TAMgr:ClearSuperProperties()
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-06-30 18:59:44 +08:00
|
|
|
|
|
2020-07-13 12:25:55 +08:00
|
|
|
|
-- 打点事件
|
|
|
|
|
function this.Track(event, data)
|
2020-07-25 17:17:34 +08:00
|
|
|
|
if AppConst.isSDK then
|
|
|
|
|
Log("打点事件:"..event)
|
|
|
|
|
local dStr = data and _DicToStr(data) or ""
|
|
|
|
|
Log("打点数据:"..dStr)
|
|
|
|
|
App.TAMgr:Track(event, dStr)
|
|
|
|
|
end
|
2020-06-30 18:59:44 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ThinkingAnalyticsManager
|