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+
1622static char *tdDeviceId = NULL ;
1723
1824extern " 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
3040void 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
128138void 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
175185void TDOnPunch (const char *profileId, const char *punchId) {
@@ -178,9 +188,7 @@ void TDOnPunch(const char *profileId, const char *punchId) {
178188}
179189
180190void 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
264274void 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
299306void 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
319324void 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) {
345348void 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
442446void TDSetGlobalKV (const char *key, const char *strVal, double numVal) {
0 commit comments