Tracking.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. using UnityEngine;
  2. using System.Runtime.InteropServices;
  3. using AOT;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using System.IO;
  8. using System.Text.RegularExpressions;
  9. using System.Collections;
  10. public class Tracking: MonoBehaviour
  11. {
  12. private static Tracking _instance = null;
  13. //private static Regex regex = new Regex("^([a-zA-Z])([a-zA-Z0-9_]){0,63}$");
  14. public static Tracking Instance {
  15. get {
  16. if (!_instance) {
  17. _instance = FindObjectOfType (typeof(Tracking)) as Tracking;
  18. if (!_instance) {
  19. GameObject am = new GameObject ("Tracking");
  20. _instance = am.AddComponent (typeof(Tracking)) as Tracking;
  21. }
  22. }
  23. return _instance;
  24. }
  25. }
  26. private static List<Action> waitingTaskList = new List<Action>();
  27. private static List<Action> executingTaskList = new List<Action>();
  28. public static void PostTask(Action task)
  29. {
  30. lock (waitingTaskList)
  31. {
  32. waitingTaskList.Add(task);
  33. }
  34. }
  35. private void Update()
  36. {
  37. lock (waitingTaskList)
  38. {
  39. if (waitingTaskList.Count > 0)
  40. {
  41. executingTaskList.AddRange(waitingTaskList);
  42. waitingTaskList.Clear();
  43. }
  44. }
  45. for (int i = 0; i < executingTaskList.Count; ++i)
  46. {
  47. Action task = executingTaskList[i];
  48. try
  49. {
  50. task();
  51. }
  52. catch (Exception e)
  53. {
  54. Debug.LogError(e.Message, this);
  55. }
  56. }
  57. executingTaskList.Clear();
  58. }
  59. void Awake ()
  60. {
  61. DontDestroyOnLoad (this);
  62. }
  63. public delegate void DeferredDeeplinkCallBack(string result);
  64. public delegate void AttributionCalllback(string result, int status);
  65. private DeferredDeeplinkCallBack deferredDeeplinCallback_private = null;
  66. private AttributionCalllback attributionCalllback_private = null;
  67. #if UNITY_IOS && !UNITY_EDITOR
  68. internal delegate void _internalDeferredDeeplinkCallBack(string result);
  69. internal delegate void _internalAttributionCalllback(string result, int status);
  70. [DllImport ("__Internal")]
  71. private static extern void _internalInitWithAppKeyAndChannel_Tracking (string appKey, string channelId);
  72. [DllImport ("__Internal")]
  73. private static extern void _preInit_newer (string appKey);
  74. [DllImport ("__Internal")]
  75. private static extern void _internalInitWithAppKeyAndChannel_Tracking_newer (string appKey, string channelId,string caid1,string caid2,string oid,string install_params,string startup_params);
  76. [DllImport ("__Internal")]
  77. private static extern void _internalSetRegisterWithAccountID_Tracking_newer (string account,string params_string);
  78. [DllImport ("__Internal")]
  79. private static extern void _internalSetLoginWithAccountIDAndServerId_Tracking_newer (string account,string serverId,string params_string);
  80. [DllImport ("__Internal")]
  81. private static extern void _internalSetRyzf_Tracking_newer (string ryTID, string ryzfType, string hbType, float hbAmount,string params_string);
  82. [DllImport ("__Internal")]
  83. private static extern void _internalSetDD_Tracking_newer (string ryTID, string hbType, float hbAmount,string params_string);
  84. [DllImport ("__Internal")]
  85. private static extern void _internalSetEvent_Tracking_newer (string EventName,string params_string);
  86. [DllImport ("__Internal")]
  87. private static extern void _internalSetTrackViewDuration_Tracking_newer (string viewID,long duration,string params_string);
  88. [DllImport ("__Internal")]
  89. private static extern void _internalSetAdShow_Tracking_newer(string adPlatform,string adid,int success,string params_string);
  90. [DllImport ("__Internal")]
  91. private static extern void _internalSetAdClick_Tracking_newer(string adPlatform,string adid,string params_string);
  92. [DllImport ("__Internal")]
  93. private static extern void _internalSetTrackAppDuration_Tracking_newer(long duration,string params_string);
  94. [DllImport ("__Internal")]
  95. private static extern string _internalGetDeviceId_Tracking ();
  96. [DllImport ("__Internal")]
  97. private static extern void _internalSetPrintLog_Tracking (bool printLog);
  98. [DllImport ("__Internal")]
  99. private static extern void _internalSetASAEnable_Tracking (bool enable);
  100. [DllImport("__Internal")]
  101. private static extern void _internal_SetAttributionCalllbackDelegate_Tracing(_internalAttributionCalllback callback);
  102. [DllImport("__Internal")]
  103. private static extern void _internal_SetDeferredDeeplinkCallBack_Tracking(_internalDeferredDeeplinkCallBack callback);
  104. [DllImport ("__Internal")]
  105. private static extern void _internalSetIPAdds6Enable_Tracking (bool enable);
  106. #endif
  107. #if UNITY_ANDROID && !UNITY_EDITOR
  108. public static AndroidJavaObject getApplicationContext ()
  109. {
  110. using (AndroidJavaClass jc = new AndroidJavaClass ("com.unity3d.player.UnityPlayer")) {
  111. using (AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject> ("currentActivity")) {
  112. return jo.Call<AndroidJavaObject> ("getApplicationContext");
  113. }
  114. }
  115. return null;
  116. }
  117. #endif
  118. /// <summary>
  119. /// 预初始化方法
  120. /// </summary>
  121. public void preInit(string appKey)
  122. {
  123. #if UNITY_IOS && !UNITY_EDITOR
  124. _preInit_newer (appKey);
  125. #elif UNITY_ANDROID && !UNITY_EDITOR
  126. using (AndroidJavaClass TrackingIO = new AndroidJavaClass("com.reyun.tracking.sdk.Tracking"))
  127. {
  128. TrackingIO.CallStatic("preInit", getApplicationContext(), appKey);
  129. }
  130. #else
  131. Debug.LogError("Current platform not implemented!");
  132. #endif
  133. }
  134. /// <summary>
  135. /// 初始化方法
  136. /// </summary>
  137. /// <param name="appKey">appKey</param>
  138. /// <param name="channelId">标识推广渠道的字符</param>
  139. /// <param name="caid1">caid1 ios 专用字段,广告协会caid字段,默认为空</param>
  140. /// <param name="caid2">caid2 ios 专用字段,广告协会caid字段,默认为空</param>
  141. /// <param name="startupParams">自定义startup参数</param>
  142. /// <param name="installParams">自定义install参数</param>
  143. public void init (string appKey, string channelId,string caid1 = null,string caid2 = null,
  144. Dictionary<string,object> startupParams = null, Dictionary<string, object> installParams = null)
  145. {
  146. #if UNITY_IOS && !UNITY_EDITOR
  147. string paramstring_install = DictionaryToJsonString(installParams);
  148. if (paramstring_install == null) {
  149. paramstring_install = "{}";
  150. }
  151. string paramstring_startup = DictionaryToJsonString(startupParams);
  152. if (paramstring_startup == null) {
  153. paramstring_startup = "{}";
  154. }
  155. _internalInitWithAppKeyAndChannel_Tracking_newer (appKey, channelId,caid1,caid2,null, paramstring_install,paramstring_startup);
  156. #elif UNITY_ANDROID && !UNITY_EDITOR
  157. string paramstring_install = DictionaryToJsonString(installParams);
  158. if (paramstring_install == null) {
  159. paramstring_install = "{}";
  160. }
  161. string paramstring_startup = DictionaryToJsonString(startupParams);
  162. if (paramstring_startup == null) {
  163. paramstring_startup = "{}";
  164. }
  165. using (AndroidJavaClass TrackingIO = new AndroidJavaClass ("com.reyun.tracking.sdk.Tracking")) {
  166. TrackingIO.CallStatic ("initWithKeyAndChannelId", getApplicationContext (), appKey, channelId,paramstring_startup,paramstring_install,null,false);
  167. }
  168. #else
  169. Debug.LogError("Current platform not implemented!");
  170. #endif
  171. }
  172. /// <summary>
  173. /// 玩家服务器注册
  174. /// </summary>
  175. /// <param name="account">账号ID</param>
  176. ///
  177. public void register (string account, Dictionary<string, object> customParams = null)
  178. {
  179. #if UNITY_IOS && !UNITY_EDITOR
  180. string paramstring = DictionaryToJsonString(customParams);
  181. _internalSetRegisterWithAccountID_Tracking_newer(account,paramstring);
  182. #elif UNITY_ANDROID && !UNITY_EDITOR
  183. string paramstring = DictionaryToJsonString(customParams);
  184. if (paramstring == null) {
  185. paramstring = "{}";
  186. }
  187. using (AndroidJavaClass TrackingIO = new AndroidJavaClass ("com.reyun.tracking.sdk.Tracking")) {
  188. TrackingIO.CallStatic ("setRegisterWithAccountID", account,paramstring);
  189. }
  190. #else
  191. Debug.LogError("Current platform not implemented!");
  192. #endif
  193. }
  194. /// <summary>
  195. /// 玩家的账号登陆服务器
  196. /// </summary>
  197. /// <param name="account">账号</param>
  198. public void login (string account,string serverId = null, Dictionary<string, object> customParams = null)
  199. {
  200. #if UNITY_IOS && !UNITY_EDITOR
  201. string paramstring = DictionaryToJsonString(customParams);
  202. _internalSetLoginWithAccountIDAndServerId_Tracking_newer (account,serverId,paramstring);
  203. #elif UNITY_ANDROID && !UNITY_EDITOR
  204. string paramstring = DictionaryToJsonString(customParams);
  205. if (paramstring == null) {
  206. paramstring = "{}";
  207. }
  208. using (AndroidJavaClass TrackingIO = new AndroidJavaClass ("com.reyun.tracking.sdk.Tracking")) {
  209. TrackingIO.CallStatic ("setLoginSuccessBusiness", account,serverId,paramstring);
  210. }
  211. #else
  212. Debug.LogError("Current platform not implemented!");
  213. #endif
  214. }
  215. /// <summary>
  216. /// 玩家的充值数据
  217. /// </summary>
  218. /// <param name="ryTID">交易的流水号</param>
  219. /// <param name="ryzfType">支付类型</param>
  220. /// <param name="hbType">货币类型</param>
  221. /// <param name="hbAmount">支付的真实货币的金额</param>
  222. public void setryzf (string ryTID, string ryzfType, string hbType, float hbAmount, Dictionary<string, object> customParams = null)
  223. {
  224. #if UNITY_IOS && !UNITY_EDITOR
  225. string paramstring = DictionaryToJsonString(customParams);
  226. _internalSetRyzf_Tracking_newer (ryTID, ryzfType, hbType, hbAmount,paramstring);
  227. #elif UNITY_ANDROID && !UNITY_EDITOR
  228. string paramstring = DictionaryToJsonString(customParams);
  229. if (paramstring == null) {
  230. paramstring = "{}";
  231. }
  232. using (AndroidJavaClass TrackingIO = new AndroidJavaClass ("com.reyun.tracking.sdk.Tracking")) {
  233. TrackingIO.CallStatic ("setPayment", ryTID, ryzfType, hbType, hbAmount,paramstring);
  234. }
  235. #else
  236. Debug.LogError("Current platform not implemented!");
  237. #endif
  238. }
  239. /// <summary>
  240. /// 玩家的订单数据
  241. /// </summary>
  242. /// <param name="ryTID">交易的流水号</param>
  243. /// <param name="hbType">货币类型</param>
  244. /// <param name="hbAmount">支付的真实货币的金额</param>
  245. public void setDD (string ryTID, string hbType, float hbAmount, Dictionary<string, object> customParams = null)
  246. {
  247. #if UNITY_IOS && !UNITY_EDITOR
  248. string paramstring = DictionaryToJsonString(customParams);
  249. _internalSetDD_Tracking_newer (ryTID,hbType,hbAmount,paramstring);
  250. #elif UNITY_ANDROID && !UNITY_EDITOR
  251. string paramstring = DictionaryToJsonString(customParams);
  252. if (paramstring == null) {
  253. paramstring = "{}";
  254. }
  255. using (AndroidJavaClass TrackingIO = new AndroidJavaClass ("com.reyun.tracking.sdk.Tracking")) {
  256. TrackingIO.CallStatic ("setOrder", ryTID, hbType, hbAmount,paramstring);
  257. }
  258. #else
  259. Debug.LogError("Current platform not implemented!");
  260. #endif
  261. }
  262. /// <summary>
  263. /// 统计玩家的自定义事件
  264. /// </summary>
  265. /// <param name="eventName">事件名 必须为event_1到event_30</param>
  266. public void setEvent (string eventName, Dictionary<string, object> customParams = null)
  267. {
  268. #if UNITY_IOS && !UNITY_EDITOR
  269. string paramstring = DictionaryToJsonString(customParams);
  270. _internalSetEvent_Tracking_newer (eventName,paramstring);
  271. #elif UNITY_ANDROID && !UNITY_EDITOR
  272. string paramstring = DictionaryToJsonString(customParams);
  273. if (paramstring == null) {
  274. paramstring = "{}";
  275. }
  276. using (AndroidJavaClass reyun = new AndroidJavaClass ("com.reyun.tracking.sdk.Tracking")) {
  277. reyun.CallStatic ("setEvent", eventName, paramstring);
  278. }
  279. #else
  280. Debug.LogError("Current platform not implemented!");
  281. #endif
  282. }
  283. /// <summary>
  284. /// 监测页面展示时长
  285. /// </summary>
  286. /// <param name="pageID">页面唯一标识</param>
  287. /// <param name="duration">页面展示时长</param>
  288. public void setTrackViewDuration(string pageID,long duration, Dictionary<string, object> customParams = null)
  289. {
  290. #if UNITY_IOS && !UNITY_EDITOR
  291. string paramstring = DictionaryToJsonString(customParams);
  292. _internalSetTrackViewDuration_Tracking_newer(pageID,duration,paramstring);
  293. #elif UNITY_ANDROID && !UNITY_EDITOR
  294. string paramstring = DictionaryToJsonString(customParams);
  295. if (paramstring == null) {
  296. paramstring = "{}";
  297. }
  298. using (AndroidJavaClass reyun = new AndroidJavaClass("com.reyun.tracking.sdk.Tracking"))
  299. {
  300. reyun.CallStatic("setPageDuration", pageID, duration*1000,paramstring);
  301. }
  302. #else
  303. Debug.LogError("Current platform not implemented!");
  304. #endif
  305. }
  306. /// <summary>
  307. /// //广告展示时调用
  308. /// </summary>
  309. /// <param name="adPlatform">广告平台缩写,如穿山甲广告平台传入 "csj"</param>
  310. /// <param name="adId">广告位ID</param>
  311. /// /// <param name="playSuccess">是否展示成功</param>
  312. public void setTrackAdShow(string adPlatform,string adId,bool playSuccess, Dictionary<string, object> customParams = null)
  313. {
  314. #if UNITY_IOS && !UNITY_EDITOR
  315. string paramstring = DictionaryToJsonString(customParams);
  316. int successInt = playSuccess ? 1 : 2;
  317. _internalSetAdShow_Tracking_newer(adPlatform,adId,successInt,paramstring);
  318. #elif UNITY_ANDROID && !UNITY_EDITOR
  319. string successString = playSuccess ? "1" : "2";
  320. string paramstring = DictionaryToJsonString(customParams);
  321. if (paramstring == null) {
  322. paramstring = "{}";
  323. }
  324. using (AndroidJavaClass reyun = new AndroidJavaClass("com.reyun.tracking.sdk.Tracking"))
  325. {
  326. reyun.CallStatic("setAdShow", adPlatform, adId,successString,paramstring);
  327. }
  328. #else
  329. Debug.LogError("Current platform not implemented!");
  330. #endif
  331. }
  332. /// <summary>
  333. /// //广告点击时调用
  334. /// </summary>
  335. /// <param name="adPlatform">广告平台缩写,如穿山甲广告平台传入 "csj"</param>
  336. /// <param name="adId">广告位ID</param>
  337. public void setTrackAdClick(string adPlatform, string adId, Dictionary<string, object> customParams = null)
  338. {
  339. #if UNITY_IOS && !UNITY_EDITOR
  340. string paramstring = DictionaryToJsonString(customParams);
  341. _internalSetAdClick_Tracking_newer(adPlatform,adId,paramstring);
  342. #elif UNITY_ANDROID && !UNITY_EDITOR
  343. string paramstring = DictionaryToJsonString(customParams);
  344. if (paramstring == null) {
  345. paramstring = "{}";
  346. }
  347. using (AndroidJavaClass reyun = new AndroidJavaClass("com.reyun.tracking.sdk.Tracking"))
  348. {
  349. reyun.CallStatic("setAdClick", adPlatform, adId,paramstring);
  350. }
  351. #else
  352. Debug.LogError("Current platform not implemented!");
  353. #endif
  354. }
  355. /// <summary>
  356. /// 统计APP运行时长
  357. /// </summary>
  358. /// <param name="duration">时间长度</param>
  359. public void setTrackAppDuration(long duration, Dictionary<string, object> customParams = null)
  360. {
  361. #if UNITY_IOS && !UNITY_EDITOR
  362. string paramstring = DictionaryToJsonString(customParams);
  363. _internalSetTrackAppDuration_Tracking_newer(duration,paramstring);
  364. #elif UNITY_ANDROID && !UNITY_EDITOR
  365. string paramstring = DictionaryToJsonString(customParams);
  366. if (paramstring == null) {
  367. paramstring = "{}";
  368. }
  369. using (AndroidJavaClass reyun = new AndroidJavaClass("com.reyun.tracking.sdk.Tracking"))
  370. {
  371. reyun.CallStatic("setAppDuration", duration*1000,paramstring);
  372. }
  373. #else
  374. Debug.LogError("Current platform not implemented!");
  375. #endif
  376. }
  377. /// <summary>
  378. /// 获取用户的设备ID信息
  379. /// </summary>
  380. public string getDeviceId ()
  381. {
  382. #if UNITY_IOS && !UNITY_EDITOR
  383. return _internalGetDeviceId_Tracking ();
  384. #elif UNITY_ANDROID && !UNITY_EDITOR
  385. string str = "unknown";
  386. using (AndroidJavaClass TrackingIO = new AndroidJavaClass ("com.reyun.tracking.sdk.Tracking")) {
  387. str = TrackingIO.CallStatic<string> ("getDeviceId");
  388. }
  389. return str;
  390. #else
  391. Debug.LogError("Current platform not implemented!");
  392. return "unknown";
  393. #endif
  394. }
  395. /// 开启日志打印
  396. public void setPrintLog (bool print)
  397. {
  398. #if UNITY_IOS && !UNITY_EDITOR
  399. _internalSetPrintLog_Tracking (print);
  400. #elif UNITY_ANDROID && !UNITY_EDITOR
  401. using (AndroidJavaClass TrackingIO = new AndroidJavaClass ("com.reyun.tracking.sdk.Tracking")) {
  402. TrackingIO.CallStatic("setDebugMode", print);
  403. }
  404. #else
  405. Debug.LogError("Current platform not implemented!");
  406. #endif
  407. }
  408. public void setASAEnable(bool enable)
  409. {
  410. #if UNITY_IOS && !UNITY_EDITOR
  411. _internalSetASAEnable_Tracking (enable);
  412. #else
  413. Debug.LogError("Current platform not implemented!");
  414. #endif
  415. }
  416. #if UNITY_IOS && !UNITY_EDITOR
  417. [MonoPInvokeCallback(typeof(_internalDeferredDeeplinkCallBack))]
  418. private static void OnDeeplinkCallback(string msg)
  419. {
  420. PostTask(() =>
  421. {
  422. if (Tracking.Instance.deferredDeeplinCallback_private != null && msg != null)
  423. {
  424. Tracking.Instance.deferredDeeplinCallback_private.Invoke(msg);
  425. }
  426. });
  427. }
  428. [MonoPInvokeCallback(typeof(_internalAttributionCalllback))]
  429. private static void OnAttibutionCallback(string result, int status)
  430. {
  431. PostTask(() =>
  432. {
  433. if (Tracking.Instance.attributionCalllback_private != null)
  434. {
  435. Tracking.Instance.attributionCalllback_private.Invoke(result, status);
  436. }
  437. });
  438. }
  439. #endif
  440. #region iOS install Attribution
  441. public void setAttributionCalllbackDelegate(AttributionCalllback callback)
  442. {
  443. #if UNITY_IOS && !UNITY_EDITOR
  444. Tracking.Instance.attributionCalllback_private = callback;
  445. _internal_SetAttributionCalllbackDelegate_Tracing(OnAttibutionCallback);
  446. #elif UNITY_ANDROID && !UNITY_EDITOR
  447. Tracking.Instance.attributionCalllback_private = callback;
  448. using (AndroidJavaClass TrackingIO = new AndroidJavaClass("com.reyun.tracking.sdk.Tracking"))
  449. {
  450. TrackingIO.CallStatic("setAttributionQueryListener", new AndroidAttributionQuery());
  451. }
  452. #else
  453. Debug.LogError("Current platform not implemented!");
  454. #endif
  455. }
  456. #endregion
  457. #region iOS deferred deeplink
  458. public void setDeferredDeeplinkCalllbackDelegate(DeferredDeeplinkCallBack callback)
  459. {
  460. #if UNITY_IOS && !UNITY_EDITOR
  461. Tracking.Instance.deferredDeeplinCallback_private = callback;
  462. _internal_SetDeferredDeeplinkCallBack_Tracking(OnDeeplinkCallback);
  463. #elif UNITY_ANDROID && !UNITY_EDITOR
  464. Tracking.Instance.deferredDeeplinCallback_private = callback;
  465. using (AndroidJavaClass TrackingIO = new AndroidJavaClass("com.reyun.tracking.sdk.Tracking"))
  466. {
  467. TrackingIO.CallStatic("setDeepLinkListener", new AndroidDeferredDeeplink());
  468. }
  469. #else
  470. Debug.LogError("Current platform not implemented!");
  471. #endif
  472. }
  473. #endregion
  474. #if UNITY_ANDROID && !UNITY_EDITOR
  475. private sealed class AndroidAttributionQuery : AndroidJavaProxy {
  476. public AndroidAttributionQuery() : base("com.reyun.tracking.utils.IAttributionQueryListener")
  477. {
  478. }
  479. public void onComplete(int paramInt, String param_string) {
  480. Tracking.PostTask(() =>
  481. {
  482. if (Tracking.Instance.attributionCalllback_private != null)
  483. {
  484. Tracking.Instance.attributionCalllback_private.Invoke(param_string, paramInt);
  485. }
  486. });
  487. }
  488. }
  489. private sealed class AndroidDeferredDeeplink : AndroidJavaProxy
  490. {
  491. public AndroidDeferredDeeplink() : base("com.reyun.tracking.utils.IDeepLinkListener")
  492. {
  493. }
  494. public void onComplete(bool isSuccess, String dpUrl, String dpPath)
  495. {
  496. Tracking.PostTask(() =>
  497. {
  498. if (Tracking.Instance.deferredDeeplinCallback_private != null)
  499. {
  500. string jsonString = "";
  501. if (isSuccess)
  502. {
  503. jsonString += "{\"dp_url\":\"" + (dpUrl != null? dpUrl : "") + "\",";
  504. jsonString += "\"dp_path\":\"" + (dpPath != null ? dpPath : "") + "\"}";
  505. }
  506. else
  507. {
  508. jsonString = "{}";
  509. }
  510. Tracking.Instance.deferredDeeplinCallback_private.Invoke(jsonString);
  511. }
  512. });
  513. }
  514. }
  515. #endif
  516. private static String DictionaryToJsonString (Dictionary<string, object> dictionary)
  517. {
  518. string result = null;
  519. try
  520. {
  521. if (!CheckDictionary(dictionary)) {
  522. return result;
  523. }
  524. result = MiniJSON.Json.Serialize(dictionary);
  525. }
  526. catch (Exception e)
  527. {
  528. Debug.LogError("ToJsonString error:" + e.Message);
  529. }
  530. return result;
  531. }
  532. private static bool CheckDictionary(Dictionary<string, object> dictionary)
  533. {
  534. if (dictionary == null || dictionary.Count == 0)
  535. {
  536. return false;
  537. }
  538. foreach (var entry in dictionary)
  539. {
  540. if (entry.Key == null)
  541. {
  542. return false;
  543. }
  544. if (entry.Value == null)
  545. {
  546. return false;
  547. }
  548. if (entry.Value is string stringvalue)
  549. {
  550. if (stringvalue == null || stringvalue.Length == 0)
  551. {
  552. return false;
  553. }
  554. }
  555. }
  556. return true;
  557. }
  558. //private static bool isNumber(object value)
  559. //{
  560. // if (value == null)
  561. // {
  562. // return false;
  563. // }
  564. // if (value is float || value is int
  565. // || value is uint
  566. // || value is long
  567. // || value is sbyte
  568. // || value is byte
  569. // || value is short
  570. // || value is ushort
  571. // || value is ulong
  572. // || value is double
  573. // || value is decimal)
  574. // {
  575. // return true;
  576. // }
  577. // return false;
  578. //}
  579. }