From: Vincent Vanwaelscappel Date: Fri, 19 Jan 2024 09:39:35 +0000 (+0100) Subject: wait #6643 @0:20 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=1e080a6e5f9ef580c591e83a8a1de86359b1d264;p=fluidbook-html5.git wait #6643 @0:20 --- diff --git a/js/libs/fluidbook/fluidbook.stats.js b/js/libs/fluidbook/fluidbook.stats.js index ec64fb28..dae210c4 100644 --- a/js/libs/fluidbook/fluidbook.stats.js +++ b/js/libs/fluidbook/fluidbook.stats.js @@ -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(); diff --git a/style/fluidbook.less b/style/fluidbook.less index aae19aa7..261eec70 100644 --- a/style/fluidbook.less +++ b/style/fluidbook.less @@ -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%;