feat: demo version additions

This commit is contained in:
Sergey Andrievskiy 2019-07-15 18:52:01 +03:00
parent 06cda13fd0
commit 62e6828680
36 changed files with 1494 additions and 65 deletions

View file

@ -1,16 +1,17 @@
import { Injectable } from '@angular/core';
import { Inject, Injectable } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { Location } from '@angular/common';
import { filter } from 'rxjs/operators';
declare const ga: any;
import { NB_WINDOW } from '@nebular/theme';
@Injectable()
export class AnalyticsService {
private enabled: boolean;
private enabled = false;
constructor(private location: Location, private router: Router) {
this.enabled = false;
constructor(@Inject(NB_WINDOW) private window,
private location: Location,
private router: Router) {
this.enabled = this.window.location.href.indexOf('akveo.com') >= 0;
}
trackPageViews() {
@ -19,14 +20,18 @@ export class AnalyticsService {
filter((event) => event instanceof NavigationEnd),
)
.subscribe(() => {
ga('send', {hitType: 'pageview', page: this.location.path()});
this.gtmPushToDataLayer({event: 'pageView' , path: this.location.path()});
});
}
}
trackEvent(eventName: string) {
trackEvent(eventName: string, eventVal: string = '') {
if (this.enabled) {
ga('send', 'event', eventName);
this.gtmPushToDataLayer({ event: eventName, eventValue: eventVal });
}
}
private gtmPushToDataLayer(params) {
this.window.dataLayer.push(params);
}
}