From: Vincent Vanwaelscappel Date: Fri, 12 Jan 2024 10:52:27 +0000 (+0100) Subject: wip #6625 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=704105f57c4e6638605248decdf801398e0ea4c7;p=fluidbook-html5.git wip #6625 @1 --- diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index 5b17b9a0..55e9b168 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -166,11 +166,15 @@ Fluidbook.prototype = { this.interface = new FluidbookInterface(this); this.resize = new FluidbookResize(this); this.pagetransitions = new FluidbookPageTransition(this); - this.stats = new FluidbookStats(this); + + this.stats = window.stats; + this.stats.setup(this); this.stats.track(10); + this.help = new FluidbookHelp(this); this.articles = new FluidbookArticles(this); + $(this).trigger('fluidbook.lib.ready'); this.initTheme(); @@ -180,6 +184,7 @@ Fluidbook.prototype = { if (this.initEventsWhenSecureOK) { initEvents(); } + }, initEvents: function () { diff --git a/js/libs/fluidbook/fluidbook.stats.js b/js/libs/fluidbook/fluidbook.stats.js index 6119d40d..ec64fb28 100644 --- a/js/libs/fluidbook/fluidbook.stats.js +++ b/js/libs/fluidbook/fluidbook.stats.js @@ -1,102 +1,112 @@ -function FluidbookStats(fluidbook) { - var $this = this; - this.fluidbook = fluidbook; - this.id = this.fluidbook.settings.id; - this.vid = guid(); - this.relay_url_params = ''; - this.lastTCHash = ''; - this.gaqueue = []; - this.baseURL = trim((window.location.origin + window.location.pathname).replace("index.html", ""), '/'); - - this.matomoServers = []; - if (this.fluidbook.settings.statsMatomo) { - if (this.fluidbook.settings.statsMatomoServer === undefined || this.fluidbook.settings.statsMatomoServer === null) { - this.fluidbook.settings.statsMatomoServer = '3'; - } - this.matomoServers.push({ - server: 'stats' + this.fluidbook.settings.statsMatomoServer + '.fluidbook.com', - siteId: this.fluidbook.settings.statsMatomo, - lastURL: '', - referer: '', - fullURL: false, - }); - } - if (this.fluidbook.settings.matomoServer && this.fluidbook.settings.matomoSiteId) { - this.matomoServers.push({ - server: this.fluidbook.settings.matomoServer, - siteId: this.fluidbook.settings.matomoSiteId, - lastURL: '', - referer: '', - fullURL: true - }); - } +function FluidbookStats() { + this.setupMatomo(); +} - if ($_GET['puppeteer'] !== undefined) { - this.fluidbook.settings.stats = false; - this.fluidbook.settings.googleTagManager = ''; - this.fluidbook.settings.googleAnalytics = ''; - this.fluidbook.settings.statsMatomo = false; - this.fluidbook.settings.tagcommander_id = ''; - this.fluidbook.settings.xiti = ''; - this.fluidbook.settings.tagcommander_plan_type = ''; +FluidbookStats.prototype = { + setupMatomo: function () { this.matomoServers = []; - } + if (SETTINGS.statsMatomo) { + if (SETTINGS.statsMatomoServer === undefined || SETTINGS.statsMatomoServer === null) { + SETTINGS.statsMatomoServer = '3'; + } + this.matomoServers.push({ + server: 'stats' + SETTINGS.statsMatomoServer + '.fluidbook.com', + siteId: SETTINGS.statsMatomo, + lastURL: '', + referer: '', + fullURL: false, + }); + } + if (SETTINGS.matomoServer && SETTINGS.matomoSiteId) { + this.matomoServers.push({ + server: SETTINGS.matomoServer, + siteId: SETTINGS.matomoSiteId, + lastURL: '', + referer: '', + fullURL: true + }); + } - if (this.fluidbook.settings.tagcommander_plan_type === 'esm') { - this.esm = new FluidbookStatsEsm(this.fluidbook); - } - if (this.fluidbook.settings.stats) { - this.worker = new Worker('js/libs/fluidbook/workers/stats.js'); - } - if (this.matomoServers.length > 0) { - let u = 'https://' + this.matomoServers[0].server + '/'; - window._paq = window._paq || []; - window._paq.push(["setDoNotTrack", true]); - window._paq.push(['enableHeartBeatTimer']); - window._paq.push(['enableLinkTracking']); - if (this.matomoServers.length === 1) { - window._paq.push(['setTrackerUrl', 'https://' + this.matomoServers[0].server + '/matomo.php']); - window._paq.push(['setSiteId', this.matomoServers[0].siteId]); + if (this.matomoServers.length > 0) { + let u = 'https://' + this.matomoServers[0].server + '/'; + window._paq = window._paq || []; + window._paq.push(["setDoNotTrack", true]); + window._paq.push(['enableHeartBeatTimer']); + window._paq.push(['enableLinkTracking']); + window._paq.push(['enableJSErrorTracking']); + if (this.matomoServers.length === 1) { + window._paq.push(['setTrackerUrl', 'https://' + this.matomoServers[0].server + '/matomo.php']); + window._paq.push(['setSiteId', this.matomoServers[0].siteId]); + } + var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0]; + g.async = true; + g.src = u + 'matomo.js'; + s.parentNode.insertBefore(g, s); } - var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0]; - g.async = true; - g.src = u + 'matomo.js'; - s.parentNode.insertBefore(g, s); - } - 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) { - gtag('js', new Date()); + }, + + setup: function (fluidbook) { + var $this = this; + this.fluidbook = fluidbook; + this.id = this.fluidbook.settings.id; + this.vid = guid(); + this.relay_url_params = ''; + this.lastTCHash = ''; + this.gaqueue = []; + this.baseURL = trim((window.location.origin + window.location.pathname).replace("index.html", ""), '/'); + + if ($_GET['puppeteer'] !== undefined) { + this.fluidbook.settings.stats = false; + this.fluidbook.settings.googleTagManager = ''; + this.fluidbook.settings.googleAnalytics = ''; + this.fluidbook.settings.statsMatomo = false; + this.fluidbook.settings.tagcommander_id = ''; + this.fluidbook.settings.xiti = ''; + this.fluidbook.settings.tagcommander_plan_type = ''; + this.matomoServers = []; + } + + if (this.fluidbook.settings.tagcommander_plan_type === 'esm') { + this.esm = new FluidbookStatsEsm(this.fluidbook); } - $.each(this.gaCodes, function (k, code) { + if (this.fluidbook.settings.stats) { + this.worker = new Worker('js/libs/fluidbook/workers/stats.js'); + } + + 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) { - gtag('config', code, {'send_page_view': false}); + gtag('js', new Date()); } - }); - if (this.fluidbook.settings.gtag_additional_code !== '') { - eval(this.fluidbook.settings.gtag_additional_code); - } - } else { - this.checkGoogleAnalytics(); - } - if (this.fluidbook.settings.relay_url_params !== '') { - var e = this.fluidbook.settings.relay_url_params.split(','); - var p = []; - $.each(e, function (k, v) { - v = v.trim(); - if ($_GET[v] !== undefined && $_GET[v] !== null) { - p.push(v + '=' + encodeURIComponent($_GET[v])); + $.each(this.gaCodes, function (k, code) { + if (window.gtag !== undefined) { + gtag('config', code, {'send_page_view': false}); + } + }); + if (this.fluidbook.settings.gtag_additional_code !== '') { + eval(this.fluidbook.settings.gtag_additional_code); } - }); - this.relay_url_params = p.join('&'); - } - this.init(); -} + } else { + this.checkGoogleAnalytics(); + } + if (this.fluidbook.settings.relay_url_params !== '') { + var e = this.fluidbook.settings.relay_url_params.split(','); + var p = []; + $.each(e, function (k, v) { + v = v.trim(); + if ($_GET[v] !== undefined && $_GET[v] !== null) { + p.push(v + '=' + encodeURIComponent($_GET[v])); + } + }); + this.relay_url_params = p.join('&'); + } + + this.init(); + }, -FluidbookStats.prototype = { init: function () { var $this = this; $(document).on(this.fluidbook.input.clickEvent, 'a[data-track]', function () { diff --git a/js/main.js b/js/main.js index fab799cc..b738c0b9 100644 --- a/js/main.js +++ b/js/main.js @@ -1,3 +1,5 @@ +window.stats=new FluidbookStats(); + var DEVICE_READY_BEFORE_JQUERY = false; var JQUERY_READY = false; document.addEventListener('deviceready', _onDeviceReady, false);