161 lines
4.8 KiB
C#
161 lines
4.8 KiB
C#
|
|
#if UNITY_ANDROID || UNITY_IOS || WEBGL_BYTEDANCE
|
|||
|
|
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using ThinkingAnalytics;
|
|||
|
|
using ThinkingData.Analytics;
|
|||
|
|
|
|||
|
|
namespace HC.Plugins
|
|||
|
|
{
|
|||
|
|
public class HCTDAnalyticsUnity : HCSingleton<HCTDAnalyticsUnity>, HCIBaseAnalytics
|
|||
|
|
{
|
|||
|
|
public void InitializeSdk()
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(HCStaticParams.TDAppId) || string.IsNullOrEmpty(HCStaticParams.TDServerUrl))
|
|||
|
|
{
|
|||
|
|
HCDebugger.LogError($"[HCTDAnalytics] 初始化失败,HCStaticParams.TDAppId = {HCStaticParams.TDAppId} HCStaticParams.TDServerUrl = {HCStaticParams.TDServerUrl}");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TDAnalytics.Init(HCStaticParams.TDAppId, HCStaticParams.TDServerUrl);
|
|||
|
|
TDAnalytics.EnableAutoTrack(TDAutoTrackEventType.All);
|
|||
|
|
TDAnalytics.EnableLog(false);
|
|||
|
|
|
|||
|
|
#if WEBGL_BYTEDANCE
|
|||
|
|
SetSuperProperties(HCWebGLSDKManager.AppInfo.GetBaseInfo());
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
var tdFirstEventModel = new TDFirstEventModel("new_device")
|
|||
|
|
{
|
|||
|
|
Properties = new Dictionary<string, object>
|
|||
|
|
{
|
|||
|
|
["status"] = 1
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
TDAnalytics.Track(tdFirstEventModel);
|
|||
|
|
#if WEBGL_BYTEDANCE
|
|||
|
|
// // 首次启动,微信的onShow回调已经执行,需要单独上报一个 start 事件
|
|||
|
|
TrackStart();
|
|||
|
|
|
|||
|
|
StarkSDKSpace.StarkSDK.API.GetStarkAppLifeCycle().OnShowWithDict += e => { TrackStart(); };
|
|||
|
|
StarkSDKSpace.StarkSDK.API.GetStarkAppLifeCycle().OnHide += TrackEnd;
|
|||
|
|
#endif
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static void TrackStart()
|
|||
|
|
{
|
|||
|
|
TDAnalytics.Track("ta_mg_show");
|
|||
|
|
TDAnalytics.TimeEvent("ta_mg_hide");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static void TrackEnd()
|
|||
|
|
{
|
|||
|
|
TDAnalytics.Track("ta_mg_hide");
|
|||
|
|
TDAnalytics.Flush();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public TrackEventPlatform GetTrackEventPlatform()
|
|||
|
|
{
|
|||
|
|
return TrackEventPlatform.TD;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public bool ContainsRemoteConfigKey(string key)
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetRemoteConfigStr(string key, string defaultValue)
|
|||
|
|
{
|
|||
|
|
return defaultValue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public int GetRemoteConfigInt(string key, int defaultValue)
|
|||
|
|
{
|
|||
|
|
return defaultValue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public bool GetRemoteConfigBool(string key, bool defaultValue)
|
|||
|
|
{
|
|||
|
|
return defaultValue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void SetUserId(string userId)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(HCStaticParams.TDAppId) || string.IsNullOrEmpty(HCStaticParams.TDServerUrl))
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TDAnalytics.Login(userId);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void TrackEvent(string eventName, Dictionary<string, object> eventDic = null)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(HCStaticParams.TDAppId) || string.IsNullOrEmpty(HCStaticParams.TDServerUrl))
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
eventDic ??= new Dictionary<string, object>();
|
|||
|
|
TDAnalytics.Track(eventName, eventDic);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void TrackAdRevenue(string eventName, Dictionary<string, object> eventDic)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void SetSuperProperties(Dictionary<string, object> eventDic)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(HCStaticParams.TDAppId) || string.IsNullOrEmpty(HCStaticParams.TDServerUrl))
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
eventDic ??= new Dictionary<string, object>();
|
|||
|
|
TDAnalytics.SetSuperProperties(eventDic);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void UserSet(Dictionary<string, object> eventDic)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(HCStaticParams.TDAppId) || string.IsNullOrEmpty(HCStaticParams.TDServerUrl))
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
eventDic ??= new Dictionary<string, object>();
|
|||
|
|
TDAnalytics.UserSet(eventDic);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Login(string userId)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(HCStaticParams.TDAppId) || string.IsNullOrEmpty(HCStaticParams.TDServerUrl))
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TDAnalytics.Login(userId);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void UserSetOnce(Dictionary<string, object> eventDic)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(HCStaticParams.TDAppId) || string.IsNullOrEmpty(HCStaticParams.TDServerUrl))
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
eventDic ??= new Dictionary<string, object>();
|
|||
|
|
TDAnalytics.UserSetOnce(eventDic);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void SetLogEnable(bool enable)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(HCStaticParams.TDAppId) || string.IsNullOrEmpty(HCStaticParams.TDServerUrl))
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TDAnalytics.EnableLog(enable);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endif
|