]> _ Git - fluidbook-html5.git/commitdiff
wait #4442 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 25 May 2021 15:21:30 +0000 (17:21 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 25 May 2021 15:21:30 +0000 (17:21 +0200)
js/libs/fluidbook/fluidbook.stats.js

index 7b819d2adfb703f449b802e7c6e23d255aa67f88..2b199493b85d9e5ceb9eefda8778ca5ccaf8a866 100644 (file)
@@ -5,6 +5,7 @@ function FluidbookStats(fluidbook) {
     this.vid = guid();\r
     this.relay_url_params = '';\r
     this.lastTCHash = '';\r
+    this.gaqueue = [];\r
     if (this.fluidbook.settings.stats) {\r
         this.worker = new Worker('js/libs/fluidbook/workers/stats.js');\r
     }\r
@@ -23,11 +24,7 @@ function FluidbookStats(fluidbook) {
             eval(this.fluidbook.settings.gtag_additional_code);\r
         }\r
     } else {\r
-        if ('ga' in window) {\r
-            this.ga = 'ga';\r
-        } else {\r
-            this.ga = false;\r
-        }\r
+        this.checkGoogleAnalytics();\r
     }\r
     if (this.fluidbook.settings.relay_url_params !== '') {\r
         var e = this.fluidbook.settings.relay_url_params.split(',');\r
@@ -44,10 +41,7 @@ function FluidbookStats(fluidbook) {
 }\r
 \r
 FluidbookStats.prototype = {\r
-\r
-\r
     init: function () {\r
-\r
         var $this = this;\r
         $(document).on('click', 'a[data-track]', function () {\r
             $this.track(6, 0, $(this).attr('data-track'));\r
@@ -91,12 +85,37 @@ FluidbookStats.prototype = {
         this.trackGoogleAnalytics(type, page, extra);\r
     },\r
 \r
-    trackGoogleAnalytics: function (type, page, extra) {\r
-        if (this.ga === false) {\r
+    checkGoogleAnalytics: function () {\r
+        if (this.ga !== false && this.ga !== undefined) {\r
             return;\r
         }\r
+        if ('gtag' in window) {\r
+            this.ga = 'gtag';\r
+        } else if ('ga' in window && "getAll" in window.ga) {\r
+            this.ga = 'ga';\r
+        } else {\r
+            this.ga = false;\r
+        }\r
 \r
-        var url = location.pathname + location.search + location.hash\r
+        if (this.ga !== false && this.gaqueue.length > 0) {\r
+            var $this = this;\r
+            $.each(this.gaqueue, function (k, v) {\r
+                $this.trackGoogleAnalytics(v[0], v[1], v[2], v[3]);\r
+            });\r
+            this.gaqueue = [];\r
+        }\r
+    },\r
+\r
+    trackGoogleAnalytics: function (type, page, extra, url) {\r
+        this.checkGoogleAnalytics();\r
+\r
+        if (url === undefined) {\r
+            url = location.pathname + location.search + location.hash\r
+        }\r
+        if (this.ga === false) {\r
+            this.gaqueue.push([type, page, extra, url]);\r
+            return;\r
+        }\r
 \r
         switch (type) {\r
             case 0: // Change page\r
@@ -183,8 +202,12 @@ FluidbookStats.prototype = {
                 }\r
             }\r
         } else if (this.ga === 'ga') {\r
-            args.unshift('send');\r
-            window['ga'].apply(null, args);\r
+            $.each(ga.getAll(), function (k, tracker) {\r
+                try {\r
+                    tracker.send.apply(tracker, args);\r
+                } catch (e) {\r
+                }\r
+            });\r
         }\r
     },\r
 \r