mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-22 18:30:14 +01:00
fix(analytics): update analytics service, add google tag manager support
This commit is contained in:
parent
c019de67c6
commit
995e2c4a80
2 changed files with 16 additions and 5 deletions
|
|
@ -22,19 +22,27 @@ export class AnalyticsService {
|
||||||
filter((event) => event instanceof NavigationEnd),
|
filter((event) => event instanceof NavigationEnd),
|
||||||
)
|
)
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
ga('send', {hitType: 'pageview', page: this.location.path()});
|
this.gtm({'pageview': this.location.path()});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trackEvent(eventName: string, eventVal: string = '') {
|
trackEvent(eventName: string, eventVal: string = '') {
|
||||||
if (this.enabled && this.window.ga) {
|
if (this.enabled) {
|
||||||
ga('send', 'event', eventName, eventVal);
|
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(() => {
|
setTimeout(() => {
|
||||||
this.trackEvent(eventName, eventVal);
|
this.gtm(params);
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@
|
||||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||||
|
|
||||||
<!-- Google Tag Manager -->
|
<!-- Google Tag Manager -->
|
||||||
|
<script>
|
||||||
|
dataLayer = [];
|
||||||
|
</script>
|
||||||
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
||||||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
||||||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue