]> _ Git - fluidbook-html5.git/commitdiff
wip #6625 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 12 Jan 2024 10:52:27 +0000 (11:52 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 12 Jan 2024 10:52:27 +0000 (11:52 +0100)
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.stats.js
js/main.js

index 5b17b9a062fdfaa0ed0f464f1649e09ac875c6e3..55e9b168073e456d859d45566611e7b15a9f7000 100644 (file)
@@ -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 () {
index 6119d40d5092b80d8f213f9caf59c62170588994..ec64fb2830d209e7d9b440f33ad8b76766ad0ba4 100644 (file)
-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 () {
index fab799cc6673407257abd46d28a09540506a63dd..b738c0b97850d0fd2c84b746657ceb4ceb4277ed 100644 (file)
@@ -1,3 +1,5 @@
+window.stats=new FluidbookStats();
+
 var DEVICE_READY_BEFORE_JQUERY = false;
 var JQUERY_READY = false;
 document.addEventListener('deviceready', _onDeviceReady, false);