using UnityEngine; using ThinkingAnalytics; using System.Collections.Generic; using UnityEngine.SceneManagement; using System; using GameCore; // 数数 数据平台 namespace GameLogic { public class ThinkingAnalyticsManager :UnitySingleton, IDynamicSuperProperties { //public GUISkin skin; // 动态公共属性接口 public Dictionary GetDynamicSuperProperties() { return new Dictionary() { //{"KEY_DYNAMIC_Time", DateTime.Now} }; } private Dictionary stringToDic(string s) { Dictionary d = new Dictionary(); string[] kvs = s.Split('|'); foreach (string ss in kvs) { string[] kv = ss.Split('#'); d.Add(kv[0], kv[1]); Debug.Log(kv[0] + "***************" + kv[1]); } return d; } void Awake() { // 以时间戳校准 SDK 时间 //ThinkingAnalyticsAPI.CalibrateTime(1585555578000); ThinkingAnalyticsAPI.CalibrateTimeWithNtp("ntp.aliyun.com"); } void Start() { // 开启自动采集启动和关闭事件 ThinkingAnalyticsAPI.EnableAutoTrack(AUTO_TRACK_EVENTS.ALL); } // 设置访客Id public void SetDistinctId(string distinctId) { ThinkingAnalyticsAPI.Identify(distinctId); } // 设置访客Id public string GetDistinctId() { return ThinkingAnalyticsAPI.GetDistinctId(); } // 登录 public void Login(string accountId) { Debug.LogWarning("当前accountId = " + accountId); ThinkingAnalyticsAPI.Login(accountId); } // 登出 public void Logout() { ThinkingAnalyticsAPI.Logout(); } // 设置 public void SetSuperProperties(string sData) { Dictionary data = stringToDic(sData); foreach (string id in data.Keys) { object value = data[id]; Debug.Log("value:" + value.ToString()); } ThinkingAnalyticsAPI.SetSuperProperties(data); } public void ClearSuperProperties() { // 清除公共事件属性 ThinkingAnalyticsAPI.ClearSuperProperties(); } public void Track(string trackEvent, string trackData) { Debug.Log("事件名称:" + trackEvent); Debug.Log("事件数据:" + trackData); Dictionary data = stringToDic(trackData); foreach (string id in data.Keys) { object value = data[id]; Debug.Log("key:" + trackEvent + ", value:" + value.ToString()); } ThinkingAnalyticsAPI.Track(trackEvent, data); } // Debug.Log("TA.TAExample - current disctinct ID is: " + ThinkingAnalyticsAPI.GetDistinctId()); // Debug.Log("TA.TAExample - the device ID is: " + ThinkingAnalyticsAPI.GetDeviceId()); // // 设置动态公共属性,传 this 是因为 this 实现了 IDynamicSuperProperties // ThinkingAnalyticsAPI.SetDynamicSuperProperties(this); // // Track 简单事件 // Scene scene = SceneManager.GetActiveScene(); // ThinkingAnalyticsAPI.Track("unity_start", new Dictionary() { // {"SCENE_NAME", scene.name} // }); // if (scene.name == "scene1") // { // // 设置 SuperProperties // Dictionary superProperties = new Dictionary() // { // {"super_date", DateTime.Now.AddDays(1)}, // {"super_string", "B1"}, // {"super_bool", true}, // {"super_number", 100} // }; // ThinkingAnalyticsAPI.SetSuperProperties(superProperties); // Dictionary response = ThinkingAnalyticsAPI.GetSuperProperties(); // // 测试公共事件属性返回值 // if (response != null) // { // foreach (KeyValuePair kv in response) // { // if (kv.Value is DateTime) // { // Debug.LogWarning("TA.TAExample - Returned super property date: " + ((DateTime)kv.Value).ToString("yyyy-MM-dd")); // } // if (kv.Value is bool) // { // Debug.LogWarning("TA.TAExample - Returned super property bool: " + Convert.ToBoolean(kv.Value)); // } // Debug.LogWarning("TA.TAExample - Returned super property: " + kv.Key + ": " + kv.Value); // } // } // } //} //void OnGUI() //{ // GUI.skin = this.skin; // GUILayout.BeginArea(new Rect(Screen.width * 0.15f, Screen.height * 0.3f, Screen.width * 0.7f, Screen.height * 2.5f)); // if (GUILayout.Button("TRACK TEST_EVENT")) // { // //List listProps = new List(); // //listProps.Add(DateTime.Now); // //listProps.Add("bbb"); // //listProps.Add("ccc"); // // a simple tracking call // Dictionary properties = new Dictionary() // { // {"KEY_DateTime", DateTime.Now.AddDays(1)}, // {"KEY_STRING", "B1"}, // {"KEY_BOOL", true}, // {"KEY_NUMBER", 50.65}, // //{"KEY_LIST", listProps} // }; // ThinkingAnalyticsAPI.Track("TEST_EVENT", properties); // } // if (GUILayout.Button("LOGIN UNITY_USER")) // 设置 account ID // { // ThinkingAnalytics.ThinkingAnalyticsAPI.Login("unity_user"); // } // if (GUILayout.Button("LOGOUT")) // 清除 account ID // { // ThinkingAnalytics.ThinkingAnalyticsAPI.Logout(); // } // if (GUILayout.Button("SET SUPER_PROPERTIES")) // 设置公共属性 // { // Dictionary superProperties = new Dictionary() // { // {"SUPER_LEVEL", 0}, // {"SUPER_CHANNEL", "A3"} // }; // ThinkingAnalyticsAPI.SetSuperProperties(superProperties); // } // if (GUILayout.Button("UNSET SUPER_CHANNEL")) // 清除某条公共属性 // { // ThinkingAnalyticsAPI.UnsetSuperProperty("SUPER_CHANNEL"); // } // if (GUILayout.Button("CLEAR SUPER_PROPERTIES")) // 清除公共属性 // { // ThinkingAnalyticsAPI.ClearSuperProperties(); // } // if (GUILayout.Button("SET USER_PROPERTIES")) // 设置用户属性 // { // ThinkingAnalyticsAPI.UserSet(new Dictionary(){ // {"USER_PROP_NUM", 0}, // {"USER_PROP_STRING", "A3"} // }); // ThinkingAnalyticsAPI.UserSetOnce(new Dictionary(){ // {"USER_PROP_NUM", -50}, // {"USER_PROP_STRING", "A3"} // }); // ThinkingAnalyticsAPI.UserAdd(new Dictionary(){ // {"USER_PROP_NUM", -100.9}, // {"USER_PROP_NUM2", 10.0} // }); // } // if (GUILayout.Button("FLUSH")) // an engage call // { // ThinkingAnalyticsAPI.Flush(); // } // Scene scene = SceneManager.GetActiveScene(); // if (scene.name == "scene1") // { // // Show a button to allow scene2 to be switched to. // if (GUILayout.Button("LOAD SAMPLE")) // { // SceneManager.LoadScene("Sample"); // } // } // else // { // // Show a button to allow scene1 to be returned to. // if (GUILayout.Button("LOAD SCENE1")) // { // SceneManager.LoadScene("scene1"); // } // } // GUILayout.EndArea(); //} } }