13
13
return string ? [NSString stringWithUTF8String: string] : nil ;
14
14
}
15
15
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
+
16
22
static char *tdDeviceId = NULL ;
17
23
18
24
extern " C" {
19
25
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
20
26
21
- void TDInit (const char *appId, const char *channelId, const char *custom) {
27
+ void TDInitSDK (const char *appId, const char *channelId, const char *custom) {
22
28
if ([TalkingDataSDK respondsToSelector: @selector (setFrameworkTag: )]) {
23
29
[TalkingDataSDK performSelector: @selector (setFrameworkTag: ) withObject: @2 ];
24
30
}
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 ];
28
38
}
29
39
30
40
void TDBackgroundSessionEnabled () {
@@ -60,10 +70,8 @@ void TDOnReceiveDeepLink(const char *url) {
60
70
[TalkingDataSDK onReceiveDeepLink: [NSURL URLWithString: TDCreateNSString (url)]];
61
71
}
62
72
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);
67
75
TalkingDataProfile *profile = [TalkingDataProfile createProfile ];
68
76
profile.name = [profileDic objectForKey: @" name" ];
69
77
NSNumber *typeNum = [profileDic objectForKey: @" type" ];
@@ -90,13 +98,14 @@ void TDOnRegister(const char *profileId, const char *profileJson, const char *in
90
98
profile.property10 = [profileDic objectForKey: @" property10" ];
91
99
[TalkingDataSDK onRegister: TDCreateNSString (profileId)
92
100
profile: profile
93
- invitationCode: TDCreateNSString (invitationCode)];
101
+ invitationCode: TDCreateNSString (invitationCode)
102
+ eventValue: TDCreateNSDictionary (eventValueJson)];
94
103
}
95
104
96
- void TDOnLogin (const char *profileId, const char *profileJson) {
105
+ void TDOnLogin (const char *profileId, const char *profileJson, const char *eventValueJson ) {
97
106
NSString *profileStr = TDCreateNSString (profileJson);
98
107
NSData *profileData = [profileStr dataUsingEncoding: NSUTF8StringEncoding];
99
- NSDictionary *profileDic = [ NSJSONSerialization JSONObjectWithData: profileData options: 0 error: nil ] ;
108
+ NSDictionary *profileDic = TDCreateNSDictionary (eventValueJson) ;
100
109
TalkingDataProfile *profile = [TalkingDataProfile createProfile ];
101
110
profile.name = [profileDic objectForKey: @" name" ];
102
111
NSNumber *typeNum = [profileDic objectForKey: @" type" ];
@@ -122,13 +131,12 @@ void TDOnLogin(const char *profileId, const char *profileJson) {
122
131
profile.property9 = [profileDic objectForKey: @" property9" ];
123
132
profile.property10 = [profileDic objectForKey: @" property10" ];
124
133
[TalkingDataSDK onLogin: TDCreateNSString (profileId)
125
- profile: profile];
134
+ profile: profile
135
+ eventValue: TDCreateNSDictionary (eventValueJson)];
126
136
}
127
137
128
138
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);
132
140
TalkingDataProfile *profile = [TalkingDataProfile createProfile ];
133
141
profile.name = [profileDic objectForKey: @" name" ];
134
142
NSNumber *typeNum = [profileDic objectForKey: @" type" ];
@@ -162,14 +170,16 @@ void TDOnCreateCard(const char *profileId, const char *method, const char *conte
162
170
content: TDCreateNSString (content)];
163
171
}
164
172
165
- void TDOnFavorite (const char *category, const char *content) {
173
+ void TDOnFavorite (const char *category, const char *content, const char *eventValue ) {
166
174
[TalkingDataSDK onFavorite: TDCreateNSString (category)
167
- content: TDCreateNSString (content)];
175
+ content: TDCreateNSString (content)
176
+ eventValue: TDCreateNSDictionary (eventValue)];
168
177
}
169
178
170
- void TDOnShare (const char *profileId, const char *content) {
179
+ void TDOnShare (const char *profileId, const char *content, const char *eventValue ) {
171
180
[TalkingDataSDK onShare: TDCreateNSString (profileId)
172
- content: TDCreateNSString (content)];
181
+ content: TDCreateNSString (content)
182
+ eventValue: TDCreateNSDictionary (eventValue)];
173
183
}
174
184
175
185
void TDOnPunch (const char *profileId, const char *punchId) {
@@ -178,9 +188,7 @@ void TDOnPunch(const char *profileId, const char *punchId) {
178
188
}
179
189
180
190
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);
184
192
TalkingDataSearch *search = [TalkingDataSearch createSearch ];
185
193
search.category = [searchDic objectForKey: @" category" ];
186
194
search.content = [searchDic objectForKey: @" content" ];
@@ -246,25 +254,25 @@ void TDOnBooking(const char *profileId, const char *bookingId, const char *categ
246
254
#endif
247
255
248
256
#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 ) {
250
258
[TalkingDataSDK onViewItem: TDCreateNSString (itemId)
251
259
category: TDCreateNSString (category)
252
260
name: TDCreateNSString (name)
253
- unitPrice: unitPrice];
261
+ unitPrice: unitPrice
262
+ eventValue: TDCreateNSDictionary (eventValueJson)];
254
263
}
255
264
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 ) {
257
266
[TalkingDataSDK onAddItemToShoppingCart: TDCreateNSString (itemId)
258
267
category: TDCreateNSString (category)
259
268
name: TDCreateNSString (name)
260
269
unitPrice: unitPrice
261
- amount: amount];
270
+ amount: amount
271
+ eventValue: TDCreateNSDictionary (eventValueJson)];
262
272
}
263
273
264
274
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);
268
276
TalkingDataShoppingCart *shoppingCart = [TalkingDataShoppingCart createShoppingCart ];
269
277
NSArray *items = shoppingCartDic[@" items" ];
270
278
for (NSDictionary *item in items) {
@@ -277,10 +285,8 @@ void TDOnViewShoppingCart(const char *shoppingCartJson) {
277
285
[TalkingDataSDK onViewShoppingCart: shoppingCart];
278
286
}
279
287
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);
284
290
TalkingDataOrder *order = [TalkingDataOrder createOrder: orderDic[@" orderId" ]
285
291
total: [orderDic[@" total" ] intValue ]
286
292
currencyType: orderDic[@" currencyType" ]];
@@ -293,13 +299,12 @@ void TDOnPlaceOrder(const char *orderJson, const char *profileId) {
293
299
amount: [item[@" amount" ] intValue ]];
294
300
}
295
301
[TalkingDataSDK onPlaceOrder: order
296
- profileId: TDCreateNSString (profileId)];
302
+ profileId: TDCreateNSString (profileId)
303
+ eventValue: TDCreateNSDictionary (eventValueJson)];
297
304
}
298
305
299
306
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);
303
308
TalkingDataOrder *order = [TalkingDataOrder createOrder: orderDic[@" orderId" ]
304
309
total: [orderDic[@" total" ] intValue ]
305
310
currencyType: orderDic[@" currencyType" ]];
@@ -317,9 +322,7 @@ void TDOnOrderPaySucc(const char *orderJson, const char *paymentType, const char
317
322
}
318
323
319
324
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);
323
326
TalkingDataOrder *order = [TalkingDataOrder createOrder: orderDic[@" orderId" ]
324
327
total: [orderDic[@" total" ] intValue ]
325
328
currencyType: orderDic[@" currencyType" ]];
@@ -345,7 +348,7 @@ void TDOnCredit(const char *profileId, int amount, const char *content) {
345
348
void TDOnTransaction (const char *profileId, const char *transactionJson) {
346
349
NSString *transactionStr = TDCreateNSString (transactionJson);
347
350
NSData *transactionData = [transactionStr dataUsingEncoding: NSUTF8StringEncoding];
348
- NSDictionary *transactionDic = [ NSJSONSerialization JSONObjectWithData: transactionData options: 0 error: nil ] ;
351
+ NSDictionary *transactionDic = TDCreateNSDictionary (transactionJson) ;
349
352
TalkingDataTransaction *transaction = [TalkingDataTransaction createTransaction ];
350
353
transaction.transactionId = [transactionDic objectForKey: @" transactionId" ];
351
354
transaction.category = [transactionDic objectForKey: @" category" ];
@@ -428,15 +431,16 @@ void TDOnTrialFinished(const char *profileId, const char *content) {
428
431
}
429
432
#endif
430
433
431
- void TDOnEvent (const char *eventId, const char *parameters) {
434
+ void TDOnEvent (const char *eventId, const char *parameters, const char *eventValueJson ) {
432
435
NSString *parameterStr = TDCreateNSString (parameters);
433
436
NSDictionary *parameterDic = nil ;
434
437
if (parameterStr) {
435
438
NSData *parameterData = [parameterStr dataUsingEncoding: NSUTF8StringEncoding];
436
439
parameterDic = [NSJSONSerialization JSONObjectWithData: parameterData options: 0 error: nil ];
437
440
}
438
441
[TalkingDataSDK onEvent: TDCreateNSString (eventId)
439
- parameters: parameterDic];
442
+ parameters: parameterDic
443
+ eventValue: TDCreateNSDictionary (eventValueJson)];
440
444
}
441
445
442
446
void TDSetGlobalKV (const char *key, const char *strVal, double numVal) {
0 commit comments