From 03fb0876d7fe0ceba39062d698fa5a5c4d7a95eb Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 26 May 2021 17:21:11 +0200 Subject: [PATCH] wait #4493 @0.5 --- js/libs/fluidbook/fluidbook.stats.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.stats.js b/js/libs/fluidbook/fluidbook.stats.js index 2b199493..52fba07d 100644 --- a/js/libs/fluidbook/fluidbook.stats.js +++ b/js/libs/fluidbook/fluidbook.stats.js @@ -9,7 +9,9 @@ function FluidbookStats(fluidbook) { if (this.fluidbook.settings.stats) { this.worker = new Worker('js/libs/fluidbook/workers/stats.js'); } - if (this.fluidbook.settings.googleAnalytics !== '') { + if (this.fluidbook.settings.googleTagManager !== undefined && this.fluidbook.settings.googleTagManager !== '') { + this.ga = 'gtm'; + } else if (this.fluidbook.settings.googleAnalytics !== '') { this.ga = 'gtag'; this.gaCodes = this.fluidbook.settings.googleAnalytics.split(','); if (window.gtag !== undefined) { @@ -172,7 +174,21 @@ FluidbookStats.prototype = { _ga: function (a0, a1, a2, a3, a4) { var args = Array.prototype.slice.call(arguments); - if (this.ga === 'gtag') { + if (this.ga === 'gtm') { + var dl = {}; + if (a0 === 'pageview') { + dl.event = 'pageview'; + if (a1 !== undefined) { + dl.location = a1; + } + } else if (a0 === 'event') { + dl.event = a1; + dl.eventLabel = a3; + dl.eventAction = a2; + } + console.log('datalayer', dl); + dataLayer.push(dl); + } else if (this.ga === 'gtag') { var f, o, c, a; o = {}; if (a0 === 'pageview') { @@ -192,12 +208,10 @@ FluidbookStats.prototype = { if (c) { $.each(this.gaCodes, function (k, code) { - if (window.gtag !== undefined) { - gtag(f, code, o); - } + gtag(f, code, o); }); } else { - if (window.gtag !== undefined) { + if (this.ga === 'gtag') { gtag(f, a, o); } } -- 2.39.5