feat(analytics): update analytics service, use google tag manager (#1932)

This commit is contained in:
Denis Strigo 2018-11-27 18:24:17 +03:00 committed by Sergey Andrievskiy
parent 52e3126141
commit b8726fc314
4 changed files with 9 additions and 23 deletions

View file

@ -20,28 +20,18 @@ export class AnalyticsService {
filter((event) => event instanceof NavigationEnd),
)
.subscribe(() => {
this.gtm({'pageview': this.location.path()});
this.gtmPushToDataLayer({event: 'pageView' , path: this.location.path()});
});
}
}
trackEvent(eventName: string, eventVal: string = '') {
if (this.enabled) {
this.gtm({ event: eventName, value: eventVal });
this.gtmPushToDataLayer({ event: eventName, eventValue: eventVal });
}
}
private isGaLoaded() {
return this.window.ga;
}
private gtm(params) {
if (this.isGaLoaded()) {
this.window.dataLayer.push(params);
} else {
setTimeout(() => {
this.gtm(params);
}, 500);
}
private gtmPushToDataLayer(params) {
this.window.dataLayer.push(params);
}
}

View file

@ -41,7 +41,7 @@ export class HeaderComponent implements OnInit , OnDestroy {
}
if (selection && selection.toString() === 'contact@akveo.com') {
this.analytics.trackEvent('contactEmail', 'select');
this.analytics.trackEvent('clickContactEmail', 'select');
}
});
}
@ -69,7 +69,7 @@ export class HeaderComponent implements OnInit , OnDestroy {
}
trackEmailClick() {
this.analytics.trackEvent('contactEmail', 'click');
this.analytics.trackEvent('clickContactEmail', 'click');
}
ngOnDestroy() {

View file

@ -1,6 +1,5 @@
import {Component, Input} from '@angular/core';
import { NbThemeService, NbPopoverDirective } from '@nebular/theme';
import { AnalyticsService } from '../../../../@core/utils/analytics.service';
import { NbJSThemeOptions } from '@nebular/theme/services/js-themes/theme.options';
@Component({
@ -38,14 +37,11 @@ export class ThemeSwitcherListComponent {
},
];
constructor(
private themeService: NbThemeService,
private analyticsService: AnalyticsService,
) {}
constructor(private themeService: NbThemeService) {
}
onToggleTheme(themeKey: string) {
this.themeService.changeTheme(themeKey);
this.analyticsService.trackEvent('switchTheme');
this.popover.hide();
}
}

View file

@ -26,7 +26,7 @@ export class AppComponent implements OnInit {
this.themeService.onThemeChange()
.subscribe((theme: any) => {
this.analytics.trackEvent('themeUsed', theme.name);
this.analytics.trackEvent('changeTheme', theme.name);
});
this.activatedRoute.queryParams