From: Vincent Vanwaelscappel Date: Thu, 23 May 2024 10:33:00 +0000 (+0200) Subject: wip #6934 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=cca445c140093e59f043085507bd35a8afea785b;p=fluidbook-html5.git wip #6934 @1 --- diff --git a/js/libs/fluidbook/fluidbook.stats.js b/js/libs/fluidbook/fluidbook.stats.js index 422805b9..5df7c3dd 100644 --- a/js/libs/fluidbook/fluidbook.stats.js +++ b/js/libs/fluidbook/fluidbook.stats.js @@ -1,6 +1,7 @@ function FluidbookStats() { this.hasMatomoTagManager = this.setupMatomoTagManager(); this.pixel_pv_id; + this.user_id = window.MATOMO_USER_ID !== undefined ? window.MATOMO_USER_ID : window.sessionStorage.getItem('secureUsername'); this.matomo_stack = []; this.setupMatomo(); } @@ -25,6 +26,7 @@ FluidbookStats.prototype = { if (SETTINGS.statsMatomoServer === undefined || SETTINGS.statsMatomoServer === null) { SETTINGS.statsMatomoServer = '3'; } + let pixel = this.hasMatomoTagManager || SETTINGS.matomoTracking === 'pixel' || SETTINGS.matomoTracking === 'proxy' ? this.getPixelUUID() : false; this.matomoServers.push({ server: 'stats' + SETTINGS.statsMatomoServer + '.fluidbook.com', siteId: SETTINGS.statsMatomo, @@ -32,7 +34,8 @@ FluidbookStats.prototype = { referer: '', fullURL: false, mtm: false, - pixel: this.hasMatomoTagManager ? this.getPixelUUID() : false, + pixel: pixel, + pixelProxy: SETTINGS.matomoTracking === 'proxy', }); } if (SETTINGS.matomoServer && SETTINGS.matomoSiteId && !this.hasMatomoTagManager) { @@ -43,14 +46,17 @@ FluidbookStats.prototype = { referer: '', fullURL: true, mtm: false, + pixel: SETTINGS.matomoTracking === 'pixel' || SETTINGS.matomoTracking === 'proxy' ? this.getPixelUUID() : false, + pixelProxy: SETTINGS.matomoTracking === 'proxy', }); } - if (this.matomoServers.length > 0 && !this.hasMatomoTagManager) { + + if (this.matomoServers.length > 0 && !this.hasMatomoTagManager && SETTINGS.matomoTracking !== 'pixel' || SETTINGS.matomoTracking !== 'proxy') { let u = 'https://' + this.matomoServers[0].server + '/'; window._paq = window._paq || []; - if (window.MATOMO_USER_ID !== undefined) { - window._paq.push(['setUserId', window.MATOMO_USER_ID]); + if (this.user_id !== null) { + window._paq.push(['setUserId', this.user_id]); } window._paq.push(["setDoNotTrack", true]); window._paq.push(['enableHeartBeatTimer']); @@ -161,13 +167,11 @@ FluidbookStats.prototype = { matomoSetCartItems: function (items) { for (var i in items) { let item = items[i]; - this.matomoPush(['addEcommerceItem', - item.reference, // (Required) productSKU + this.matomoPush(['addEcommerceItem', item.reference, // (Required) productSKU item.name, // (Optional) productName item.categories, // (Optional) productCategory item.price, // (Recommended) price - item.quantity - ]); + item.quantity]); } }, @@ -198,7 +202,7 @@ FluidbookStats.prototype = { } url += '&res=' + screen.width + 'x' + screen.height; if (data[0] === 'trackPageView') { - url += '&action_name=' + data[1]; + url += '&action_name=' + encodeURIComponent(data[1]); this.pixel_pv_id = this.generatePixelPVID(); } else if (data[0] === 'trackSiteSearch') { url += '&search=' + encodeURIComponent(data[1]); @@ -210,7 +214,15 @@ FluidbookStats.prototype = { url += '&e_' + order[i - 1] + '=' + encodeURIComponent(data[i]); } } + if (this.user_id !== null) { + url += '&uid=' + encodeURIComponent(this.user_id); + } url += '&pv_id=' + this.pixel_pv_id; + + if (server.pixelProxy) { + url = 'https://toolbox.fluidbook.com/s/prxtm?d=' + btoa(url); + } + let i = new Image(); i.src = url; return;