TalkingDataManager.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Collections.Generic;
  2. using Fort23.UTool;
  3. using UnityEngine;
  4. using Utility;
  5. public class TalkingDataManager : Singleton<TalkingDataManager>
  6. {
  7. private string appID = "965461C1FE104336864EF6D7EBABC2A7";
  8. #if Taptap
  9. private string channelID = "Taptap_Android";
  10. #elif HaoYouKuaiBao
  11. private string channelID = "好友快报_Android";
  12. #elif Google
  13. private string channelID = "Google_Android";
  14. #else
  15. private string channelID = "Unity_Android";
  16. #endif
  17. private bool isInitialized = false;
  18. public void CustomInit()
  19. {
  20. InitializeTalkingData();
  21. }
  22. /// <summary>
  23. /// 初始化TalkingData SDK
  24. /// </summary>
  25. public void InitializeTalkingData()
  26. {
  27. if (isInitialized) return;
  28. try
  29. {
  30. // TalkingDataSDKConfig config = TalkingDataSDKConfig.CreateConfig();
  31. // config.SetIMEIAndMEIDEnabled(true) //不允许收集IMEI和MEID
  32. // .SetMACEnabled(true) //不允许收集MAC
  33. // .SetAppListEnabled(true) //不允许收集应用列表
  34. // .SetLocationEnabled(true) //不允许收集位置信息
  35. // .SetWifiEnabled(true); //不允许收集网络信息
  36. // TalkingDataSDK.SetConfig(config);
  37. TalkingDataSDK.BackgroundSessionEnabled();
  38. TalkingDataSDK.InitSDK(appID, channelID, "");
  39. TalkingDataSDK.StartA();
  40. TalkingDataSDK.SetReportUncaughtExceptions(true);
  41. isInitialized = true;
  42. LogTool.Log($"TalkingData 初始化成功 - AppID: {appID}, Channel: {channelID}");
  43. }
  44. catch (System.Exception e)
  45. {
  46. LogTool.Error($"TalkingData 初始化失败: {e.Message}");
  47. }
  48. }
  49. /// <summary>
  50. /// 账户登录
  51. /// </summary>
  52. public void OnLogin()
  53. {
  54. if (!isInitialized) return;
  55. try
  56. {
  57. TalkingDataProfile profile = TalkingDataProfile.CreateProfile();
  58. profile.SetName(PlayerManager.Instance.PlayerName);
  59. profile.SetType(TalkingDataProfileType.TYPE1);
  60. profile.SetGender(TalkingDataGender.UNKNOWN);
  61. Dictionary<string, object> eventValue = new Dictionary<string, object>
  62. {
  63. };
  64. TalkingDataSDK.OnLogin(PlayerManager.Instance.PlayerName, profile, eventValue);
  65. LogTool.Log($"TalkingData 设置账户: {PlayerManager.Instance.PlayerName}");
  66. }
  67. catch (System.Exception e)
  68. {
  69. LogTool.Error($"TalkingData 设置账户失败: {e.Message}");
  70. }
  71. }
  72. /// <summary>
  73. /// 记录自定义事件
  74. /// </summary>
  75. public void TrackEvent(string eventID, Dictionary<string, object> parameters,
  76. Dictionary<string, object> eventValue = null)
  77. {
  78. if (!isInitialized) return;
  79. try
  80. {
  81. TalkingDataSDK.OnEvent(eventID, parameters, eventValue);
  82. LogTool.Log($"TalkingData 记录事件: {eventID} ");
  83. }
  84. catch (System.Exception e)
  85. {
  86. LogTool.Error($"TalkingData 记录事件失败: {e.Message}");
  87. }
  88. }
  89. }