#if UNITY_WEBGL using System.Collections.Generic; namespace HC.Plugins { public class HCTDAnalyticsWebGL : HCSingleton, HCIBaseAnalytics { public void InitializeSdk() { CallNative("InitializeSdk"); #if WEBGL_WX HCSDKManager.Instance.GetUserInfo(result => { if (result.Code == WxUserInfo.CODE_SUCCESS) { TrackWxUserInfo(result); } }); #endif } #if WEBGL_WX public void TrackWxUserInfo(WxUserInfo result) { UserSet(new Dictionary { ["user_AvatarUrl"] = result.AvatarUrl, ["user_City"] = result.City, ["user_Country"] = result.Country, ["user_Gender"] = result.Gender, ["user_Language"] = result.Language, ["user_NickName"] = result.NickName, ["user_Province"] = result.Province, }); } #endif 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) { CallNative("SetUserId", new Dictionary { ["userId"] = userId }); } public void TrackEvent(string eventName, Dictionary eventDic = null) { eventDic ??= new Dictionary(); eventDic["eventName"] = eventName; CallNative("TrackEvent", eventDic); } public void TrackAdRevenue(string eventName, Dictionary eventDic) { eventDic ??= new Dictionary(); eventDic["eventName"] = eventName; CallNative("TrackAdRevenue", eventDic); } public void SetSuperProperties(Dictionary eventDic) { eventDic ??= new Dictionary(); CallNative("SetSuperProperties", eventDic); } public void UserSet(Dictionary eventDic) { eventDic ??= new Dictionary(); CallNative("UserSet", eventDic); } public void Login(string userId) { var eventDic = new Dictionary { ["userId"] = userId }; CallNative("Login", eventDic); } public void UserSetOnce(Dictionary eventDic) { eventDic ??= new Dictionary(); CallNative("UserSetOnce", eventDic); } public void SetLogEnable(bool enable) { var eventDic = new Dictionary { ["enable"] = enable }; CallNative("SetLogEnable", eventDic); } private string CallNative(string methodName, Dictionary args = null) { #if UNITY_EDITOR HCDebugger.LogDebug($"[CallNative] methodName = {methodName} args = {MiniJSON.Json.Serialize(args)}"); #else args ??= new Dictionary(); var requestDict = new Dictionary(); requestDict["cmd"] = "HCTDAnalytics"; requestDict["methodName"] = methodName; requestDict["args"] = args; var requestMsg = MiniJSON.Json.Serialize(requestDict); HCWxTools.UnityToWxMiniGame(requestMsg); #endif return ""; } public string GetDistinctId() { return CallNative("GetDistinctId"); } } } #endif