@@ -54,15 +54,18 @@ export class ScreenTrackingService implements OnDestroy {
54
54
} ;
55
55
const component = activationEnd . snapshot . component ;
56
56
const routeConfig = activationEnd . snapshot . routeConfig ;
57
+ const loadedConfig = routeConfig && ( routeConfig as any ) . _loadedConfig ;
57
58
const loadChildren = routeConfig && routeConfig . loadChildren ;
58
59
if ( component ) {
59
60
return of ( { ...params , firebase_screen_class : nameOrToString ( component ) } ) ;
61
+ } else if ( loadedConfig && loadedConfig . module && loadedConfig . module . _moduleType ) {
62
+ return of ( { ...params , firebase_screen_class : nameOrToString ( loadedConfig . module . _moduleType ) } ) ;
60
63
} else if ( typeof loadChildren === "string" ) {
61
64
// TODO is this an older lazy loading style parse
62
65
return of ( { ...params , firebase_screen_class : loadChildren } ) ;
63
66
} else if ( loadChildren ) {
64
- // TODO look into the return types here
65
- return from ( loadChildren ) . pipe ( map ( child => ( { ...params , firebase_screen_class : nameOrToString ( child ) } ) ) ) ;
67
+ // TODO look into the other return types here
68
+ return from ( loadChildren ( ) as Promise < any > ) . pipe ( map ( child => ( { ...params , firebase_screen_class : nameOrToString ( child ) } ) ) ) ;
66
69
} else {
67
70
// TODO figure out what forms of router events I might be missing
68
71
return of ( params ) ;
@@ -77,7 +80,7 @@ export class ScreenTrackingService implements OnDestroy {
77
80
analytics . setCurrentScreen ( params . screen_name , { global : true } )
78
81
}
79
82
} ) ,
80
- map ( params => ( { firebase_screen_id : getScreenId ( params ) , ...params } ) ) ,
83
+ map ( params => ( { firebase_screen_id : nextScreenId ( params ) , ...params } ) ) ,
81
84
groupBy ( params => params . outlet ) ,
82
85
mergeMap ( group => group . pipe ( startWith ( undefined ) , pairwise ( ) ) ) ,
83
86
map ( ( [ prior , current ] ) => prior ? {
@@ -123,19 +126,19 @@ export class UserTrackingService implements OnDestroy {
123
126
}
124
127
}
125
128
126
- let nextScreenId = Math . floor ( Math . random ( ) * 2 ** 64 ) - 2 ** 63 ;
129
+ // firebase_screen_id is an INT64 but use INT32 cause javascript
130
+ const randomInt32 = ( ) => Math . floor ( Math . random ( ) * ( 2 ** 32 - 1 ) ) - 2 ** 31 ;
127
131
128
- const screenIds : { [ key :string ] : number } = { } ;
132
+ const currentScreenIds : { [ key :string ] : number } = { } ;
129
133
130
- const getScreenId = ( params :AngularFireAnalyticsEventParams ) => {
131
- const name = params . firebase_screen_class || params . screen_name ;
132
- const existingScreenId = screenIds [ name ] ;
133
- if ( existingScreenId ) {
134
- return existingScreenId ;
134
+ const nextScreenId = ( params :AngularFireAnalyticsEventParams ) => {
135
+ const scope = params . outlet ;
136
+ if ( currentScreenIds . hasOwnProperty ( scope ) ) {
137
+ return ++ currentScreenIds [ scope ] ;
135
138
} else {
136
- const screenId = nextScreenId ++ ;
137
- screenIds [ name ] = screenId ;
138
- return screenId ;
139
+ const ret = randomInt32 ( ) ;
140
+ currentScreenIds [ scope ] = ret ;
141
+ return ret ;
139
142
}
140
143
}
141
144
0 commit comments