From 995e2c4a8034c4d855e63a207e68445c04e26d61 Mon Sep 17 00:00:00 2001 From: denStrigo Date: Fri, 23 Nov 2018 18:54:28 +0300 Subject: [PATCH] fix(analytics): update analytics service, add google tag manager support --- src/app/@core/utils/analytics.service.ts | 18 +++++++++++++----- src/index.html | 3 +++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/app/@core/utils/analytics.service.ts b/src/app/@core/utils/analytics.service.ts index 6772fdea..f5484ab4 100644 --- a/src/app/@core/utils/analytics.service.ts +++ b/src/app/@core/utils/analytics.service.ts @@ -22,19 +22,27 @@ export class AnalyticsService { filter((event) => event instanceof NavigationEnd), ) .subscribe(() => { - ga('send', {hitType: 'pageview', page: this.location.path()}); + this.gtm({'pageview': this.location.path()}); }); } } trackEvent(eventName: string, eventVal: string = '') { - if (this.enabled && this.window.ga) { - ga('send', 'event', eventName, eventVal); + if (this.enabled) { + this.gtm({ event: eventName, value: eventVal }); } + } - if (!this.window.ga) { + private isGaLoaded() { + return this.window.ga; + } + + private gtm(params) { + if (this.isGaLoaded()) { + this.window.dataLayer.push(params); + } else { setTimeout(() => { - this.trackEvent(eventName, eventVal); + this.gtm(params); }, 500); } } diff --git a/src/index.html b/src/index.html index e79ebf31..8f6f1639 100644 --- a/src/index.html +++ b/src/index.html @@ -11,6 +11,9 @@ +