Skip to content

Commit 1d992b4

Browse files
talkingdatatalkingdata
authored andcommitted
update
1 parent 9d89ab4 commit 1d992b4

File tree

3 files changed

+250
-134
lines changed

3 files changed

+250
-134
lines changed

Assets/Plugins/iOS/TalkingDataSDK.mm

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,28 @@
1313
return string ? [NSString stringWithUTF8String:string] : nil;
1414
}
1515

16+
static NSDictionary *TDCreateNSDictionary(const char *json) {
17+
NSString *valStr = TDCreateNSString(json);
18+
NSData *valData = [valStr dataUsingEncoding:NSUTF8StringEncoding];
19+
return [NSJSONSerialization JSONObjectWithData:valData options:0 error:nil];
20+
}
21+
1622
static char *tdDeviceId = NULL;
1723

1824
extern "C" {
1925
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
2026

21-
void TDInit(const char *appId, const char *channelId, const char *custom) {
27+
void TDInitSDK(const char *appId, const char *channelId, const char *custom) {
2228
if ([TalkingDataSDK respondsToSelector:@selector(setFrameworkTag:)]) {
2329
[TalkingDataSDK performSelector:@selector(setFrameworkTag:) withObject:@2];
2430
}
25-
[TalkingDataSDK init:TDCreateNSString(appId)
26-
channelId:TDCreateNSString(channelId)
27-
custom:TDCreateNSString(custom)];
31+
[TalkingDataSDK initSDK:TDCreateNSString(appId)
32+
channelId:TDCreateNSString(channelId)
33+
custom:TDCreateNSString(custom)];
34+
}
35+
36+
void TDStartA() {
37+
[TalkingDataSDK startA];
2838
}
2939

3040
void TDBackgroundSessionEnabled() {
@@ -60,10 +70,8 @@ void TDOnReceiveDeepLink(const char *url) {
6070
[TalkingDataSDK onReceiveDeepLink:[NSURL URLWithString:TDCreateNSString(url)]];
6171
}
6272

63-
void TDOnRegister(const char *profileId, const char *profileJson, const char *invitationCode) {
64-
NSString *profileStr = TDCreateNSString(profileJson);
65-
NSData *profileData = [profileStr dataUsingEncoding:NSUTF8StringEncoding];
66-
NSDictionary *profileDic = [NSJSONSerialization JSONObjectWithData:profileData options:0 error:nil];
73+
void TDOnRegister(const char *profileId, const char *profileJson, const char *invitationCode, const char *eventValueJson) {
74+
NSDictionary *profileDic = TDCreateNSDictionary(profileJson);
6775
TalkingDataProfile *profile = [TalkingDataProfile createProfile];
6876
profile.name = [profileDic objectForKey:@"name"];
6977
NSNumber *typeNum = [profileDic objectForKey:@"type"];
@@ -90,13 +98,14 @@ void TDOnRegister(const char *profileId, const char *profileJson, const char *in
9098
profile.property10 = [profileDic objectForKey:@"property10"];
9199
[TalkingDataSDK onRegister:TDCreateNSString(profileId)
92100
profile:profile
93-
invitationCode:TDCreateNSString(invitationCode)];
101+
invitationCode:TDCreateNSString(invitationCode)
102+
eventValue:TDCreateNSDictionary(eventValueJson)];
94103
}
95104

96-
void TDOnLogin(const char *profileId, const char *profileJson) {
105+
void TDOnLogin(const char *profileId, const char *profileJson, const char *eventValueJson) {
97106
NSString *profileStr = TDCreateNSString(profileJson);
98107
NSData *profileData = [profileStr dataUsingEncoding:NSUTF8StringEncoding];
99-
NSDictionary *profileDic = [NSJSONSerialization JSONObjectWithData:profileData options:0 error:nil];
108+
NSDictionary *profileDic = TDCreateNSDictionary(eventValueJson);
100109
TalkingDataProfile *profile = [TalkingDataProfile createProfile];
101110
profile.name = [profileDic objectForKey:@"name"];
102111
NSNumber *typeNum = [profileDic objectForKey:@"type"];
@@ -122,13 +131,12 @@ void TDOnLogin(const char *profileId, const char *profileJson) {
122131
profile.property9 = [profileDic objectForKey:@"property9"];
123132
profile.property10 = [profileDic objectForKey:@"property10"];
124133
[TalkingDataSDK onLogin:TDCreateNSString(profileId)
125-
profile:profile];
134+
profile:profile
135+
eventValue:TDCreateNSDictionary(eventValueJson)];
126136
}
127137

128138
void TDOnProfileUpdate(const char *profileJson) {
129-
NSString *profileStr = TDCreateNSString(profileJson);
130-
NSData *profileData = [profileStr dataUsingEncoding:NSUTF8StringEncoding];
131-
NSDictionary *profileDic = [NSJSONSerialization JSONObjectWithData:profileData options:0 error:nil];
139+
NSDictionary *profileDic = TDCreateNSDictionary(profileJson);
132140
TalkingDataProfile *profile = [TalkingDataProfile createProfile];
133141
profile.name = [profileDic objectForKey:@"name"];
134142
NSNumber *typeNum = [profileDic objectForKey:@"type"];
@@ -162,14 +170,16 @@ void TDOnCreateCard(const char *profileId, const char *method, const char *conte
162170
content:TDCreateNSString(content)];
163171
}
164172

165-
void TDOnFavorite(const char *category, const char *content) {
173+
void TDOnFavorite(const char *category, const char *content, const char *eventValue) {
166174
[TalkingDataSDK onFavorite:TDCreateNSString(category)
167-
content:TDCreateNSString(content)];
175+
content:TDCreateNSString(content)
176+
eventValue:TDCreateNSDictionary(eventValue)];
168177
}
169178

170-
void TDOnShare(const char *profileId, const char *content) {
179+
void TDOnShare(const char *profileId, const char *content, const char *eventValue) {
171180
[TalkingDataSDK onShare:TDCreateNSString(profileId)
172-
content:TDCreateNSString(content)];
181+
content:TDCreateNSString(content)
182+
eventValue:TDCreateNSDictionary(eventValue)];
173183
}
174184

175185
void TDOnPunch(const char *profileId, const char *punchId) {
@@ -178,9 +188,7 @@ void TDOnPunch(const char *profileId, const char *punchId) {
178188
}
179189

180190
void TDOnSearch(const char *searchJson) {
181-
NSString *searchStr = TDCreateNSString(searchJson);
182-
NSData *searchData = [searchStr dataUsingEncoding:NSUTF8StringEncoding];
183-
NSDictionary *searchDic = [NSJSONSerialization JSONObjectWithData:searchData options:0 error:nil];
191+
NSDictionary *searchDic = TDCreateNSDictionary(searchJson);
184192
TalkingDataSearch *search = [TalkingDataSearch createSearch];
185193
search.category = [searchDic objectForKey:@"category"];
186194
search.content = [searchDic objectForKey:@"content"];
@@ -246,25 +254,25 @@ void TDOnBooking(const char *profileId, const char *bookingId, const char *categ
246254
#endif
247255

248256
#ifdef TD_RETAIL
249-
void TDOnViewItem(const char *itemId, const char *category, const char *name, int unitPrice) {
257+
void TDOnViewItem(const char *itemId, const char *category, const char *name, int unitPrice, const char *eventValueJson) {
250258
[TalkingDataSDK onViewItem:TDCreateNSString(itemId)
251259
category:TDCreateNSString(category)
252260
name:TDCreateNSString(name)
253-
unitPrice:unitPrice];
261+
unitPrice:unitPrice
262+
eventValue:TDCreateNSDictionary(eventValueJson)];
254263
}
255264

256-
void TDOnAddItemToShoppingCart(const char *itemId, const char *category, const char *name, int unitPrice, int amount) {
265+
void TDOnAddItemToShoppingCart(const char *itemId, const char *category, const char *name, int unitPrice, int amount, const char *eventValueJson) {
257266
[TalkingDataSDK onAddItemToShoppingCart:TDCreateNSString(itemId)
258267
category:TDCreateNSString(category)
259268
name:TDCreateNSString(name)
260269
unitPrice:unitPrice
261-
amount:amount];
270+
amount:amount
271+
eventValue:TDCreateNSDictionary(eventValueJson)];
262272
}
263273

264274
void TDOnViewShoppingCart(const char *shoppingCartJson) {
265-
NSString *shoppingCartStr = TDCreateNSString(shoppingCartJson);
266-
NSData *shoppingCartData = [shoppingCartStr dataUsingEncoding:NSUTF8StringEncoding];
267-
NSDictionary *shoppingCartDic = [NSJSONSerialization JSONObjectWithData:shoppingCartData options:0 error:nil];
275+
NSDictionary *shoppingCartDic = TDCreateNSDictionary(shoppingCartJson);
268276
TalkingDataShoppingCart *shoppingCart = [TalkingDataShoppingCart createShoppingCart];
269277
NSArray *items = shoppingCartDic[@"items"];
270278
for (NSDictionary *item in items) {
@@ -277,10 +285,8 @@ void TDOnViewShoppingCart(const char *shoppingCartJson) {
277285
[TalkingDataSDK onViewShoppingCart:shoppingCart];
278286
}
279287

280-
void TDOnPlaceOrder(const char *orderJson, const char *profileId) {
281-
NSString *orderStr = TDCreateNSString(orderJson);
282-
NSData *orderData = [orderStr dataUsingEncoding:NSUTF8StringEncoding];
283-
NSDictionary *orderDic = [NSJSONSerialization JSONObjectWithData:orderData options:0 error:nil];
288+
void TDOnPlaceOrder(const char *orderJson, const char *profileId, const char *eventValueJson) {
289+
NSDictionary *orderDic = TDCreateNSDictionary(orderJson);
284290
TalkingDataOrder *order = [TalkingDataOrder createOrder:orderDic[@"orderId"]
285291
total:[orderDic[@"total"] intValue]
286292
currencyType:orderDic[@"currencyType"]];
@@ -293,13 +299,12 @@ void TDOnPlaceOrder(const char *orderJson, const char *profileId) {
293299
amount:[item[@"amount"] intValue]];
294300
}
295301
[TalkingDataSDK onPlaceOrder:order
296-
profileId:TDCreateNSString(profileId)];
302+
profileId:TDCreateNSString(profileId)
303+
eventValue:TDCreateNSDictionary(eventValueJson)];
297304
}
298305

299306
void TDOnOrderPaySucc(const char *orderJson, const char *paymentType, const char *profileId) {
300-
NSString *orderStr = TDCreateNSString(orderJson);
301-
NSData *orderData = [orderStr dataUsingEncoding:NSUTF8StringEncoding];
302-
NSDictionary *orderDic = [NSJSONSerialization JSONObjectWithData:orderData options:0 error:nil];
307+
NSDictionary *orderDic = TDCreateNSDictionary(orderJson);
303308
TalkingDataOrder *order = [TalkingDataOrder createOrder:orderDic[@"orderId"]
304309
total:[orderDic[@"total"] intValue]
305310
currencyType:orderDic[@"currencyType"]];
@@ -317,9 +322,7 @@ void TDOnOrderPaySucc(const char *orderJson, const char *paymentType, const char
317322
}
318323

319324
void TDOnCancelOrder(const char *orderJson) {
320-
NSString *orderStr = TDCreateNSString(orderJson);
321-
NSData *orderData = [orderStr dataUsingEncoding:NSUTF8StringEncoding];
322-
NSDictionary *orderDic = [NSJSONSerialization JSONObjectWithData:orderData options:0 error:nil];
325+
NSDictionary *orderDic = TDCreateNSDictionary(orderJson);
323326
TalkingDataOrder *order = [TalkingDataOrder createOrder:orderDic[@"orderId"]
324327
total:[orderDic[@"total"] intValue]
325328
currencyType:orderDic[@"currencyType"]];
@@ -345,7 +348,7 @@ void TDOnCredit(const char *profileId, int amount, const char *content) {
345348
void TDOnTransaction(const char *profileId, const char *transactionJson) {
346349
NSString *transactionStr = TDCreateNSString(transactionJson);
347350
NSData *transactionData = [transactionStr dataUsingEncoding:NSUTF8StringEncoding];
348-
NSDictionary *transactionDic = [NSJSONSerialization JSONObjectWithData:transactionData options:0 error:nil];
351+
NSDictionary *transactionDic = TDCreateNSDictionary(transactionJson);
349352
TalkingDataTransaction *transaction = [TalkingDataTransaction createTransaction];
350353
transaction.transactionId = [transactionDic objectForKey:@"transactionId"];
351354
transaction.category = [transactionDic objectForKey:@"category"];
@@ -428,15 +431,16 @@ void TDOnTrialFinished(const char *profileId, const char *content) {
428431
}
429432
#endif
430433

431-
void TDOnEvent(const char *eventId, const char *parameters) {
434+
void TDOnEvent(const char *eventId, const char *parameters, const char *eventValueJson) {
432435
NSString *parameterStr = TDCreateNSString(parameters);
433436
NSDictionary *parameterDic = nil;
434437
if (parameterStr) {
435438
NSData *parameterData = [parameterStr dataUsingEncoding:NSUTF8StringEncoding];
436439
parameterDic = [NSJSONSerialization JSONObjectWithData:parameterData options:0 error:nil];
437440
}
438441
[TalkingDataSDK onEvent:TDCreateNSString(eventId)
439-
parameters:parameterDic];
442+
parameters:parameterDic
443+
eventValue:TDCreateNSDictionary(eventValueJson)];
440444
}
441445

442446
void TDSetGlobalKV(const char *key, const char *strVal, double numVal) {

Assets/TalkingDataScripts/TDDemoScript.cs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ private void OnGUI()
6363
profile.SetProperty8("property8");
6464
profile.SetProperty9(9.8);
6565
profile.SetProperty10("property10");
66-
TalkingDataSDK.OnRegister("user01", profile, "123456");
66+
Dictionary<string, object> eventValue = new Dictionary<string, object>
67+
{
68+
{ "key", "value" }
69+
};
70+
TalkingDataSDK.OnRegister("user01", profile, "123456", eventValue);
6771
}
6872

6973
if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnLogin"))
@@ -83,7 +87,11 @@ private void OnGUI()
8387
profile.SetProperty8("property8");
8488
profile.SetProperty9(9.8);
8589
profile.SetProperty10("property10");
86-
TalkingDataSDK.OnLogin("user01", profile);
90+
Dictionary<string, object> eventValue = new Dictionary<string, object>
91+
{
92+
{ "key", "value" }
93+
};
94+
TalkingDataSDK.OnLogin("user01", profile, eventValue);
8795
}
8896

8997
if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnProfileUpdate"))
@@ -113,12 +121,20 @@ private void OnGUI()
113121

114122
if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnFavorite"))
115123
{
116-
TalkingDataSDK.OnFavorite("服装", "2019新款");
124+
Dictionary<string, object> eventValue = new Dictionary<string, object>
125+
{
126+
{ "key", "value" }
127+
};
128+
TalkingDataSDK.OnFavorite("服装", "2019新款", eventValue);
117129
}
118130

119131
if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnShare"))
120132
{
121-
TalkingDataSDK.OnShare("user01", "课程");
133+
Dictionary<string, object> eventValue = new Dictionary<string, object>
134+
{
135+
{ "key", "value" }
136+
};
137+
TalkingDataSDK.OnShare("user01", "课程", eventValue);
122138
}
123139

124140
if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnPunch"))
@@ -182,12 +198,20 @@ private void OnGUI()
182198
#if TD_RETAIL
183199
if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnViewItem"))
184200
{
185-
TalkingDataSDK.OnViewItem("A1660", "手机", "iPhone 7", 538800);
201+
Dictionary<string, object> eventValue = new Dictionary<string, object>
202+
{
203+
{ "key", "value" }
204+
};
205+
TalkingDataSDK.OnViewItem("A1660", "手机", "iPhone 7", 538800, eventValue);
186206
}
187207

188208
if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnAddItemToShoppingCart"))
189209
{
190-
TalkingDataSDK.OnAddItemToShoppingCart("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
210+
Dictionary<string, object> eventValue = new Dictionary<string, object>
211+
{
212+
{ "key", "value" }
213+
};
214+
TalkingDataSDK.OnAddItemToShoppingCart("MLH12CH", "电脑", "MacBook Pro", 1388800, 1, eventValue);
191215
}
192216

193217
if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnViewShoppingCart"))
@@ -206,7 +230,11 @@ private void OnGUI()
206230
TalkingDataOrder order = TalkingDataOrder.CreateOrder("order01", 2466400, "CNY");
207231
order.AddItem("A1660", "手机", "iPhone 7", 538800, 2);
208232
order.AddItem("MLH12CH", "电脑", "MacBook Pro", 1388800, 1);
209-
TalkingDataSDK.OnPlaceOrder(order, "user01");
233+
Dictionary<string, object> eventValue = new Dictionary<string, object>
234+
{
235+
{ "key", "value" }
236+
};
237+
TalkingDataSDK.OnPlaceOrder(order, "user01", eventValue);
210238
}
211239

212240
if (GUI.Button(new Rect(left + i % 2 * (width + spacing), top + step * (i++ / 2), width, height), "OnOrderPaySucc"))
@@ -317,7 +345,11 @@ private void OnGUI()
317345
{ "StringValue", "Pi" },
318346
{ "NumberValue", 3.14 }
319347
};
320-
TalkingDataSDK.OnEvent("action_id", dic);
348+
Dictionary<string, object> eventValue = new Dictionary<string, object>
349+
{
350+
{ "key", "value" }
351+
};
352+
TalkingDataSDK.OnEvent("action_id", dic, eventValue);
321353
}
322354
}
323355

@@ -326,7 +358,8 @@ void Start()
326358
Debug.Log("Start");
327359
// TalkingDataSDK.SetVerboseLogDisable();
328360
TalkingDataSDK.BackgroundSessionEnabled();
329-
TalkingDataSDK.Init("your_app_id", "your_channel_id", "your_custom_parameter");
361+
TalkingDataSDK.InitSDK("your_app_id", "your_channel_id", "your_custom_parameter");
362+
TalkingDataSDK.StartA();
330363
}
331364

332365
void Update()

0 commit comments

Comments
 (0)