@@ -3,6 +3,23 @@ import { NativeModules } from 'react-native';
33import { Base } from './base' ;
44
55const 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+ ] ;
623
724export default class Analytics extends Base {
825 /**
@@ -12,6 +29,25 @@ export default class Analytics extends Base {
1229 * @return {Promise }
1330 */
1431 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+
1551 return FirestackAnalytics . logEvent ( name , params ) ;
1652 }
1753
0 commit comments