diff options
Diffstat (limited to 'webapp/src/app/@core/utils/analytics.service.ts')
-rw-r--r-- | webapp/src/app/@core/utils/analytics.service.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/webapp/src/app/@core/utils/analytics.service.ts b/webapp/src/app/@core/utils/analytics.service.ts new file mode 100644 index 0000000..73f1332 --- /dev/null +++ b/webapp/src/app/@core/utils/analytics.service.ts @@ -0,0 +1,31 @@ +import { Injectable } from '@angular/core'; +import { NavigationEnd, Router } from '@angular/router'; +import { Location } from '@angular/common'; + +import { filter } from 'rxjs/operator/filter'; + +declare const ga: any; + +@Injectable() +export class AnalyticsService { + private enabled: boolean; + + constructor(private location: Location, private router: Router) { + this.enabled = false; + } + + trackPageViews() { + if (this.enabled) { + filter.call(this.router.events, (event) => event instanceof NavigationEnd) + .subscribe(() => { + ga('send', {hitType: 'pageview', page: this.location.path()}); + }); + } + } + + trackEvent(eventName: string) { + if (this.enabled) { + ga('send', 'event', eventName); + } + } +} |