@@ -6,6 +6,7 @@ import { filter, pairwise } from "rxjs/operators";
66import { Subscription } from "rxjs" ;
77
88const notFoundPageUrl = '/404' ;
9+ declare const gtag : any ;
910
1011@Component ( {
1112 selector : 'valor-software-site-base-root' ,
@@ -16,6 +17,7 @@ export class AppComponent implements OnDestroy, AfterViewInit {
1617 title = 'valor-software-site' ;
1718 scrollPosition = 0 ;
1819 $routeEvents ?: Subscription ;
20+ $gaRouteEvents ?: Subscription ;
1921 $routerEventNavigationEnd : Subscription ;
2022 showFooterAndHeader = true ;
2123
@@ -45,6 +47,7 @@ export class AppComponent implements OnDestroy, AfterViewInit {
4547 }
4648
4749 ngAfterViewInit ( ) {
50+ this . handleGoogleAnalyticsTracking ( ) ;
4851 setTimeout ( ( ) => {
4952 if ( this . scrollPosition ) {
5053 this . scrollToPosition ( this . scrollPosition ) ;
@@ -77,5 +80,22 @@ export class AppComponent implements OnDestroy, AfterViewInit {
7780 ngOnDestroy ( ) {
7881 this . $routeEvents ?. unsubscribe ( ) ;
7982 this . $routerEventNavigationEnd ?. unsubscribe ( ) ;
83+ this . $gaRouteEvents ?. unsubscribe ( ) ;
8084 }
85+
86+ private handleGoogleAnalyticsTracking ( ) : void {
87+ let configured = false ;
88+ this . $gaRouteEvents = this . router . events . subscribe ( ( event ) => {
89+ if ( event instanceof NavigationEnd ) {
90+ if ( ! configured ) {
91+ gtag ( 'config' , 'UA-73071494-2' , { send_page_view : false } ) ;
92+ configured = true ;
93+ }
94+ gtag ( 'event' , 'page_view' , {
95+ page_location : window . location . href ,
96+ page_path : event . urlAfterRedirects ,
97+ } ) ;
98+ }
99+ } ) ;
100+ }
81101}
0 commit comments