121 lines
2.8 KiB
Lua
121 lines
2.8 KiB
Lua
|
|
ThinkingAnalyticsManager = {}
|
|||
|
|
local this = ThinkingAnalyticsManager
|
|||
|
|
|
|||
|
|
TA_EVENT = {
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
local function _DicToStr(data)
|
|||
|
|
local index = 1
|
|||
|
|
local str = ""
|
|||
|
|
local fmt = "%s#%s#%s"
|
|||
|
|
for key, value in pairs(data) do
|
|||
|
|
if index ~= 1 then
|
|||
|
|
str = str .."|"
|
|||
|
|
end
|
|||
|
|
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)
|
|||
|
|
index = index + 1
|
|||
|
|
end
|
|||
|
|
return str
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
function this.Initialize()
|
|||
|
|
--什么都不干,Init单独做
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
function this.Init()
|
|||
|
|
if GetChannelConfig().IsOpenTD 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
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
-- 校对时间
|
|||
|
|
function this.CalibrateTime(time)
|
|||
|
|
if GetChannelConfig().IsOpenTD then
|
|||
|
|
App.TAMgr:CalibrateTime(time*1000)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
|
|||
|
|
-- 设置访客Id
|
|||
|
|
function this.SetDistinctId(distinctId)
|
|||
|
|
if GetChannelConfig().IsOpenTD then
|
|||
|
|
App.TAMgr:SetDistinctId(distinctId)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
-- 获取访客Id
|
|||
|
|
function this.GetDistinctId()
|
|||
|
|
if GetChannelConfig().IsOpenTD then
|
|||
|
|
return App.TAMgr:GetDistinctId()
|
|||
|
|
end
|
|||
|
|
return ""
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
-- 登录
|
|||
|
|
function this.Login(accountId)
|
|||
|
|
if GetChannelConfig().IsOpenTD then
|
|||
|
|
App.TAMgr:Login(accountId)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
-- 登出
|
|||
|
|
function this.Logout()
|
|||
|
|
if GetChannelConfig().IsOpenTD then
|
|||
|
|
App.TAMgr:Logout()
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
-- 静态数据设置
|
|||
|
|
local _SuperPropertise = {}
|
|||
|
|
function this.SetSuperProperties(data)
|
|||
|
|
if GetChannelConfig().IsOpenTD then
|
|||
|
|
for key, value in pairs(data) do
|
|||
|
|
_SuperPropertise[key] = value
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local sData = _DicToStr(_SuperPropertise)
|
|||
|
|
Log("打点静态数据:"..sData)
|
|||
|
|
App.TAMgr:SetSuperProperties(sData)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
-- 清除静态数据
|
|||
|
|
function this.ClearSuperProperties()
|
|||
|
|
if GetChannelConfig().IsOpenTD then
|
|||
|
|
_SuperPropertise = {}
|
|||
|
|
App.TAMgr:ClearSuperProperties()
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
-- 打点事件
|
|||
|
|
function this.Track(event, data)
|
|||
|
|
if GetChannelConfig().IsOpenTD then
|
|||
|
|
Log("打点事件:"..event)
|
|||
|
|
local dStr = data and _DicToStr(data) or ""
|
|||
|
|
Log("打点数据:"..dStr)
|
|||
|
|
App.TAMgr:Track(event, dStr)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
return ThinkingAnalyticsManager
|