File tree Expand file tree Collapse file tree 2 files changed +25
-27
lines changed
Expand file tree Collapse file tree 2 files changed +25
-27
lines changed Original file line number Diff line number Diff line change 11import EmberRouter from '@ember/routing/router' ;
2- import { scheduleOnce } from '@ember/runloop' ;
32import config from 'ember-api-docs/config/environment' ;
4- import { inject as service } from '@ember/service' ;
53
64class AppRouter extends EmberRouter {
75 location = config . locationType ;
86 rootURL = config . routerRootURL ;
9-
10- @service metrics ;
11- @service fastboot ;
12-
13- constructor ( ) {
14- super ( ...arguments ) ;
15-
16- if ( ! this . fastboot . isFastBoot ) {
17- this . on ( 'routeDidChange' , this , this . _trackPage ) ;
18- }
19- }
20-
21- _trackPage ( ) {
22- scheduleOnce ( 'afterRender' , this , this . __trackPage ) ;
23- }
24-
25- __trackPage ( ) {
26- // this is constant for this app and is only used to identify page views in the GA dashboard
27- const hostname = config . APP . domain . replace ( / ( h t t p | h t t p s ) ? : ? \/ \/ / g, '' ) ;
28-
29- const page = this . url ;
30- const title =
31- this . currentRouteName === undefined ? 'unknown' : this . currentRouteName ;
32- this . metrics . trackPage ( { page, title, hostname } ) ;
33- }
347}
358
369AppRouter . map ( function ( ) {
Original file line number Diff line number Diff line change @@ -10,6 +10,31 @@ export default class ApplicationRoute extends Route {
1010 @service
1111 legacyModuleMappings ;
1212
13+ @service
14+ router ;
15+
16+ @service
17+ fastboot ;
18+
19+ @service
20+ metrics ;
21+
22+ constructor ( ) {
23+ super ( ...arguments ) ;
24+ if ( ! this . fastboot . isFastBoot ) {
25+ this . router . on ( 'routeDidChange' , this . trackPage ) ;
26+ }
27+ }
28+
29+ trackPage = ( ) => {
30+ // this is constant for this app and is only used to identify page views in the GA dashboard
31+ const hostname = ENV . APP . domain . replace ( / ( h t t p | h t t p s ) ? : ? \/ \/ / g, '' ) ;
32+
33+ const page = this . router . currentURL ;
34+ const title = this . router . currentRouteName ?? 'unknown' ;
35+ this . metrics . trackPage ( { page, title, hostname } ) ;
36+ } ;
37+
1338 async afterModel ( ) {
1439 set ( this , 'headData.cdnDomain' , ENV . API_HOST ) ;
1540 await this . legacyModuleMappings . initMappings ( ) ;
You can’t perform that action at this time.
0 commit comments