Unity3D使用talkingData应用数据统计

来源:互联网 发布:中国 菲律宾 知乎 编辑:程序博客网 时间:2024/05/16 17:03

Lixi

1.到官网注册:http://www.talkingdata.com/

2.创建引用或者游戏

3.下载demo:https://github.com/TalkingData/AppAnalytics_SDK_Unity

4.复制TalkingData平台发送到你邮箱的两个jar和a文件到unity对应的文件夹下(android和ios)

5.在代码中使用:  TalkingDataPlugin.SessionStarted(appkeyid, chanel);开启检测; appkeyid是talkingData分配的,chanel是你自定义检测的渠道(appstore)

6.在应用退出前调用: TalkingDataPlugin.SessionStoped();结束检测


相关代码如下:


using UnityEngine;using UnityEngine.UI;using System.Collections;using System.Collections.Generic;using System;using System.Threading;public class TalkingDataDemoScript : MonoBehaviour {    public Text tip;    const int left = 90;const int height = 50;const int top = 60;int width = Screen.width - left * 2;const int step = 60;void OnApplySucc(string requestId) {     Debug.Log ("OnApplySucc:" + requestId);}void OnApplyFailed(int errorCode, string errorMessage) {Debug.Log ("OnApplyFailed:" + errorCode + " " + errorMessage);}void OnVerifySucc(string requestId) {Debug.Log ("OnVerifySucc:" + requestId);}void OnVerifyFailed(int errorCode, string errorMessage) {Debug.Log ("OnVerifyFailed:" + errorCode + " " + errorMessage);}void OnGUI() {int i = 0;GUI.Box(new Rect(10, 10, Screen.width - 20, Screen.height - 20), "Demo Menu");if (GUI.Button(new Rect(left, top + step * i++, width, height), "Apply Auth Code")) {TalkingDataSMSPlugin.SuccDelegate succMethod = new TalkingDataSMSPlugin.SuccDelegate(this.OnApplySucc);TalkingDataSMSPlugin.FailedDelegate failedMethod = new TalkingDataSMSPlugin.FailedDelegate(this.OnApplyFailed);TalkingDataSMSPlugin.ApplyAuthCode("86", "mobile", succMethod, failedMethod);}if (GUI.Button(new Rect(left, top + step * i++, width, height), "Reapply Auth Code")) {TalkingDataSMSPlugin.SuccDelegate succMethod = new TalkingDataSMSPlugin.SuccDelegate(this.OnApplySucc);TalkingDataSMSPlugin.FailedDelegate failedMethod = new TalkingDataSMSPlugin.FailedDelegate(this.OnApplyFailed);TalkingDataSMSPlugin.ReapplyAuthCode("86", "mobile", "request_id", succMethod, failedMethod);}if (GUI.Button(new Rect(left, top + step * i++, width, height), "Verify Auth Code")) {TalkingDataSMSPlugin.SuccDelegate succMethod = new TalkingDataSMSPlugin.SuccDelegate(this.OnVerifySucc);TalkingDataSMSPlugin.FailedDelegate failedMethod = new TalkingDataSMSPlugin.FailedDelegate(this.OnVerifyFailed);TalkingDataSMSPlugin.VerifyAuthCode("86", "mobile", "auth_code", succMethod, failedMethod);}if (GUI.Button (new Rect (left, top + step * i++, width, height), "OnRegister")) {TalkingDataPlugin.OnRegister ("user01", TalkingDataAccountType.ANONYMOUS, "abc");}if (GUI.Button (new Rect (left, top + step * i++, width, height), "OnLogin")) {TalkingDataPlugin.OnLogin ("user01", TalkingDataAccountType.TYPE1, "abc");}if (GUI.Button (new Rect (left, top + step * i++, width, height), "OnPlaceOrder")) {TalkingDataOrder order = TalkingDataOrder.CreateOrder ("order01", 2466400, "CNY");order.AddItem ("A1660", "手机", "iPhone 7", 538800, 2);order.AddItem ("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);TalkingDataPlugin.OnPlaceOrder ("user01", order);}if (GUI.Button (new Rect (left, top + step * i++, width, height), "OnOrderPaySucc")) {TalkingDataOrder order = TalkingDataOrder.CreateOrder ("order01", 2466400, "CNY");order.AddItem ("A1660", "手机", "iPhone 7", 538800, 2);order.AddItem ("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);TalkingDataPlugin.OnOrderPaySucc ("user01", "AliPay", order);}if (GUI.Button (new Rect (left, top + step * i++, width, height), "OnViewItem")) {TalkingDataPlugin.OnViewItem ("A1660", "手机", "iPhone 7", 538800);}if (GUI.Button (new Rect (left, top + step * i++, width, height), "OnAddItemToShoppingCart")) {TalkingDataPlugin.OnAddItemToShoppingCart ("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);}if (GUI.Button (new Rect (left, top + step * i++, width, height), "OnViewShoppingCart")) {TalkingDataShoppingCart shoppingCart = TalkingDataShoppingCart.CreateShoppingCart ();if (shoppingCart != null) {shoppingCart.AddItem ("A1660", "手机", "iPhone 7", 538800, 2);shoppingCart.AddItem ("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);TalkingDataPlugin.OnViewShoppingCart (shoppingCart);}}if (GUI.Button(new Rect(left, top + step * i++, width, height), "TrackPageBegin")) {TalkingDataPlugin.TrackPageBegin("page_name");}if (GUI.Button(new Rect(left, top + step * i++, width, height), "TrackPageEnd")) {TalkingDataPlugin.TrackPageEnd("page_name");}if (GUI.Button(new Rect(left, top + step * i++, width, height), "TrackEvent")) {TalkingDataPlugin.TrackEvent("action_id");}if (GUI.Button(new Rect(left, top + step * i++, width, height), "TrackEventWithLabel")) {TalkingDataPlugin.TrackEventWithLabel("action_id", "action_label");}if (GUI.Button(new Rect(left, top + step * i++, width, height), "TrackEventWithParameters")) {Dictionary<string, object> dic = new Dictionary<string, object>();dic.Add("StartApp"+"StartAppTime", "startAppMac"+"#"+"02/01/2013 09:52:24");dic.Add("IntValue", 1);TalkingDataPlugin.TrackEventWithParameters("action_id", "action_label", dic);}}void Start () {Debug.Log("start...!!!!!!!!!!");TalkingDataPlugin.SetLogEnabled(true);//TalkingDataPlugin.SessionStarted("E7538D90715219B3A2272A3E07E69C57", "your_channel_id");        TalkingDataPlugin.SessionStarted("ABFFCE86547D472FA95AA8B1AEBA9CC4", "your_channel_id");        TalkingDataSMSPlugin.Init("E7538D90715219B3A2272A3E07E69C57", "your_secret_id");TalkingDataPlugin.SetExceptionReportEnabled(true);        tip.text = "talking data";        Debug.Log("start...!!!!!!!!!!");#if UNITY_IPHONE#if UNITY_5UnityEngine.iOS.NotificationServices.RegisterForNotifications(UnityEngine.iOS.NotificationType.Alert |UnityEngine.iOS.NotificationType.Badge |UnityEngine.iOS.NotificationType.Sound);#elseNotificationServices.RegisterForRemoteNotificationTypes(RemoteNotificationType.Alert |RemoteNotificationType.Badge |RemoteNotificationType.Sound);#endif#endif    }void Update () {if (Input.GetKey(KeyCode.Escape)) {Application.Quit();}#if UNITY_IPHONETalkingDataPlugin.SetDeviceToken();TalkingDataPlugin.HandlePushMessage();#endif}void OnDestroy (){TalkingDataPlugin.SessionStoped();Debug.Log("onDestroy");}
public void GameRank(){TalkingDataPlugin.TrackEventWithLabel("游戏排行榜", "认知大作战");}/// <summary>/// 检测玩家等级/// </summary>/// <param name="grade">1-10.</param>public void GameGrade(int grade){TalkingDataPlugin.TrackEventWithLabel(grade+"级关卡", "认知大作战");}    public void BtnClick()    {        TalkingDataPlugin.TrackPageBegin("检测某一页");        talkingData = "检测某一页";    }    public void BtnLeaveClick()    {        TalkingDataPlugin.TrackPageEnd("检测某一页");        talkingData = "结束检测某一页";    }void Awake () {Debug.Log("Awake");}void OnEnable () {Debug.Log("OnEnable");}void OnDisable () {Debug.Log("OnDisable");}}


原创粉丝点击