2019-07-15 18:52:01 +03:00
|
|
|
import { Inject, Injectable } from '@angular/core';
|
2017-09-29 19:34:07 +03:00
|
|
|
import { NavigationEnd, Router } from '@angular/router';
|
|
|
|
|
import { Location } from '@angular/common';
|
2018-05-10 23:48:39 +03:00
|
|
|
import { filter } from 'rxjs/operators';
|
2019-07-15 18:52:01 +03:00
|
|
|
import { NB_WINDOW } from '@nebular/theme';
|
2017-09-20 13:55:34 +03:00
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class AnalyticsService {
|
2019-07-15 18:52:01 +03:00
|
|
|
private enabled = false;
|
2017-09-20 13:55:34 +03:00
|
|
|
|
2019-07-15 18:52:01 +03:00
|
|
|
constructor(@Inject(NB_WINDOW) private window,
|
|
|
|
|
private location: Location,
|
|
|
|
|
private router: Router) {
|
|
|
|
|
this.enabled = this.window.location.href.indexOf('akveo.com') >= 0;
|
2017-09-20 13:55:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trackPageViews() {
|
2017-09-29 19:34:07 +03:00
|
|
|
if (this.enabled) {
|
2018-05-10 23:48:39 +03:00
|
|
|
this.router.events.pipe(
|
|
|
|
|
filter((event) => event instanceof NavigationEnd),
|
|
|
|
|
)
|
2017-09-20 13:55:34 +03:00
|
|
|
.subscribe(() => {
|
2019-07-15 18:52:01 +03:00
|
|
|
this.gtmPushToDataLayer({event: 'pageView' , path: this.location.path()});
|
2017-09-20 13:55:34 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-20 15:48:30 +03:00
|
|
|
|
2019-07-15 18:52:01 +03:00
|
|
|
trackEvent(eventName: string, eventVal: string = '') {
|
2017-09-29 19:34:07 +03:00
|
|
|
if (this.enabled) {
|
2019-07-15 18:52:01 +03:00
|
|
|
this.gtmPushToDataLayer({ event: eventName, eventValue: eventVal });
|
2017-09-20 15:48:30 +03:00
|
|
|
}
|
|
|
|
|
}
|
2019-07-15 18:52:01 +03:00
|
|
|
|
|
|
|
|
private gtmPushToDataLayer(params) {
|
|
|
|
|
this.window.dataLayer.push(params);
|
|
|
|
|
}
|
2017-09-20 13:55:34 +03:00
|
|
|
}
|