TDDemoScript.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. TalkingDataSDK.OnRegister("user01", profile, "123456");
  59. }
  60. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnLogin"))
  61. {
  62. TalkingDataProfile profile = TalkingDataProfile.CreateProfile();
  63. profile.SetName("name01");
  64. profile.SetType(TalkingDataProfileType.WEIXIN);
  65. profile.SetGender(TalkingDataGender.MALE);
  66. profile.SetAge(18);
  67. profile.SetProperty1("property1");
  68. profile.SetProperty2(2);
  69. profile.SetProperty3(3.14);
  70. profile.SetProperty4("property4");
  71. profile.SetProperty5("property5");
  72. profile.SetProperty6(0.618);
  73. profile.SetProperty7("property7");
  74. profile.SetProperty8("property8");
  75. profile.SetProperty9(9.8);
  76. profile.SetProperty10("property10");
  77. TalkingDataSDK.OnLogin("user01", profile);
  78. }
  79. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnProfileUpdate"))
  80. {
  81. TalkingDataProfile profile = TalkingDataProfile.CreateProfile();
  82. profile.SetName("name01");
  83. profile.SetType(TalkingDataProfileType.WEIXIN);
  84. profile.SetGender(TalkingDataGender.MALE);
  85. profile.SetAge(18);
  86. profile.SetProperty1("property1");
  87. profile.SetProperty2(2);
  88. profile.SetProperty3(3.14);
  89. profile.SetProperty4("property4");
  90. profile.SetProperty5("property5");
  91. profile.SetProperty6(0.618);
  92. profile.SetProperty7("property7");
  93. profile.SetProperty8("property8");
  94. profile.SetProperty9(9.8);
  95. profile.SetProperty10("property10");
  96. TalkingDataSDK.OnProfileUpdate(profile);
  97. }
  98. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnCreateCard"))
  99. {
  100. TalkingDataSDK.OnCreateCard("user01", "支付宝", "支付宝账号123456789");
  101. }
  102. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnFavorite"))
  103. {
  104. TalkingDataSDK.OnFavorite("服装", "2019新款");
  105. }
  106. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnShare"))
  107. {
  108. TalkingDataSDK.OnShare("user01", "课程");
  109. }
  110. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPunch"))
  111. {
  112. TalkingDataSDK.OnPunch("user01", "签到0023");
  113. }
  114. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnSearch"))
  115. {
  116. TalkingDataSearch search = TalkingDataSearch.CreateSearch();
  117. search.SetCategory("类型");
  118. search.SetContent("内容");
  119. #if TD_RETAIL
  120. search.SetItemId("商品ID");
  121. search.SetItemLocationId("location12314");
  122. #endif
  123. #if TD_TOUR
  124. search.SetDestination("目的地");
  125. search.SetOrigin("出发地");
  126. search.SetStartDate(1565176907309);
  127. search.SetEndDate(1565176908309);
  128. #endif
  129. TalkingDataSDK.OnSearch(search);
  130. }
  131. #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_ONLINEEDU
  132. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnContact"))
  133. {
  134. TalkingDataSDK.OnContact("user01", "联系平台内容");
  135. }
  136. #endif
  137. #if TD_GAME || TD_TOUR || TD_ONLINEEDU || TD_READING || TD_OTHER
  138. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPay"))
  139. {
  140. TalkingDataSDK.OnPay("user01", "order01", 1077600, "CNY", "Apple Pay", "item01", 2);
  141. }
  142. #endif
  143. #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_ONLINEEDU
  144. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnChargeBack"))
  145. {
  146. TalkingDataSDK.OnChargeBack("user01", "order01", "7天无理由退货", "仅退款");
  147. }
  148. #endif
  149. #if TD_FINANCE || TD_ONLINEEDU
  150. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnReservation"))
  151. {
  152. TalkingDataSDK.OnReservation("user01", "AdTracking_123456", "借贷类", 12, "商品信息");
  153. }
  154. #endif
  155. #if TD_RETAIL || TD_TOUR
  156. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnBooking"))
  157. {
  158. TalkingDataSDK.OnBooking("user01", "002391", "电子", 123, "商品信息");
  159. }
  160. #endif
  161. #if TD_RETAIL
  162. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnViewItem"))
  163. {
  164. TalkingDataSDK.OnViewItem("A1660", "手机", "iPhone 7", 538800);
  165. }
  166. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnAddItemToShoppingCart"))
  167. {
  168. TalkingDataSDK.OnAddItemToShoppingCart("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
  169. }
  170. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnViewShoppingCart"))
  171. {
  172. TalkingDataShoppingCart shoppingCart = TalkingDataShoppingCart.CreateShoppingCart();
  173. if (shoppingCart != null)
  174. {
  175. shoppingCart.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
  176. shoppingCart.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
  177. TalkingDataSDK.OnViewShoppingCart(shoppingCart);
  178. }
  179. }
  180. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPlaceOrder"))
  181. {
  182. TalkingDataOrder order = TalkingDataOrder.CreateOrder("order01", 2466400, "CNY");
  183. order.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
  184. order.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
  185. TalkingDataSDK.OnPlaceOrder(order, "user01");
  186. }
  187. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnOrderPaySucc"))
  188. {
  189. TalkingDataOrder order = TalkingDataOrder.CreateOrder("order01", 2466400, "CNY");
  190. order.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
  191. order.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
  192. TalkingDataSDK.OnOrderPaySucc(order, "AliPay", "user01");
  193. }
  194. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnCancelOrder"))
  195. {
  196. TalkingDataOrder order = TalkingDataOrder.CreateOrder("order01", 2466400, "CNY");
  197. order.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
  198. order.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
  199. TalkingDataSDK.OnCancelOrder(order);
  200. }
  201. #endif
  202. #if TD_FINANCE
  203. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnCredit"))
  204. {
  205. TalkingDataSDK.OnCredit("user01", 123456, "授信详情为......");
  206. }
  207. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnTransaction"))
  208. {
  209. TalkingDataTransaction transaction = TalkingDataTransaction.CreateTransaction();
  210. transaction.SetTransactionId("AdTracking_123456");
  211. transaction.SetCategory("定期");
  212. transaction.SetAmount(3222);
  213. transaction.SetPersonA("张三");
  214. transaction.SetPersonB("金融平台");
  215. transaction.SetStartDate(1565176907309);
  216. transaction.SetEndDate(1565176908309);
  217. transaction.SetCurrencyType("CNY");
  218. transaction.SetContent("交易详情为......");
  219. TalkingDataSDK.OnTransaction("user01", transaction);
  220. }
  221. #endif
  222. #if TD_GAME
  223. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnCreateRole"))
  224. {
  225. TalkingDataSDK.OnCreateRole("role01");
  226. }
  227. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnLevelPass"))
  228. {
  229. TalkingDataSDK.OnLevelPass("user01", "AdTracking_123456");
  230. }
  231. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnGuideFinished"))
  232. {
  233. TalkingDataSDK.OnGuideFinished("user01", "新手教程顺利通过");
  234. }
  235. #endif
  236. #if TD_ONLINEEDU
  237. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnLearn"))
  238. {
  239. TalkingDataSDK.OnLearn("user01", "成人教育第一节", 1501234567890, 20);
  240. }
  241. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPreviewFinished"))
  242. {
  243. TalkingDataSDK.OnPreviewFinished("user01", "基础课程试听结束");
  244. }
  245. #endif
  246. #if TD_READING
  247. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnRead"))
  248. {
  249. TalkingDataSDK.OnRead("user01", "西游记第一章", 1501234567890, 20);
  250. }
  251. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnFreeFinished"))
  252. {
  253. TalkingDataSDK.OnFreeFinished("user01", "免费章节阅读结束");
  254. }
  255. #endif
  256. #if TD_GAME || TD_ONLINEEDU
  257. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnAchievementUnlock"))
  258. {
  259. TalkingDataSDK.OnAchievementUnlock("user01", "AdTracking_123456");
  260. }
  261. #endif
  262. #if TD_FINANCE || TD_TOUR || TD_OTHER
  263. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnBrowse"))
  264. {
  265. TalkingDataSDK.OnBrowse("user01", "详情页page1", 1501234567890, 20);
  266. }
  267. #endif
  268. #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_OTHER
  269. if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnTrialFinished"))
  270. {
  271. TalkingDataSDK.OnTrialFinished("user01", "试用体验结束");
  272. }
  273. #endif
  274. if (GUI.Button(new Rect(left, top + (step * i++), width, height), "OnEvent"))
  275. {
  276. Dictionary<string, object> dic = new Dictionary<string, object>
  277. {
  278. { "StringValue", "Pi" },
  279. { "NumberValue", 3.14 }
  280. };
  281. TalkingDataSDK.OnEvent("action_id", dic);
  282. }
  283. }
  284. void Start()
  285. {
  286. Debug.Log("Start");
  287. // TalkingDataSDK.SetVerboseLogDisable();
  288. TalkingDataSDK.BackgroundSessionEnabled();
  289. TalkingDataSDK.Init("your_app_id", "your_channel_id", "your_custom_parameter");
  290. }
  291. void Update()
  292. {
  293. if (Input.GetKey(KeyCode.Escape))
  294. {
  295. Application.Quit();
  296. }
  297. }
  298. void OnDestroy()
  299. {
  300. Debug.Log("onDestroy");
  301. TalkingDataSDK.OnPause();
  302. }
  303. void Awake()
  304. {
  305. Debug.Log("Awake");
  306. }
  307. void OnEnable()
  308. {
  309. Debug.Log("OnEnable");
  310. }
  311. void OnDisable()
  312. {
  313. Debug.Log("OnDisable");
  314. }
  315. }