From 11baa331692f547df1ac0550a03b7f339e6e1ca9 Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Fri, 3 Jan 2020 03:53:33 -0800 Subject: [PATCH] GoogleAnalytics service added --- src/app/app.module.ts | 4 +++- src/app/services/google-analytics.service.ts | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/app/services/google-analytics.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index c1a1006b..7c16b328 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -258,6 +258,7 @@ import { Gns3vmService } from './services/gns3vm.service'; import { ThemeService } from './services/theme.service'; import { ConfigureGns3VMDialogComponent } from './components/servers/configure-gns3vm-dialog/configure-gns3vm-dialog.component'; import { ImportApplianceComponent } from './components/project-map/import-appliance/import-appliance.component'; +import { GoogleAnalyticsService } from './services/google-analytics.service'; if (environment.production) { Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', { @@ -522,7 +523,8 @@ if (environment.production) { PacketCaptureService, NotificationService, Gns3vmService, - ThemeService + ThemeService, + GoogleAnalyticsService ], entryComponents: [ AddServerDialogComponent, diff --git a/src/app/services/google-analytics.service.ts b/src/app/services/google-analytics.service.ts new file mode 100644 index 00000000..536c6ba1 --- /dev/null +++ b/src/app/services/google-analytics.service.ts @@ -0,0 +1,20 @@ + +import { Injectable } from '@angular/core'; +import {Router, NavigationEnd} from '@angular/router'; +import { environment } from '../../environments/environment'; +declare var ga:Function; + +@Injectable() +export class GoogleAnalyticsService { + + constructor(router: Router) { + if (!environment.production) return; + router.events.subscribe(event => { + if (event instanceof NavigationEnd) { + ga('set', 'page', event.url); + ga('send', 'pageview'); + } + }) + } + +}