wangguan
2020-12-16 ecc314323bc050612d47511689b5b4222718fd06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using UnityEngine;
using System.Collections.Generic;
 
public class TDAADemoScript : MonoBehaviour
{
    private const int top = 100;
    private const int left = 80;
    private const int height = 50;
    private readonly int width = Screen.width - (left * 2);
    private const int step = 60;
    private string deviceId;
    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, top + (step * i++), width, height), deviceId);
        if (GUI.Button(new Rect(left, top + (step * i++), width, height), "getDeviceId"))
        {
            deviceId = TalkingDataPlugin.GetDeviceId();
        }
 
        GUI.Label(new Rect(left, top + (step * i++), width, height), oaid);
        if (GUI.Button(new Rect(left, top + (step * i++), width, height), "getOAID"))
        {
            oaid = TalkingDataPlugin.GetOAID();
        }
 
        if (GUI.Button(new Rect(left, top + (step * i++), width, height), "设置位置信息 纬度39.94  经度116.43"))
        {
            TalkingDataPlugin.SetLocation(39.94, 116.43);
        }
 
        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 TDAA_STANDARD
        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), "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);
        }
#endif
 
//自定义事件
#if TDAA_CUSTOM
        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>
            {
                { "StringValue", "Pi" },
                { "NumberValue", 3.14 }
            };
            TalkingDataPlugin.TrackEventWithParameters("action_id", "action_label", dic);
        }
 
        if (GUI.Button(new Rect(left, top + (step * i++), width, height), "首页推荐位点击"))
        {
            // 可定义eventId=点击首页推荐位;event_LABEL=具体的位置编号
            string recommandClick = "首页推荐位点击";
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("服装", "商品类别");
            dic.Add("5~10", "price");
            TalkingDataPlugin.TrackEventWithParameters(recommandClick, "第一广告位", dic);
            Dictionary<string, object> dic2 = new Dictionary<string, object>();
            dic2.Add("家电", "商品类别");
            dic2.Add("500~1000", "price");
            TalkingDataPlugin.TrackEventWithParameters(recommandClick, "第三广告位", dic2);
        }
        if (GUI.Button(new Rect(left, top + (step * i++), width, height), "战斗失败"))
        {
            // 可定义eventId=战斗失败
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("20-30", "等级");//级别区间
            dic.Add("沼泽地阿卡村", "关卡名"); //关卡名称
            dic.Add("主动退出", "失败原因"); //失败原因
            dic.Add("10000~12000", "coin"); //携带金币数量
            TalkingDataPlugin.TrackEventWithParameters("战斗失败", null, dic);
        }
#endif
 
        //页面统计
#if TDAA_PAGE
        if (GUI.Button(new Rect(left, top + (step * i++), width, height), "进入应用首页"))
        {
            TalkingDataPlugin.TrackPageBegin("应用首页");//传入的是页面名称
        }
 
        if (GUI.Button(new Rect(left, top + (step * i++), width, height), "离开应用首页"))
        {
            TalkingDataPlugin.TrackPageEnd("应用首页");
        }
#endif
    }
 
    private void Start()
    {
        Debug.Log("Start");
        //TalkingDataPlugin.SetLogEnabled(false);
        TalkingDataPlugin.BackgroundSessionEnabled();
        TalkingDataPlugin.SessionStarted("41F4DA3B72CF48D2ADAB761E6C17D12D", "1");
        TalkingDataPlugin.SetExceptionReportEnabled(true);
#if TDAA_PUSH
#if UNITY_IPHONE
        UnityEngine.iOS.NotificationServices.RegisterForNotifications(
            UnityEngine.iOS.NotificationType.Alert |
            UnityEngine.iOS.NotificationType.Badge |
            UnityEngine.iOS.NotificationType.Sound);
#endif
#endif
    }
 
    private void Update()
    {
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
#if TDAA_PUSH
        TalkingDataPlugin.SetDeviceToken();
        TalkingDataPlugin.HandlePushMessage();
#endif
    }
 
    private void OnDestroy()
    {
        Debug.Log("onDestroy");
        TalkingDataPlugin.SessionStoped();
    }
 
    private void Awake()
    {
        Debug.Log("Awake");
    }
 
    private void OnEnable()
    {
        Debug.Log("OnEnable");
    }
 
    private void OnDisable()
    {
        Debug.Log("OnDisable");
    }
}