New dashboard look & feel
[src/xds/xds-agent.git] / webapp / src / app / @core / utils / analytics.service.ts
1 import { Injectable } from '@angular/core';
2 import { NavigationEnd, Router } from '@angular/router';
3 import { Location } from '@angular/common';
4
5 import { filter } from 'rxjs/operator/filter';
6
7 declare const ga: any;
8
9 @Injectable()
10 export class AnalyticsService {
11   private enabled: boolean;
12
13   constructor(private location: Location, private router: Router) {
14     this.enabled = false;
15   }
16
17   trackPageViews() {
18     if (this.enabled) {
19       filter.call(this.router.events, (event) => event instanceof NavigationEnd)
20         .subscribe(() => {
21           ga('send', {hitType: 'pageview', page: this.location.path()});
22         });
23     }
24   }
25
26   trackEvent(eventName: string) {
27     if (this.enabled) {
28       ga('send', 'event', eventName);
29     }
30   }
31 }