123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- using UnityEngine;
- using System.Collections.Generic;
- public class TDDemoScript : MonoBehaviour
- {
- private const int top = 100;
- private const int left = 80;
- private const int height = 60;
- private const int spacing = 20;
- private readonly int width = (Screen.width - (left * 2) - spacing) / 2;
- private const int step = 80;
- private string tdid;
- private string oaid;
- private void OnGUI()
- {
- int i = 0;
- GUI.Box(new Rect(10, 10, Screen.width - 20, Screen.height - 20), "Demo Menu");
- GUI.Label(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), tdid);
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "getTDID"))
- {
- tdid = TalkingDataSDK.GetDeviceId();
- }
- #if UNITY_ANDROID
- GUI.Label(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), oaid);
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "getOAID"))
- {
- oaid = TalkingDataSDK.GetOAID();
- }
- #endif
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPageBegin"))
- {
- TalkingDataSDK.OnPageBegin("home_page");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPageEnd"))
- {
- TalkingDataSDK.OnPageEnd("home_page");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnReceiveDeepLink"))
- {
- TalkingDataSDK.OnReceiveDeepLink("https://www.talkingdata.com");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnRegister"))
- {
- TalkingDataProfile profile = TalkingDataProfile.CreateProfile();
- profile.SetName("name01");
- profile.SetType(TalkingDataProfileType.WEIXIN);
- profile.SetGender(TalkingDataGender.MALE);
- profile.SetAge(18);
- profile.SetProperty1("property1");
- profile.SetProperty2(2);
- profile.SetProperty3(3.14);
- profile.SetProperty4("property4");
- profile.SetProperty5("property5");
- profile.SetProperty6(0.618);
- profile.SetProperty7("property7");
- profile.SetProperty8("property8");
- profile.SetProperty9(9.8);
- profile.SetProperty10("property10");
- TalkingDataSDK.OnRegister("user01", profile, "123456");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnLogin"))
- {
- TalkingDataProfile profile = TalkingDataProfile.CreateProfile();
- profile.SetName("name01");
- profile.SetType(TalkingDataProfileType.WEIXIN);
- profile.SetGender(TalkingDataGender.MALE);
- profile.SetAge(18);
- profile.SetProperty1("property1");
- profile.SetProperty2(2);
- profile.SetProperty3(3.14);
- profile.SetProperty4("property4");
- profile.SetProperty5("property5");
- profile.SetProperty6(0.618);
- profile.SetProperty7("property7");
- profile.SetProperty8("property8");
- profile.SetProperty9(9.8);
- profile.SetProperty10("property10");
- TalkingDataSDK.OnLogin("user01", profile);
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnProfileUpdate"))
- {
- TalkingDataProfile profile = TalkingDataProfile.CreateProfile();
- profile.SetName("name01");
- profile.SetType(TalkingDataProfileType.WEIXIN);
- profile.SetGender(TalkingDataGender.MALE);
- profile.SetAge(18);
- profile.SetProperty1("property1");
- profile.SetProperty2(2);
- profile.SetProperty3(3.14);
- profile.SetProperty4("property4");
- profile.SetProperty5("property5");
- profile.SetProperty6(0.618);
- profile.SetProperty7("property7");
- profile.SetProperty8("property8");
- profile.SetProperty9(9.8);
- profile.SetProperty10("property10");
- TalkingDataSDK.OnProfileUpdate(profile);
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnCreateCard"))
- {
- TalkingDataSDK.OnCreateCard("user01", "支付宝", "支付宝账号123456789");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnFavorite"))
- {
- TalkingDataSDK.OnFavorite("服装", "2019新款");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnShare"))
- {
- TalkingDataSDK.OnShare("user01", "课程");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPunch"))
- {
- TalkingDataSDK.OnPunch("user01", "签到0023");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnSearch"))
- {
- TalkingDataSearch search = TalkingDataSearch.CreateSearch();
- search.SetCategory("类型");
- search.SetContent("内容");
- #if TD_RETAIL
- search.SetItemId("商品ID");
- search.SetItemLocationId("location12314");
- #endif
- #if TD_TOUR
- search.SetDestination("目的地");
- search.SetOrigin("出发地");
- search.SetStartDate(1565176907309);
- search.SetEndDate(1565176908309);
- #endif
- TalkingDataSDK.OnSearch(search);
- }
- #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_ONLINEEDU
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnContact"))
- {
- TalkingDataSDK.OnContact("user01", "联系平台内容");
- }
- #endif
- #if TD_GAME || TD_TOUR || TD_ONLINEEDU || TD_READING || TD_OTHER
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPay"))
- {
- TalkingDataSDK.OnPay("user01", "order01", 1077600, "CNY", "Apple Pay", "item01", 2);
- }
- #endif
- #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_ONLINEEDU
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnChargeBack"))
- {
- TalkingDataSDK.OnChargeBack("user01", "order01", "7天无理由退货", "仅退款");
- }
- #endif
- #if TD_FINANCE || TD_ONLINEEDU
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnReservation"))
- {
- TalkingDataSDK.OnReservation("user01", "AdTracking_123456", "借贷类", 12, "商品信息");
- }
- #endif
- #if TD_RETAIL || TD_TOUR
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnBooking"))
- {
- TalkingDataSDK.OnBooking("user01", "002391", "电子", 123, "商品信息");
- }
- #endif
- #if TD_RETAIL
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnViewItem"))
- {
- TalkingDataSDK.OnViewItem("A1660", "手机", "iPhone 7", 538800);
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnAddItemToShoppingCart"))
- {
- TalkingDataSDK.OnAddItemToShoppingCart("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnViewShoppingCart"))
- {
- TalkingDataShoppingCart shoppingCart = TalkingDataShoppingCart.CreateShoppingCart();
- if (shoppingCart != null)
- {
- shoppingCart.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
- shoppingCart.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
- TalkingDataSDK.OnViewShoppingCart(shoppingCart);
- }
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPlaceOrder"))
- {
- TalkingDataOrder order = TalkingDataOrder.CreateOrder("order01", 2466400, "CNY");
- order.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
- order.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
- TalkingDataSDK.OnPlaceOrder(order, "user01");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnOrderPaySucc"))
- {
- TalkingDataOrder order = TalkingDataOrder.CreateOrder("order01", 2466400, "CNY");
- order.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
- order.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
- TalkingDataSDK.OnOrderPaySucc(order, "AliPay", "user01");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnCancelOrder"))
- {
- TalkingDataOrder order = TalkingDataOrder.CreateOrder("order01", 2466400, "CNY");
- order.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
- order.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
- TalkingDataSDK.OnCancelOrder(order);
- }
- #endif
- #if TD_FINANCE
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnCredit"))
- {
- TalkingDataSDK.OnCredit("user01", 123456, "授信详情为......");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnTransaction"))
- {
- TalkingDataTransaction transaction = TalkingDataTransaction.CreateTransaction();
- transaction.SetTransactionId("AdTracking_123456");
- transaction.SetCategory("定期");
- transaction.SetAmount(3222);
- transaction.SetPersonA("张三");
- transaction.SetPersonB("金融平台");
- transaction.SetStartDate(1565176907309);
- transaction.SetEndDate(1565176908309);
- transaction.SetCurrencyType("CNY");
- transaction.SetContent("交易详情为......");
- TalkingDataSDK.OnTransaction("user01", transaction);
- }
- #endif
- #if TD_GAME
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnCreateRole"))
- {
- TalkingDataSDK.OnCreateRole("role01");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnLevelPass"))
- {
- TalkingDataSDK.OnLevelPass("user01", "AdTracking_123456");
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnGuideFinished"))
- {
- TalkingDataSDK.OnGuideFinished("user01", "新手教程顺利通过");
- }
- #endif
- #if TD_ONLINEEDU
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnLearn"))
- {
- TalkingDataSDK.OnLearn("user01", "成人教育第一节", 1501234567890, 20);
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPreviewFinished"))
- {
- TalkingDataSDK.OnPreviewFinished("user01", "基础课程试听结束");
- }
- #endif
- #if TD_READING
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnRead"))
- {
- TalkingDataSDK.OnRead("user01", "西游记第一章", 1501234567890, 20);
- }
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnFreeFinished"))
- {
- TalkingDataSDK.OnFreeFinished("user01", "免费章节阅读结束");
- }
- #endif
- #if TD_GAME || TD_ONLINEEDU
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnAchievementUnlock"))
- {
- TalkingDataSDK.OnAchievementUnlock("user01", "AdTracking_123456");
- }
- #endif
- #if TD_FINANCE || TD_TOUR || TD_OTHER
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnBrowse"))
- {
- TalkingDataSDK.OnBrowse("user01", "详情页page1", 1501234567890, 20);
- }
- #endif
- #if TD_RETAIL || TD_FINANCE || TD_TOUR || TD_OTHER
- if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnTrialFinished"))
- {
- TalkingDataSDK.OnTrialFinished("user01", "试用体验结束");
- }
- #endif
- if (GUI.Button(new Rect(left, top + (step * i++), width, height), "OnEvent"))
- {
- Dictionary<string, object> dic = new Dictionary<string, object>
- {
- { "StringValue", "Pi" },
- { "NumberValue", 3.14 }
- };
- TalkingDataSDK.OnEvent("action_id", dic);
- }
- }
- void Start()
- {
- Debug.Log("Start");
- // TalkingDataSDK.SetVerboseLogDisable();
- TalkingDataSDK.BackgroundSessionEnabled();
- TalkingDataSDK.Init("your_app_id", "your_channel_id", "your_custom_parameter");
- }
- void Update()
- {
- if (Input.GetKey(KeyCode.Escape))
- {
- Application.Quit();
- }
- }
- void OnDestroy()
- {
- Debug.Log("onDestroy");
- TalkingDataSDK.OnPause();
- }
- void Awake()
- {
- Debug.Log("Awake");
- }
- void OnEnable()
- {
- Debug.Log("OnEnable");
- }
- void OnDisable()
- {
- Debug.Log("OnDisable");
- }
- }
|