File tree 3 files changed +15
-5
lines changed
android/src/main/java/com/batch/batch_rn
3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -733,9 +733,17 @@ public void profile_identify(String identifier) {
733
733
}
734
734
735
735
@ ReactMethod
736
- public void profile_trackEvent (String name , ReadableMap serializedEventData ) {
736
+ public void profile_trackEvent (@ NonNull String name , @ Nullable ReadableMap serializedEventData , @ NonNull Promise promise ) {
737
737
BatchEventAttributes attributes = RNUtils .convertSerializedEventDataToEventAttributes (serializedEventData );
738
+ if (attributes != null ) {
739
+ List <String > errors = attributes .validateEventAttributes ();
740
+ if (!errors .isEmpty ()) {
741
+ promise .reject (BATCH_BRIDGE_ERROR_CODE , errors .toString ());
742
+ return ;
743
+ }
744
+ }
738
745
Batch .Profile .trackEvent (name , attributes );
746
+ promise .resolve (null );
739
747
}
740
748
741
749
@ ReactMethod
Original file line number Diff line number Diff line change @@ -406,7 +406,7 @@ -(void)stopObserving {
406
406
[BatchProfile identify: identifier];
407
407
}
408
408
409
- RCT_EXPORT_METHOD (profile_trackEvent:(NSString *)name data:(NSDictionary *)serializedEventData)
409
+ RCT_EXPORT_METHOD (profile_trackEvent:(NSString *)name data:(NSDictionary *)serializedEventData resolver: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject )
410
410
{
411
411
BatchEventAttributes *batchEventAttributes = nil ;
412
412
@@ -418,12 +418,14 @@ -(void)stopObserving {
418
418
[batchEventAttributes validateWithError: &err];
419
419
if (batchEventAttributes != nil && err == nil ) {
420
420
[BatchProfile trackEventWithName: name attributes: batchEventAttributes];
421
+ resolve ([NSNull null ]);
421
422
} else {
422
- NSLog (@" Event validation error: %@ " , err. description );
423
+ reject (@" BatchBridgeError " , @" Event attributes validation failed: " , err);
423
424
return ;
424
425
}
425
426
}
426
427
[BatchProfile trackEventWithName: name attributes: batchEventAttributes];
428
+ resolve ([NSNull null ]);
427
429
}
428
430
429
431
- (BatchEventAttributes*) convertSerializedEventDataToEventAttributes : (NSDictionary *) serializedAttributes {
Original file line number Diff line number Diff line change @@ -56,10 +56,10 @@ export const BatchProfile = {
56
56
* @param name The event name. Must be a string.
57
57
* @param data The event attributes (optional). Must be an object.
58
58
*/
59
- trackEvent : ( name : string , data ?: BatchEventAttributes ) : void => {
59
+ trackEvent : ( name : string , data ?: BatchEventAttributes ) : Promise < void > => {
60
60
// Since _toInternalRepresentation is private, we have to resort to this little hack to access the method.
61
61
// That syntax keeps the argument type checking, while casting as any would not.
62
- RNBatch . profile_trackEvent ( name , data instanceof BatchEventAttributes ? data [ '_toInternalRepresentation' ] ( ) : null ) ;
62
+ return RNBatch . profile_trackEvent ( name , data instanceof BatchEventAttributes ? data [ '_toInternalRepresentation' ] ( ) : null ) ;
63
63
} ,
64
64
65
65
/**
You can’t perform that action at this time.
0 commit comments