TDDemoScript.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. public class TDDemoScript : MonoBehaviour
  4. {
  5. private const int top = 100;
  6. private const int left = 80;
  7. private const int height = 60;
  8. private const int spacing = 20;
  9. private readonly int width = (Screen.width - (left * 2) - spacing) / 2;
  10. private const int step = 80;
  11. private string tdid;
  12. private string oaid;
  13. private void OnGUI()
  14. {
  15. int i = 0;
  16. GUI.Box(new Rect(10, 10, Screen.width - 20, Screen.height - 20), "Demo Menu");
  17. GUI.Label(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), tdid);
  18. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "getTDID"))
  19. {
  20. tdid = TalkingDataSDK.GetDeviceId();
  21. }
  22. #if UNITY_ANDROID
  23. GUI.Label(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), oaid);
  24. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "getOAID"))
  25. {
  26. oaid = TalkingDataSDK.GetOAID();
  27. }
  28. #endif
  29. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPageBegin"))
  30. {
  31. TalkingDataSDK.OnPageBegin("home_page");
  32. }
  33. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPageEnd"))
  34. {
  35. TalkingDataSDK.OnPageEnd("home_page");
  36. }
  37. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnReceiveDeepLink"))
  38. {
  39. TalkingDataSDK.OnReceiveDeepLink("https://www.talkingdata.com");
  40. }
  41. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnRegister"))
  42. {
  43. TalkingDataProfile profile = TalkingDataProfile.CreateProfile();
  44. profile.SetName("name01");
  45. profile.SetType(TalkingDataProfileType.WEIXIN);
  46. profile.SetGender(TalkingDataGender.MALE);
  47. profile.SetAge(18);
  48. profile.SetProperty1("property1");
  49. profile.SetProperty2(2);
  50. profile.SetProperty3(3.14);
  51. profile.SetProperty4("property4");
  52. profile.SetProperty5("property5");
  53. profile.SetProperty6(0.618);
  54. profile.SetProperty7("property7");
  55. profile.SetProperty8("property8");
  56. profile.SetProperty9(9.8);
  57. profile.SetProperty10("property10");
  58. Dictionary<string, object> eventValue = new Dictionary<string, object>
  59. {
  60. { "key", "value" }
  61. };
  62. TalkingDataSDK.OnRegister("user01", profile, "123456", eventValue);
  63. }
  64. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnLogin"))
  65. {
  66. TalkingDataProfile profile = TalkingDataProfile.CreateProfile();
  67. profile.SetName("name01");
  68. profile.SetType(TalkingDataProfileType.WEIXIN);
  69. profile.SetGender(TalkingDataGender.MALE);
  70. profile.SetAge(18);
  71. profile.SetProperty1("property1");
  72. profile.SetProperty2(2);
  73. profile.SetProperty3(3.14);
  74. profile.SetProperty4("property4");
  75. profile.SetProperty5("property5");
  76. profile.SetProperty6(0.618);
  77. profile.SetProperty7("property7");
  78. profile.SetProperty8("property8");
  79. profile.SetProperty9(9.8);
  80. profile.SetProperty10("property10");
  81. Dictionary<string, object> eventValue = new Dictionary<string, object>
  82. {
  83. { "key", "value" }
  84. };
  85. TalkingDataSDK.OnLogin("user01", profile, eventValue);
  86. }
  87. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnProfileUpdate"))
  88. {
  89. TalkingDataProfile profile = TalkingDataProfile.CreateProfile();
  90. profile.SetName("name01");
  91. profile.SetType(TalkingDataProfileType.WEIXIN);
  92. profile.SetGender(TalkingDataGender.MALE);
  93. profile.SetAge(18);
  94. profile.SetProperty1("property1");
  95. profile.SetProperty2(2);
  96. profile.SetProperty3(3.14);
  97. profile.SetProperty4("property4");
  98. profile.SetProperty5("property5");
  99. profile.SetProperty6(0.618);
  100. profile.SetProperty7("property7");
  101. profile.SetProperty8("property8");
  102. profile.SetProperty9(9.8);
  103. profile.SetProperty10("property10");
  104. TalkingDataSDK.OnProfileUpdate(profile);
  105. }
  106. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnCreateCard"))
  107. {
  108. TalkingDataSDK.OnCreateCard("user01", "支付宝", "支付宝账号123456789");
  109. }
  110. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnFavorite"))
  111. {
  112. Dictionary<string, object> eventValue = new Dictionary<string, object>
  113. {
  114. { "key", "value" }
  115. };
  116. TalkingDataSDK.OnFavorite("服装", "2019新款", eventValue);
  117. }
  118. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnShare"))
  119. {
  120. Dictionary<string, object> eventValue = new Dictionary<string, object>
  121. {
  122. { "key", "value" }
  123. };
  124. TalkingDataSDK.OnShare("user01", "课程", eventValue);
  125. }
  126. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPunch"))
  127. {
  128. TalkingDataSDK.OnPunch("user01", "签到0023");
  129. }
  130. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnSearch"))
  131. {
  132. TalkingDataSearch search = TalkingDataSearch.CreateSearch();
  133. search.SetCategory("类型");
  134. search.SetContent("内容");
  135. #if TD_RETAIL
  136. search.SetItemId("商品ID");
  137. search.SetItemLocationId("location12314");
  138. #endif
  139. #if TD_TOUR
  140. search.SetDestination("目的地");
  141. search.SetOrigin("出发地");
  142. search.SetStartDate(1565176907309);
  143. search.SetEndDate(1565176908309);
  144. #endif
  145. TalkingDataSDK.OnSearch(search);
  146. }
  147. #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_ONLINEEDU
  148. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnContact"))
  149. {
  150. TalkingDataSDK.OnContact("user01", "联系平台内容");
  151. }
  152. #endif
  153. #if TD_GAME || TD_TOUR || TD_ONLINEEDU || TD_READING || TD_OTHER
  154. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPay"))
  155. {
  156. TalkingDataSDK.OnPay("user01", "order01", 1077600, "CNY", "Apple Pay", "item01", 2);
  157. }
  158. #endif
  159. #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_ONLINEEDU
  160. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnChargeBack"))
  161. {
  162. TalkingDataSDK.OnChargeBack("user01", "order01", "7天无理由退货", "仅退款");
  163. }
  164. #endif
  165. #if TD_FINANCE || TD_ONLINEEDU
  166. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnReservation"))
  167. {
  168. TalkingDataSDK.OnReservation("user01", "AdTracking_123456", "借贷类", 12, "商品信息");
  169. }
  170. #endif
  171. #if TD_RETAIL || TD_TOUR
  172. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnBooking"))
  173. {
  174. TalkingDataSDK.OnBooking("user01", "002391", "电子", 123, "商品信息");
  175. }
  176. #endif
  177. #if TD_RETAIL
  178. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnViewItem"))
  179. {
  180. Dictionary<string, object> eventValue = new Dictionary<string, object>
  181. {
  182. { "key", "value" }
  183. };
  184. TalkingDataSDK.OnViewItem("A1660", "手机", "iPhone 7", 538800, eventValue);
  185. }
  186. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnAddItemToShoppingCart"))
  187. {
  188. Dictionary<string, object> eventValue = new Dictionary<string, object>
  189. {
  190. { "key", "value" }
  191. };
  192. TalkingDataSDK.OnAddItemToShoppingCart("MLH12CH", "电脑", "MacBook Pro", 1388800, 1, eventValue);
  193. }
  194. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnViewShoppingCart"))
  195. {
  196. TalkingDataShoppingCart shoppingCart = TalkingDataShoppingCart.CreateShoppingCart();
  197. if (shoppingCart != null)
  198. {
  199. shoppingCart.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
  200. shoppingCart.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
  201. TalkingDataSDK.OnViewShoppingCart(shoppingCart);
  202. }
  203. }
  204. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPlaceOrder"))
  205. {
  206. TalkingDataOrder order = TalkingDataOrder.CreateOrder("order01", 2466400, "CNY");
  207. order.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
  208. order.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
  209. Dictionary<string, object> eventValue = new Dictionary<string, object>
  210. {
  211. { "key", "value" }
  212. };
  213. TalkingDataSDK.OnPlaceOrder(order, "user01", eventValue);
  214. }
  215. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnOrderPaySucc"))
  216. {
  217. TalkingDataOrder order = TalkingDataOrder.CreateOrder("order01", 2466400, "CNY");
  218. order.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
  219. order.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
  220. TalkingDataSDK.OnOrderPaySucc(order, "AliPay", "user01");
  221. }
  222. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnCancelOrder"))
  223. {
  224. TalkingDataOrder order = TalkingDataOrder.CreateOrder("order01", 2466400, "CNY");
  225. order.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
  226. order.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
  227. TalkingDataSDK.OnCancelOrder(order);
  228. }
  229. #endif
  230. #if TD_FINANCE
  231. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnCredit"))
  232. {
  233. TalkingDataSDK.OnCredit("user01", 123456, "授信详情为......");
  234. }
  235. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnTransaction"))
  236. {
  237. TalkingDataTransaction transaction = TalkingDataTransaction.CreateTransaction();
  238. transaction.SetTransactionId("AdTracking_123456");
  239. transaction.SetCategory("定期");
  240. transaction.SetAmount(3222);
  241. transaction.SetPersonA("张三");
  242. transaction.SetPersonB("金融平台");
  243. transaction.SetStartDate(1565176907309);
  244. transaction.SetEndDate(1565176908309);
  245. transaction.SetCurrencyType("CNY");
  246. transaction.SetContent("交易详情为......");
  247. TalkingDataSDK.OnTransaction("user01", transaction);
  248. }
  249. #endif
  250. #if TD_GAME
  251. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnCreateRole"))
  252. {
  253. TalkingDataSDK.OnCreateRole("role01");
  254. }
  255. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnLevelPass"))
  256. {
  257. TalkingDataSDK.OnLevelPass("user01", "AdTracking_123456");
  258. }
  259. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnGuideFinished"))
  260. {
  261. TalkingDataSDK.OnGuideFinished("user01", "新手教程顺利通过");
  262. }
  263. #endif
  264. #if TD_ONLINEEDU
  265. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnLearn"))
  266. {
  267. TalkingDataSDK.OnLearn("user01", "成人教育第一节", 1501234567890, 20);
  268. }
  269. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPreviewFinished"))
  270. {
  271. TalkingDataSDK.OnPreviewFinished("user01", "基础课程试听结束");
  272. }
  273. #endif
  274. #if TD_READING
  275. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnRead"))
  276. {
  277. TalkingDataSDK.OnRead("user01", "西游记第一章", 1501234567890, 20);
  278. }
  279. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnFreeFinished"))
  280. {
  281. TalkingDataSDK.OnFreeFinished("user01", "免费章节阅读结束");
  282. }
  283. #endif
  284. #if TD_GAME || TD_ONLINEEDU
  285. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnAchievementUnlock"))
  286. {
  287. TalkingDataSDK.OnAchievementUnlock("user01", "AdTracking_123456");
  288. }
  289. #endif
  290. #if TD_FINANCE || TD_TOUR || TD_OTHER
  291. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnBrowse"))
  292. {
  293. TalkingDataSDK.OnBrowse("user01", "详情页page1", 1501234567890, 20);
  294. }
  295. #endif
  296. #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_OTHER
  297. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnTrialFinished"))
  298. {
  299. TalkingDataSDK.OnTrialFinished("user01", "试用体验结束");
  300. }
  301. #endif
  302. if (GUI.Button(new Rect(left, top + (step * i++), width, height), "OnEvent"))
  303. {
  304. Dictionary<string, object> dic = new Dictionary<string, object>
  305. {
  306. { "StringValue", "Pi" },
  307. { "NumberValue", 3.14 }
  308. };
  309. Dictionary<string, object> eventValue = new Dictionary<string, object>
  310. {
  311. { "key", "value" }
  312. };
  313. TalkingDataSDK.OnEvent("action_id", dic, eventValue);
  314. }
  315. }
  316. void Start()
  317. {
  318. Debug.Log("Start");
  319. // TalkingDataSDK.SetVerboseLogDisable();
  320. TalkingDataSDKConfig config = TalkingDataSDKConfig.CreateConfig();
  321. config.SetIMEIAndMEIDEnabled(false)//不允许收集IMEI和MEID
  322. .SetMACEnabled(false)//不允许收集MAC
  323. .SetAppListEnabled(false)//不允许收集应用列表
  324. .SetLocationEnabled(false)//不允许收集位置信息
  325. .SetWifiEnabled(false);//不允许收集网络信息
  326. TalkingDataSDK.SetConfig(config);
  327. TalkingDataSDK.BackgroundSessionEnabled();
  328. TalkingDataSDK.InitSDK("your_app_id", "your_channel_id", "your_custom_parameter");
  329. TalkingDataSDK.StartA();
  330. }
  331. void Update()
  332. {
  333. if (Input.GetKey(KeyCode.Escape))
  334. {
  335. Application.Quit();
  336. }
  337. }
  338. void OnDestroy()
  339. {
  340. Debug.Log("onDestroy");
  341. TalkingDataSDK.OnPause();
  342. }
  343. void Awake()
  344. {
  345. Debug.Log("Awake");
  346. }
  347. void OnEnable()
  348. {
  349. Debug.Log("OnEnable");
  350. }
  351. void OnDisable()
  352. {
  353. Debug.Log("OnDisable");
  354. }
  355. }