@@ -3,6 +3,23 @@ import { NativeModules } from 'react-native';
3
3
import { Base } from './base' ;
4
4
5
5
const FirestackAnalytics = NativeModules . FirestackAnalytics ;
6
+ const AlphaNumericUnderscore = / ^ [ a - z A - Z 0 - 9 _ ] + $ / ;
7
+
8
+ const ReservedEventNames = [
9
+ 'app_clear_data' ,
10
+ 'app_uninstall' ,
11
+ 'app_update' ,
12
+ 'error' ,
13
+ 'first_open' ,
14
+ 'in_app_purchase' ,
15
+ 'notification_dismiss' ,
16
+ 'notification_foreground' ,
17
+ 'notification_open' ,
18
+ 'notification_receive' ,
19
+ 'os_update' ,
20
+ 'session_start' ,
21
+ 'user_engagement' ,
22
+ ] ;
6
23
7
24
export default class Analytics extends Base {
8
25
/**
@@ -12,6 +29,25 @@ export default class Analytics extends Base {
12
29
* @return {Promise }
13
30
*/
14
31
logEvent ( name : string , params : Object = { } ) : void {
32
+ // check name is not a reserved event name
33
+ if ( ReservedEventNames . includes ( name ) ) {
34
+ throw new Error ( `event name '${ name } ' is a reserved event name and can not be used.` ) ;
35
+ }
36
+
37
+ // name format validation
38
+ if ( ! AlphaNumericUnderscore . test ( name ) ) {
39
+ throw new Error ( `Event name '${ name } ' is invalid. Names should contain 1 to 32 alphanumeric characters or underscores.` ) ;
40
+ }
41
+
42
+ // maximum number of allowed params check
43
+ if ( Object . keys ( params ) . length > 25 ) throw new Error ( 'Maximum number of parameters exceeded (25).' ) ;
44
+
45
+ // TODO validate param names and values
46
+ // Parameter names can be up to 24 characters long and must start with an alphabetic character
47
+ // and contain only alphanumeric characters and underscores. Only String, long and double param
48
+ // types are supported. String parameter values can be up to 36 characters long. The "firebase_"
49
+ // prefix is reserved and should not be used for parameter names.
50
+
15
51
return FirestackAnalytics . logEvent ( name , params ) ;
16
52
}
17
53
0 commit comments