File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -435,7 +435,7 @@ class OSButtons extends React.Component<Props> {
435435 loggingFunction ( 'Tracking event: ' , 'ReactNative' ) ;
436436 const platform = Platform . OS ; // This will be 'ios' or 'android'
437437 OneSignal . User . trackEvent ( `ReactNative-${ platform } ` , {
438- ABC : '123 ' ,
438+ DEF : '456 ' ,
439439 } ) ;
440440 } ) ;
441441
Original file line number Diff line number Diff line change @@ -609,10 +609,14 @@ export namespace OneSignal {
609609 /** Track custom events for the current user. */
610610 export function trackEvent (
611611 name : string ,
612- properties ?: Record < string , string > ,
612+ properties ?: Record < string , unknown > ,
613613 ) {
614614 if ( ! isNativeModuleLoaded ( RNOneSignal ) ) return ;
615615
616+ if ( ! isObjectSerializable ( properties ) ) {
617+ return console . error ( 'Properties must be JSON-serializable' ) ;
618+ }
619+
616620 RNOneSignal . trackEvent ( name , properties ) ;
617621 }
618622 }
@@ -1010,6 +1014,21 @@ export namespace OneSignal {
10101014 }
10111015}
10121016
1017+ /**
1018+ * Returns true if the value is a JSON-serializable object.
1019+ */
1020+ function isObjectSerializable ( value : unknown ) : boolean {
1021+ if ( ! ( typeof value === 'object' && value !== null && ! Array . isArray ( value ) ) ) {
1022+ return false ;
1023+ }
1024+ try {
1025+ JSON . stringify ( value ) ;
1026+ return true ;
1027+ } catch ( e ) {
1028+ return false ;
1029+ }
1030+ }
1031+
10131032export {
10141033 InAppMessage ,
10151034 InAppMessageClickEvent ,
You can’t perform that action at this time.
0 commit comments