]> _ Git - fluidbook-html5.git/commitdiff
wait #6643 @0:20
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 19 Jan 2024 09:39:35 +0000 (10:39 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 19 Jan 2024 09:39:35 +0000 (10:39 +0100)
js/libs/fluidbook/fluidbook.stats.js
style/fluidbook.less

index ec64fb2830d209e7d9b440f33ad8b76766ad0ba4..dae210c4cd53ae9b79343f03d46c81a674ee479f 100644 (file)
@@ -1,11 +1,25 @@
 function FluidbookStats() {
+    this.hasMatomoTagManager = this.setupMatomoTagManager();
     this.setupMatomo();
 }
 
 FluidbookStats.prototype = {
+    setupMatomoTagManager: function () {
+        if (SETTINGS.matomoTagManager !== '') {
+            var _mtm = window._mtm = window._mtm || [];
+            _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
+            var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
+            g.async = true;
+            g.src = '//' + SETTINGS.matomoTagManager;
+            s.parentNode.insertBefore(g, s);
+            return true;
+        }
+        return false;
+    },
+
     setupMatomo: function () {
         this.matomoServers = [];
-        if (SETTINGS.statsMatomo) {
+        if (SETTINGS.statsMatomo && !this.hasMatomoTagManager) {
             if (SETTINGS.statsMatomoServer === undefined || SETTINGS.statsMatomoServer === null) {
                 SETTINGS.statsMatomoServer = '3';
             }
@@ -15,19 +29,21 @@ FluidbookStats.prototype = {
                 lastURL: '',
                 referer: '',
                 fullURL: false,
+                mtm: false,
             });
         }
-        if (SETTINGS.matomoServer && SETTINGS.matomoSiteId) {
+        if (SETTINGS.matomoServer && SETTINGS.matomoSiteId && !this.hasMatomoTagManager) {
             this.matomoServers.push({
                 server: SETTINGS.matomoServer,
                 siteId: SETTINGS.matomoSiteId,
                 lastURL: '',
                 referer: '',
-                fullURL: true
+                fullURL: true,
+                mtm: false,
             });
         }
 
-        if (this.matomoServers.length > 0) {
+        if (this.matomoServers.length > 0 && !this.hasMatomoTagManager) {
             let u = 'https://' + this.matomoServers[0].server + '/';
             window._paq = window._paq || [];
             window._paq.push(["setDoNotTrack", true]);
@@ -43,6 +59,86 @@ FluidbookStats.prototype = {
             g.src = u + 'matomo.js';
             s.parentNode.insertBefore(g, s);
         }
+
+        if (this.hasMatomoTagManager) {
+            this.matomoServers.push({mtm: true, fullURL: true, lastURL: '', referer: ''});
+        }
+    },
+
+    matomoTrack(type, page, extra, url) {
+        if (url === undefined) {
+            url = window.location;
+        }
+        switch (type) {
+            case 0: // Change page
+                this.matomoViewPage(page);
+                break;
+            case 14: // Open chapters menu
+                this.matomoPush(['trackEvent', 'menu', 'click', 'chapters']);
+                break;
+            case 6: // Click a link in a page
+                this.matomoPush(['trackEvent', 'link', 'click', extra]);
+                this.matomoPush(['trackLink', extra]);
+                break;
+            case 1: // Search
+                this.matomoPush(['trackSiteSearch', extra]);
+                break;
+            case 3: // Print
+                this.matomoPush(['trackEvent', 'menu', 'click', 'print']);
+                break;
+            case 5: // Share
+            case 12: // Facebook
+            case 13: // Twitter
+                this.matomoPush(['trackEvent', 'share', 'send', extra]);
+                break;
+            case 7: // PDF
+            case 8: // Partial PDF
+                this.matomoPush(['trackEvent', 'menu', 'click', 'download']);
+                break;
+            case 4: // Bookmarks
+                this.matomoPush(['trackEvent', 'bookmark', 'page', 'page ' + page]);
+                break;
+            case 9: // Extras
+                this.matomoPush(['trackEvent', 'extra', 'click', extra]);
+                break;
+            case 2:// Zoom
+                this.matomoPush(['trackEvent', 'zoom', 'page', page]);
+                break;
+            case 15://
+                this.matomoPush(['trackEvent', 'cart', 'addproduct', extra]);
+        }
+    },
+
+    matomoViewPage: function (page) {
+        for (let i in this.matomoServers) {
+            let s = this.matomoServers[i];
+            let url = s.fullURL ? this.baseURL : 'http://fluidbook.' + s.siteId;
+            url += '/page/' + page;
+            s.referer = this.matomoServers[i].lastURL = s.lastURL;
+            s.lastURL = this.matomoServers[i].lastURL = url;
+            this.matomoPushToServer(['trackPageView', 'View page ' + page], s);
+        }
+    },
+
+    matomoPushToServer: function (data, server) {
+        if (this.matomoServers.length > 1) {
+            window._paq.push(['setTrackerUrl', 'https://' + server.server + '/matomo.php']);
+            window._paq.push(['setSiteId', server.siteId]);
+            if (server.referer !== '' && server.referer !== server.lastURL) {
+                _paq.push(['setReferrerUrl', server.referer]);
+            }
+            window._paq.push(['setCustomUrl', server.lastURL]);
+        } else if (data[0] === 'trackPageView') {
+            window._paq.push(['setCustomUrl', server.lastURL]);
+        }
+        window._paq.push(data);
+    },
+
+    matomoPush(data) {
+        for (let i in this.matomoServers) {
+            let dataCopy = data.slice(0);
+            this.matomoPushToServer(dataCopy, this.matomoServers[i]);
+        }
     },
 
     setup: function (fluidbook) {
@@ -287,81 +383,6 @@ FluidbookStats.prototype = {
         }
     },
 
-    matomoTrack(type, page, extra, url) {
-        if (url === undefined) {
-            url = window.location;
-        }
-        switch (type) {
-            case 0: // Change page
-                this.matomoViewPage(page);
-                break;
-            case 14: // Open chapters menu
-                this.matomoPush(['trackEvent', 'menu', 'click', 'chapters']);
-                break;
-            case 6: // Click a link in a page
-                this.matomoPush(['trackEvent', 'link', 'click', extra]);
-                this.matomoPush(['trackLink', extra]);
-                break;
-            case 1: // Search
-                this.matomoPush(['trackSiteSearch', extra]);
-                break;
-            case 3: // Print
-                this.matomoPush(['trackEvent', 'menu', 'click', 'print']);
-                break;
-            case 5: // Share
-            case 12: // Facebook
-            case 13: // Twitter
-                this.matomoPush(['trackEvent', 'share', 'send', extra]);
-                break;
-            case 7: // PDF
-            case 8: // Partial PDF
-                this.matomoPush(['trackEvent', 'menu', 'click', 'download']);
-                break;
-            case 4: // Bookmarks
-                this.matomoPush(['trackEvent', 'bookmark', 'page', 'page ' + page]);
-                break;
-            case 9: // Extras
-                this.matomoPush(['trackEvent', 'extra', 'click', extra]);
-                break;
-            case 2:// Zoom
-                this.matomoPush(['trackEvent', 'zoom', 'page', page]);
-                break;
-            case 15://
-                this.matomoPush(['trackEvent', 'cart', 'addproduct', extra]);
-        }
-    },
-
-    matomoViewPage: function (page) {
-        for (var i in this.matomoServers) {
-            let s = this.matomoServers[i];
-            let url = s.fullURL ? this.baseURL : 'http://fluidbook.' + s.siteId;
-            url += '/page/' + page;
-            s.referer = this.matomoServers[i].lastURL = s.lastURL;
-            s.lastURL = this.matomoServers[i].lastURL = url;
-            this.matomoPushToServer(['trackPageView', 'View page ' + page], s);
-        }
-    },
-
-    matomoPushToServer: function (data, server) {
-        if (this.matomoServers.length > 1) {
-            window._paq.push(['setTrackerUrl', 'https://' + server.server + '/matomo.php']);
-            window._paq.push(['setSiteId', server.siteId]);
-            if (server.referer !== '' && server.referer !== server.lastURL) {
-                _paq.push(['setReferrerUrl', server.referer]);
-            }
-            window._paq.push(['setCustomUrl', server.lastURL]);
-        } else if (data[0] === 'trackPageView') {
-            window._paq.push(['setCustomUrl', server.lastURL]);
-        }
-        window._paq.push(data);
-    },
-
-    matomoPush(data) {
-        for (let i in this.matomoServers) {
-            let dataCopy = data.slice(0);
-            this.matomoPushToServer(dataCopy, this.matomoServers[i]);
-        }
-    },
 
     trackGoogleAnalytics: function (type, page, extra, url) {
         this.checkGoogleAnalytics();
index aae19aa72718706d2bbc91df8c4eeed640dba43a..261eec7035a52563e83d2e80a60ede05df6478c0 100644 (file)
@@ -1413,6 +1413,31 @@ html.ios body.portrait #interface {
   cursor: auto;
 }
 
+.linkshowclose {
+  position: absolute;
+  display: block;
+  top: 0;
+  left: 0;
+
+  &.topleft, &.topright {
+    width: 200px;
+    height: 200px;
+  }
+
+  &.topleft {
+    left: 0;
+  }
+
+  &.topright {
+    left: auto;
+    right: 0;
+  }
+
+  &.none {
+    display: none;
+  }
+}
+
 .link.multimedia {
   position: absolute;
   -ms-touch-action: manipulation;
@@ -1459,29 +1484,6 @@ html.ios body.portrait #interface {
     }
   }
 
-  .linkshowclose {
-    position: absolute;
-    display: block;
-    top: 0;
-
-    &.topleft, &.topright {
-      width: 200px;
-      height: 200px;
-    }
-
-    &.topleft {
-      left: 0;
-    }
-
-    &.topright {
-      right: 0;
-    }
-
-    &.none {
-      display: none;
-    }
-  }
-
   // Force images to take space provided (see: https://team.cubedesigners.com/redmine/issues/1457)
   > img.multimediaimage {
     width: 100%;