diff --git a/package.json b/package.json index d57a1bc..5bb1156 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@angular-devkit/build-angular": "~0.803.24", "@angular/cli": "~8.3.24", "@angular/compiler-cli": "~8.2.14", + "@types/google.analytics": "0.0.40", "@angular/language-service": "~8.2.14", "@types/jasmine": "~3.3.8", "@types/jasminewd2": "~2.0.3", diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 1898d86..7aa8f83 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,17 +1,50 @@ -import { Component } from '@angular/core'; +import { Component, OnDestroy } from '@angular/core'; +import { Router, NavigationEnd } from '@angular/router'; +import { + StorefrontComponent, + HamburgerMenuService, +} from '@spartacus/storefront'; +import { ContentSlotComponentData, RoutingService } from '@spartacus/core'; +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; -import { StorefrontComponent } from '@spartacus/storefront'; -import { ContentSlotComponentData } from '@spartacus/core'; +import { GoogleAnalyticsEventsService } from './shared/google-analytics/google-analytics-event.service'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'], }) -export class AppComponent extends StorefrontComponent { +export class AppComponent extends StorefrontComponent implements OnDestroy { public footerComponent: ContentSlotComponentData = { uid: 'FooterNavigationComponent', typeCode: 'FooterNavigationComponent', flexType: 'FooterNavigationComponent', }; + + private routerEventsSubscription: Subject = new Subject(); + + constructor( + hamburgerMenuService: HamburgerMenuService, + routingService: RoutingService, + private googleAnalyticsEventsService: GoogleAnalyticsEventsService, + private router: Router + ) { + super(hamburgerMenuService, routingService); + + this.router.events + .pipe(takeUntil(this.routerEventsSubscription)) + .subscribe((event) => { + if (event instanceof NavigationEnd) { + this.googleAnalyticsEventsService.emitSetPage( + event.urlAfterRedirects + ); + } + }); + } + + public ngOnDestroy(): void { + this.routerEventsSubscription.next(); + this.routerEventsSubscription.complete(); + } } diff --git a/src/app/features/dvnt-bottom-navigation/dvnt-bottom-navigation.component.html b/src/app/features/dvnt-bottom-navigation/dvnt-bottom-navigation.component.html index be6fd65..a898667 100644 --- a/src/app/features/dvnt-bottom-navigation/dvnt-bottom-navigation.component.html +++ b/src/app/features/dvnt-bottom-navigation/dvnt-bottom-navigation.component.html @@ -1,5 +1,5 @@
-